yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame^] | 1 | /* crypto.h |
| 2 | * |
| 3 | * Copyright (C) 2006-2021 wolfSSL Inc. |
| 4 | * |
| 5 | * This file is part of wolfSSL. |
| 6 | * |
| 7 | * wolfSSL is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * wolfSSL is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA |
| 20 | */ |
| 21 | |
| 22 | /* crypto.h for openSSL */ |
| 23 | |
| 24 | #ifndef WOLFSSL_CRYPTO_H_ |
| 25 | #define WOLFSSL_CRYPTO_H_ |
| 26 | |
| 27 | #include <wolfssl/wolfcrypt/settings.h> |
| 28 | |
| 29 | #include <wolfssl/openssl/opensslv.h> |
| 30 | #include <wolfssl/openssl/conf.h> |
| 31 | |
| 32 | #ifdef WOLFSSL_PREFIX |
| 33 | #include "prefix_crypto.h" |
| 34 | #endif |
| 35 | |
| 36 | typedef struct WOLFSSL_INIT_SETTINGS { |
| 37 | char* appname; |
| 38 | } WOLFSSL_INIT_SETTINGS; |
| 39 | |
| 40 | typedef WOLFSSL_INIT_SETTINGS OPENSSL_INIT_SETTINGS; |
| 41 | |
| 42 | WOLFSSL_API const char* wolfSSLeay_version(int type); |
| 43 | WOLFSSL_API unsigned long wolfSSLeay(void); |
| 44 | WOLFSSL_API unsigned long wolfSSL_OpenSSL_version_num(void); |
| 45 | |
| 46 | #ifdef OPENSSL_EXTRA |
| 47 | WOLFSSL_API void wolfSSL_OPENSSL_free(void*); |
| 48 | WOLFSSL_API void *wolfSSL_OPENSSL_malloc(size_t a); |
| 49 | WOLFSSL_API int wolfSSL_OPENSSL_hexchar2int(unsigned char c); |
| 50 | WOLFSSL_API unsigned char *wolfSSL_OPENSSL_hexstr2buf(const char *str, long *len); |
| 51 | |
| 52 | WOLFSSL_API int wolfSSL_OPENSSL_init_crypto(word64 opts, const OPENSSL_INIT_SETTINGS *settings); |
| 53 | #endif |
| 54 | |
| 55 | typedef struct WOLFSSL_CRYPTO_THREADID { |
| 56 | int dummy; |
| 57 | }WOLFSSL_CRYPTO_THREADID; |
| 58 | typedef struct crypto_threadid_st CRYPTO_THREADID; |
| 59 | |
| 60 | #define crypto_threadid_st WOLFSSL_CRYPTO_THREADID |
| 61 | #define CRYPTO_THREADID WOLFSSL_CRYPTO_THREADID |
| 62 | |
| 63 | #define SSLeay_version wolfSSLeay_version |
| 64 | #define SSLeay wolfSSLeay |
| 65 | #define OpenSSL_version_num wolfSSL_OpenSSL_version_num |
| 66 | |
| 67 | #ifdef WOLFSSL_QT |
| 68 | #define SSLEAY_VERSION 0x10001000L |
| 69 | #else |
| 70 | #define SSLEAY_VERSION 0x0090600fL |
| 71 | #endif |
| 72 | #define SSLEAY_VERSION_NUMBER SSLEAY_VERSION |
| 73 | #define CRYPTO_lock wc_LockMutex_ex |
| 74 | |
| 75 | /* this function was used to set the default malloc, free, and realloc */ |
| 76 | #define CRYPTO_malloc_init() 0 /* CRYPTO_malloc_init is not needed */ |
| 77 | |
| 78 | #define OPENSSL_free wolfSSL_OPENSSL_free |
| 79 | #define OPENSSL_malloc wolfSSL_OPENSSL_malloc |
| 80 | #define OPENSSL_hexchar2int wolfSSL_OPENSSL_hexchar2int |
| 81 | #define OPENSSL_hexstr2buf wolfSSL_OPENSSL_hexstr2buf |
| 82 | |
| 83 | #define OPENSSL_INIT_ENGINE_ALL_BUILTIN 0x00000001L |
| 84 | #define OPENSSL_INIT_ADD_ALL_CIPHERS 0x00000004L |
| 85 | #define OPENSSL_INIT_ADD_ALL_DIGESTS 0x00000008L |
| 86 | #define OPENSSL_INIT_LOAD_CONFIG 0x00000040L |
| 87 | |
| 88 | #define OPENSSL_init_crypto wolfSSL_OPENSSL_init_crypto |
| 89 | |
| 90 | #ifdef WOLFSSL_OPENVPN |
| 91 | # define OPENSSL_assert(e) \ |
| 92 | if (!(e)) { \ |
| 93 | fprintf(stderr, "%s:%d wolfSSL internal error: assertion failed: " #e, \ |
| 94 | __FILE__, __LINE__); \ |
| 95 | raise(SIGABRT); \ |
| 96 | _exit(3); \ |
| 97 | } |
| 98 | #endif |
| 99 | |
| 100 | #if defined(OPENSSL_ALL) || defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \ |
| 101 | defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA) || defined(HAVE_EX_DATA) |
| 102 | #define CRYPTO_set_mem_ex_functions wolfSSL_CRYPTO_set_mem_ex_functions |
| 103 | #define FIPS_mode wolfSSL_FIPS_mode |
| 104 | #define FIPS_mode_set wolfSSL_FIPS_mode_set |
| 105 | typedef struct CRYPTO_EX_DATA CRYPTO_EX_DATA; |
| 106 | typedef void (CRYPTO_free_func)(void*parent, void*ptr, CRYPTO_EX_DATA *ad, int idx, |
| 107 | long argl, void* argp); |
| 108 | #define CRYPTO_THREADID_set_callback wolfSSL_THREADID_set_callback |
| 109 | #define CRYPTO_THREADID_set_numeric wolfSSL_THREADID_set_numeric |
| 110 | #define CRYPTO_THREADID_current wolfSSL_THREADID_current |
| 111 | #define CRYPTO_THREADID_hash wolfSSL_THREADID_hash |
| 112 | |
| 113 | #define CRYPTO_r_lock wc_LockMutex_ex |
| 114 | #define CRYPTO_unlock wc_LockMutex_ex |
| 115 | |
| 116 | #define CRYPTO_THREAD_lock wc_LockMutex |
| 117 | #define CRYPTO_THREAD_r_lock wc_LockMutex |
| 118 | #define CRYPTO_THREAD_unlock wc_UnLockMutex |
| 119 | |
| 120 | #define CRYPTO_THREAD_lock_new wc_InitAndAllocMutex |
| 121 | #define CRYPTO_THREAD_read_lock wc_LockMutex |
| 122 | #define CRYPTO_THREAD_write_lock wc_LockMutex |
| 123 | #define CRYPTO_THREAD_lock_free wc_FreeMutex |
| 124 | |
| 125 | #define CRYPTO_set_ex_data wolfSSL_CRYPTO_set_ex_data |
| 126 | |
| 127 | #endif /* OPENSSL_ALL || HAVE_STUNNEL || WOLFSSL_NGINX || WOLFSSL_HAPROXY || HAVE_EX_DATA */ |
| 128 | |
| 129 | #endif /* header */ |