1 #ifndef __LIBSSH2_MISC_H 2 #define __LIBSSH2_MISC_H 3 /* Copyright (c) 2009-2019 by Daniel Stenberg 4 * 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, 8 * with or without modification, are permitted provided 9 * that the following conditions are met: 10 * 11 * Redistributions of source code must retain the above 12 * copyright notice, this list of conditions and the 13 * following disclaimer. 14 * 15 * Redistributions in binary form must reproduce the above 16 * copyright notice, this list of conditions and the following 17 * disclaimer in the documentation and/or other materials 18 * provided with the distribution. 19 * 20 * Neither the name of the copyright holder nor the names 21 * of any other contributors may be used to endorse or 22 * promote products derived from this software without 23 * specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 26 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 27 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 28 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 30 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 32 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 33 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 35 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 36 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 37 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 38 * OF SUCH DAMAGE. 39 */ 40 41 struct list_head { 42 struct list_node *last; 43 struct list_node *first; 44 }; 45 46 struct list_node { 47 struct list_node *next; 48 struct list_node *prev; 49 struct list_head *head; 50 }; 51 52 struct string_buf { 53 unsigned char *data; 54 unsigned char *dataptr; 55 size_t len; 56 }; 57 58 int _libssh2_error_flags(LIBSSH2_SESSION* session, int errcode, 59 const char *errmsg, int errflags); 60 int _libssh2_error(LIBSSH2_SESSION* session, int errcode, const char *errmsg); 61 62 void _libssh2_list_init(struct list_head *head); 63 64 /* add a node last in the list */ 65 void _libssh2_list_add(struct list_head *head, 66 struct list_node *entry); 67 68 /* return the "first" node in the list this head points to */ 69 void *_libssh2_list_first(struct list_head *head); 70 71 /* return the next node in the list */ 72 void *_libssh2_list_next(struct list_node *node); 73 74 /* return the prev node in the list */ 75 void *_libssh2_list_prev(struct list_node *node); 76 77 /* remove this node from the list */ 78 void _libssh2_list_remove(struct list_node *entry); 79 80 size_t _libssh2_base64_encode(LIBSSH2_SESSION *session, 81 const char *inp, size_t insize, char **outptr); 82 83 unsigned int _libssh2_ntohu32(const unsigned char *buf); 84 libssh2_uint64_t _libssh2_ntohu64(const unsigned char *buf); 85 void _libssh2_htonu32(unsigned char *buf, uint32_t val); 86 void _libssh2_store_u32(unsigned char **buf, uint32_t value); 87 void _libssh2_store_str(unsigned char **buf, const char *str, size_t len); 88 void *_libssh2_calloc(LIBSSH2_SESSION *session, size_t size); 89 void _libssh2_explicit_zero(void *buf, size_t size); 90 91 struct string_buf* _libssh2_string_buf_new(LIBSSH2_SESSION *session); 92 void _libssh2_string_buf_free(LIBSSH2_SESSION *session, 93 struct string_buf *buf); 94 int _libssh2_get_u32(struct string_buf *buf, uint32_t *out); 95 int _libssh2_get_u64(struct string_buf *buf, libssh2_uint64_t *out); 96 int _libssh2_match_string(struct string_buf *buf, const char *match); 97 int _libssh2_get_string(struct string_buf *buf, unsigned char **outbuf, 98 size_t *outlen); 99 int _libssh2_copy_string(LIBSSH2_SESSION* session, struct string_buf *buf, 100 unsigned char **outbuf, size_t *outlen); 101 int _libssh2_get_bignum_bytes(struct string_buf *buf, unsigned char **outbuf, 102 size_t *outlen); 103 int _libssh2_check_length(struct string_buf *buf, size_t requested_len); 104 105 #if defined(LIBSSH2_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) 106 /* provide a private one */ 107 #undef HAVE_GETTIMEOFDAY 108 int __cdecl _libssh2_gettimeofday(struct timeval *tp, void *tzp); 109 #define HAVE_LIBSSH2_GETTIMEOFDAY 110 #define LIBSSH2_GETTIMEOFDAY_WIN32 /* enable the win32 implementation */ 111 #else 112 #ifdef HAVE_GETTIMEOFDAY 113 #define _libssh2_gettimeofday(x,y) gettimeofday(x,y) 114 #define HAVE_LIBSSH2_GETTIMEOFDAY 115 #endif 116 #endif 117 118 void _libssh2_xor_data(unsigned char *output, 119 const unsigned char *input1, 120 const unsigned char *input2, 121 size_t length); 122 123 void _libssh2_aes_ctr_increment(unsigned char *ctr, size_t length); 124 125 #endif /* _LIBSSH2_MISC_H */ 126