SSL/TLS Library
CyaSSL is SSL/TLS library for embedded systems.
cyassl/internal.h@0:9d17e4342598, 2014-04-20 (annotated)
- Committer:
- wolfSSL
- Date:
- Sun Apr 20 12:40:57 2014 +0000
- Revision:
- 0:9d17e4342598
CyaSSL SSL/TLS Library 2.9.4;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wolfSSL | 0:9d17e4342598 | 1 | /* internal.h |
wolfSSL | 0:9d17e4342598 | 2 | * |
wolfSSL | 0:9d17e4342598 | 3 | * Copyright (C) 2006-2013 wolfSSL Inc. |
wolfSSL | 0:9d17e4342598 | 4 | * |
wolfSSL | 0:9d17e4342598 | 5 | * This file is part of CyaSSL. |
wolfSSL | 0:9d17e4342598 | 6 | * |
wolfSSL | 0:9d17e4342598 | 7 | * CyaSSL is free software; you can redistribute it and/or modify |
wolfSSL | 0:9d17e4342598 | 8 | * it under the terms of the GNU General Public License as published by |
wolfSSL | 0:9d17e4342598 | 9 | * the Free Software Foundation; either version 2 of the License, or |
wolfSSL | 0:9d17e4342598 | 10 | * (at your option) any later version. |
wolfSSL | 0:9d17e4342598 | 11 | * |
wolfSSL | 0:9d17e4342598 | 12 | * CyaSSL is distributed in the hope that it will be useful, |
wolfSSL | 0:9d17e4342598 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
wolfSSL | 0:9d17e4342598 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wolfSSL | 0:9d17e4342598 | 15 | * GNU General Public License for more details. |
wolfSSL | 0:9d17e4342598 | 16 | * |
wolfSSL | 0:9d17e4342598 | 17 | * You should have received a copy of the GNU General Public License |
wolfSSL | 0:9d17e4342598 | 18 | * along with this program; if not, write to the Free Software |
wolfSSL | 0:9d17e4342598 | 19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
wolfSSL | 0:9d17e4342598 | 20 | */ |
wolfSSL | 0:9d17e4342598 | 21 | |
wolfSSL | 0:9d17e4342598 | 22 | |
wolfSSL | 0:9d17e4342598 | 23 | #ifndef CYASSL_INT_H |
wolfSSL | 0:9d17e4342598 | 24 | #define CYASSL_INT_H |
wolfSSL | 0:9d17e4342598 | 25 | |
wolfSSL | 0:9d17e4342598 | 26 | |
wolfSSL | 0:9d17e4342598 | 27 | #include <cyassl/ctaocrypt/types.h> |
wolfSSL | 0:9d17e4342598 | 28 | #include <cyassl/ssl.h> |
wolfSSL | 0:9d17e4342598 | 29 | #include <cyassl/crl.h> |
wolfSSL | 0:9d17e4342598 | 30 | #include <cyassl/ctaocrypt/random.h> |
wolfSSL | 0:9d17e4342598 | 31 | #include <cyassl/ctaocrypt/des3.h> |
wolfSSL | 0:9d17e4342598 | 32 | #include <cyassl/ctaocrypt/hc128.h> |
wolfSSL | 0:9d17e4342598 | 33 | #include <cyassl/ctaocrypt/rabbit.h> |
wolfSSL | 0:9d17e4342598 | 34 | #include <cyassl/ctaocrypt/asn.h> |
wolfSSL | 0:9d17e4342598 | 35 | #include <cyassl/ctaocrypt/md5.h> |
wolfSSL | 0:9d17e4342598 | 36 | #include <cyassl/ctaocrypt/sha.h> |
wolfSSL | 0:9d17e4342598 | 37 | #include <cyassl/ctaocrypt/aes.h> |
wolfSSL | 0:9d17e4342598 | 38 | #include <cyassl/ctaocrypt/camellia.h> |
wolfSSL | 0:9d17e4342598 | 39 | #include <cyassl/ctaocrypt/logging.h> |
wolfSSL | 0:9d17e4342598 | 40 | #include <cyassl/ctaocrypt/hmac.h> |
wolfSSL | 0:9d17e4342598 | 41 | #ifndef NO_RC4 |
wolfSSL | 0:9d17e4342598 | 42 | #include <cyassl/ctaocrypt/arc4.h> |
wolfSSL | 0:9d17e4342598 | 43 | #endif |
wolfSSL | 0:9d17e4342598 | 44 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 45 | #include <cyassl/ctaocrypt/ecc.h> |
wolfSSL | 0:9d17e4342598 | 46 | #endif |
wolfSSL | 0:9d17e4342598 | 47 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 48 | #include <cyassl/ctaocrypt/sha256.h> |
wolfSSL | 0:9d17e4342598 | 49 | #endif |
wolfSSL | 0:9d17e4342598 | 50 | #ifdef HAVE_OCSP |
wolfSSL | 0:9d17e4342598 | 51 | #include <cyassl/ocsp.h> |
wolfSSL | 0:9d17e4342598 | 52 | #endif |
wolfSSL | 0:9d17e4342598 | 53 | #ifdef CYASSL_SHA512 |
wolfSSL | 0:9d17e4342598 | 54 | #include <cyassl/ctaocrypt/sha512.h> |
wolfSSL | 0:9d17e4342598 | 55 | #endif |
wolfSSL | 0:9d17e4342598 | 56 | |
wolfSSL | 0:9d17e4342598 | 57 | #ifdef HAVE_AESGCM |
wolfSSL | 0:9d17e4342598 | 58 | #include <cyassl/ctaocrypt/sha512.h> |
wolfSSL | 0:9d17e4342598 | 59 | #endif |
wolfSSL | 0:9d17e4342598 | 60 | |
wolfSSL | 0:9d17e4342598 | 61 | #ifdef CYASSL_RIPEMD |
wolfSSL | 0:9d17e4342598 | 62 | #include <cyassl/ctaocrypt/ripemd.h> |
wolfSSL | 0:9d17e4342598 | 63 | #endif |
wolfSSL | 0:9d17e4342598 | 64 | |
wolfSSL | 0:9d17e4342598 | 65 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 66 | #include <cyassl/callbacks.h> |
wolfSSL | 0:9d17e4342598 | 67 | #include <signal.h> |
wolfSSL | 0:9d17e4342598 | 68 | #endif |
wolfSSL | 0:9d17e4342598 | 69 | |
wolfSSL | 0:9d17e4342598 | 70 | #ifdef USE_WINDOWS_API |
wolfSSL | 0:9d17e4342598 | 71 | #ifdef CYASSL_GAME_BUILD |
wolfSSL | 0:9d17e4342598 | 72 | #include "system/xtl.h" |
wolfSSL | 0:9d17e4342598 | 73 | #else |
wolfSSL | 0:9d17e4342598 | 74 | #if defined(_WIN32_WCE) || defined(WIN32_LEAN_AND_MEAN) |
wolfSSL | 0:9d17e4342598 | 75 | /* On WinCE winsock2.h must be included before windows.h */ |
wolfSSL | 0:9d17e4342598 | 76 | #include <winsock2.h> |
wolfSSL | 0:9d17e4342598 | 77 | #endif |
wolfSSL | 0:9d17e4342598 | 78 | #include <windows.h> |
wolfSSL | 0:9d17e4342598 | 79 | #endif |
wolfSSL | 0:9d17e4342598 | 80 | #elif defined(THREADX) |
wolfSSL | 0:9d17e4342598 | 81 | #ifndef SINGLE_THREADED |
wolfSSL | 0:9d17e4342598 | 82 | #include "tx_api.h" |
wolfSSL | 0:9d17e4342598 | 83 | #endif |
wolfSSL | 0:9d17e4342598 | 84 | #elif defined(MICRIUM) |
wolfSSL | 0:9d17e4342598 | 85 | /* do nothing, just don't pick Unix */ |
wolfSSL | 0:9d17e4342598 | 86 | #elif defined(FREERTOS) || defined(CYASSL_SAFERTOS) |
wolfSSL | 0:9d17e4342598 | 87 | /* do nothing */ |
wolfSSL | 0:9d17e4342598 | 88 | #elif defined(EBSNET) |
wolfSSL | 0:9d17e4342598 | 89 | /* do nothing */ |
wolfSSL | 0:9d17e4342598 | 90 | #elif defined(FREESCALE_MQX) |
wolfSSL | 0:9d17e4342598 | 91 | /* do nothing */ |
wolfSSL | 0:9d17e4342598 | 92 | #elif defined(CYASSL_MDK_ARM) |
wolfSSL | 0:9d17e4342598 | 93 | #if defined(CYASSL_MDK5) |
wolfSSL | 0:9d17e4342598 | 94 | #include "cmsis_os.h" |
wolfSSL | 0:9d17e4342598 | 95 | #else |
wolfSSL | 0:9d17e4342598 | 96 | #include <rtl.h> |
wolfSSL | 0:9d17e4342598 | 97 | #endif |
wolfSSL | 0:9d17e4342598 | 98 | #elif defined(MBED) |
wolfSSL | 0:9d17e4342598 | 99 | |
wolfSSL | 0:9d17e4342598 | 100 | #else |
wolfSSL | 0:9d17e4342598 | 101 | #ifndef SINGLE_THREADED |
wolfSSL | 0:9d17e4342598 | 102 | #define CYASSL_PTHREADS |
wolfSSL | 0:9d17e4342598 | 103 | #include <pthread.h> |
wolfSSL | 0:9d17e4342598 | 104 | #endif |
wolfSSL | 0:9d17e4342598 | 105 | #if defined(OPENSSL_EXTRA) || defined(GOAHEAD_WS) |
wolfSSL | 0:9d17e4342598 | 106 | #include <unistd.h> /* for close of BIO */ |
wolfSSL | 0:9d17e4342598 | 107 | #endif |
wolfSSL | 0:9d17e4342598 | 108 | #endif |
wolfSSL | 0:9d17e4342598 | 109 | |
wolfSSL | 0:9d17e4342598 | 110 | |
wolfSSL | 0:9d17e4342598 | 111 | #ifdef HAVE_LIBZ |
wolfSSL | 0:9d17e4342598 | 112 | #include "zlib.h" |
wolfSSL | 0:9d17e4342598 | 113 | #endif |
wolfSSL | 0:9d17e4342598 | 114 | |
wolfSSL | 0:9d17e4342598 | 115 | #ifdef _MSC_VER |
wolfSSL | 0:9d17e4342598 | 116 | /* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */ |
wolfSSL | 0:9d17e4342598 | 117 | #pragma warning(disable: 4996) |
wolfSSL | 0:9d17e4342598 | 118 | #endif |
wolfSSL | 0:9d17e4342598 | 119 | |
wolfSSL | 0:9d17e4342598 | 120 | #ifdef NO_AES |
wolfSSL | 0:9d17e4342598 | 121 | #if !defined (ALIGN16) |
wolfSSL | 0:9d17e4342598 | 122 | #define ALIGN16 |
wolfSSL | 0:9d17e4342598 | 123 | #endif |
wolfSSL | 0:9d17e4342598 | 124 | #endif |
wolfSSL | 0:9d17e4342598 | 125 | |
wolfSSL | 0:9d17e4342598 | 126 | #ifdef NO_SHA |
wolfSSL | 0:9d17e4342598 | 127 | #define SHA_DIGEST_SIZE 20 |
wolfSSL | 0:9d17e4342598 | 128 | #endif |
wolfSSL | 0:9d17e4342598 | 129 | |
wolfSSL | 0:9d17e4342598 | 130 | #ifdef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 131 | #define SHA256_DIGEST_SIZE 32 |
wolfSSL | 0:9d17e4342598 | 132 | #endif |
wolfSSL | 0:9d17e4342598 | 133 | |
wolfSSL | 0:9d17e4342598 | 134 | |
wolfSSL | 0:9d17e4342598 | 135 | #ifdef __cplusplus |
wolfSSL | 0:9d17e4342598 | 136 | extern "C" { |
wolfSSL | 0:9d17e4342598 | 137 | #endif |
wolfSSL | 0:9d17e4342598 | 138 | |
wolfSSL | 0:9d17e4342598 | 139 | |
wolfSSL | 0:9d17e4342598 | 140 | #ifdef USE_WINDOWS_API |
wolfSSL | 0:9d17e4342598 | 141 | typedef unsigned int SOCKET_T; |
wolfSSL | 0:9d17e4342598 | 142 | #else |
wolfSSL | 0:9d17e4342598 | 143 | typedef int SOCKET_T; |
wolfSSL | 0:9d17e4342598 | 144 | #endif |
wolfSSL | 0:9d17e4342598 | 145 | |
wolfSSL | 0:9d17e4342598 | 146 | |
wolfSSL | 0:9d17e4342598 | 147 | typedef byte word24[3]; |
wolfSSL | 0:9d17e4342598 | 148 | |
wolfSSL | 0:9d17e4342598 | 149 | /* used by ssl.c and cyassl_int.c */ |
wolfSSL | 0:9d17e4342598 | 150 | void c32to24(word32 in, word24 out); |
wolfSSL | 0:9d17e4342598 | 151 | |
wolfSSL | 0:9d17e4342598 | 152 | /* Define or comment out the cipher suites you'd like to be compiled in |
wolfSSL | 0:9d17e4342598 | 153 | make sure to use at least one BUILD_SSL_xxx or BUILD_TLS_xxx is defined |
wolfSSL | 0:9d17e4342598 | 154 | |
wolfSSL | 0:9d17e4342598 | 155 | When adding cipher suites, add name to cipher_names, idx to cipher_name_idx |
wolfSSL | 0:9d17e4342598 | 156 | */ |
wolfSSL | 0:9d17e4342598 | 157 | #if !defined(NO_RSA) && !defined(NO_RC4) |
wolfSSL | 0:9d17e4342598 | 158 | #if !defined(NO_SHA) |
wolfSSL | 0:9d17e4342598 | 159 | #define BUILD_SSL_RSA_WITH_RC4_128_SHA |
wolfSSL | 0:9d17e4342598 | 160 | #endif |
wolfSSL | 0:9d17e4342598 | 161 | #if !defined(NO_MD5) |
wolfSSL | 0:9d17e4342598 | 162 | #define BUILD_SSL_RSA_WITH_RC4_128_MD5 |
wolfSSL | 0:9d17e4342598 | 163 | #endif |
wolfSSL | 0:9d17e4342598 | 164 | #if !defined(NO_TLS) && defined(HAVE_NTRU) && !defined(NO_SHA) |
wolfSSL | 0:9d17e4342598 | 165 | #define BUILD_TLS_NTRU_RSA_WITH_RC4_128_SHA |
wolfSSL | 0:9d17e4342598 | 166 | #endif |
wolfSSL | 0:9d17e4342598 | 167 | #endif |
wolfSSL | 0:9d17e4342598 | 168 | |
wolfSSL | 0:9d17e4342598 | 169 | #if !defined(NO_RSA) && !defined(NO_DES3) |
wolfSSL | 0:9d17e4342598 | 170 | #if !defined(NO_SHA) |
wolfSSL | 0:9d17e4342598 | 171 | #define BUILD_SSL_RSA_WITH_3DES_EDE_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 172 | #if !defined(NO_TLS) && defined(HAVE_NTRU) |
wolfSSL | 0:9d17e4342598 | 173 | #define BUILD_TLS_NTRU_RSA_WITH_3DES_EDE_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 174 | #endif |
wolfSSL | 0:9d17e4342598 | 175 | #endif |
wolfSSL | 0:9d17e4342598 | 176 | #endif |
wolfSSL | 0:9d17e4342598 | 177 | |
wolfSSL | 0:9d17e4342598 | 178 | #if !defined(NO_RSA) && !defined(NO_AES) && !defined(NO_TLS) |
wolfSSL | 0:9d17e4342598 | 179 | #if !defined(NO_SHA) |
wolfSSL | 0:9d17e4342598 | 180 | #define BUILD_TLS_RSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 181 | #define BUILD_TLS_RSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 182 | #if defined(HAVE_NTRU) |
wolfSSL | 0:9d17e4342598 | 183 | #define BUILD_TLS_NTRU_RSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 184 | #define BUILD_TLS_NTRU_RSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 185 | #endif |
wolfSSL | 0:9d17e4342598 | 186 | #endif |
wolfSSL | 0:9d17e4342598 | 187 | #if !defined (NO_SHA256) |
wolfSSL | 0:9d17e4342598 | 188 | #define BUILD_TLS_RSA_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 189 | #define BUILD_TLS_RSA_WITH_AES_256_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 190 | #endif |
wolfSSL | 0:9d17e4342598 | 191 | #if defined (HAVE_AESGCM) |
wolfSSL | 0:9d17e4342598 | 192 | #define BUILD_TLS_RSA_WITH_AES_128_GCM_SHA256 |
wolfSSL | 0:9d17e4342598 | 193 | #if defined (CYASSL_SHA384) |
wolfSSL | 0:9d17e4342598 | 194 | #define BUILD_TLS_RSA_WITH_AES_256_GCM_SHA384 |
wolfSSL | 0:9d17e4342598 | 195 | #endif |
wolfSSL | 0:9d17e4342598 | 196 | #endif |
wolfSSL | 0:9d17e4342598 | 197 | #if defined (HAVE_AESCCM) |
wolfSSL | 0:9d17e4342598 | 198 | #define BUILD_TLS_RSA_WITH_AES_128_CCM_8 |
wolfSSL | 0:9d17e4342598 | 199 | #define BUILD_TLS_RSA_WITH_AES_256_CCM_8 |
wolfSSL | 0:9d17e4342598 | 200 | #endif |
wolfSSL | 0:9d17e4342598 | 201 | #if defined(HAVE_BLAKE2) |
wolfSSL | 0:9d17e4342598 | 202 | #define BUILD_TLS_RSA_WITH_AES_128_CBC_B2B256 |
wolfSSL | 0:9d17e4342598 | 203 | #define BUILD_TLS_RSA_WITH_AES_256_CBC_B2B256 |
wolfSSL | 0:9d17e4342598 | 204 | #endif |
wolfSSL | 0:9d17e4342598 | 205 | #endif |
wolfSSL | 0:9d17e4342598 | 206 | |
wolfSSL | 0:9d17e4342598 | 207 | #if defined(HAVE_CAMELLIA) && !defined(NO_TLS) |
wolfSSL | 0:9d17e4342598 | 208 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 209 | #if !defined(NO_SHA) |
wolfSSL | 0:9d17e4342598 | 210 | #define BUILD_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 211 | #define BUILD_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 212 | #endif |
wolfSSL | 0:9d17e4342598 | 213 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 214 | #define BUILD_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 215 | #define BUILD_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 216 | #endif |
wolfSSL | 0:9d17e4342598 | 217 | #if !defined(NO_DH) && defined(OPENSSL_EXTRA) |
wolfSSL | 0:9d17e4342598 | 218 | #if !defined(NO_SHA) |
wolfSSL | 0:9d17e4342598 | 219 | #define BUILD_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 220 | #define BUILD_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 221 | #endif |
wolfSSL | 0:9d17e4342598 | 222 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 223 | #define BUILD_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 224 | #define BUILD_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 225 | #endif |
wolfSSL | 0:9d17e4342598 | 226 | #endif |
wolfSSL | 0:9d17e4342598 | 227 | #endif |
wolfSSL | 0:9d17e4342598 | 228 | #endif |
wolfSSL | 0:9d17e4342598 | 229 | |
wolfSSL | 0:9d17e4342598 | 230 | #if !defined(NO_PSK) && !defined(NO_AES) && !defined(NO_TLS) |
wolfSSL | 0:9d17e4342598 | 231 | #if !defined(NO_SHA) |
wolfSSL | 0:9d17e4342598 | 232 | #define BUILD_TLS_PSK_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 233 | #define BUILD_TLS_PSK_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 234 | #endif |
wolfSSL | 0:9d17e4342598 | 235 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 236 | #define BUILD_TLS_PSK_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 237 | #ifdef HAVE_AESCCM |
wolfSSL | 0:9d17e4342598 | 238 | #define BUILD_TLS_PSK_WITH_AES_128_CCM_8 |
wolfSSL | 0:9d17e4342598 | 239 | #define BUILD_TLS_PSK_WITH_AES_256_CCM_8 |
wolfSSL | 0:9d17e4342598 | 240 | #endif |
wolfSSL | 0:9d17e4342598 | 241 | #endif |
wolfSSL | 0:9d17e4342598 | 242 | #endif |
wolfSSL | 0:9d17e4342598 | 243 | |
wolfSSL | 0:9d17e4342598 | 244 | #if !defined(NO_TLS) && defined(HAVE_NULL_CIPHER) |
wolfSSL | 0:9d17e4342598 | 245 | #if !defined(NO_RSA) |
wolfSSL | 0:9d17e4342598 | 246 | #if !defined(NO_SHA) |
wolfSSL | 0:9d17e4342598 | 247 | #define BUILD_TLS_RSA_WITH_NULL_SHA |
wolfSSL | 0:9d17e4342598 | 248 | #endif |
wolfSSL | 0:9d17e4342598 | 249 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 250 | #define BUILD_TLS_RSA_WITH_NULL_SHA256 |
wolfSSL | 0:9d17e4342598 | 251 | #endif |
wolfSSL | 0:9d17e4342598 | 252 | #endif |
wolfSSL | 0:9d17e4342598 | 253 | #if !defined(NO_PSK) |
wolfSSL | 0:9d17e4342598 | 254 | #if !defined(NO_SHA) |
wolfSSL | 0:9d17e4342598 | 255 | #define BUILD_TLS_PSK_WITH_NULL_SHA |
wolfSSL | 0:9d17e4342598 | 256 | #endif |
wolfSSL | 0:9d17e4342598 | 257 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 258 | #define BUILD_TLS_PSK_WITH_NULL_SHA256 |
wolfSSL | 0:9d17e4342598 | 259 | #endif |
wolfSSL | 0:9d17e4342598 | 260 | #endif |
wolfSSL | 0:9d17e4342598 | 261 | #endif |
wolfSSL | 0:9d17e4342598 | 262 | |
wolfSSL | 0:9d17e4342598 | 263 | #if !defined(NO_HC128) && !defined(NO_RSA) && !defined(NO_TLS) |
wolfSSL | 0:9d17e4342598 | 264 | #define BUILD_TLS_RSA_WITH_HC_128_MD5 |
wolfSSL | 0:9d17e4342598 | 265 | #if !defined(NO_SHA) |
wolfSSL | 0:9d17e4342598 | 266 | #define BUILD_TLS_RSA_WITH_HC_128_SHA |
wolfSSL | 0:9d17e4342598 | 267 | #endif |
wolfSSL | 0:9d17e4342598 | 268 | #if defined(HAVE_BLAKE2) |
wolfSSL | 0:9d17e4342598 | 269 | #define BUILD_TLS_RSA_WITH_HC_128_B2B256 |
wolfSSL | 0:9d17e4342598 | 270 | #endif |
wolfSSL | 0:9d17e4342598 | 271 | #endif |
wolfSSL | 0:9d17e4342598 | 272 | |
wolfSSL | 0:9d17e4342598 | 273 | #if !defined(NO_RABBIT) && !defined(NO_TLS) && !defined(NO_RSA) |
wolfSSL | 0:9d17e4342598 | 274 | #if !defined(NO_SHA) |
wolfSSL | 0:9d17e4342598 | 275 | #define BUILD_TLS_RSA_WITH_RABBIT_SHA |
wolfSSL | 0:9d17e4342598 | 276 | #endif |
wolfSSL | 0:9d17e4342598 | 277 | #endif |
wolfSSL | 0:9d17e4342598 | 278 | |
wolfSSL | 0:9d17e4342598 | 279 | #if !defined(NO_DH) && !defined(NO_AES) && !defined(NO_TLS) && \ |
wolfSSL | 0:9d17e4342598 | 280 | !defined(NO_RSA) && defined(OPENSSL_EXTRA) |
wolfSSL | 0:9d17e4342598 | 281 | #if !defined(NO_SHA) |
wolfSSL | 0:9d17e4342598 | 282 | #define BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 283 | #define BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 284 | #endif |
wolfSSL | 0:9d17e4342598 | 285 | #if !defined (NO_SHA256) |
wolfSSL | 0:9d17e4342598 | 286 | #define BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 287 | #define BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 288 | #if defined (HAVE_AESGCM) |
wolfSSL | 0:9d17e4342598 | 289 | #define BUILD_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 |
wolfSSL | 0:9d17e4342598 | 290 | #if defined (CYASSL_SHA384) |
wolfSSL | 0:9d17e4342598 | 291 | #define BUILD_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 |
wolfSSL | 0:9d17e4342598 | 292 | #endif |
wolfSSL | 0:9d17e4342598 | 293 | #endif |
wolfSSL | 0:9d17e4342598 | 294 | #endif |
wolfSSL | 0:9d17e4342598 | 295 | #endif |
wolfSSL | 0:9d17e4342598 | 296 | |
wolfSSL | 0:9d17e4342598 | 297 | #if defined(HAVE_ECC) && !defined(NO_TLS) |
wolfSSL | 0:9d17e4342598 | 298 | #if !defined(NO_AES) |
wolfSSL | 0:9d17e4342598 | 299 | #if !defined(NO_SHA) |
wolfSSL | 0:9d17e4342598 | 300 | #if !defined(NO_RSA) |
wolfSSL | 0:9d17e4342598 | 301 | #define BUILD_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 302 | #define BUILD_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 303 | #define BUILD_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 304 | #define BUILD_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 305 | #endif |
wolfSSL | 0:9d17e4342598 | 306 | |
wolfSSL | 0:9d17e4342598 | 307 | #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 308 | #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 309 | |
wolfSSL | 0:9d17e4342598 | 310 | #define BUILD_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 311 | #define BUILD_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 312 | #endif /* NO_SHA */ |
wolfSSL | 0:9d17e4342598 | 313 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 314 | #if !defined(NO_RSA) |
wolfSSL | 0:9d17e4342598 | 315 | #define BUILD_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 316 | #define BUILD_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 317 | #endif |
wolfSSL | 0:9d17e4342598 | 318 | #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 319 | #define BUILD_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 320 | #endif |
wolfSSL | 0:9d17e4342598 | 321 | |
wolfSSL | 0:9d17e4342598 | 322 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 323 | #if !defined(NO_RSA) |
wolfSSL | 0:9d17e4342598 | 324 | #define BUILD_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 |
wolfSSL | 0:9d17e4342598 | 325 | #define BUILD_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 |
wolfSSL | 0:9d17e4342598 | 326 | #endif |
wolfSSL | 0:9d17e4342598 | 327 | #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 |
wolfSSL | 0:9d17e4342598 | 328 | #define BUILD_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 |
wolfSSL | 0:9d17e4342598 | 329 | #endif |
wolfSSL | 0:9d17e4342598 | 330 | |
wolfSSL | 0:9d17e4342598 | 331 | #if defined (HAVE_AESGCM) |
wolfSSL | 0:9d17e4342598 | 332 | #if !defined(NO_RSA) |
wolfSSL | 0:9d17e4342598 | 333 | #define BUILD_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 |
wolfSSL | 0:9d17e4342598 | 334 | #define BUILD_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 |
wolfSSL | 0:9d17e4342598 | 335 | #if defined(CYASSL_SHA384) |
wolfSSL | 0:9d17e4342598 | 336 | #define BUILD_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 |
wolfSSL | 0:9d17e4342598 | 337 | #define BUILD_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 |
wolfSSL | 0:9d17e4342598 | 338 | #endif |
wolfSSL | 0:9d17e4342598 | 339 | #endif |
wolfSSL | 0:9d17e4342598 | 340 | |
wolfSSL | 0:9d17e4342598 | 341 | #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 |
wolfSSL | 0:9d17e4342598 | 342 | #define BUILD_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 |
wolfSSL | 0:9d17e4342598 | 343 | |
wolfSSL | 0:9d17e4342598 | 344 | #if defined(CYASSL_SHA384) |
wolfSSL | 0:9d17e4342598 | 345 | #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 |
wolfSSL | 0:9d17e4342598 | 346 | #define BUILD_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 |
wolfSSL | 0:9d17e4342598 | 347 | #endif |
wolfSSL | 0:9d17e4342598 | 348 | #endif |
wolfSSL | 0:9d17e4342598 | 349 | #if defined (HAVE_AESCCM) |
wolfSSL | 0:9d17e4342598 | 350 | #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 |
wolfSSL | 0:9d17e4342598 | 351 | #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 |
wolfSSL | 0:9d17e4342598 | 352 | #endif |
wolfSSL | 0:9d17e4342598 | 353 | #endif /* NO_AES */ |
wolfSSL | 0:9d17e4342598 | 354 | #if !defined(NO_RC4) |
wolfSSL | 0:9d17e4342598 | 355 | #if !defined(NO_SHA) |
wolfSSL | 0:9d17e4342598 | 356 | #if !defined(NO_RSA) |
wolfSSL | 0:9d17e4342598 | 357 | #define BUILD_TLS_ECDHE_RSA_WITH_RC4_128_SHA |
wolfSSL | 0:9d17e4342598 | 358 | #define BUILD_TLS_ECDH_RSA_WITH_RC4_128_SHA |
wolfSSL | 0:9d17e4342598 | 359 | #endif |
wolfSSL | 0:9d17e4342598 | 360 | |
wolfSSL | 0:9d17e4342598 | 361 | #define BUILD_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA |
wolfSSL | 0:9d17e4342598 | 362 | #define BUILD_TLS_ECDH_ECDSA_WITH_RC4_128_SHA |
wolfSSL | 0:9d17e4342598 | 363 | #endif |
wolfSSL | 0:9d17e4342598 | 364 | #endif |
wolfSSL | 0:9d17e4342598 | 365 | #if !defined(NO_DES3) |
wolfSSL | 0:9d17e4342598 | 366 | #if !defined(NO_RSA) |
wolfSSL | 0:9d17e4342598 | 367 | #define BUILD_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 368 | #define BUILD_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 369 | #endif |
wolfSSL | 0:9d17e4342598 | 370 | |
wolfSSL | 0:9d17e4342598 | 371 | #define BUILD_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 372 | #define BUILD_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 373 | #endif |
wolfSSL | 0:9d17e4342598 | 374 | #endif |
wolfSSL | 0:9d17e4342598 | 375 | |
wolfSSL | 0:9d17e4342598 | 376 | |
wolfSSL | 0:9d17e4342598 | 377 | #if defined(BUILD_SSL_RSA_WITH_RC4_128_SHA) || \ |
wolfSSL | 0:9d17e4342598 | 378 | defined(BUILD_SSL_RSA_WITH_RC4_128_MD5) |
wolfSSL | 0:9d17e4342598 | 379 | #define BUILD_ARC4 |
wolfSSL | 0:9d17e4342598 | 380 | #endif |
wolfSSL | 0:9d17e4342598 | 381 | |
wolfSSL | 0:9d17e4342598 | 382 | #if defined(BUILD_SSL_RSA_WITH_3DES_EDE_CBC_SHA) |
wolfSSL | 0:9d17e4342598 | 383 | #define BUILD_DES3 |
wolfSSL | 0:9d17e4342598 | 384 | #endif |
wolfSSL | 0:9d17e4342598 | 385 | |
wolfSSL | 0:9d17e4342598 | 386 | #if defined(BUILD_TLS_RSA_WITH_AES_128_CBC_SHA) || \ |
wolfSSL | 0:9d17e4342598 | 387 | defined(BUILD_TLS_RSA_WITH_AES_256_CBC_SHA) || \ |
wolfSSL | 0:9d17e4342598 | 388 | defined(BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256) |
wolfSSL | 0:9d17e4342598 | 389 | #undef BUILD_AES |
wolfSSL | 0:9d17e4342598 | 390 | #define BUILD_AES |
wolfSSL | 0:9d17e4342598 | 391 | #endif |
wolfSSL | 0:9d17e4342598 | 392 | |
wolfSSL | 0:9d17e4342598 | 393 | #if defined(BUILD_TLS_RSA_WITH_AES_128_GCM_SHA256) || \ |
wolfSSL | 0:9d17e4342598 | 394 | defined(BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256) |
wolfSSL | 0:9d17e4342598 | 395 | #define BUILD_AESGCM |
wolfSSL | 0:9d17e4342598 | 396 | #endif |
wolfSSL | 0:9d17e4342598 | 397 | |
wolfSSL | 0:9d17e4342598 | 398 | #if defined(BUILD_TLS_RSA_WITH_HC_128_SHA) || \ |
wolfSSL | 0:9d17e4342598 | 399 | defined(BUILD_TLS_RSA_WITH_HC_128_MD5) || \ |
wolfSSL | 0:9d17e4342598 | 400 | defined(BUILD_TLS_RSA_WITH_HC_128_B2B256) |
wolfSSL | 0:9d17e4342598 | 401 | #define BUILD_HC128 |
wolfSSL | 0:9d17e4342598 | 402 | #endif |
wolfSSL | 0:9d17e4342598 | 403 | |
wolfSSL | 0:9d17e4342598 | 404 | #if defined(BUILD_TLS_RSA_WITH_RABBIT_SHA) |
wolfSSL | 0:9d17e4342598 | 405 | #define BUILD_RABBIT |
wolfSSL | 0:9d17e4342598 | 406 | #endif |
wolfSSL | 0:9d17e4342598 | 407 | |
wolfSSL | 0:9d17e4342598 | 408 | #ifdef NO_DES3 |
wolfSSL | 0:9d17e4342598 | 409 | #define DES_BLOCK_SIZE 8 |
wolfSSL | 0:9d17e4342598 | 410 | #else |
wolfSSL | 0:9d17e4342598 | 411 | #undef BUILD_DES3 |
wolfSSL | 0:9d17e4342598 | 412 | #define BUILD_DES3 |
wolfSSL | 0:9d17e4342598 | 413 | #endif |
wolfSSL | 0:9d17e4342598 | 414 | |
wolfSSL | 0:9d17e4342598 | 415 | #ifdef NO_AES |
wolfSSL | 0:9d17e4342598 | 416 | #define AES_BLOCK_SIZE 16 |
wolfSSL | 0:9d17e4342598 | 417 | #else |
wolfSSL | 0:9d17e4342598 | 418 | #undef BUILD_AES |
wolfSSL | 0:9d17e4342598 | 419 | #define BUILD_AES |
wolfSSL | 0:9d17e4342598 | 420 | #endif |
wolfSSL | 0:9d17e4342598 | 421 | |
wolfSSL | 0:9d17e4342598 | 422 | #ifndef NO_RC4 |
wolfSSL | 0:9d17e4342598 | 423 | #undef BUILD_ARC4 |
wolfSSL | 0:9d17e4342598 | 424 | #define BUILD_ARC4 |
wolfSSL | 0:9d17e4342598 | 425 | #endif |
wolfSSL | 0:9d17e4342598 | 426 | |
wolfSSL | 0:9d17e4342598 | 427 | |
wolfSSL | 0:9d17e4342598 | 428 | |
wolfSSL | 0:9d17e4342598 | 429 | #if defined(BUILD_AESGCM) || defined(HAVE_AESCCM) |
wolfSSL | 0:9d17e4342598 | 430 | #define HAVE_AEAD |
wolfSSL | 0:9d17e4342598 | 431 | #endif |
wolfSSL | 0:9d17e4342598 | 432 | |
wolfSSL | 0:9d17e4342598 | 433 | |
wolfSSL | 0:9d17e4342598 | 434 | /* actual cipher values, 2nd byte */ |
wolfSSL | 0:9d17e4342598 | 435 | enum { |
wolfSSL | 0:9d17e4342598 | 436 | TLS_DHE_RSA_WITH_AES_256_CBC_SHA = 0x39, |
wolfSSL | 0:9d17e4342598 | 437 | TLS_DHE_RSA_WITH_AES_128_CBC_SHA = 0x33, |
wolfSSL | 0:9d17e4342598 | 438 | TLS_RSA_WITH_AES_256_CBC_SHA = 0x35, |
wolfSSL | 0:9d17e4342598 | 439 | TLS_RSA_WITH_AES_128_CBC_SHA = 0x2F, |
wolfSSL | 0:9d17e4342598 | 440 | TLS_RSA_WITH_NULL_SHA = 0x02, |
wolfSSL | 0:9d17e4342598 | 441 | TLS_PSK_WITH_AES_256_CBC_SHA = 0x8d, |
wolfSSL | 0:9d17e4342598 | 442 | TLS_PSK_WITH_AES_128_CBC_SHA256 = 0xae, |
wolfSSL | 0:9d17e4342598 | 443 | TLS_PSK_WITH_AES_128_CBC_SHA = 0x8c, |
wolfSSL | 0:9d17e4342598 | 444 | TLS_PSK_WITH_NULL_SHA256 = 0xb0, |
wolfSSL | 0:9d17e4342598 | 445 | TLS_PSK_WITH_NULL_SHA = 0x2c, |
wolfSSL | 0:9d17e4342598 | 446 | SSL_RSA_WITH_RC4_128_SHA = 0x05, |
wolfSSL | 0:9d17e4342598 | 447 | SSL_RSA_WITH_RC4_128_MD5 = 0x04, |
wolfSSL | 0:9d17e4342598 | 448 | SSL_RSA_WITH_3DES_EDE_CBC_SHA = 0x0A, |
wolfSSL | 0:9d17e4342598 | 449 | |
wolfSSL | 0:9d17e4342598 | 450 | /* ECC suites, first byte is 0xC0 (ECC_BYTE) */ |
wolfSSL | 0:9d17e4342598 | 451 | TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA = 0x14, |
wolfSSL | 0:9d17e4342598 | 452 | TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA = 0x13, |
wolfSSL | 0:9d17e4342598 | 453 | TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA = 0x0A, |
wolfSSL | 0:9d17e4342598 | 454 | TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA = 0x09, |
wolfSSL | 0:9d17e4342598 | 455 | TLS_ECDHE_RSA_WITH_RC4_128_SHA = 0x11, |
wolfSSL | 0:9d17e4342598 | 456 | TLS_ECDHE_ECDSA_WITH_RC4_128_SHA = 0x07, |
wolfSSL | 0:9d17e4342598 | 457 | TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA = 0x12, |
wolfSSL | 0:9d17e4342598 | 458 | TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA = 0x08, |
wolfSSL | 0:9d17e4342598 | 459 | TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 = 0x27, |
wolfSSL | 0:9d17e4342598 | 460 | TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 = 0x23, |
wolfSSL | 0:9d17e4342598 | 461 | TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 = 0x28, |
wolfSSL | 0:9d17e4342598 | 462 | TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 = 0x24, |
wolfSSL | 0:9d17e4342598 | 463 | |
wolfSSL | 0:9d17e4342598 | 464 | /* static ECDH, first byte is 0xC0 (ECC_BYTE) */ |
wolfSSL | 0:9d17e4342598 | 465 | TLS_ECDH_RSA_WITH_AES_256_CBC_SHA = 0x0F, |
wolfSSL | 0:9d17e4342598 | 466 | TLS_ECDH_RSA_WITH_AES_128_CBC_SHA = 0x0E, |
wolfSSL | 0:9d17e4342598 | 467 | TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA = 0x05, |
wolfSSL | 0:9d17e4342598 | 468 | TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA = 0x04, |
wolfSSL | 0:9d17e4342598 | 469 | TLS_ECDH_RSA_WITH_RC4_128_SHA = 0x0C, |
wolfSSL | 0:9d17e4342598 | 470 | TLS_ECDH_ECDSA_WITH_RC4_128_SHA = 0x02, |
wolfSSL | 0:9d17e4342598 | 471 | TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA = 0x0D, |
wolfSSL | 0:9d17e4342598 | 472 | TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA = 0x03, |
wolfSSL | 0:9d17e4342598 | 473 | TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 = 0x29, |
wolfSSL | 0:9d17e4342598 | 474 | TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 = 0x25, |
wolfSSL | 0:9d17e4342598 | 475 | TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 = 0x2A, |
wolfSSL | 0:9d17e4342598 | 476 | TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 = 0x26, |
wolfSSL | 0:9d17e4342598 | 477 | |
wolfSSL | 0:9d17e4342598 | 478 | /* CyaSSL extension - eSTREAM */ |
wolfSSL | 0:9d17e4342598 | 479 | TLS_RSA_WITH_HC_128_MD5 = 0xFB, |
wolfSSL | 0:9d17e4342598 | 480 | TLS_RSA_WITH_HC_128_SHA = 0xFC, |
wolfSSL | 0:9d17e4342598 | 481 | TLS_RSA_WITH_RABBIT_SHA = 0xFD, |
wolfSSL | 0:9d17e4342598 | 482 | |
wolfSSL | 0:9d17e4342598 | 483 | /* CyaSSL extension - Blake2b 256 */ |
wolfSSL | 0:9d17e4342598 | 484 | TLS_RSA_WITH_AES_128_CBC_B2B256 = 0xF8, |
wolfSSL | 0:9d17e4342598 | 485 | TLS_RSA_WITH_AES_256_CBC_B2B256 = 0xF9, |
wolfSSL | 0:9d17e4342598 | 486 | TLS_RSA_WITH_HC_128_B2B256 = 0xFA, /* eSTREAM too */ |
wolfSSL | 0:9d17e4342598 | 487 | |
wolfSSL | 0:9d17e4342598 | 488 | /* CyaSSL extension - NTRU */ |
wolfSSL | 0:9d17e4342598 | 489 | TLS_NTRU_RSA_WITH_RC4_128_SHA = 0xe5, |
wolfSSL | 0:9d17e4342598 | 490 | TLS_NTRU_RSA_WITH_3DES_EDE_CBC_SHA = 0xe6, |
wolfSSL | 0:9d17e4342598 | 491 | TLS_NTRU_RSA_WITH_AES_128_CBC_SHA = 0xe7, /* clases w/ official SHA-256 */ |
wolfSSL | 0:9d17e4342598 | 492 | TLS_NTRU_RSA_WITH_AES_256_CBC_SHA = 0xe8, |
wolfSSL | 0:9d17e4342598 | 493 | |
wolfSSL | 0:9d17e4342598 | 494 | /* SHA256 */ |
wolfSSL | 0:9d17e4342598 | 495 | TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 = 0x6b, |
wolfSSL | 0:9d17e4342598 | 496 | TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 = 0x67, |
wolfSSL | 0:9d17e4342598 | 497 | TLS_RSA_WITH_AES_256_CBC_SHA256 = 0x3d, |
wolfSSL | 0:9d17e4342598 | 498 | TLS_RSA_WITH_AES_128_CBC_SHA256 = 0x3c, |
wolfSSL | 0:9d17e4342598 | 499 | TLS_RSA_WITH_NULL_SHA256 = 0x3b, |
wolfSSL | 0:9d17e4342598 | 500 | |
wolfSSL | 0:9d17e4342598 | 501 | /* AES-GCM */ |
wolfSSL | 0:9d17e4342598 | 502 | TLS_RSA_WITH_AES_128_GCM_SHA256 = 0x9c, |
wolfSSL | 0:9d17e4342598 | 503 | TLS_RSA_WITH_AES_256_GCM_SHA384 = 0x9d, |
wolfSSL | 0:9d17e4342598 | 504 | TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 = 0x9e, |
wolfSSL | 0:9d17e4342598 | 505 | TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 = 0x9f, |
wolfSSL | 0:9d17e4342598 | 506 | |
wolfSSL | 0:9d17e4342598 | 507 | /* ECC AES-GCM, first byte is 0xC0 (ECC_BYTE) */ |
wolfSSL | 0:9d17e4342598 | 508 | TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 = 0x2b, |
wolfSSL | 0:9d17e4342598 | 509 | TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 = 0x2c, |
wolfSSL | 0:9d17e4342598 | 510 | TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 = 0x2d, |
wolfSSL | 0:9d17e4342598 | 511 | TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 = 0x2e, |
wolfSSL | 0:9d17e4342598 | 512 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 = 0x2f, |
wolfSSL | 0:9d17e4342598 | 513 | TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 = 0x30, |
wolfSSL | 0:9d17e4342598 | 514 | TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 = 0x31, |
wolfSSL | 0:9d17e4342598 | 515 | TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 = 0x32, |
wolfSSL | 0:9d17e4342598 | 516 | |
wolfSSL | 0:9d17e4342598 | 517 | /* AES-CCM, first byte is 0xC0 but isn't ECC, |
wolfSSL | 0:9d17e4342598 | 518 | * also, in some of the other AES-CCM suites |
wolfSSL | 0:9d17e4342598 | 519 | * there will be second byte number conflicts |
wolfSSL | 0:9d17e4342598 | 520 | * with non-ECC AES-GCM */ |
wolfSSL | 0:9d17e4342598 | 521 | TLS_RSA_WITH_AES_128_CCM_8 = 0xa0, |
wolfSSL | 0:9d17e4342598 | 522 | TLS_RSA_WITH_AES_256_CCM_8 = 0xa1, |
wolfSSL | 0:9d17e4342598 | 523 | TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 = 0xc6, /* Still TBD, made up */ |
wolfSSL | 0:9d17e4342598 | 524 | TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 = 0xc7, /* Still TBD, made up */ |
wolfSSL | 0:9d17e4342598 | 525 | TLS_PSK_WITH_AES_128_CCM = 0xa4, |
wolfSSL | 0:9d17e4342598 | 526 | TLS_PSK_WITH_AES_256_CCM = 0xa5, |
wolfSSL | 0:9d17e4342598 | 527 | TLS_PSK_WITH_AES_128_CCM_8 = 0xa8, |
wolfSSL | 0:9d17e4342598 | 528 | TLS_PSK_WITH_AES_256_CCM_8 = 0xa9, |
wolfSSL | 0:9d17e4342598 | 529 | |
wolfSSL | 0:9d17e4342598 | 530 | TLS_RSA_WITH_CAMELLIA_128_CBC_SHA = 0x41, |
wolfSSL | 0:9d17e4342598 | 531 | TLS_RSA_WITH_CAMELLIA_256_CBC_SHA = 0x84, |
wolfSSL | 0:9d17e4342598 | 532 | TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 = 0xba, |
wolfSSL | 0:9d17e4342598 | 533 | TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 = 0xc0, |
wolfSSL | 0:9d17e4342598 | 534 | TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA = 0x45, |
wolfSSL | 0:9d17e4342598 | 535 | TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA = 0x88, |
wolfSSL | 0:9d17e4342598 | 536 | TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 = 0xbe, |
wolfSSL | 0:9d17e4342598 | 537 | TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 = 0xc4, |
wolfSSL | 0:9d17e4342598 | 538 | |
wolfSSL | 0:9d17e4342598 | 539 | /* Renegotiation Indication Extension Special Suite */ |
wolfSSL | 0:9d17e4342598 | 540 | TLS_EMPTY_RENEGOTIATION_INFO_SCSV = 0xff |
wolfSSL | 0:9d17e4342598 | 541 | }; |
wolfSSL | 0:9d17e4342598 | 542 | |
wolfSSL | 0:9d17e4342598 | 543 | |
wolfSSL | 0:9d17e4342598 | 544 | enum Misc { |
wolfSSL | 0:9d17e4342598 | 545 | ECC_BYTE = 0xC0, /* ECC first cipher suite byte */ |
wolfSSL | 0:9d17e4342598 | 546 | |
wolfSSL | 0:9d17e4342598 | 547 | SEND_CERT = 1, |
wolfSSL | 0:9d17e4342598 | 548 | SEND_BLANK_CERT = 2, |
wolfSSL | 0:9d17e4342598 | 549 | |
wolfSSL | 0:9d17e4342598 | 550 | DTLS_MAJOR = 0xfe, /* DTLS major version number */ |
wolfSSL | 0:9d17e4342598 | 551 | DTLS_MINOR = 0xff, /* DTLS minor version number */ |
wolfSSL | 0:9d17e4342598 | 552 | DTLSv1_2_MINOR = 0xfd, /* DTLS minor version number */ |
wolfSSL | 0:9d17e4342598 | 553 | SSLv3_MAJOR = 3, /* SSLv3 and TLSv1+ major version number */ |
wolfSSL | 0:9d17e4342598 | 554 | SSLv3_MINOR = 0, /* TLSv1 minor version number */ |
wolfSSL | 0:9d17e4342598 | 555 | TLSv1_MINOR = 1, /* TLSv1 minor version number */ |
wolfSSL | 0:9d17e4342598 | 556 | TLSv1_1_MINOR = 2, /* TLSv1_1 minor version number */ |
wolfSSL | 0:9d17e4342598 | 557 | TLSv1_2_MINOR = 3, /* TLSv1_2 minor version number */ |
wolfSSL | 0:9d17e4342598 | 558 | INVALID_BYTE = 0xff, /* Used to initialize cipher specs values */ |
wolfSSL | 0:9d17e4342598 | 559 | NO_COMPRESSION = 0, |
wolfSSL | 0:9d17e4342598 | 560 | ZLIB_COMPRESSION = 221, /* CyaSSL zlib compression */ |
wolfSSL | 0:9d17e4342598 | 561 | HELLO_EXT_SIG_ALGO = 13, /* ID for the sig_algo hello extension */ |
wolfSSL | 0:9d17e4342598 | 562 | SECRET_LEN = 48, /* pre RSA and all master */ |
wolfSSL | 0:9d17e4342598 | 563 | ENCRYPT_LEN = 512, /* allow 4096 bit static buffer */ |
wolfSSL | 0:9d17e4342598 | 564 | SIZEOF_SENDER = 4, /* clnt or srvr */ |
wolfSSL | 0:9d17e4342598 | 565 | FINISHED_SZ = 36, /* MD5_DIGEST_SIZE + SHA_DIGEST_SIZE */ |
wolfSSL | 0:9d17e4342598 | 566 | MAX_RECORD_SIZE = 16384, /* 2^14, max size by standard */ |
wolfSSL | 0:9d17e4342598 | 567 | MAX_MSG_EXTRA = 38 + MAX_DIGEST_SIZE, |
wolfSSL | 0:9d17e4342598 | 568 | /* max added to msg, mac + pad from */ |
wolfSSL | 0:9d17e4342598 | 569 | /* RECORD_HEADER_SZ + BLOCK_SZ (pad) + Max |
wolfSSL | 0:9d17e4342598 | 570 | digest sz + BLOC_SZ (iv) + pad byte (1) */ |
wolfSSL | 0:9d17e4342598 | 571 | MAX_COMP_EXTRA = 1024, /* max compression extra */ |
wolfSSL | 0:9d17e4342598 | 572 | MAX_MTU = 1500, /* max expected MTU */ |
wolfSSL | 0:9d17e4342598 | 573 | MAX_UDP_SIZE = 8192 - 100, /* was MAX_MTU - 100 */ |
wolfSSL | 0:9d17e4342598 | 574 | MAX_DH_SZ = 612, /* 2240 p, pub, g + 2 byte size for each */ |
wolfSSL | 0:9d17e4342598 | 575 | MAX_STR_VERSION = 8, /* string rep of protocol version */ |
wolfSSL | 0:9d17e4342598 | 576 | |
wolfSSL | 0:9d17e4342598 | 577 | PAD_MD5 = 48, /* pad length for finished */ |
wolfSSL | 0:9d17e4342598 | 578 | PAD_SHA = 40, /* pad length for finished */ |
wolfSSL | 0:9d17e4342598 | 579 | MAX_PAD_SIZE = 256, /* maximum length of padding */ |
wolfSSL | 0:9d17e4342598 | 580 | COMPRESS_DUMMY_SIZE = 64, /* compression dummy round size */ |
wolfSSL | 0:9d17e4342598 | 581 | COMPRESS_CONSTANT = 13, /* compression calc constant */ |
wolfSSL | 0:9d17e4342598 | 582 | COMPRESS_UPPER = 55, /* compression calc numerator */ |
wolfSSL | 0:9d17e4342598 | 583 | COMPRESS_LOWER = 64, /* compression calc denominator */ |
wolfSSL | 0:9d17e4342598 | 584 | |
wolfSSL | 0:9d17e4342598 | 585 | PEM_LINE_LEN = 80, /* PEM line max + fudge */ |
wolfSSL | 0:9d17e4342598 | 586 | LENGTH_SZ = 2, /* length field for HMAC, data only */ |
wolfSSL | 0:9d17e4342598 | 587 | VERSION_SZ = 2, /* length of proctocol version */ |
wolfSSL | 0:9d17e4342598 | 588 | SEQ_SZ = 8, /* 64 bit sequence number */ |
wolfSSL | 0:9d17e4342598 | 589 | BYTE3_LEN = 3, /* up to 24 bit byte lengths */ |
wolfSSL | 0:9d17e4342598 | 590 | ALERT_SIZE = 2, /* level + description */ |
wolfSSL | 0:9d17e4342598 | 591 | VERIFY_HEADER = 2, /* always use 2 bytes */ |
wolfSSL | 0:9d17e4342598 | 592 | EXT_ID_SZ = 2, /* always use 2 bytes */ |
wolfSSL | 0:9d17e4342598 | 593 | MAX_DH_SIZE = 513, /* 4096 bit plus possible leading 0 */ |
wolfSSL | 0:9d17e4342598 | 594 | |
wolfSSL | 0:9d17e4342598 | 595 | MAX_SUITE_SZ = 200, /* 100 suites for now! */ |
wolfSSL | 0:9d17e4342598 | 596 | RAN_LEN = 32, /* random length */ |
wolfSSL | 0:9d17e4342598 | 597 | SEED_LEN = RAN_LEN * 2, /* tls prf seed length */ |
wolfSSL | 0:9d17e4342598 | 598 | ID_LEN = 32, /* session id length */ |
wolfSSL | 0:9d17e4342598 | 599 | MAX_COOKIE_LEN = 32, /* max dtls cookie size */ |
wolfSSL | 0:9d17e4342598 | 600 | COOKIE_SZ = 20, /* use a 20 byte cookie */ |
wolfSSL | 0:9d17e4342598 | 601 | SUITE_LEN = 2, /* cipher suite sz length */ |
wolfSSL | 0:9d17e4342598 | 602 | ENUM_LEN = 1, /* always a byte */ |
wolfSSL | 0:9d17e4342598 | 603 | OPAQUE8_LEN = 1, /* 1 byte */ |
wolfSSL | 0:9d17e4342598 | 604 | OPAQUE16_LEN = 2, /* 2 bytes */ |
wolfSSL | 0:9d17e4342598 | 605 | OPAQUE24_LEN = 3, /* 3 bytes */ |
wolfSSL | 0:9d17e4342598 | 606 | COMP_LEN = 1, /* compression length */ |
wolfSSL | 0:9d17e4342598 | 607 | CURVE_LEN = 2, /* ecc named curve length */ |
wolfSSL | 0:9d17e4342598 | 608 | SERVER_ID_LEN = 20, /* server session id length */ |
wolfSSL | 0:9d17e4342598 | 609 | |
wolfSSL | 0:9d17e4342598 | 610 | HANDSHAKE_HEADER_SZ = 4, /* type + length(3) */ |
wolfSSL | 0:9d17e4342598 | 611 | RECORD_HEADER_SZ = 5, /* type + version + len(2) */ |
wolfSSL | 0:9d17e4342598 | 612 | CERT_HEADER_SZ = 3, /* always 3 bytes */ |
wolfSSL | 0:9d17e4342598 | 613 | REQ_HEADER_SZ = 2, /* cert request header sz */ |
wolfSSL | 0:9d17e4342598 | 614 | HINT_LEN_SZ = 2, /* length of hint size field */ |
wolfSSL | 0:9d17e4342598 | 615 | TRUNCATED_HMAC_SZ = 10, /* length of hmac w/ truncated hmac extension */ |
wolfSSL | 0:9d17e4342598 | 616 | HELLO_EXT_TYPE_SZ = 2, /* length of a hello extension type */ |
wolfSSL | 0:9d17e4342598 | 617 | HELLO_EXT_SZ = 8, /* total length of the lazy hello extensions */ |
wolfSSL | 0:9d17e4342598 | 618 | HELLO_EXT_LEN = 6, /* length of the lazy hello extensions */ |
wolfSSL | 0:9d17e4342598 | 619 | HELLO_EXT_SIGALGO_SZ = 2, /* length of signature algo extension */ |
wolfSSL | 0:9d17e4342598 | 620 | HELLO_EXT_SIGALGO_MAX = 32, /* number of items in the signature algo list */ |
wolfSSL | 0:9d17e4342598 | 621 | |
wolfSSL | 0:9d17e4342598 | 622 | DTLS_HANDSHAKE_HEADER_SZ = 12, /* normal + seq(2) + offset(3) + length(3) */ |
wolfSSL | 0:9d17e4342598 | 623 | DTLS_RECORD_HEADER_SZ = 13, /* normal + epoch(2) + seq_num(6) */ |
wolfSSL | 0:9d17e4342598 | 624 | DTLS_HANDSHAKE_EXTRA = 8, /* diff from normal */ |
wolfSSL | 0:9d17e4342598 | 625 | DTLS_RECORD_EXTRA = 8, /* diff from normal */ |
wolfSSL | 0:9d17e4342598 | 626 | DTLS_HANDSHAKE_SEQ_SZ = 2, /* handshake header sequence number */ |
wolfSSL | 0:9d17e4342598 | 627 | DTLS_HANDSHAKE_FRAG_SZ = 3, /* fragment offset and length are 24 bit */ |
wolfSSL | 0:9d17e4342598 | 628 | DTLS_POOL_SZ = 5, /* buffers to hold in the retry pool */ |
wolfSSL | 0:9d17e4342598 | 629 | |
wolfSSL | 0:9d17e4342598 | 630 | FINISHED_LABEL_SZ = 15, /* TLS finished label size */ |
wolfSSL | 0:9d17e4342598 | 631 | TLS_FINISHED_SZ = 12, /* TLS has a shorter size */ |
wolfSSL | 0:9d17e4342598 | 632 | MASTER_LABEL_SZ = 13, /* TLS master secret label sz */ |
wolfSSL | 0:9d17e4342598 | 633 | KEY_LABEL_SZ = 13, /* TLS key block expansion sz */ |
wolfSSL | 0:9d17e4342598 | 634 | MAX_PRF_HALF = 128, /* Maximum half secret len */ |
wolfSSL | 0:9d17e4342598 | 635 | MAX_PRF_LABSEED = 128, /* Maximum label + seed len */ |
wolfSSL | 0:9d17e4342598 | 636 | MAX_PRF_DIG = 224, /* Maximum digest len */ |
wolfSSL | 0:9d17e4342598 | 637 | MAX_REQUEST_SZ = 256, /* Maximum cert req len (no auth yet */ |
wolfSSL | 0:9d17e4342598 | 638 | SESSION_FLUSH_COUNT = 256, /* Flush session cache unless user turns off */ |
wolfSSL | 0:9d17e4342598 | 639 | |
wolfSSL | 0:9d17e4342598 | 640 | RC4_KEY_SIZE = 16, /* always 128bit */ |
wolfSSL | 0:9d17e4342598 | 641 | DES_KEY_SIZE = 8, /* des */ |
wolfSSL | 0:9d17e4342598 | 642 | DES3_KEY_SIZE = 24, /* 3 des ede */ |
wolfSSL | 0:9d17e4342598 | 643 | DES_IV_SIZE = DES_BLOCK_SIZE, |
wolfSSL | 0:9d17e4342598 | 644 | AES_256_KEY_SIZE = 32, /* for 256 bit */ |
wolfSSL | 0:9d17e4342598 | 645 | AES_192_KEY_SIZE = 24, /* for 192 bit */ |
wolfSSL | 0:9d17e4342598 | 646 | AES_IV_SIZE = 16, /* always block size */ |
wolfSSL | 0:9d17e4342598 | 647 | AES_128_KEY_SIZE = 16, /* for 128 bit */ |
wolfSSL | 0:9d17e4342598 | 648 | |
wolfSSL | 0:9d17e4342598 | 649 | AEAD_SEQ_OFFSET = 4, /* Auth Data: Sequence number */ |
wolfSSL | 0:9d17e4342598 | 650 | AEAD_TYPE_OFFSET = 8, /* Auth Data: Type */ |
wolfSSL | 0:9d17e4342598 | 651 | AEAD_VMAJ_OFFSET = 9, /* Auth Data: Major Version */ |
wolfSSL | 0:9d17e4342598 | 652 | AEAD_VMIN_OFFSET = 10, /* Auth Data: Minor Version */ |
wolfSSL | 0:9d17e4342598 | 653 | AEAD_LEN_OFFSET = 11, /* Auth Data: Length */ |
wolfSSL | 0:9d17e4342598 | 654 | AEAD_AUTH_DATA_SZ = 13, /* Size of the data to authenticate */ |
wolfSSL | 0:9d17e4342598 | 655 | AEAD_IMP_IV_SZ = 4, /* Size of the implicit IV */ |
wolfSSL | 0:9d17e4342598 | 656 | AEAD_EXP_IV_SZ = 8, /* Size of the explicit IV */ |
wolfSSL | 0:9d17e4342598 | 657 | AEAD_NONCE_SZ = AEAD_EXP_IV_SZ + AEAD_IMP_IV_SZ, |
wolfSSL | 0:9d17e4342598 | 658 | |
wolfSSL | 0:9d17e4342598 | 659 | AES_GCM_AUTH_SZ = 16, /* AES-GCM Auth Tag length */ |
wolfSSL | 0:9d17e4342598 | 660 | AES_CCM_16_AUTH_SZ = 16, /* AES-CCM-16 Auth Tag length */ |
wolfSSL | 0:9d17e4342598 | 661 | AES_CCM_8_AUTH_SZ = 8, /* AES-CCM-8 Auth Tag Length */ |
wolfSSL | 0:9d17e4342598 | 662 | |
wolfSSL | 0:9d17e4342598 | 663 | CAMELLIA_128_KEY_SIZE = 16, /* for 128 bit */ |
wolfSSL | 0:9d17e4342598 | 664 | CAMELLIA_192_KEY_SIZE = 24, /* for 192 bit */ |
wolfSSL | 0:9d17e4342598 | 665 | CAMELLIA_256_KEY_SIZE = 32, /* for 256 bit */ |
wolfSSL | 0:9d17e4342598 | 666 | CAMELLIA_IV_SIZE = 16, /* always block size */ |
wolfSSL | 0:9d17e4342598 | 667 | |
wolfSSL | 0:9d17e4342598 | 668 | HC_128_KEY_SIZE = 16, /* 128 bits */ |
wolfSSL | 0:9d17e4342598 | 669 | HC_128_IV_SIZE = 16, /* also 128 bits */ |
wolfSSL | 0:9d17e4342598 | 670 | |
wolfSSL | 0:9d17e4342598 | 671 | RABBIT_KEY_SIZE = 16, /* 128 bits */ |
wolfSSL | 0:9d17e4342598 | 672 | RABBIT_IV_SIZE = 8, /* 64 bits for iv */ |
wolfSSL | 0:9d17e4342598 | 673 | |
wolfSSL | 0:9d17e4342598 | 674 | EVP_SALT_SIZE = 8, /* evp salt size 64 bits */ |
wolfSSL | 0:9d17e4342598 | 675 | |
wolfSSL | 0:9d17e4342598 | 676 | ECDHE_SIZE = 32, /* ECHDE server size defaults to 256 bit */ |
wolfSSL | 0:9d17e4342598 | 677 | MAX_EXPORT_ECC_SZ = 256, /* Export ANS X9.62 max future size */ |
wolfSSL | 0:9d17e4342598 | 678 | |
wolfSSL | 0:9d17e4342598 | 679 | MAX_HELLO_SZ = 128, /* max client or server hello */ |
wolfSSL | 0:9d17e4342598 | 680 | MAX_CERT_VERIFY_SZ = 1024, /* max */ |
wolfSSL | 0:9d17e4342598 | 681 | CLIENT_HELLO_FIRST = 35, /* Protocol + RAN_LEN + sizeof(id_len) */ |
wolfSSL | 0:9d17e4342598 | 682 | MAX_SUITE_NAME = 48, /* maximum length of cipher suite string */ |
wolfSSL | 0:9d17e4342598 | 683 | DEFAULT_TIMEOUT = 500, /* default resumption timeout in seconds */ |
wolfSSL | 0:9d17e4342598 | 684 | |
wolfSSL | 0:9d17e4342598 | 685 | DTLS_TIMEOUT_INIT = 1, /* default timeout init for DTLS receive */ |
wolfSSL | 0:9d17e4342598 | 686 | DTLS_TIMEOUT_MAX = 64, /* default max timeout for DTLS receive */ |
wolfSSL | 0:9d17e4342598 | 687 | DTLS_TIMEOUT_MULTIPLIER = 2, /* default timeout multiplier for DTLS recv */ |
wolfSSL | 0:9d17e4342598 | 688 | |
wolfSSL | 0:9d17e4342598 | 689 | MAX_PSK_ID_LEN = 128, /* max psk identity/hint supported */ |
wolfSSL | 0:9d17e4342598 | 690 | MAX_PSK_KEY_LEN = 64, /* max psk key supported */ |
wolfSSL | 0:9d17e4342598 | 691 | |
wolfSSL | 0:9d17e4342598 | 692 | MAX_CYASSL_FILE_SIZE = 1024 * 1024 * 4, /* 4 mb file size alloc limit */ |
wolfSSL | 0:9d17e4342598 | 693 | |
wolfSSL | 0:9d17e4342598 | 694 | #ifdef FORTRESS |
wolfSSL | 0:9d17e4342598 | 695 | MAX_EX_DATA = 3, /* allow for three items of ex_data */ |
wolfSSL | 0:9d17e4342598 | 696 | #endif |
wolfSSL | 0:9d17e4342598 | 697 | |
wolfSSL | 0:9d17e4342598 | 698 | MAX_X509_SIZE = 2048, /* max static x509 buffer size */ |
wolfSSL | 0:9d17e4342598 | 699 | CERT_MIN_SIZE = 256, /* min PEM cert size with header/footer */ |
wolfSSL | 0:9d17e4342598 | 700 | MAX_FILENAME_SZ = 256, /* max file name length */ |
wolfSSL | 0:9d17e4342598 | 701 | FILE_BUFFER_SIZE = 1024, /* default static file buffer size for input, |
wolfSSL | 0:9d17e4342598 | 702 | will use dynamic buffer if not big enough */ |
wolfSSL | 0:9d17e4342598 | 703 | |
wolfSSL | 0:9d17e4342598 | 704 | MAX_NTRU_PUB_KEY_SZ = 1027, /* NTRU max for now */ |
wolfSSL | 0:9d17e4342598 | 705 | MAX_NTRU_ENCRYPT_SZ = 1027, /* NTRU max for now */ |
wolfSSL | 0:9d17e4342598 | 706 | MAX_NTRU_BITS = 256, /* max symmetric bit strength */ |
wolfSSL | 0:9d17e4342598 | 707 | NO_SNIFF = 0, /* not sniffing */ |
wolfSSL | 0:9d17e4342598 | 708 | SNIFF = 1, /* currently sniffing */ |
wolfSSL | 0:9d17e4342598 | 709 | |
wolfSSL | 0:9d17e4342598 | 710 | HASH_SIG_SIZE = 2, /* default SHA1 RSA */ |
wolfSSL | 0:9d17e4342598 | 711 | |
wolfSSL | 0:9d17e4342598 | 712 | NO_CAVIUM_DEVICE = -2, /* invalid cavium device id */ |
wolfSSL | 0:9d17e4342598 | 713 | |
wolfSSL | 0:9d17e4342598 | 714 | NO_COPY = 0, /* should we copy static buffer for write */ |
wolfSSL | 0:9d17e4342598 | 715 | COPY = 1 /* should we copy static buffer for write */ |
wolfSSL | 0:9d17e4342598 | 716 | }; |
wolfSSL | 0:9d17e4342598 | 717 | |
wolfSSL | 0:9d17e4342598 | 718 | |
wolfSSL | 0:9d17e4342598 | 719 | #ifdef SESSION_INDEX |
wolfSSL | 0:9d17e4342598 | 720 | /* Shift values for making a session index */ |
wolfSSL | 0:9d17e4342598 | 721 | #define SESSIDX_ROW_SHIFT 4 |
wolfSSL | 0:9d17e4342598 | 722 | #define SESSIDX_IDX_MASK 0x0F |
wolfSSL | 0:9d17e4342598 | 723 | #endif |
wolfSSL | 0:9d17e4342598 | 724 | |
wolfSSL | 0:9d17e4342598 | 725 | |
wolfSSL | 0:9d17e4342598 | 726 | /* max cert chain peer depth */ |
wolfSSL | 0:9d17e4342598 | 727 | #ifndef MAX_CHAIN_DEPTH |
wolfSSL | 0:9d17e4342598 | 728 | #define MAX_CHAIN_DEPTH 9 |
wolfSSL | 0:9d17e4342598 | 729 | #endif |
wolfSSL | 0:9d17e4342598 | 730 | |
wolfSSL | 0:9d17e4342598 | 731 | |
wolfSSL | 0:9d17e4342598 | 732 | /* don't use extra 3/4k stack space unless need to */ |
wolfSSL | 0:9d17e4342598 | 733 | #ifdef HAVE_NTRU |
wolfSSL | 0:9d17e4342598 | 734 | #define MAX_ENCRYPT_SZ MAX_NTRU_ENCRYPT_SZ |
wolfSSL | 0:9d17e4342598 | 735 | #else |
wolfSSL | 0:9d17e4342598 | 736 | #define MAX_ENCRYPT_SZ ENCRYPT_LEN |
wolfSSL | 0:9d17e4342598 | 737 | #endif |
wolfSSL | 0:9d17e4342598 | 738 | |
wolfSSL | 0:9d17e4342598 | 739 | |
wolfSSL | 0:9d17e4342598 | 740 | /* states */ |
wolfSSL | 0:9d17e4342598 | 741 | enum states { |
wolfSSL | 0:9d17e4342598 | 742 | NULL_STATE = 0, |
wolfSSL | 0:9d17e4342598 | 743 | |
wolfSSL | 0:9d17e4342598 | 744 | SERVER_HELLOVERIFYREQUEST_COMPLETE, |
wolfSSL | 0:9d17e4342598 | 745 | SERVER_HELLO_COMPLETE, |
wolfSSL | 0:9d17e4342598 | 746 | SERVER_CERT_COMPLETE, |
wolfSSL | 0:9d17e4342598 | 747 | SERVER_KEYEXCHANGE_COMPLETE, |
wolfSSL | 0:9d17e4342598 | 748 | SERVER_HELLODONE_COMPLETE, |
wolfSSL | 0:9d17e4342598 | 749 | SERVER_FINISHED_COMPLETE, |
wolfSSL | 0:9d17e4342598 | 750 | |
wolfSSL | 0:9d17e4342598 | 751 | CLIENT_HELLO_COMPLETE, |
wolfSSL | 0:9d17e4342598 | 752 | CLIENT_KEYEXCHANGE_COMPLETE, |
wolfSSL | 0:9d17e4342598 | 753 | CLIENT_FINISHED_COMPLETE, |
wolfSSL | 0:9d17e4342598 | 754 | |
wolfSSL | 0:9d17e4342598 | 755 | HANDSHAKE_DONE |
wolfSSL | 0:9d17e4342598 | 756 | }; |
wolfSSL | 0:9d17e4342598 | 757 | |
wolfSSL | 0:9d17e4342598 | 758 | |
wolfSSL | 0:9d17e4342598 | 759 | #if defined(__GNUC__) |
wolfSSL | 0:9d17e4342598 | 760 | #define CYASSL_PACK __attribute__ ((packed)) |
wolfSSL | 0:9d17e4342598 | 761 | #else |
wolfSSL | 0:9d17e4342598 | 762 | #define CYASSL_PACK |
wolfSSL | 0:9d17e4342598 | 763 | #endif |
wolfSSL | 0:9d17e4342598 | 764 | |
wolfSSL | 0:9d17e4342598 | 765 | /* SSL Version */ |
wolfSSL | 0:9d17e4342598 | 766 | typedef struct ProtocolVersion { |
wolfSSL | 0:9d17e4342598 | 767 | byte major; |
wolfSSL | 0:9d17e4342598 | 768 | byte minor; |
wolfSSL | 0:9d17e4342598 | 769 | } CYASSL_PACK ProtocolVersion; |
wolfSSL | 0:9d17e4342598 | 770 | |
wolfSSL | 0:9d17e4342598 | 771 | |
wolfSSL | 0:9d17e4342598 | 772 | CYASSL_LOCAL ProtocolVersion MakeSSLv3(void); |
wolfSSL | 0:9d17e4342598 | 773 | CYASSL_LOCAL ProtocolVersion MakeTLSv1(void); |
wolfSSL | 0:9d17e4342598 | 774 | CYASSL_LOCAL ProtocolVersion MakeTLSv1_1(void); |
wolfSSL | 0:9d17e4342598 | 775 | CYASSL_LOCAL ProtocolVersion MakeTLSv1_2(void); |
wolfSSL | 0:9d17e4342598 | 776 | |
wolfSSL | 0:9d17e4342598 | 777 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 778 | CYASSL_LOCAL ProtocolVersion MakeDTLSv1(void); |
wolfSSL | 0:9d17e4342598 | 779 | CYASSL_LOCAL ProtocolVersion MakeDTLSv1_2(void); |
wolfSSL | 0:9d17e4342598 | 780 | #endif |
wolfSSL | 0:9d17e4342598 | 781 | |
wolfSSL | 0:9d17e4342598 | 782 | |
wolfSSL | 0:9d17e4342598 | 783 | enum BIO_TYPE { |
wolfSSL | 0:9d17e4342598 | 784 | BIO_BUFFER = 1, |
wolfSSL | 0:9d17e4342598 | 785 | BIO_SOCKET = 2, |
wolfSSL | 0:9d17e4342598 | 786 | BIO_SSL = 3, |
wolfSSL | 0:9d17e4342598 | 787 | BIO_MEMORY = 4 |
wolfSSL | 0:9d17e4342598 | 788 | }; |
wolfSSL | 0:9d17e4342598 | 789 | |
wolfSSL | 0:9d17e4342598 | 790 | |
wolfSSL | 0:9d17e4342598 | 791 | /* CyaSSL BIO_METHOD type */ |
wolfSSL | 0:9d17e4342598 | 792 | struct CYASSL_BIO_METHOD { |
wolfSSL | 0:9d17e4342598 | 793 | byte type; /* method type */ |
wolfSSL | 0:9d17e4342598 | 794 | }; |
wolfSSL | 0:9d17e4342598 | 795 | |
wolfSSL | 0:9d17e4342598 | 796 | |
wolfSSL | 0:9d17e4342598 | 797 | /* CyaSSL BIO type */ |
wolfSSL | 0:9d17e4342598 | 798 | struct CYASSL_BIO { |
wolfSSL | 0:9d17e4342598 | 799 | byte type; /* method type */ |
wolfSSL | 0:9d17e4342598 | 800 | byte close; /* close flag */ |
wolfSSL | 0:9d17e4342598 | 801 | byte eof; /* eof flag */ |
wolfSSL | 0:9d17e4342598 | 802 | CYASSL* ssl; /* possible associated ssl */ |
wolfSSL | 0:9d17e4342598 | 803 | byte* mem; /* memory buffer */ |
wolfSSL | 0:9d17e4342598 | 804 | int memLen; /* memory buffer length */ |
wolfSSL | 0:9d17e4342598 | 805 | int fd; /* possible file descriptor */ |
wolfSSL | 0:9d17e4342598 | 806 | CYASSL_BIO* prev; /* previous in chain */ |
wolfSSL | 0:9d17e4342598 | 807 | CYASSL_BIO* next; /* next in chain */ |
wolfSSL | 0:9d17e4342598 | 808 | }; |
wolfSSL | 0:9d17e4342598 | 809 | |
wolfSSL | 0:9d17e4342598 | 810 | |
wolfSSL | 0:9d17e4342598 | 811 | /* CyaSSL method type */ |
wolfSSL | 0:9d17e4342598 | 812 | struct CYASSL_METHOD { |
wolfSSL | 0:9d17e4342598 | 813 | ProtocolVersion version; |
wolfSSL | 0:9d17e4342598 | 814 | byte side; /* connection side, server or client */ |
wolfSSL | 0:9d17e4342598 | 815 | byte downgrade; /* whether to downgrade version, default no */ |
wolfSSL | 0:9d17e4342598 | 816 | }; |
wolfSSL | 0:9d17e4342598 | 817 | |
wolfSSL | 0:9d17e4342598 | 818 | |
wolfSSL | 0:9d17e4342598 | 819 | /* defautls to client */ |
wolfSSL | 0:9d17e4342598 | 820 | CYASSL_LOCAL void InitSSL_Method(CYASSL_METHOD*, ProtocolVersion); |
wolfSSL | 0:9d17e4342598 | 821 | |
wolfSSL | 0:9d17e4342598 | 822 | /* for sniffer */ |
wolfSSL | 0:9d17e4342598 | 823 | CYASSL_LOCAL int DoFinished(CYASSL* ssl, const byte* input, word32* inOutIdx, |
wolfSSL | 0:9d17e4342598 | 824 | word32 size, word32 totalSz, int sniff); |
wolfSSL | 0:9d17e4342598 | 825 | CYASSL_LOCAL int DoApplicationData(CYASSL* ssl, byte* input, word32* inOutIdx); |
wolfSSL | 0:9d17e4342598 | 826 | |
wolfSSL | 0:9d17e4342598 | 827 | |
wolfSSL | 0:9d17e4342598 | 828 | /* CyaSSL buffer type */ |
wolfSSL | 0:9d17e4342598 | 829 | typedef struct buffer { |
wolfSSL | 0:9d17e4342598 | 830 | word32 length; |
wolfSSL | 0:9d17e4342598 | 831 | byte* buffer; |
wolfSSL | 0:9d17e4342598 | 832 | } buffer; |
wolfSSL | 0:9d17e4342598 | 833 | |
wolfSSL | 0:9d17e4342598 | 834 | |
wolfSSL | 0:9d17e4342598 | 835 | enum { |
wolfSSL | 0:9d17e4342598 | 836 | FORCED_FREE = 1, |
wolfSSL | 0:9d17e4342598 | 837 | NO_FORCED_FREE = 0 |
wolfSSL | 0:9d17e4342598 | 838 | }; |
wolfSSL | 0:9d17e4342598 | 839 | |
wolfSSL | 0:9d17e4342598 | 840 | |
wolfSSL | 0:9d17e4342598 | 841 | /* only use compression extra if using compression */ |
wolfSSL | 0:9d17e4342598 | 842 | #ifdef HAVE_LIBZ |
wolfSSL | 0:9d17e4342598 | 843 | #define COMP_EXTRA MAX_COMP_EXTRA |
wolfSSL | 0:9d17e4342598 | 844 | #else |
wolfSSL | 0:9d17e4342598 | 845 | #define COMP_EXTRA 0 |
wolfSSL | 0:9d17e4342598 | 846 | #endif |
wolfSSL | 0:9d17e4342598 | 847 | |
wolfSSL | 0:9d17e4342598 | 848 | /* only the sniffer needs space in the buffer for extra MTU record(s) */ |
wolfSSL | 0:9d17e4342598 | 849 | #ifdef CYASSL_SNIFFER |
wolfSSL | 0:9d17e4342598 | 850 | #define MTU_EXTRA MAX_MTU * 3 |
wolfSSL | 0:9d17e4342598 | 851 | #else |
wolfSSL | 0:9d17e4342598 | 852 | #define MTU_EXTRA 0 |
wolfSSL | 0:9d17e4342598 | 853 | #endif |
wolfSSL | 0:9d17e4342598 | 854 | |
wolfSSL | 0:9d17e4342598 | 855 | |
wolfSSL | 0:9d17e4342598 | 856 | /* embedded callbacks require large static buffers, make sure on */ |
wolfSSL | 0:9d17e4342598 | 857 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 858 | #undef LARGE_STATIC_BUFFERS |
wolfSSL | 0:9d17e4342598 | 859 | #define LARGE_STATIC_BUFFERS |
wolfSSL | 0:9d17e4342598 | 860 | #endif |
wolfSSL | 0:9d17e4342598 | 861 | |
wolfSSL | 0:9d17e4342598 | 862 | |
wolfSSL | 0:9d17e4342598 | 863 | /* give user option to use 16K static buffers */ |
wolfSSL | 0:9d17e4342598 | 864 | #if defined(LARGE_STATIC_BUFFERS) |
wolfSSL | 0:9d17e4342598 | 865 | #define RECORD_SIZE MAX_RECORD_SIZE |
wolfSSL | 0:9d17e4342598 | 866 | #else |
wolfSSL | 0:9d17e4342598 | 867 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 868 | #define RECORD_SIZE MAX_MTU |
wolfSSL | 0:9d17e4342598 | 869 | #else |
wolfSSL | 0:9d17e4342598 | 870 | #define RECORD_SIZE 128 |
wolfSSL | 0:9d17e4342598 | 871 | #endif |
wolfSSL | 0:9d17e4342598 | 872 | #endif |
wolfSSL | 0:9d17e4342598 | 873 | |
wolfSSL | 0:9d17e4342598 | 874 | |
wolfSSL | 0:9d17e4342598 | 875 | /* user option to turn off 16K output option */ |
wolfSSL | 0:9d17e4342598 | 876 | /* if using small static buffers (default) and SSL_write tries to write data |
wolfSSL | 0:9d17e4342598 | 877 | larger than the record we have, dynamically get it, unless user says only |
wolfSSL | 0:9d17e4342598 | 878 | write in static buffer chuncks */ |
wolfSSL | 0:9d17e4342598 | 879 | #ifndef STATIC_CHUNKS_ONLY |
wolfSSL | 0:9d17e4342598 | 880 | #define OUTPUT_RECORD_SIZE MAX_RECORD_SIZE |
wolfSSL | 0:9d17e4342598 | 881 | #else |
wolfSSL | 0:9d17e4342598 | 882 | #define OUTPUT_RECORD_SIZE RECORD_SIZE |
wolfSSL | 0:9d17e4342598 | 883 | #endif |
wolfSSL | 0:9d17e4342598 | 884 | |
wolfSSL | 0:9d17e4342598 | 885 | /* CyaSSL input buffer |
wolfSSL | 0:9d17e4342598 | 886 | |
wolfSSL | 0:9d17e4342598 | 887 | RFC 2246: |
wolfSSL | 0:9d17e4342598 | 888 | |
wolfSSL | 0:9d17e4342598 | 889 | length |
wolfSSL | 0:9d17e4342598 | 890 | The length (in bytes) of the following TLSPlaintext.fragment. |
wolfSSL | 0:9d17e4342598 | 891 | The length should not exceed 2^14. |
wolfSSL | 0:9d17e4342598 | 892 | */ |
wolfSSL | 0:9d17e4342598 | 893 | #if defined(LARGE_STATIC_BUFFERS) |
wolfSSL | 0:9d17e4342598 | 894 | #define STATIC_BUFFER_LEN RECORD_HEADER_SZ + RECORD_SIZE + COMP_EXTRA + \ |
wolfSSL | 0:9d17e4342598 | 895 | MTU_EXTRA + MAX_MSG_EXTRA |
wolfSSL | 0:9d17e4342598 | 896 | #else |
wolfSSL | 0:9d17e4342598 | 897 | /* don't fragment memory from the record header */ |
wolfSSL | 0:9d17e4342598 | 898 | #define STATIC_BUFFER_LEN RECORD_HEADER_SZ |
wolfSSL | 0:9d17e4342598 | 899 | #endif |
wolfSSL | 0:9d17e4342598 | 900 | |
wolfSSL | 0:9d17e4342598 | 901 | typedef struct { |
wolfSSL | 0:9d17e4342598 | 902 | word32 length; /* total buffer length used */ |
wolfSSL | 0:9d17e4342598 | 903 | word32 idx; /* idx to part of length already consumed */ |
wolfSSL | 0:9d17e4342598 | 904 | byte* buffer; /* place holder for static or dynamic buffer */ |
wolfSSL | 0:9d17e4342598 | 905 | word32 bufferSize; /* current buffer size */ |
wolfSSL | 0:9d17e4342598 | 906 | ALIGN16 byte staticBuffer[STATIC_BUFFER_LEN]; |
wolfSSL | 0:9d17e4342598 | 907 | byte dynamicFlag; /* dynamic memory currently in use */ |
wolfSSL | 0:9d17e4342598 | 908 | byte offset; /* alignment offset attempt */ |
wolfSSL | 0:9d17e4342598 | 909 | } bufferStatic; |
wolfSSL | 0:9d17e4342598 | 910 | |
wolfSSL | 0:9d17e4342598 | 911 | /* Cipher Suites holder */ |
wolfSSL | 0:9d17e4342598 | 912 | typedef struct Suites { |
wolfSSL | 0:9d17e4342598 | 913 | int setSuites; /* user set suites from default */ |
wolfSSL | 0:9d17e4342598 | 914 | byte suites[MAX_SUITE_SZ]; |
wolfSSL | 0:9d17e4342598 | 915 | word16 suiteSz; /* suite length in bytes */ |
wolfSSL | 0:9d17e4342598 | 916 | byte hashSigAlgo[HELLO_EXT_SIGALGO_MAX]; /* sig/algo to offer */ |
wolfSSL | 0:9d17e4342598 | 917 | word16 hashSigAlgoSz; /* SigAlgo extension length in bytes */ |
wolfSSL | 0:9d17e4342598 | 918 | byte hashAlgo; /* selected hash algorithm */ |
wolfSSL | 0:9d17e4342598 | 919 | byte sigAlgo; /* selected sig algorithm */ |
wolfSSL | 0:9d17e4342598 | 920 | } Suites; |
wolfSSL | 0:9d17e4342598 | 921 | |
wolfSSL | 0:9d17e4342598 | 922 | |
wolfSSL | 0:9d17e4342598 | 923 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 924 | void InitSuites(Suites*, ProtocolVersion, |
wolfSSL | 0:9d17e4342598 | 925 | byte, byte, byte, byte, byte, byte, int); |
wolfSSL | 0:9d17e4342598 | 926 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 927 | int SetCipherList(Suites*, const char* list); |
wolfSSL | 0:9d17e4342598 | 928 | |
wolfSSL | 0:9d17e4342598 | 929 | #ifndef PSK_TYPES_DEFINED |
wolfSSL | 0:9d17e4342598 | 930 | typedef unsigned int (*psk_client_callback)(CYASSL*, const char*, char*, |
wolfSSL | 0:9d17e4342598 | 931 | unsigned int, unsigned char*, unsigned int); |
wolfSSL | 0:9d17e4342598 | 932 | typedef unsigned int (*psk_server_callback)(CYASSL*, const char*, |
wolfSSL | 0:9d17e4342598 | 933 | unsigned char*, unsigned int); |
wolfSSL | 0:9d17e4342598 | 934 | #endif /* PSK_TYPES_DEFINED */ |
wolfSSL | 0:9d17e4342598 | 935 | |
wolfSSL | 0:9d17e4342598 | 936 | |
wolfSSL | 0:9d17e4342598 | 937 | #ifndef CYASSL_USER_IO |
wolfSSL | 0:9d17e4342598 | 938 | /* default IO callbacks */ |
wolfSSL | 0:9d17e4342598 | 939 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 940 | int EmbedReceive(CYASSL *ssl, char *buf, int sz, void *ctx); |
wolfSSL | 0:9d17e4342598 | 941 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 942 | int EmbedSend(CYASSL *ssl, char *buf, int sz, void *ctx); |
wolfSSL | 0:9d17e4342598 | 943 | |
wolfSSL | 0:9d17e4342598 | 944 | #ifdef HAVE_OCSP |
wolfSSL | 0:9d17e4342598 | 945 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 946 | int EmbedOcspLookup(void*, const char*, int, byte*, int, byte**); |
wolfSSL | 0:9d17e4342598 | 947 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 948 | void EmbedOcspRespFree(void*, byte*); |
wolfSSL | 0:9d17e4342598 | 949 | #endif |
wolfSSL | 0:9d17e4342598 | 950 | |
wolfSSL | 0:9d17e4342598 | 951 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 952 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 953 | int EmbedReceiveFrom(CYASSL *ssl, char *buf, int sz, void *ctx); |
wolfSSL | 0:9d17e4342598 | 954 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 955 | int EmbedSendTo(CYASSL *ssl, char *buf, int sz, void *ctx); |
wolfSSL | 0:9d17e4342598 | 956 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 957 | int EmbedGenerateCookie(CYASSL* ssl, byte *buf, int sz, void *ctx); |
wolfSSL | 0:9d17e4342598 | 958 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 959 | int IsUDP(void*); |
wolfSSL | 0:9d17e4342598 | 960 | #endif /* CYASSL_DTLS */ |
wolfSSL | 0:9d17e4342598 | 961 | #endif /* CYASSL_USER_IO */ |
wolfSSL | 0:9d17e4342598 | 962 | |
wolfSSL | 0:9d17e4342598 | 963 | #ifdef HAVE_NETX |
wolfSSL | 0:9d17e4342598 | 964 | CYASSL_LOCAL int NetX_Receive(CYASSL *ssl, char *buf, int sz, void *ctx); |
wolfSSL | 0:9d17e4342598 | 965 | CYASSL_LOCAL int NetX_Send(CYASSL *ssl, char *buf, int sz, void *ctx); |
wolfSSL | 0:9d17e4342598 | 966 | #endif /* HAVE_NETX */ |
wolfSSL | 0:9d17e4342598 | 967 | |
wolfSSL | 0:9d17e4342598 | 968 | |
wolfSSL | 0:9d17e4342598 | 969 | /* CyaSSL Cipher type just points back to SSL */ |
wolfSSL | 0:9d17e4342598 | 970 | struct CYASSL_CIPHER { |
wolfSSL | 0:9d17e4342598 | 971 | CYASSL* ssl; |
wolfSSL | 0:9d17e4342598 | 972 | }; |
wolfSSL | 0:9d17e4342598 | 973 | |
wolfSSL | 0:9d17e4342598 | 974 | |
wolfSSL | 0:9d17e4342598 | 975 | typedef struct OCSP_Entry OCSP_Entry; |
wolfSSL | 0:9d17e4342598 | 976 | |
wolfSSL | 0:9d17e4342598 | 977 | #ifdef SHA_DIGEST_SIZE |
wolfSSL | 0:9d17e4342598 | 978 | #define OCSP_DIGEST_SIZE SHA_DIGEST_SIZE |
wolfSSL | 0:9d17e4342598 | 979 | #else |
wolfSSL | 0:9d17e4342598 | 980 | #define OCSP_DIGEST_SIZE 160 |
wolfSSL | 0:9d17e4342598 | 981 | #endif |
wolfSSL | 0:9d17e4342598 | 982 | |
wolfSSL | 0:9d17e4342598 | 983 | #ifdef NO_ASN |
wolfSSL | 0:9d17e4342598 | 984 | /* no_asn won't have */ |
wolfSSL | 0:9d17e4342598 | 985 | typedef struct CertStatus CertStatus; |
wolfSSL | 0:9d17e4342598 | 986 | #endif |
wolfSSL | 0:9d17e4342598 | 987 | |
wolfSSL | 0:9d17e4342598 | 988 | struct OCSP_Entry { |
wolfSSL | 0:9d17e4342598 | 989 | OCSP_Entry* next; /* next entry */ |
wolfSSL | 0:9d17e4342598 | 990 | byte issuerHash[OCSP_DIGEST_SIZE]; /* issuer hash */ |
wolfSSL | 0:9d17e4342598 | 991 | byte issuerKeyHash[OCSP_DIGEST_SIZE]; /* issuer public key hash */ |
wolfSSL | 0:9d17e4342598 | 992 | CertStatus* status; /* OCSP response list */ |
wolfSSL | 0:9d17e4342598 | 993 | int totalStatus; /* number on list */ |
wolfSSL | 0:9d17e4342598 | 994 | }; |
wolfSSL | 0:9d17e4342598 | 995 | |
wolfSSL | 0:9d17e4342598 | 996 | |
wolfSSL | 0:9d17e4342598 | 997 | #ifndef HAVE_OCSP |
wolfSSL | 0:9d17e4342598 | 998 | typedef struct CYASSL_OCSP CYASSL_OCSP; |
wolfSSL | 0:9d17e4342598 | 999 | #endif |
wolfSSL | 0:9d17e4342598 | 1000 | |
wolfSSL | 0:9d17e4342598 | 1001 | /* CyaSSL OCSP controller */ |
wolfSSL | 0:9d17e4342598 | 1002 | struct CYASSL_OCSP { |
wolfSSL | 0:9d17e4342598 | 1003 | CYASSL_CERT_MANAGER* cm; /* pointer back to cert manager */ |
wolfSSL | 0:9d17e4342598 | 1004 | OCSP_Entry* ocspList; /* OCSP response list */ |
wolfSSL | 0:9d17e4342598 | 1005 | CyaSSL_Mutex ocspLock; /* OCSP list lock */ |
wolfSSL | 0:9d17e4342598 | 1006 | }; |
wolfSSL | 0:9d17e4342598 | 1007 | |
wolfSSL | 0:9d17e4342598 | 1008 | #ifndef MAX_DATE_SIZE |
wolfSSL | 0:9d17e4342598 | 1009 | #define MAX_DATE_SIZE 32 |
wolfSSL | 0:9d17e4342598 | 1010 | #endif |
wolfSSL | 0:9d17e4342598 | 1011 | |
wolfSSL | 0:9d17e4342598 | 1012 | typedef struct CRL_Entry CRL_Entry; |
wolfSSL | 0:9d17e4342598 | 1013 | |
wolfSSL | 0:9d17e4342598 | 1014 | #ifdef SHA_DIGEST_SIZE |
wolfSSL | 0:9d17e4342598 | 1015 | #define CRL_DIGEST_SIZE SHA_DIGEST_SIZE |
wolfSSL | 0:9d17e4342598 | 1016 | #else |
wolfSSL | 0:9d17e4342598 | 1017 | #define CRL_DIGEST_SIZE 160 |
wolfSSL | 0:9d17e4342598 | 1018 | #endif |
wolfSSL | 0:9d17e4342598 | 1019 | |
wolfSSL | 0:9d17e4342598 | 1020 | #ifdef NO_ASN |
wolfSSL | 0:9d17e4342598 | 1021 | typedef struct RevokedCert RevokedCert; |
wolfSSL | 0:9d17e4342598 | 1022 | #endif |
wolfSSL | 0:9d17e4342598 | 1023 | |
wolfSSL | 0:9d17e4342598 | 1024 | /* Complete CRL */ |
wolfSSL | 0:9d17e4342598 | 1025 | struct CRL_Entry { |
wolfSSL | 0:9d17e4342598 | 1026 | CRL_Entry* next; /* next entry */ |
wolfSSL | 0:9d17e4342598 | 1027 | byte issuerHash[CRL_DIGEST_SIZE]; /* issuer hash */ |
wolfSSL | 0:9d17e4342598 | 1028 | /* byte crlHash[CRL_DIGEST_SIZE]; raw crl data hash */ |
wolfSSL | 0:9d17e4342598 | 1029 | /* restore the hash here if needed for optimized comparisons */ |
wolfSSL | 0:9d17e4342598 | 1030 | byte lastDate[MAX_DATE_SIZE]; /* last date updated */ |
wolfSSL | 0:9d17e4342598 | 1031 | byte nextDate[MAX_DATE_SIZE]; /* next update date */ |
wolfSSL | 0:9d17e4342598 | 1032 | byte lastDateFormat; /* last date format */ |
wolfSSL | 0:9d17e4342598 | 1033 | byte nextDateFormat; /* next date format */ |
wolfSSL | 0:9d17e4342598 | 1034 | RevokedCert* certs; /* revoked cert list */ |
wolfSSL | 0:9d17e4342598 | 1035 | int totalCerts; /* number on list */ |
wolfSSL | 0:9d17e4342598 | 1036 | }; |
wolfSSL | 0:9d17e4342598 | 1037 | |
wolfSSL | 0:9d17e4342598 | 1038 | |
wolfSSL | 0:9d17e4342598 | 1039 | typedef struct CRL_Monitor CRL_Monitor; |
wolfSSL | 0:9d17e4342598 | 1040 | |
wolfSSL | 0:9d17e4342598 | 1041 | /* CRL directory monitor */ |
wolfSSL | 0:9d17e4342598 | 1042 | struct CRL_Monitor { |
wolfSSL | 0:9d17e4342598 | 1043 | char* path; /* full dir path, if valid pointer we're using */ |
wolfSSL | 0:9d17e4342598 | 1044 | int type; /* PEM or ASN1 type */ |
wolfSSL | 0:9d17e4342598 | 1045 | }; |
wolfSSL | 0:9d17e4342598 | 1046 | |
wolfSSL | 0:9d17e4342598 | 1047 | |
wolfSSL | 0:9d17e4342598 | 1048 | #ifndef HAVE_CRL |
wolfSSL | 0:9d17e4342598 | 1049 | typedef struct CYASSL_CRL CYASSL_CRL; |
wolfSSL | 0:9d17e4342598 | 1050 | #endif |
wolfSSL | 0:9d17e4342598 | 1051 | |
wolfSSL | 0:9d17e4342598 | 1052 | /* CyaSSL CRL controller */ |
wolfSSL | 0:9d17e4342598 | 1053 | struct CYASSL_CRL { |
wolfSSL | 0:9d17e4342598 | 1054 | CYASSL_CERT_MANAGER* cm; /* pointer back to cert manager */ |
wolfSSL | 0:9d17e4342598 | 1055 | CRL_Entry* crlList; /* our CRL list */ |
wolfSSL | 0:9d17e4342598 | 1056 | CyaSSL_Mutex crlLock; /* CRL list lock */ |
wolfSSL | 0:9d17e4342598 | 1057 | CRL_Monitor monitors[2]; /* PEM and DER possible */ |
wolfSSL | 0:9d17e4342598 | 1058 | #ifdef HAVE_CRL_MONITOR |
wolfSSL | 0:9d17e4342598 | 1059 | pthread_t tid; /* monitoring thread */ |
wolfSSL | 0:9d17e4342598 | 1060 | #endif |
wolfSSL | 0:9d17e4342598 | 1061 | }; |
wolfSSL | 0:9d17e4342598 | 1062 | |
wolfSSL | 0:9d17e4342598 | 1063 | |
wolfSSL | 0:9d17e4342598 | 1064 | #ifdef NO_ASN |
wolfSSL | 0:9d17e4342598 | 1065 | typedef struct Signer Signer; |
wolfSSL | 0:9d17e4342598 | 1066 | #endif |
wolfSSL | 0:9d17e4342598 | 1067 | |
wolfSSL | 0:9d17e4342598 | 1068 | |
wolfSSL | 0:9d17e4342598 | 1069 | #ifndef CA_TABLE_SIZE |
wolfSSL | 0:9d17e4342598 | 1070 | #define CA_TABLE_SIZE 11 |
wolfSSL | 0:9d17e4342598 | 1071 | #endif |
wolfSSL | 0:9d17e4342598 | 1072 | |
wolfSSL | 0:9d17e4342598 | 1073 | /* CyaSSL Certificate Manager */ |
wolfSSL | 0:9d17e4342598 | 1074 | struct CYASSL_CERT_MANAGER { |
wolfSSL | 0:9d17e4342598 | 1075 | Signer* caTable[CA_TABLE_SIZE]; /* the CA signer table */ |
wolfSSL | 0:9d17e4342598 | 1076 | CyaSSL_Mutex caLock; /* CA list lock */ |
wolfSSL | 0:9d17e4342598 | 1077 | CallbackCACache caCacheCallback; /* CA cache addition callback */ |
wolfSSL | 0:9d17e4342598 | 1078 | void* heap; /* heap helper */ |
wolfSSL | 0:9d17e4342598 | 1079 | CYASSL_CRL* crl; /* CRL checker */ |
wolfSSL | 0:9d17e4342598 | 1080 | byte crlEnabled; /* is CRL on ? */ |
wolfSSL | 0:9d17e4342598 | 1081 | byte crlCheckAll; /* always leaf, but all ? */ |
wolfSSL | 0:9d17e4342598 | 1082 | CbMissingCRL cbMissingCRL; /* notify through cb of missing crl */ |
wolfSSL | 0:9d17e4342598 | 1083 | CYASSL_OCSP* ocsp; /* OCSP checker */ |
wolfSSL | 0:9d17e4342598 | 1084 | byte ocspEnabled; /* is OCSP on ? */ |
wolfSSL | 0:9d17e4342598 | 1085 | byte ocspSendNonce; /* send the OCSP nonce ? */ |
wolfSSL | 0:9d17e4342598 | 1086 | byte ocspUseOverrideURL; /* ignore cert's responder, override */ |
wolfSSL | 0:9d17e4342598 | 1087 | char* ocspOverrideURL; /* use this responder */ |
wolfSSL | 0:9d17e4342598 | 1088 | void* ocspIOCtx; /* I/O callback CTX */ |
wolfSSL | 0:9d17e4342598 | 1089 | CbOCSPIO ocspIOCb; /* I/O callback for OCSP lookup */ |
wolfSSL | 0:9d17e4342598 | 1090 | CbOCSPRespFree ocspRespFreeCb; /* Frees OCSP Response from IO Cb */ |
wolfSSL | 0:9d17e4342598 | 1091 | }; |
wolfSSL | 0:9d17e4342598 | 1092 | |
wolfSSL | 0:9d17e4342598 | 1093 | CYASSL_LOCAL int CM_SaveCertCache(CYASSL_CERT_MANAGER*, const char*); |
wolfSSL | 0:9d17e4342598 | 1094 | CYASSL_LOCAL int CM_RestoreCertCache(CYASSL_CERT_MANAGER*, const char*); |
wolfSSL | 0:9d17e4342598 | 1095 | CYASSL_LOCAL int CM_MemSaveCertCache(CYASSL_CERT_MANAGER*, void*, int, int*); |
wolfSSL | 0:9d17e4342598 | 1096 | CYASSL_LOCAL int CM_MemRestoreCertCache(CYASSL_CERT_MANAGER*, const void*, int); |
wolfSSL | 0:9d17e4342598 | 1097 | CYASSL_LOCAL int CM_GetCertCacheMemSize(CYASSL_CERT_MANAGER*); |
wolfSSL | 0:9d17e4342598 | 1098 | |
wolfSSL | 0:9d17e4342598 | 1099 | /* CyaSSL Sock Addr */ |
wolfSSL | 0:9d17e4342598 | 1100 | struct CYASSL_SOCKADDR { |
wolfSSL | 0:9d17e4342598 | 1101 | unsigned int sz; /* sockaddr size */ |
wolfSSL | 0:9d17e4342598 | 1102 | void* sa; /* pointer to the sockaddr_in or sockaddr_in6 */ |
wolfSSL | 0:9d17e4342598 | 1103 | }; |
wolfSSL | 0:9d17e4342598 | 1104 | |
wolfSSL | 0:9d17e4342598 | 1105 | typedef struct CYASSL_DTLS_CTX { |
wolfSSL | 0:9d17e4342598 | 1106 | CYASSL_SOCKADDR peer; |
wolfSSL | 0:9d17e4342598 | 1107 | int fd; |
wolfSSL | 0:9d17e4342598 | 1108 | } CYASSL_DTLS_CTX; |
wolfSSL | 0:9d17e4342598 | 1109 | |
wolfSSL | 0:9d17e4342598 | 1110 | /* RFC 6066 TLS Extensions */ |
wolfSSL | 0:9d17e4342598 | 1111 | #ifdef HAVE_TLS_EXTENSIONS |
wolfSSL | 0:9d17e4342598 | 1112 | |
wolfSSL | 0:9d17e4342598 | 1113 | typedef enum { |
wolfSSL | 0:9d17e4342598 | 1114 | SERVER_NAME_INDICATION = 0, |
wolfSSL | 0:9d17e4342598 | 1115 | MAX_FRAGMENT_LENGTH = 1, |
wolfSSL | 0:9d17e4342598 | 1116 | TRUNCATED_HMAC = 4, |
wolfSSL | 0:9d17e4342598 | 1117 | ELLIPTIC_CURVES = 10 |
wolfSSL | 0:9d17e4342598 | 1118 | } TLSX_Type; |
wolfSSL | 0:9d17e4342598 | 1119 | |
wolfSSL | 0:9d17e4342598 | 1120 | typedef struct TLSX { |
wolfSSL | 0:9d17e4342598 | 1121 | TLSX_Type type; /* Extension Type */ |
wolfSSL | 0:9d17e4342598 | 1122 | void* data; /* Extension Data */ |
wolfSSL | 0:9d17e4342598 | 1123 | byte resp; /* IsResponse Flag */ |
wolfSSL | 0:9d17e4342598 | 1124 | struct TLSX* next; /* List Behavior */ |
wolfSSL | 0:9d17e4342598 | 1125 | } TLSX; |
wolfSSL | 0:9d17e4342598 | 1126 | |
wolfSSL | 0:9d17e4342598 | 1127 | CYASSL_LOCAL TLSX* TLSX_Find(TLSX* list, TLSX_Type type); |
wolfSSL | 0:9d17e4342598 | 1128 | CYASSL_LOCAL void TLSX_FreeAll(TLSX* list); |
wolfSSL | 0:9d17e4342598 | 1129 | |
wolfSSL | 0:9d17e4342598 | 1130 | #ifndef NO_CYASSL_CLIENT |
wolfSSL | 0:9d17e4342598 | 1131 | CYASSL_LOCAL word16 TLSX_GetRequestSize(CYASSL* ssl); |
wolfSSL | 0:9d17e4342598 | 1132 | CYASSL_LOCAL word16 TLSX_WriteRequest(CYASSL* ssl, byte* output); |
wolfSSL | 0:9d17e4342598 | 1133 | #endif |
wolfSSL | 0:9d17e4342598 | 1134 | |
wolfSSL | 0:9d17e4342598 | 1135 | #ifndef NO_CYASSL_SERVER |
wolfSSL | 0:9d17e4342598 | 1136 | CYASSL_LOCAL word16 TLSX_GetResponseSize(CYASSL* ssl); |
wolfSSL | 0:9d17e4342598 | 1137 | CYASSL_LOCAL word16 TLSX_WriteResponse(CYASSL* ssl, byte* output); |
wolfSSL | 0:9d17e4342598 | 1138 | #endif |
wolfSSL | 0:9d17e4342598 | 1139 | |
wolfSSL | 0:9d17e4342598 | 1140 | CYASSL_LOCAL int TLSX_Parse(CYASSL* ssl, byte* input, word16 length, |
wolfSSL | 0:9d17e4342598 | 1141 | byte isRequest, Suites *suites); |
wolfSSL | 0:9d17e4342598 | 1142 | |
wolfSSL | 0:9d17e4342598 | 1143 | /* Server Name Indication */ |
wolfSSL | 0:9d17e4342598 | 1144 | #ifdef HAVE_SNI |
wolfSSL | 0:9d17e4342598 | 1145 | |
wolfSSL | 0:9d17e4342598 | 1146 | typedef struct SNI { |
wolfSSL | 0:9d17e4342598 | 1147 | byte type; /* SNI Type */ |
wolfSSL | 0:9d17e4342598 | 1148 | union { char* host_name; } data; /* SNI Data */ |
wolfSSL | 0:9d17e4342598 | 1149 | struct SNI* next; /* List Behavior */ |
wolfSSL | 0:9d17e4342598 | 1150 | #ifndef NO_CYASSL_SERVER |
wolfSSL | 0:9d17e4342598 | 1151 | byte options; /* Behaviour options */ |
wolfSSL | 0:9d17e4342598 | 1152 | byte status; /* Matching result */ |
wolfSSL | 0:9d17e4342598 | 1153 | #endif |
wolfSSL | 0:9d17e4342598 | 1154 | } SNI; |
wolfSSL | 0:9d17e4342598 | 1155 | |
wolfSSL | 0:9d17e4342598 | 1156 | CYASSL_LOCAL int TLSX_UseSNI(TLSX** extensions, byte type, const void* data, |
wolfSSL | 0:9d17e4342598 | 1157 | word16 size); |
wolfSSL | 0:9d17e4342598 | 1158 | |
wolfSSL | 0:9d17e4342598 | 1159 | #ifndef NO_CYASSL_SERVER |
wolfSSL | 0:9d17e4342598 | 1160 | CYASSL_LOCAL void TLSX_SNI_SetOptions(TLSX* extensions, byte type, |
wolfSSL | 0:9d17e4342598 | 1161 | byte options); |
wolfSSL | 0:9d17e4342598 | 1162 | CYASSL_LOCAL byte TLSX_SNI_Status(TLSX* extensions, byte type); |
wolfSSL | 0:9d17e4342598 | 1163 | CYASSL_LOCAL word16 TLSX_SNI_GetRequest(TLSX* extensions, byte type, |
wolfSSL | 0:9d17e4342598 | 1164 | void** data); |
wolfSSL | 0:9d17e4342598 | 1165 | CYASSL_LOCAL int TLSX_SNI_GetFromBuffer(const byte* buffer, word32 bufferSz, |
wolfSSL | 0:9d17e4342598 | 1166 | byte type, byte* sni, word32* inOutSz); |
wolfSSL | 0:9d17e4342598 | 1167 | #endif |
wolfSSL | 0:9d17e4342598 | 1168 | |
wolfSSL | 0:9d17e4342598 | 1169 | #endif /* HAVE_SNI */ |
wolfSSL | 0:9d17e4342598 | 1170 | |
wolfSSL | 0:9d17e4342598 | 1171 | /* Maximum Fragment Length */ |
wolfSSL | 0:9d17e4342598 | 1172 | #ifdef HAVE_MAX_FRAGMENT |
wolfSSL | 0:9d17e4342598 | 1173 | |
wolfSSL | 0:9d17e4342598 | 1174 | CYASSL_LOCAL int TLSX_UseMaxFragment(TLSX** extensions, byte mfl); |
wolfSSL | 0:9d17e4342598 | 1175 | |
wolfSSL | 0:9d17e4342598 | 1176 | #endif /* HAVE_MAX_FRAGMENT */ |
wolfSSL | 0:9d17e4342598 | 1177 | |
wolfSSL | 0:9d17e4342598 | 1178 | #ifdef HAVE_TRUNCATED_HMAC |
wolfSSL | 0:9d17e4342598 | 1179 | |
wolfSSL | 0:9d17e4342598 | 1180 | CYASSL_LOCAL int TLSX_UseTruncatedHMAC(TLSX** extensions); |
wolfSSL | 0:9d17e4342598 | 1181 | |
wolfSSL | 0:9d17e4342598 | 1182 | #endif /* HAVE_TRUNCATED_HMAC */ |
wolfSSL | 0:9d17e4342598 | 1183 | |
wolfSSL | 0:9d17e4342598 | 1184 | #ifdef HAVE_SUPPORTED_CURVES |
wolfSSL | 0:9d17e4342598 | 1185 | |
wolfSSL | 0:9d17e4342598 | 1186 | typedef struct EllipticCurve { |
wolfSSL | 0:9d17e4342598 | 1187 | word16 name; /* CurveNames */ |
wolfSSL | 0:9d17e4342598 | 1188 | struct EllipticCurve* next; /* List Behavior */ |
wolfSSL | 0:9d17e4342598 | 1189 | |
wolfSSL | 0:9d17e4342598 | 1190 | } EllipticCurve; |
wolfSSL | 0:9d17e4342598 | 1191 | |
wolfSSL | 0:9d17e4342598 | 1192 | CYASSL_LOCAL int TLSX_UseSupportedCurve(TLSX** extensions, word16 name); |
wolfSSL | 0:9d17e4342598 | 1193 | |
wolfSSL | 0:9d17e4342598 | 1194 | #ifndef NO_CYASSL_SERVER |
wolfSSL | 0:9d17e4342598 | 1195 | CYASSL_LOCAL int TLSX_ValidateEllipticCurves(CYASSL* ssl, byte first, |
wolfSSL | 0:9d17e4342598 | 1196 | byte second); |
wolfSSL | 0:9d17e4342598 | 1197 | #endif |
wolfSSL | 0:9d17e4342598 | 1198 | |
wolfSSL | 0:9d17e4342598 | 1199 | #endif /* HAVE_SUPPORTED_CURVES */ |
wolfSSL | 0:9d17e4342598 | 1200 | |
wolfSSL | 0:9d17e4342598 | 1201 | #endif /* HAVE_TLS_EXTENSIONS */ |
wolfSSL | 0:9d17e4342598 | 1202 | |
wolfSSL | 0:9d17e4342598 | 1203 | /* CyaSSL context type */ |
wolfSSL | 0:9d17e4342598 | 1204 | struct CYASSL_CTX { |
wolfSSL | 0:9d17e4342598 | 1205 | CYASSL_METHOD* method; |
wolfSSL | 0:9d17e4342598 | 1206 | CyaSSL_Mutex countMutex; /* reference count mutex */ |
wolfSSL | 0:9d17e4342598 | 1207 | int refCount; /* reference count */ |
wolfSSL | 0:9d17e4342598 | 1208 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 1209 | buffer certificate; |
wolfSSL | 0:9d17e4342598 | 1210 | buffer certChain; |
wolfSSL | 0:9d17e4342598 | 1211 | /* chain after self, in DER, with leading size for each cert */ |
wolfSSL | 0:9d17e4342598 | 1212 | buffer privateKey; |
wolfSSL | 0:9d17e4342598 | 1213 | buffer serverDH_P; |
wolfSSL | 0:9d17e4342598 | 1214 | buffer serverDH_G; |
wolfSSL | 0:9d17e4342598 | 1215 | CYASSL_CERT_MANAGER* cm; /* our cert manager, ctx owns SSL will use */ |
wolfSSL | 0:9d17e4342598 | 1216 | #endif |
wolfSSL | 0:9d17e4342598 | 1217 | Suites suites; |
wolfSSL | 0:9d17e4342598 | 1218 | void* heap; /* for user memory overrides */ |
wolfSSL | 0:9d17e4342598 | 1219 | byte verifyPeer; |
wolfSSL | 0:9d17e4342598 | 1220 | byte verifyNone; |
wolfSSL | 0:9d17e4342598 | 1221 | byte failNoCert; |
wolfSSL | 0:9d17e4342598 | 1222 | byte sessionCacheOff; |
wolfSSL | 0:9d17e4342598 | 1223 | byte sessionCacheFlushOff; |
wolfSSL | 0:9d17e4342598 | 1224 | byte sendVerify; /* for client side */ |
wolfSSL | 0:9d17e4342598 | 1225 | byte haveRSA; /* RSA available */ |
wolfSSL | 0:9d17e4342598 | 1226 | byte haveDH; /* server DH parms set by user */ |
wolfSSL | 0:9d17e4342598 | 1227 | byte haveNTRU; /* server private NTRU key loaded */ |
wolfSSL | 0:9d17e4342598 | 1228 | byte haveECDSAsig; /* server cert signed w/ ECDSA */ |
wolfSSL | 0:9d17e4342598 | 1229 | byte haveStaticECC; /* static server ECC private key */ |
wolfSSL | 0:9d17e4342598 | 1230 | byte partialWrite; /* only one msg per write call */ |
wolfSSL | 0:9d17e4342598 | 1231 | byte quietShutdown; /* don't send close notify */ |
wolfSSL | 0:9d17e4342598 | 1232 | byte groupMessages; /* group handshake messages before sending */ |
wolfSSL | 0:9d17e4342598 | 1233 | CallbackIORecv CBIORecv; |
wolfSSL | 0:9d17e4342598 | 1234 | CallbackIOSend CBIOSend; |
wolfSSL | 0:9d17e4342598 | 1235 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 1236 | CallbackGenCookie CBIOCookie; /* gen cookie callback */ |
wolfSSL | 0:9d17e4342598 | 1237 | #endif |
wolfSSL | 0:9d17e4342598 | 1238 | VerifyCallback verifyCallback; /* cert verification callback */ |
wolfSSL | 0:9d17e4342598 | 1239 | word32 timeout; /* session timeout */ |
wolfSSL | 0:9d17e4342598 | 1240 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 1241 | word16 eccTempKeySz; /* in octets 20 - 66 */ |
wolfSSL | 0:9d17e4342598 | 1242 | word32 pkCurveOID; /* curve Ecc_Sum */ |
wolfSSL | 0:9d17e4342598 | 1243 | #endif |
wolfSSL | 0:9d17e4342598 | 1244 | #ifndef NO_PSK |
wolfSSL | 0:9d17e4342598 | 1245 | byte havePSK; /* psk key set by user */ |
wolfSSL | 0:9d17e4342598 | 1246 | psk_client_callback client_psk_cb; /* client callback */ |
wolfSSL | 0:9d17e4342598 | 1247 | psk_server_callback server_psk_cb; /* server callback */ |
wolfSSL | 0:9d17e4342598 | 1248 | char server_hint[MAX_PSK_ID_LEN]; |
wolfSSL | 0:9d17e4342598 | 1249 | #endif /* NO_PSK */ |
wolfSSL | 0:9d17e4342598 | 1250 | #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER) |
wolfSSL | 0:9d17e4342598 | 1251 | pem_password_cb passwd_cb; |
wolfSSL | 0:9d17e4342598 | 1252 | void* userdata; |
wolfSSL | 0:9d17e4342598 | 1253 | #endif /* OPENSSL_EXTRA */ |
wolfSSL | 0:9d17e4342598 | 1254 | #ifdef HAVE_OCSP |
wolfSSL | 0:9d17e4342598 | 1255 | CYASSL_OCSP ocsp; |
wolfSSL | 0:9d17e4342598 | 1256 | #endif |
wolfSSL | 0:9d17e4342598 | 1257 | #ifdef HAVE_CAVIUM |
wolfSSL | 0:9d17e4342598 | 1258 | int devId; /* cavium device id to use */ |
wolfSSL | 0:9d17e4342598 | 1259 | #endif |
wolfSSL | 0:9d17e4342598 | 1260 | #ifdef HAVE_TLS_EXTENSIONS |
wolfSSL | 0:9d17e4342598 | 1261 | TLSX* extensions; /* RFC 6066 TLS Extensions data */ |
wolfSSL | 0:9d17e4342598 | 1262 | #endif |
wolfSSL | 0:9d17e4342598 | 1263 | #ifdef ATOMIC_USER |
wolfSSL | 0:9d17e4342598 | 1264 | CallbackMacEncrypt MacEncryptCb; /* Atomic User Mac/Encrypt Cb */ |
wolfSSL | 0:9d17e4342598 | 1265 | CallbackDecryptVerify DecryptVerifyCb; /* Atomic User Decrypt/Verify Cb */ |
wolfSSL | 0:9d17e4342598 | 1266 | #endif |
wolfSSL | 0:9d17e4342598 | 1267 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 1268 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 1269 | CallbackEccSign EccSignCb; /* User EccSign Callback handler */ |
wolfSSL | 0:9d17e4342598 | 1270 | CallbackEccVerify EccVerifyCb; /* User EccVerify Callback handler */ |
wolfSSL | 0:9d17e4342598 | 1271 | #endif /* HAVE_ECC */ |
wolfSSL | 0:9d17e4342598 | 1272 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 1273 | CallbackRsaSign RsaSignCb; /* User RsaSign Callback handler */ |
wolfSSL | 0:9d17e4342598 | 1274 | CallbackRsaVerify RsaVerifyCb; /* User RsaVerify Callback handler */ |
wolfSSL | 0:9d17e4342598 | 1275 | CallbackRsaEnc RsaEncCb; /* User Rsa Public Encrypt handler */ |
wolfSSL | 0:9d17e4342598 | 1276 | CallbackRsaDec RsaDecCb; /* User Rsa Private Decrypt handler */ |
wolfSSL | 0:9d17e4342598 | 1277 | #endif /* NO_RSA */ |
wolfSSL | 0:9d17e4342598 | 1278 | #endif /* HAVE_PK_CALLBACKS */ |
wolfSSL | 0:9d17e4342598 | 1279 | }; |
wolfSSL | 0:9d17e4342598 | 1280 | |
wolfSSL | 0:9d17e4342598 | 1281 | |
wolfSSL | 0:9d17e4342598 | 1282 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 1283 | int InitSSL_Ctx(CYASSL_CTX*, CYASSL_METHOD*); |
wolfSSL | 0:9d17e4342598 | 1284 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 1285 | void FreeSSL_Ctx(CYASSL_CTX*); |
wolfSSL | 0:9d17e4342598 | 1286 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 1287 | void SSL_CtxResourceFree(CYASSL_CTX*); |
wolfSSL | 0:9d17e4342598 | 1288 | |
wolfSSL | 0:9d17e4342598 | 1289 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 1290 | int DeriveTlsKeys(CYASSL* ssl); |
wolfSSL | 0:9d17e4342598 | 1291 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 1292 | int ProcessOldClientHello(CYASSL* ssl, const byte* input, word32* inOutIdx, |
wolfSSL | 0:9d17e4342598 | 1293 | word32 inSz, word16 sz); |
wolfSSL | 0:9d17e4342598 | 1294 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 1295 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 1296 | int AddCA(CYASSL_CERT_MANAGER* ctx, buffer der, int type, int verify); |
wolfSSL | 0:9d17e4342598 | 1297 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 1298 | int AlreadySigner(CYASSL_CERT_MANAGER* cm, byte* hash); |
wolfSSL | 0:9d17e4342598 | 1299 | #endif |
wolfSSL | 0:9d17e4342598 | 1300 | |
wolfSSL | 0:9d17e4342598 | 1301 | /* All cipher suite related info */ |
wolfSSL | 0:9d17e4342598 | 1302 | typedef struct CipherSpecs { |
wolfSSL | 0:9d17e4342598 | 1303 | byte bulk_cipher_algorithm; |
wolfSSL | 0:9d17e4342598 | 1304 | byte cipher_type; /* block, stream, or aead */ |
wolfSSL | 0:9d17e4342598 | 1305 | byte mac_algorithm; |
wolfSSL | 0:9d17e4342598 | 1306 | byte kea; /* key exchange algo */ |
wolfSSL | 0:9d17e4342598 | 1307 | byte sig_algo; |
wolfSSL | 0:9d17e4342598 | 1308 | byte hash_size; |
wolfSSL | 0:9d17e4342598 | 1309 | byte pad_size; |
wolfSSL | 0:9d17e4342598 | 1310 | byte static_ecdh; |
wolfSSL | 0:9d17e4342598 | 1311 | word16 key_size; |
wolfSSL | 0:9d17e4342598 | 1312 | word16 iv_size; |
wolfSSL | 0:9d17e4342598 | 1313 | word16 block_size; |
wolfSSL | 0:9d17e4342598 | 1314 | word16 aead_mac_size; |
wolfSSL | 0:9d17e4342598 | 1315 | } CipherSpecs; |
wolfSSL | 0:9d17e4342598 | 1316 | |
wolfSSL | 0:9d17e4342598 | 1317 | |
wolfSSL | 0:9d17e4342598 | 1318 | void InitCipherSpecs(CipherSpecs* cs); |
wolfSSL | 0:9d17e4342598 | 1319 | |
wolfSSL | 0:9d17e4342598 | 1320 | |
wolfSSL | 0:9d17e4342598 | 1321 | /* Supported Message Authentication Codes from page 43 */ |
wolfSSL | 0:9d17e4342598 | 1322 | enum MACAlgorithm { |
wolfSSL | 0:9d17e4342598 | 1323 | no_mac, |
wolfSSL | 0:9d17e4342598 | 1324 | md5_mac, |
wolfSSL | 0:9d17e4342598 | 1325 | sha_mac, |
wolfSSL | 0:9d17e4342598 | 1326 | sha224_mac, |
wolfSSL | 0:9d17e4342598 | 1327 | sha256_mac, |
wolfSSL | 0:9d17e4342598 | 1328 | sha384_mac, |
wolfSSL | 0:9d17e4342598 | 1329 | sha512_mac, |
wolfSSL | 0:9d17e4342598 | 1330 | rmd_mac, |
wolfSSL | 0:9d17e4342598 | 1331 | blake2b_mac |
wolfSSL | 0:9d17e4342598 | 1332 | }; |
wolfSSL | 0:9d17e4342598 | 1333 | |
wolfSSL | 0:9d17e4342598 | 1334 | |
wolfSSL | 0:9d17e4342598 | 1335 | /* Supported Key Exchange Protocols */ |
wolfSSL | 0:9d17e4342598 | 1336 | enum KeyExchangeAlgorithm { |
wolfSSL | 0:9d17e4342598 | 1337 | no_kea, |
wolfSSL | 0:9d17e4342598 | 1338 | rsa_kea, |
wolfSSL | 0:9d17e4342598 | 1339 | diffie_hellman_kea, |
wolfSSL | 0:9d17e4342598 | 1340 | fortezza_kea, |
wolfSSL | 0:9d17e4342598 | 1341 | psk_kea, |
wolfSSL | 0:9d17e4342598 | 1342 | ntru_kea, |
wolfSSL | 0:9d17e4342598 | 1343 | ecc_diffie_hellman_kea, |
wolfSSL | 0:9d17e4342598 | 1344 | ecc_static_diffie_hellman_kea /* for verify suite only */ |
wolfSSL | 0:9d17e4342598 | 1345 | }; |
wolfSSL | 0:9d17e4342598 | 1346 | |
wolfSSL | 0:9d17e4342598 | 1347 | |
wolfSSL | 0:9d17e4342598 | 1348 | /* Supported Authentication Schemes */ |
wolfSSL | 0:9d17e4342598 | 1349 | enum SignatureAlgorithm { |
wolfSSL | 0:9d17e4342598 | 1350 | anonymous_sa_algo, |
wolfSSL | 0:9d17e4342598 | 1351 | rsa_sa_algo, |
wolfSSL | 0:9d17e4342598 | 1352 | dsa_sa_algo, |
wolfSSL | 0:9d17e4342598 | 1353 | ecc_dsa_sa_algo |
wolfSSL | 0:9d17e4342598 | 1354 | }; |
wolfSSL | 0:9d17e4342598 | 1355 | |
wolfSSL | 0:9d17e4342598 | 1356 | |
wolfSSL | 0:9d17e4342598 | 1357 | /* Supprted ECC Curve Types */ |
wolfSSL | 0:9d17e4342598 | 1358 | enum EccCurves { |
wolfSSL | 0:9d17e4342598 | 1359 | named_curve = 3 |
wolfSSL | 0:9d17e4342598 | 1360 | }; |
wolfSSL | 0:9d17e4342598 | 1361 | |
wolfSSL | 0:9d17e4342598 | 1362 | |
wolfSSL | 0:9d17e4342598 | 1363 | /* Supprted ECC Named Curves */ |
wolfSSL | 0:9d17e4342598 | 1364 | enum EccNamedCurves { |
wolfSSL | 0:9d17e4342598 | 1365 | secp256r1 = 0x17, /* default, OpenSSL also calls it prime256v1 */ |
wolfSSL | 0:9d17e4342598 | 1366 | secp384r1 = 0x18, |
wolfSSL | 0:9d17e4342598 | 1367 | secp521r1 = 0x19, |
wolfSSL | 0:9d17e4342598 | 1368 | |
wolfSSL | 0:9d17e4342598 | 1369 | secp160r1 = 0x10, |
wolfSSL | 0:9d17e4342598 | 1370 | secp192r1 = 0x13, /* Openssl also call it prime192v1 */ |
wolfSSL | 0:9d17e4342598 | 1371 | secp224r1 = 0x15 |
wolfSSL | 0:9d17e4342598 | 1372 | }; |
wolfSSL | 0:9d17e4342598 | 1373 | |
wolfSSL | 0:9d17e4342598 | 1374 | |
wolfSSL | 0:9d17e4342598 | 1375 | /* Valid client certificate request types from page 27 */ |
wolfSSL | 0:9d17e4342598 | 1376 | enum ClientCertificateType { |
wolfSSL | 0:9d17e4342598 | 1377 | rsa_sign = 1, |
wolfSSL | 0:9d17e4342598 | 1378 | dss_sign = 2, |
wolfSSL | 0:9d17e4342598 | 1379 | rsa_fixed_dh = 3, |
wolfSSL | 0:9d17e4342598 | 1380 | dss_fixed_dh = 4, |
wolfSSL | 0:9d17e4342598 | 1381 | rsa_ephemeral_dh = 5, |
wolfSSL | 0:9d17e4342598 | 1382 | dss_ephemeral_dh = 6, |
wolfSSL | 0:9d17e4342598 | 1383 | fortezza_kea_cert = 20 |
wolfSSL | 0:9d17e4342598 | 1384 | }; |
wolfSSL | 0:9d17e4342598 | 1385 | |
wolfSSL | 0:9d17e4342598 | 1386 | |
wolfSSL | 0:9d17e4342598 | 1387 | enum CipherType { stream, block, aead }; |
wolfSSL | 0:9d17e4342598 | 1388 | |
wolfSSL | 0:9d17e4342598 | 1389 | |
wolfSSL | 0:9d17e4342598 | 1390 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 1391 | |
wolfSSL | 0:9d17e4342598 | 1392 | #ifdef WORD64_AVAILABLE |
wolfSSL | 0:9d17e4342598 | 1393 | typedef word64 DtlsSeq; |
wolfSSL | 0:9d17e4342598 | 1394 | #else |
wolfSSL | 0:9d17e4342598 | 1395 | typedef word32 DtlsSeq; |
wolfSSL | 0:9d17e4342598 | 1396 | #endif |
wolfSSL | 0:9d17e4342598 | 1397 | #define DTLS_SEQ_BITS (sizeof(DtlsSeq) * CHAR_BIT) |
wolfSSL | 0:9d17e4342598 | 1398 | |
wolfSSL | 0:9d17e4342598 | 1399 | typedef struct DtlsState { |
wolfSSL | 0:9d17e4342598 | 1400 | DtlsSeq window; /* Sliding window for current epoch */ |
wolfSSL | 0:9d17e4342598 | 1401 | word16 nextEpoch; /* Expected epoch in next record */ |
wolfSSL | 0:9d17e4342598 | 1402 | word32 nextSeq; /* Expected sequence in next record */ |
wolfSSL | 0:9d17e4342598 | 1403 | |
wolfSSL | 0:9d17e4342598 | 1404 | word16 curEpoch; /* Received epoch in current record */ |
wolfSSL | 0:9d17e4342598 | 1405 | word32 curSeq; /* Received sequence in current record */ |
wolfSSL | 0:9d17e4342598 | 1406 | |
wolfSSL | 0:9d17e4342598 | 1407 | DtlsSeq prevWindow; /* Sliding window for old epoch */ |
wolfSSL | 0:9d17e4342598 | 1408 | word32 prevSeq; /* Next sequence in allowed old epoch */ |
wolfSSL | 0:9d17e4342598 | 1409 | } DtlsState; |
wolfSSL | 0:9d17e4342598 | 1410 | |
wolfSSL | 0:9d17e4342598 | 1411 | #endif /* CYASSL_DTLS */ |
wolfSSL | 0:9d17e4342598 | 1412 | |
wolfSSL | 0:9d17e4342598 | 1413 | |
wolfSSL | 0:9d17e4342598 | 1414 | /* keys and secrets */ |
wolfSSL | 0:9d17e4342598 | 1415 | typedef struct Keys { |
wolfSSL | 0:9d17e4342598 | 1416 | byte client_write_MAC_secret[MAX_DIGEST_SIZE]; /* max sizes */ |
wolfSSL | 0:9d17e4342598 | 1417 | byte server_write_MAC_secret[MAX_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 1418 | byte client_write_key[AES_256_KEY_SIZE]; /* max sizes */ |
wolfSSL | 0:9d17e4342598 | 1419 | byte server_write_key[AES_256_KEY_SIZE]; |
wolfSSL | 0:9d17e4342598 | 1420 | byte client_write_IV[AES_IV_SIZE]; /* max sizes */ |
wolfSSL | 0:9d17e4342598 | 1421 | byte server_write_IV[AES_IV_SIZE]; |
wolfSSL | 0:9d17e4342598 | 1422 | #ifdef HAVE_AEAD |
wolfSSL | 0:9d17e4342598 | 1423 | byte aead_exp_IV[AEAD_EXP_IV_SZ]; |
wolfSSL | 0:9d17e4342598 | 1424 | byte aead_enc_imp_IV[AEAD_IMP_IV_SZ]; |
wolfSSL | 0:9d17e4342598 | 1425 | byte aead_dec_imp_IV[AEAD_IMP_IV_SZ]; |
wolfSSL | 0:9d17e4342598 | 1426 | #endif |
wolfSSL | 0:9d17e4342598 | 1427 | |
wolfSSL | 0:9d17e4342598 | 1428 | word32 peer_sequence_number; |
wolfSSL | 0:9d17e4342598 | 1429 | word32 sequence_number; |
wolfSSL | 0:9d17e4342598 | 1430 | |
wolfSSL | 0:9d17e4342598 | 1431 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 1432 | DtlsState dtls_state; /* Peer's state */ |
wolfSSL | 0:9d17e4342598 | 1433 | word16 dtls_peer_handshake_number; |
wolfSSL | 0:9d17e4342598 | 1434 | word16 dtls_expected_peer_handshake_number; |
wolfSSL | 0:9d17e4342598 | 1435 | |
wolfSSL | 0:9d17e4342598 | 1436 | word16 dtls_epoch; /* Current tx epoch */ |
wolfSSL | 0:9d17e4342598 | 1437 | word32 dtls_sequence_number; /* Current tx sequence */ |
wolfSSL | 0:9d17e4342598 | 1438 | word16 dtls_handshake_number; /* Current tx handshake seq */ |
wolfSSL | 0:9d17e4342598 | 1439 | #endif |
wolfSSL | 0:9d17e4342598 | 1440 | |
wolfSSL | 0:9d17e4342598 | 1441 | word32 encryptSz; /* last size of encrypted data */ |
wolfSSL | 0:9d17e4342598 | 1442 | word32 padSz; /* how much to advance after decrypt part */ |
wolfSSL | 0:9d17e4342598 | 1443 | byte encryptionOn; /* true after change cipher spec */ |
wolfSSL | 0:9d17e4342598 | 1444 | byte decryptedCur; /* only decrypt current record once */ |
wolfSSL | 0:9d17e4342598 | 1445 | } Keys; |
wolfSSL | 0:9d17e4342598 | 1446 | |
wolfSSL | 0:9d17e4342598 | 1447 | |
wolfSSL | 0:9d17e4342598 | 1448 | /* cipher for now */ |
wolfSSL | 0:9d17e4342598 | 1449 | typedef struct Ciphers { |
wolfSSL | 0:9d17e4342598 | 1450 | #ifdef BUILD_ARC4 |
wolfSSL | 0:9d17e4342598 | 1451 | Arc4* arc4; |
wolfSSL | 0:9d17e4342598 | 1452 | #endif |
wolfSSL | 0:9d17e4342598 | 1453 | #ifdef BUILD_DES3 |
wolfSSL | 0:9d17e4342598 | 1454 | Des3* des3; |
wolfSSL | 0:9d17e4342598 | 1455 | #endif |
wolfSSL | 0:9d17e4342598 | 1456 | #if defined(BUILD_AES) || defined(BUILD_AESGCM) |
wolfSSL | 0:9d17e4342598 | 1457 | Aes* aes; |
wolfSSL | 0:9d17e4342598 | 1458 | #endif |
wolfSSL | 0:9d17e4342598 | 1459 | #ifdef HAVE_CAMELLIA |
wolfSSL | 0:9d17e4342598 | 1460 | Camellia* cam; |
wolfSSL | 0:9d17e4342598 | 1461 | #endif |
wolfSSL | 0:9d17e4342598 | 1462 | #ifdef HAVE_HC128 |
wolfSSL | 0:9d17e4342598 | 1463 | HC128* hc128; |
wolfSSL | 0:9d17e4342598 | 1464 | #endif |
wolfSSL | 0:9d17e4342598 | 1465 | #ifdef BUILD_RABBIT |
wolfSSL | 0:9d17e4342598 | 1466 | Rabbit* rabbit; |
wolfSSL | 0:9d17e4342598 | 1467 | #endif |
wolfSSL | 0:9d17e4342598 | 1468 | byte setup; /* have we set it up flag for detection */ |
wolfSSL | 0:9d17e4342598 | 1469 | } Ciphers; |
wolfSSL | 0:9d17e4342598 | 1470 | |
wolfSSL | 0:9d17e4342598 | 1471 | |
wolfSSL | 0:9d17e4342598 | 1472 | CYASSL_LOCAL void InitCiphers(CYASSL* ssl); |
wolfSSL | 0:9d17e4342598 | 1473 | CYASSL_LOCAL void FreeCiphers(CYASSL* ssl); |
wolfSSL | 0:9d17e4342598 | 1474 | |
wolfSSL | 0:9d17e4342598 | 1475 | |
wolfSSL | 0:9d17e4342598 | 1476 | /* hashes type */ |
wolfSSL | 0:9d17e4342598 | 1477 | typedef struct Hashes { |
wolfSSL | 0:9d17e4342598 | 1478 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 1479 | byte md5[MD5_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 1480 | #endif |
wolfSSL | 0:9d17e4342598 | 1481 | byte sha[SHA_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 1482 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 1483 | byte sha256[SHA256_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 1484 | #endif |
wolfSSL | 0:9d17e4342598 | 1485 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 1486 | byte sha384[SHA384_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 1487 | #endif |
wolfSSL | 0:9d17e4342598 | 1488 | } Hashes; |
wolfSSL | 0:9d17e4342598 | 1489 | |
wolfSSL | 0:9d17e4342598 | 1490 | |
wolfSSL | 0:9d17e4342598 | 1491 | /* Static x509 buffer */ |
wolfSSL | 0:9d17e4342598 | 1492 | typedef struct x509_buffer { |
wolfSSL | 0:9d17e4342598 | 1493 | int length; /* actual size */ |
wolfSSL | 0:9d17e4342598 | 1494 | byte buffer[MAX_X509_SIZE]; /* max static cert size */ |
wolfSSL | 0:9d17e4342598 | 1495 | } x509_buffer; |
wolfSSL | 0:9d17e4342598 | 1496 | |
wolfSSL | 0:9d17e4342598 | 1497 | |
wolfSSL | 0:9d17e4342598 | 1498 | /* CyaSSL X509_CHAIN, for no dynamic memory SESSION_CACHE */ |
wolfSSL | 0:9d17e4342598 | 1499 | struct CYASSL_X509_CHAIN { |
wolfSSL | 0:9d17e4342598 | 1500 | int count; /* total number in chain */ |
wolfSSL | 0:9d17e4342598 | 1501 | x509_buffer certs[MAX_CHAIN_DEPTH]; /* only allow max depth 4 for now */ |
wolfSSL | 0:9d17e4342598 | 1502 | }; |
wolfSSL | 0:9d17e4342598 | 1503 | |
wolfSSL | 0:9d17e4342598 | 1504 | |
wolfSSL | 0:9d17e4342598 | 1505 | /* CyaSSL session type */ |
wolfSSL | 0:9d17e4342598 | 1506 | struct CYASSL_SESSION { |
wolfSSL | 0:9d17e4342598 | 1507 | byte sessionID[ID_LEN]; /* id for protocol */ |
wolfSSL | 0:9d17e4342598 | 1508 | byte masterSecret[SECRET_LEN]; /* stored secret */ |
wolfSSL | 0:9d17e4342598 | 1509 | word32 bornOn; /* create time in seconds */ |
wolfSSL | 0:9d17e4342598 | 1510 | word32 timeout; /* timeout in seconds */ |
wolfSSL | 0:9d17e4342598 | 1511 | #ifdef SESSION_CERTS |
wolfSSL | 0:9d17e4342598 | 1512 | CYASSL_X509_CHAIN chain; /* peer cert chain, static */ |
wolfSSL | 0:9d17e4342598 | 1513 | ProtocolVersion version; /* which version was used */ |
wolfSSL | 0:9d17e4342598 | 1514 | byte cipherSuite0; /* first byte, normally 0 */ |
wolfSSL | 0:9d17e4342598 | 1515 | byte cipherSuite; /* 2nd byte, actual suite */ |
wolfSSL | 0:9d17e4342598 | 1516 | #endif |
wolfSSL | 0:9d17e4342598 | 1517 | #ifndef NO_CLIENT_CACHE |
wolfSSL | 0:9d17e4342598 | 1518 | byte serverID[SERVER_ID_LEN]; /* for easier client lookup */ |
wolfSSL | 0:9d17e4342598 | 1519 | word16 idLen; /* serverID length */ |
wolfSSL | 0:9d17e4342598 | 1520 | #endif |
wolfSSL | 0:9d17e4342598 | 1521 | }; |
wolfSSL | 0:9d17e4342598 | 1522 | |
wolfSSL | 0:9d17e4342598 | 1523 | |
wolfSSL | 0:9d17e4342598 | 1524 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 1525 | CYASSL_SESSION* GetSession(CYASSL*, byte*); |
wolfSSL | 0:9d17e4342598 | 1526 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 1527 | int SetSession(CYASSL*, CYASSL_SESSION*); |
wolfSSL | 0:9d17e4342598 | 1528 | |
wolfSSL | 0:9d17e4342598 | 1529 | typedef int (*hmacfp) (CYASSL*, byte*, const byte*, word32, int, int); |
wolfSSL | 0:9d17e4342598 | 1530 | |
wolfSSL | 0:9d17e4342598 | 1531 | #ifndef NO_CLIENT_CACHE |
wolfSSL | 0:9d17e4342598 | 1532 | CYASSL_SESSION* GetSessionClient(CYASSL*, const byte*, int); |
wolfSSL | 0:9d17e4342598 | 1533 | #endif |
wolfSSL | 0:9d17e4342598 | 1534 | |
wolfSSL | 0:9d17e4342598 | 1535 | /* client connect state for nonblocking restart */ |
wolfSSL | 0:9d17e4342598 | 1536 | enum ConnectState { |
wolfSSL | 0:9d17e4342598 | 1537 | CONNECT_BEGIN = 0, |
wolfSSL | 0:9d17e4342598 | 1538 | CLIENT_HELLO_SENT, |
wolfSSL | 0:9d17e4342598 | 1539 | HELLO_AGAIN, /* HELLO_AGAIN s for DTLS case */ |
wolfSSL | 0:9d17e4342598 | 1540 | HELLO_AGAIN_REPLY, |
wolfSSL | 0:9d17e4342598 | 1541 | FIRST_REPLY_DONE, |
wolfSSL | 0:9d17e4342598 | 1542 | FIRST_REPLY_FIRST, |
wolfSSL | 0:9d17e4342598 | 1543 | FIRST_REPLY_SECOND, |
wolfSSL | 0:9d17e4342598 | 1544 | FIRST_REPLY_THIRD, |
wolfSSL | 0:9d17e4342598 | 1545 | FIRST_REPLY_FOURTH, |
wolfSSL | 0:9d17e4342598 | 1546 | FINISHED_DONE, |
wolfSSL | 0:9d17e4342598 | 1547 | SECOND_REPLY_DONE |
wolfSSL | 0:9d17e4342598 | 1548 | }; |
wolfSSL | 0:9d17e4342598 | 1549 | |
wolfSSL | 0:9d17e4342598 | 1550 | |
wolfSSL | 0:9d17e4342598 | 1551 | /* server accept state for nonblocking restart */ |
wolfSSL | 0:9d17e4342598 | 1552 | enum AcceptState { |
wolfSSL | 0:9d17e4342598 | 1553 | ACCEPT_BEGIN = 0, |
wolfSSL | 0:9d17e4342598 | 1554 | ACCEPT_CLIENT_HELLO_DONE, |
wolfSSL | 0:9d17e4342598 | 1555 | HELLO_VERIFY_SENT, |
wolfSSL | 0:9d17e4342598 | 1556 | ACCEPT_FIRST_REPLY_DONE, |
wolfSSL | 0:9d17e4342598 | 1557 | SERVER_HELLO_SENT, |
wolfSSL | 0:9d17e4342598 | 1558 | CERT_SENT, |
wolfSSL | 0:9d17e4342598 | 1559 | KEY_EXCHANGE_SENT, |
wolfSSL | 0:9d17e4342598 | 1560 | CERT_REQ_SENT, |
wolfSSL | 0:9d17e4342598 | 1561 | SERVER_HELLO_DONE, |
wolfSSL | 0:9d17e4342598 | 1562 | ACCEPT_SECOND_REPLY_DONE, |
wolfSSL | 0:9d17e4342598 | 1563 | CHANGE_CIPHER_SENT, |
wolfSSL | 0:9d17e4342598 | 1564 | ACCEPT_FINISHED_DONE, |
wolfSSL | 0:9d17e4342598 | 1565 | ACCEPT_THIRD_REPLY_DONE |
wolfSSL | 0:9d17e4342598 | 1566 | }; |
wolfSSL | 0:9d17e4342598 | 1567 | |
wolfSSL | 0:9d17e4342598 | 1568 | |
wolfSSL | 0:9d17e4342598 | 1569 | typedef struct Buffers { |
wolfSSL | 0:9d17e4342598 | 1570 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 1571 | buffer certificate; /* CYASSL_CTX owns, unless we own */ |
wolfSSL | 0:9d17e4342598 | 1572 | buffer key; /* CYASSL_CTX owns, unless we own */ |
wolfSSL | 0:9d17e4342598 | 1573 | buffer certChain; /* CYASSL_CTX owns */ |
wolfSSL | 0:9d17e4342598 | 1574 | /* chain after self, in DER, with leading size for each cert */ |
wolfSSL | 0:9d17e4342598 | 1575 | buffer serverDH_P; /* CYASSL_CTX owns, unless we own */ |
wolfSSL | 0:9d17e4342598 | 1576 | buffer serverDH_G; /* CYASSL_CTX owns, unless we own */ |
wolfSSL | 0:9d17e4342598 | 1577 | buffer serverDH_Pub; |
wolfSSL | 0:9d17e4342598 | 1578 | buffer serverDH_Priv; |
wolfSSL | 0:9d17e4342598 | 1579 | #endif |
wolfSSL | 0:9d17e4342598 | 1580 | buffer domainName; /* for client check */ |
wolfSSL | 0:9d17e4342598 | 1581 | bufferStatic inputBuffer; |
wolfSSL | 0:9d17e4342598 | 1582 | bufferStatic outputBuffer; |
wolfSSL | 0:9d17e4342598 | 1583 | buffer clearOutputBuffer; |
wolfSSL | 0:9d17e4342598 | 1584 | int prevSent; /* previous plain text bytes sent |
wolfSSL | 0:9d17e4342598 | 1585 | when got WANT_WRITE */ |
wolfSSL | 0:9d17e4342598 | 1586 | int plainSz; /* plain text bytes in buffer to send |
wolfSSL | 0:9d17e4342598 | 1587 | when got WANT_WRITE */ |
wolfSSL | 0:9d17e4342598 | 1588 | byte weOwnCert; /* SSL own cert flag */ |
wolfSSL | 0:9d17e4342598 | 1589 | byte weOwnKey; /* SSL own key flag */ |
wolfSSL | 0:9d17e4342598 | 1590 | byte weOwnDH; /* SSL own dh (p,g) flag */ |
wolfSSL | 0:9d17e4342598 | 1591 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 1592 | CYASSL_DTLS_CTX dtlsCtx; /* DTLS connection context */ |
wolfSSL | 0:9d17e4342598 | 1593 | #endif |
wolfSSL | 0:9d17e4342598 | 1594 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 1595 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 1596 | buffer peerEccDsaKey; /* we own for Ecc Verify Callbacks */ |
wolfSSL | 0:9d17e4342598 | 1597 | #endif /* HAVE_ECC */ |
wolfSSL | 0:9d17e4342598 | 1598 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 1599 | buffer peerRsaKey; /* we own for Rsa Verify Callbacks */ |
wolfSSL | 0:9d17e4342598 | 1600 | #endif /* NO_RSA */ |
wolfSSL | 0:9d17e4342598 | 1601 | #endif /* HAVE_PK_CALLBACKS */ |
wolfSSL | 0:9d17e4342598 | 1602 | } Buffers; |
wolfSSL | 0:9d17e4342598 | 1603 | |
wolfSSL | 0:9d17e4342598 | 1604 | typedef struct Options { |
wolfSSL | 0:9d17e4342598 | 1605 | byte sessionCacheOff; |
wolfSSL | 0:9d17e4342598 | 1606 | byte sessionCacheFlushOff; |
wolfSSL | 0:9d17e4342598 | 1607 | byte cipherSuite0; /* first byte, normally 0 */ |
wolfSSL | 0:9d17e4342598 | 1608 | byte cipherSuite; /* second byte, actual suite */ |
wolfSSL | 0:9d17e4342598 | 1609 | byte serverState; |
wolfSSL | 0:9d17e4342598 | 1610 | byte clientState; |
wolfSSL | 0:9d17e4342598 | 1611 | byte handShakeState; |
wolfSSL | 0:9d17e4342598 | 1612 | byte side; /* client or server end */ |
wolfSSL | 0:9d17e4342598 | 1613 | byte verifyPeer; |
wolfSSL | 0:9d17e4342598 | 1614 | byte verifyNone; |
wolfSSL | 0:9d17e4342598 | 1615 | byte failNoCert; |
wolfSSL | 0:9d17e4342598 | 1616 | byte downgrade; /* allow downgrade of versions */ |
wolfSSL | 0:9d17e4342598 | 1617 | byte sendVerify; /* false = 0, true = 1, sendBlank = 2 */ |
wolfSSL | 0:9d17e4342598 | 1618 | byte resuming; |
wolfSSL | 0:9d17e4342598 | 1619 | byte haveSessionId; /* server may not send */ |
wolfSSL | 0:9d17e4342598 | 1620 | byte tls; /* using TLS ? */ |
wolfSSL | 0:9d17e4342598 | 1621 | byte tls1_1; /* using TLSv1.1+ ? */ |
wolfSSL | 0:9d17e4342598 | 1622 | byte dtls; /* using datagrams ? */ |
wolfSSL | 0:9d17e4342598 | 1623 | byte connReset; /* has the peer reset */ |
wolfSSL | 0:9d17e4342598 | 1624 | byte isClosed; /* if we consider conn closed */ |
wolfSSL | 0:9d17e4342598 | 1625 | byte closeNotify; /* we've recieved a close notify */ |
wolfSSL | 0:9d17e4342598 | 1626 | byte sentNotify; /* we've sent a close notify */ |
wolfSSL | 0:9d17e4342598 | 1627 | byte connectState; /* nonblocking resume */ |
wolfSSL | 0:9d17e4342598 | 1628 | byte acceptState; /* nonblocking resume */ |
wolfSSL | 0:9d17e4342598 | 1629 | byte usingCompression; /* are we using compression */ |
wolfSSL | 0:9d17e4342598 | 1630 | byte haveRSA; /* RSA available */ |
wolfSSL | 0:9d17e4342598 | 1631 | byte haveDH; /* server DH parms set by user */ |
wolfSSL | 0:9d17e4342598 | 1632 | byte haveNTRU; /* server NTRU private key loaded */ |
wolfSSL | 0:9d17e4342598 | 1633 | byte haveECDSAsig; /* server ECDSA signed cert */ |
wolfSSL | 0:9d17e4342598 | 1634 | byte haveStaticECC; /* static server ECC private key */ |
wolfSSL | 0:9d17e4342598 | 1635 | byte havePeerCert; /* do we have peer's cert */ |
wolfSSL | 0:9d17e4342598 | 1636 | byte havePeerVerify; /* and peer's cert verify */ |
wolfSSL | 0:9d17e4342598 | 1637 | byte usingPSK_cipher; /* whether we're using psk as cipher */ |
wolfSSL | 0:9d17e4342598 | 1638 | byte sendAlertState; /* nonblocking resume */ |
wolfSSL | 0:9d17e4342598 | 1639 | byte processReply; /* nonblocking resume */ |
wolfSSL | 0:9d17e4342598 | 1640 | byte partialWrite; /* only one msg per write call */ |
wolfSSL | 0:9d17e4342598 | 1641 | byte quietShutdown; /* don't send close notify */ |
wolfSSL | 0:9d17e4342598 | 1642 | byte certOnly; /* stop once we get cert */ |
wolfSSL | 0:9d17e4342598 | 1643 | byte groupMessages; /* group handshake messages */ |
wolfSSL | 0:9d17e4342598 | 1644 | byte usingNonblock; /* set when using nonblocking socket */ |
wolfSSL | 0:9d17e4342598 | 1645 | byte saveArrays; /* save array Memory for user get keys |
wolfSSL | 0:9d17e4342598 | 1646 | or psk */ |
wolfSSL | 0:9d17e4342598 | 1647 | #ifndef NO_PSK |
wolfSSL | 0:9d17e4342598 | 1648 | byte havePSK; /* psk key set by user */ |
wolfSSL | 0:9d17e4342598 | 1649 | psk_client_callback client_psk_cb; |
wolfSSL | 0:9d17e4342598 | 1650 | psk_server_callback server_psk_cb; |
wolfSSL | 0:9d17e4342598 | 1651 | #endif /* NO_PSK */ |
wolfSSL | 0:9d17e4342598 | 1652 | } Options; |
wolfSSL | 0:9d17e4342598 | 1653 | |
wolfSSL | 0:9d17e4342598 | 1654 | typedef struct Arrays { |
wolfSSL | 0:9d17e4342598 | 1655 | byte clientRandom[RAN_LEN]; |
wolfSSL | 0:9d17e4342598 | 1656 | byte serverRandom[RAN_LEN]; |
wolfSSL | 0:9d17e4342598 | 1657 | byte sessionID[ID_LEN]; |
wolfSSL | 0:9d17e4342598 | 1658 | byte preMasterSecret[ENCRYPT_LEN]; |
wolfSSL | 0:9d17e4342598 | 1659 | byte masterSecret[SECRET_LEN]; |
wolfSSL | 0:9d17e4342598 | 1660 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 1661 | byte cookie[MAX_COOKIE_LEN]; |
wolfSSL | 0:9d17e4342598 | 1662 | byte cookieSz; |
wolfSSL | 0:9d17e4342598 | 1663 | #endif |
wolfSSL | 0:9d17e4342598 | 1664 | #ifndef NO_PSK |
wolfSSL | 0:9d17e4342598 | 1665 | char client_identity[MAX_PSK_ID_LEN]; |
wolfSSL | 0:9d17e4342598 | 1666 | char server_hint[MAX_PSK_ID_LEN]; |
wolfSSL | 0:9d17e4342598 | 1667 | byte psk_key[MAX_PSK_KEY_LEN]; |
wolfSSL | 0:9d17e4342598 | 1668 | word32 psk_keySz; /* acutal size */ |
wolfSSL | 0:9d17e4342598 | 1669 | #endif |
wolfSSL | 0:9d17e4342598 | 1670 | word32 preMasterSz; /* differs for DH, actual size */ |
wolfSSL | 0:9d17e4342598 | 1671 | } Arrays; |
wolfSSL | 0:9d17e4342598 | 1672 | |
wolfSSL | 0:9d17e4342598 | 1673 | #ifndef ASN_NAME_MAX |
wolfSSL | 0:9d17e4342598 | 1674 | #define ASN_NAME_MAX 256 |
wolfSSL | 0:9d17e4342598 | 1675 | #endif |
wolfSSL | 0:9d17e4342598 | 1676 | |
wolfSSL | 0:9d17e4342598 | 1677 | #ifndef MAX_DATE_SZ |
wolfSSL | 0:9d17e4342598 | 1678 | #define MAX_DATE_SZ 32 |
wolfSSL | 0:9d17e4342598 | 1679 | #endif |
wolfSSL | 0:9d17e4342598 | 1680 | |
wolfSSL | 0:9d17e4342598 | 1681 | struct CYASSL_X509_NAME { |
wolfSSL | 0:9d17e4342598 | 1682 | char *name; |
wolfSSL | 0:9d17e4342598 | 1683 | char staticName[ASN_NAME_MAX]; |
wolfSSL | 0:9d17e4342598 | 1684 | int dynamicName; |
wolfSSL | 0:9d17e4342598 | 1685 | int sz; |
wolfSSL | 0:9d17e4342598 | 1686 | #ifdef OPENSSL_EXTRA |
wolfSSL | 0:9d17e4342598 | 1687 | DecodedName fullName; |
wolfSSL | 0:9d17e4342598 | 1688 | #endif /* OPENSSL_EXTRA */ |
wolfSSL | 0:9d17e4342598 | 1689 | }; |
wolfSSL | 0:9d17e4342598 | 1690 | |
wolfSSL | 0:9d17e4342598 | 1691 | #ifndef EXTERNAL_SERIAL_SIZE |
wolfSSL | 0:9d17e4342598 | 1692 | #define EXTERNAL_SERIAL_SIZE 32 |
wolfSSL | 0:9d17e4342598 | 1693 | #endif |
wolfSSL | 0:9d17e4342598 | 1694 | |
wolfSSL | 0:9d17e4342598 | 1695 | #ifdef NO_ASN |
wolfSSL | 0:9d17e4342598 | 1696 | typedef struct DNS_entry DNS_entry; |
wolfSSL | 0:9d17e4342598 | 1697 | #endif |
wolfSSL | 0:9d17e4342598 | 1698 | |
wolfSSL | 0:9d17e4342598 | 1699 | struct CYASSL_X509 { |
wolfSSL | 0:9d17e4342598 | 1700 | int version; |
wolfSSL | 0:9d17e4342598 | 1701 | CYASSL_X509_NAME issuer; |
wolfSSL | 0:9d17e4342598 | 1702 | CYASSL_X509_NAME subject; |
wolfSSL | 0:9d17e4342598 | 1703 | int serialSz; |
wolfSSL | 0:9d17e4342598 | 1704 | byte serial[EXTERNAL_SERIAL_SIZE]; |
wolfSSL | 0:9d17e4342598 | 1705 | char subjectCN[ASN_NAME_MAX]; /* common name short cut */ |
wolfSSL | 0:9d17e4342598 | 1706 | #ifdef CYASSL_SEP |
wolfSSL | 0:9d17e4342598 | 1707 | int deviceTypeSz; |
wolfSSL | 0:9d17e4342598 | 1708 | byte deviceType[EXTERNAL_SERIAL_SIZE]; |
wolfSSL | 0:9d17e4342598 | 1709 | int hwTypeSz; |
wolfSSL | 0:9d17e4342598 | 1710 | byte hwType[EXTERNAL_SERIAL_SIZE]; |
wolfSSL | 0:9d17e4342598 | 1711 | int hwSerialNumSz; |
wolfSSL | 0:9d17e4342598 | 1712 | byte hwSerialNum[EXTERNAL_SERIAL_SIZE]; |
wolfSSL | 0:9d17e4342598 | 1713 | #ifdef OPENSSL_EXTRA |
wolfSSL | 0:9d17e4342598 | 1714 | byte certPolicySet; |
wolfSSL | 0:9d17e4342598 | 1715 | byte certPolicyCrit; |
wolfSSL | 0:9d17e4342598 | 1716 | #endif /* OPENSSL_EXTRA */ |
wolfSSL | 0:9d17e4342598 | 1717 | #endif |
wolfSSL | 0:9d17e4342598 | 1718 | int notBeforeSz; |
wolfSSL | 0:9d17e4342598 | 1719 | byte notBefore[MAX_DATE_SZ]; |
wolfSSL | 0:9d17e4342598 | 1720 | int notAfterSz; |
wolfSSL | 0:9d17e4342598 | 1721 | byte notAfter[MAX_DATE_SZ]; |
wolfSSL | 0:9d17e4342598 | 1722 | int sigOID; |
wolfSSL | 0:9d17e4342598 | 1723 | buffer sig; |
wolfSSL | 0:9d17e4342598 | 1724 | int pubKeyOID; |
wolfSSL | 0:9d17e4342598 | 1725 | buffer pubKey; |
wolfSSL | 0:9d17e4342598 | 1726 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 1727 | word32 pkCurveOID; |
wolfSSL | 0:9d17e4342598 | 1728 | #endif /* HAVE_ECC */ |
wolfSSL | 0:9d17e4342598 | 1729 | buffer derCert; /* may need */ |
wolfSSL | 0:9d17e4342598 | 1730 | DNS_entry* altNames; /* alt names list */ |
wolfSSL | 0:9d17e4342598 | 1731 | DNS_entry* altNamesNext; /* hint for retrieval */ |
wolfSSL | 0:9d17e4342598 | 1732 | byte dynamicMemory; /* dynamic memory flag */ |
wolfSSL | 0:9d17e4342598 | 1733 | byte isCa; |
wolfSSL | 0:9d17e4342598 | 1734 | #ifdef OPENSSL_EXTRA |
wolfSSL | 0:9d17e4342598 | 1735 | word32 pathLength; |
wolfSSL | 0:9d17e4342598 | 1736 | word16 keyUsage; |
wolfSSL | 0:9d17e4342598 | 1737 | byte basicConstSet; |
wolfSSL | 0:9d17e4342598 | 1738 | byte basicConstCrit; |
wolfSSL | 0:9d17e4342598 | 1739 | byte basicConstPlSet; |
wolfSSL | 0:9d17e4342598 | 1740 | byte subjAltNameSet; |
wolfSSL | 0:9d17e4342598 | 1741 | byte subjAltNameCrit; |
wolfSSL | 0:9d17e4342598 | 1742 | byte authKeyIdSet; |
wolfSSL | 0:9d17e4342598 | 1743 | byte authKeyIdCrit; |
wolfSSL | 0:9d17e4342598 | 1744 | byte* authKeyId; |
wolfSSL | 0:9d17e4342598 | 1745 | word32 authKeyIdSz; |
wolfSSL | 0:9d17e4342598 | 1746 | byte subjKeyIdSet; |
wolfSSL | 0:9d17e4342598 | 1747 | byte subjKeyIdCrit; |
wolfSSL | 0:9d17e4342598 | 1748 | byte* subjKeyId; |
wolfSSL | 0:9d17e4342598 | 1749 | word32 subjKeyIdSz; |
wolfSSL | 0:9d17e4342598 | 1750 | byte keyUsageSet; |
wolfSSL | 0:9d17e4342598 | 1751 | byte keyUsageCrit; |
wolfSSL | 0:9d17e4342598 | 1752 | #endif /* OPENSSL_EXTRA */ |
wolfSSL | 0:9d17e4342598 | 1753 | }; |
wolfSSL | 0:9d17e4342598 | 1754 | |
wolfSSL | 0:9d17e4342598 | 1755 | |
wolfSSL | 0:9d17e4342598 | 1756 | /* record layer header for PlainText, Compressed, and CipherText */ |
wolfSSL | 0:9d17e4342598 | 1757 | typedef struct RecordLayerHeader { |
wolfSSL | 0:9d17e4342598 | 1758 | byte type; |
wolfSSL | 0:9d17e4342598 | 1759 | byte pvMajor; |
wolfSSL | 0:9d17e4342598 | 1760 | byte pvMinor; |
wolfSSL | 0:9d17e4342598 | 1761 | byte length[2]; |
wolfSSL | 0:9d17e4342598 | 1762 | } RecordLayerHeader; |
wolfSSL | 0:9d17e4342598 | 1763 | |
wolfSSL | 0:9d17e4342598 | 1764 | |
wolfSSL | 0:9d17e4342598 | 1765 | /* record layer header for DTLS PlainText, Compressed, and CipherText */ |
wolfSSL | 0:9d17e4342598 | 1766 | typedef struct DtlsRecordLayerHeader { |
wolfSSL | 0:9d17e4342598 | 1767 | byte type; |
wolfSSL | 0:9d17e4342598 | 1768 | byte pvMajor; |
wolfSSL | 0:9d17e4342598 | 1769 | byte pvMinor; |
wolfSSL | 0:9d17e4342598 | 1770 | byte epoch[2]; /* increment on cipher state change */ |
wolfSSL | 0:9d17e4342598 | 1771 | byte sequence_number[6]; /* per record */ |
wolfSSL | 0:9d17e4342598 | 1772 | byte length[2]; |
wolfSSL | 0:9d17e4342598 | 1773 | } DtlsRecordLayerHeader; |
wolfSSL | 0:9d17e4342598 | 1774 | |
wolfSSL | 0:9d17e4342598 | 1775 | |
wolfSSL | 0:9d17e4342598 | 1776 | typedef struct DtlsPool { |
wolfSSL | 0:9d17e4342598 | 1777 | buffer buf[DTLS_POOL_SZ]; |
wolfSSL | 0:9d17e4342598 | 1778 | int used; |
wolfSSL | 0:9d17e4342598 | 1779 | } DtlsPool; |
wolfSSL | 0:9d17e4342598 | 1780 | |
wolfSSL | 0:9d17e4342598 | 1781 | typedef struct DtlsMsg { |
wolfSSL | 0:9d17e4342598 | 1782 | struct DtlsMsg* next; |
wolfSSL | 0:9d17e4342598 | 1783 | word32 seq; /* Handshake sequence number */ |
wolfSSL | 0:9d17e4342598 | 1784 | word32 sz; /* Length of whole mesage */ |
wolfSSL | 0:9d17e4342598 | 1785 | word32 fragSz; /* Length of fragments received */ |
wolfSSL | 0:9d17e4342598 | 1786 | byte type; |
wolfSSL | 0:9d17e4342598 | 1787 | byte* buf; |
wolfSSL | 0:9d17e4342598 | 1788 | byte* msg; |
wolfSSL | 0:9d17e4342598 | 1789 | } DtlsMsg; |
wolfSSL | 0:9d17e4342598 | 1790 | |
wolfSSL | 0:9d17e4342598 | 1791 | |
wolfSSL | 0:9d17e4342598 | 1792 | #ifdef HAVE_NETX |
wolfSSL | 0:9d17e4342598 | 1793 | |
wolfSSL | 0:9d17e4342598 | 1794 | /* NETX I/O Callback default */ |
wolfSSL | 0:9d17e4342598 | 1795 | typedef struct NetX_Ctx { |
wolfSSL | 0:9d17e4342598 | 1796 | NX_TCP_SOCKET* nxSocket; /* send/recv socket handle */ |
wolfSSL | 0:9d17e4342598 | 1797 | NX_PACKET* nxPacket; /* incoming packet handle for short reads */ |
wolfSSL | 0:9d17e4342598 | 1798 | ULONG nxOffset; /* offset already read from nxPacket */ |
wolfSSL | 0:9d17e4342598 | 1799 | ULONG nxWait; /* wait option flag */ |
wolfSSL | 0:9d17e4342598 | 1800 | } NetX_Ctx; |
wolfSSL | 0:9d17e4342598 | 1801 | |
wolfSSL | 0:9d17e4342598 | 1802 | #endif |
wolfSSL | 0:9d17e4342598 | 1803 | |
wolfSSL | 0:9d17e4342598 | 1804 | |
wolfSSL | 0:9d17e4342598 | 1805 | /* CyaSSL ssl type */ |
wolfSSL | 0:9d17e4342598 | 1806 | struct CYASSL { |
wolfSSL | 0:9d17e4342598 | 1807 | CYASSL_CTX* ctx; |
wolfSSL | 0:9d17e4342598 | 1808 | int error; |
wolfSSL | 0:9d17e4342598 | 1809 | ProtocolVersion version; /* negotiated version */ |
wolfSSL | 0:9d17e4342598 | 1810 | ProtocolVersion chVersion; /* client hello version */ |
wolfSSL | 0:9d17e4342598 | 1811 | Suites* suites; /* only need during handshake */ |
wolfSSL | 0:9d17e4342598 | 1812 | Ciphers encrypt; |
wolfSSL | 0:9d17e4342598 | 1813 | Ciphers decrypt; |
wolfSSL | 0:9d17e4342598 | 1814 | CipherSpecs specs; |
wolfSSL | 0:9d17e4342598 | 1815 | Keys keys; |
wolfSSL | 0:9d17e4342598 | 1816 | int rfd; /* read file descriptor */ |
wolfSSL | 0:9d17e4342598 | 1817 | int wfd; /* write file descriptor */ |
wolfSSL | 0:9d17e4342598 | 1818 | int rflags; /* user read flags */ |
wolfSSL | 0:9d17e4342598 | 1819 | int wflags; /* user write flags */ |
wolfSSL | 0:9d17e4342598 | 1820 | CYASSL_BIO* biord; /* socket bio read to free/close */ |
wolfSSL | 0:9d17e4342598 | 1821 | CYASSL_BIO* biowr; /* socket bio write to free/close */ |
wolfSSL | 0:9d17e4342598 | 1822 | void* IOCB_ReadCtx; |
wolfSSL | 0:9d17e4342598 | 1823 | void* IOCB_WriteCtx; |
wolfSSL | 0:9d17e4342598 | 1824 | RNG* rng; |
wolfSSL | 0:9d17e4342598 | 1825 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 1826 | #ifndef NO_SHA |
wolfSSL | 0:9d17e4342598 | 1827 | Sha hashSha; /* sha hash of handshake msgs */ |
wolfSSL | 0:9d17e4342598 | 1828 | #endif |
wolfSSL | 0:9d17e4342598 | 1829 | #ifndef NO_MD5 |
wolfSSL | 0:9d17e4342598 | 1830 | Md5 hashMd5; /* md5 hash of handshake msgs */ |
wolfSSL | 0:9d17e4342598 | 1831 | #endif |
wolfSSL | 0:9d17e4342598 | 1832 | #endif |
wolfSSL | 0:9d17e4342598 | 1833 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 1834 | Sha256 hashSha256; /* sha256 hash of handshake msgs */ |
wolfSSL | 0:9d17e4342598 | 1835 | #endif |
wolfSSL | 0:9d17e4342598 | 1836 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 1837 | Sha384 hashSha384; /* sha384 hash of handshake msgs */ |
wolfSSL | 0:9d17e4342598 | 1838 | #endif |
wolfSSL | 0:9d17e4342598 | 1839 | Hashes verifyHashes; |
wolfSSL | 0:9d17e4342598 | 1840 | Hashes certHashes; /* for cert verify */ |
wolfSSL | 0:9d17e4342598 | 1841 | Buffers buffers; |
wolfSSL | 0:9d17e4342598 | 1842 | Options options; |
wolfSSL | 0:9d17e4342598 | 1843 | Arrays* arrays; |
wolfSSL | 0:9d17e4342598 | 1844 | CYASSL_SESSION session; |
wolfSSL | 0:9d17e4342598 | 1845 | VerifyCallback verifyCallback; /* cert verification callback */ |
wolfSSL | 0:9d17e4342598 | 1846 | void* verifyCbCtx; /* cert verify callback user ctx*/ |
wolfSSL | 0:9d17e4342598 | 1847 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 1848 | RsaKey* peerRsaKey; |
wolfSSL | 0:9d17e4342598 | 1849 | byte peerRsaKeyPresent; |
wolfSSL | 0:9d17e4342598 | 1850 | #endif |
wolfSSL | 0:9d17e4342598 | 1851 | #ifdef HAVE_NTRU |
wolfSSL | 0:9d17e4342598 | 1852 | word16 peerNtruKeyLen; |
wolfSSL | 0:9d17e4342598 | 1853 | byte peerNtruKey[MAX_NTRU_PUB_KEY_SZ]; |
wolfSSL | 0:9d17e4342598 | 1854 | byte peerNtruKeyPresent; |
wolfSSL | 0:9d17e4342598 | 1855 | #endif |
wolfSSL | 0:9d17e4342598 | 1856 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 1857 | ecc_key* peerEccKey; /* peer's ECDHE key */ |
wolfSSL | 0:9d17e4342598 | 1858 | ecc_key* peerEccDsaKey; /* peer's ECDSA key */ |
wolfSSL | 0:9d17e4342598 | 1859 | ecc_key* eccTempKey; /* private ECDHE key */ |
wolfSSL | 0:9d17e4342598 | 1860 | ecc_key* eccDsaKey; /* private ECDSA key */ |
wolfSSL | 0:9d17e4342598 | 1861 | word16 eccTempKeySz; /* in octets 20 - 66 */ |
wolfSSL | 0:9d17e4342598 | 1862 | word32 pkCurveOID; /* curve Ecc_Sum */ |
wolfSSL | 0:9d17e4342598 | 1863 | byte peerEccKeyPresent; |
wolfSSL | 0:9d17e4342598 | 1864 | byte peerEccDsaKeyPresent; |
wolfSSL | 0:9d17e4342598 | 1865 | byte eccTempKeyPresent; |
wolfSSL | 0:9d17e4342598 | 1866 | byte eccDsaKeyPresent; |
wolfSSL | 0:9d17e4342598 | 1867 | #endif |
wolfSSL | 0:9d17e4342598 | 1868 | hmacfp hmac; |
wolfSSL | 0:9d17e4342598 | 1869 | void* heap; /* for user overrides */ |
wolfSSL | 0:9d17e4342598 | 1870 | RecordLayerHeader curRL; |
wolfSSL | 0:9d17e4342598 | 1871 | word16 curSize; |
wolfSSL | 0:9d17e4342598 | 1872 | word32 timeout; /* session timeout */ |
wolfSSL | 0:9d17e4342598 | 1873 | CYASSL_CIPHER cipher; |
wolfSSL | 0:9d17e4342598 | 1874 | #ifdef HAVE_LIBZ |
wolfSSL | 0:9d17e4342598 | 1875 | z_stream c_stream; /* compression stream */ |
wolfSSL | 0:9d17e4342598 | 1876 | z_stream d_stream; /* decompression stream */ |
wolfSSL | 0:9d17e4342598 | 1877 | byte didStreamInit; /* for stream init and end */ |
wolfSSL | 0:9d17e4342598 | 1878 | #endif |
wolfSSL | 0:9d17e4342598 | 1879 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 1880 | int dtls_timeout_init; /* starting timeout vaule */ |
wolfSSL | 0:9d17e4342598 | 1881 | int dtls_timeout_max; /* maximum timeout value */ |
wolfSSL | 0:9d17e4342598 | 1882 | int dtls_timeout; /* current timeout value, changes */ |
wolfSSL | 0:9d17e4342598 | 1883 | DtlsPool* dtls_pool; |
wolfSSL | 0:9d17e4342598 | 1884 | DtlsMsg* dtls_msg_list; |
wolfSSL | 0:9d17e4342598 | 1885 | void* IOCB_CookieCtx; /* gen cookie ctx */ |
wolfSSL | 0:9d17e4342598 | 1886 | word32 dtls_expected_rx; |
wolfSSL | 0:9d17e4342598 | 1887 | #endif |
wolfSSL | 0:9d17e4342598 | 1888 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 1889 | HandShakeInfo handShakeInfo; /* info saved during handshake */ |
wolfSSL | 0:9d17e4342598 | 1890 | TimeoutInfo timeoutInfo; /* info saved during handshake */ |
wolfSSL | 0:9d17e4342598 | 1891 | byte hsInfoOn; /* track handshake info */ |
wolfSSL | 0:9d17e4342598 | 1892 | byte toInfoOn; /* track timeout info */ |
wolfSSL | 0:9d17e4342598 | 1893 | #endif |
wolfSSL | 0:9d17e4342598 | 1894 | #ifdef KEEP_PEER_CERT |
wolfSSL | 0:9d17e4342598 | 1895 | CYASSL_X509 peerCert; /* X509 peer cert */ |
wolfSSL | 0:9d17e4342598 | 1896 | #endif |
wolfSSL | 0:9d17e4342598 | 1897 | #ifdef FORTRESS |
wolfSSL | 0:9d17e4342598 | 1898 | void* ex_data[MAX_EX_DATA]; /* external data, for Fortress */ |
wolfSSL | 0:9d17e4342598 | 1899 | #endif |
wolfSSL | 0:9d17e4342598 | 1900 | #ifdef HAVE_CAVIUM |
wolfSSL | 0:9d17e4342598 | 1901 | int devId; /* cavium device id to use */ |
wolfSSL | 0:9d17e4342598 | 1902 | #endif |
wolfSSL | 0:9d17e4342598 | 1903 | #ifdef HAVE_TLS_EXTENSIONS |
wolfSSL | 0:9d17e4342598 | 1904 | TLSX* extensions; /* RFC 6066 TLS Extensions data */ |
wolfSSL | 0:9d17e4342598 | 1905 | #ifdef HAVE_MAX_FRAGMENT |
wolfSSL | 0:9d17e4342598 | 1906 | word16 max_fragment; |
wolfSSL | 0:9d17e4342598 | 1907 | #endif |
wolfSSL | 0:9d17e4342598 | 1908 | #ifdef HAVE_TRUNCATED_HMAC |
wolfSSL | 0:9d17e4342598 | 1909 | byte truncated_hmac; |
wolfSSL | 0:9d17e4342598 | 1910 | #endif |
wolfSSL | 0:9d17e4342598 | 1911 | #endif |
wolfSSL | 0:9d17e4342598 | 1912 | #ifdef HAVE_NETX |
wolfSSL | 0:9d17e4342598 | 1913 | NetX_Ctx nxCtx; /* NetX IO Context */ |
wolfSSL | 0:9d17e4342598 | 1914 | #endif |
wolfSSL | 0:9d17e4342598 | 1915 | #ifdef SESSION_INDEX |
wolfSSL | 0:9d17e4342598 | 1916 | int sessionIndex; /* Session's location in the cache. */ |
wolfSSL | 0:9d17e4342598 | 1917 | #endif |
wolfSSL | 0:9d17e4342598 | 1918 | CYASSL_ALERT_HISTORY alert_history; |
wolfSSL | 0:9d17e4342598 | 1919 | #ifdef ATOMIC_USER |
wolfSSL | 0:9d17e4342598 | 1920 | void* MacEncryptCtx; /* Atomic User Mac/Encrypt Callback Context */ |
wolfSSL | 0:9d17e4342598 | 1921 | void* DecryptVerifyCtx; /* Atomic User Decrypt/Verify Callback Context */ |
wolfSSL | 0:9d17e4342598 | 1922 | #endif |
wolfSSL | 0:9d17e4342598 | 1923 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 1924 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 1925 | void* EccSignCtx; /* Ecc Sign Callback Context */ |
wolfSSL | 0:9d17e4342598 | 1926 | void* EccVerifyCtx; /* Ecc Verify Callback Context */ |
wolfSSL | 0:9d17e4342598 | 1927 | #endif /* HAVE_ECC */ |
wolfSSL | 0:9d17e4342598 | 1928 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 1929 | void* RsaSignCtx; /* Rsa Sign Callback Context */ |
wolfSSL | 0:9d17e4342598 | 1930 | void* RsaVerifyCtx; /* Rsa Verify Callback Context */ |
wolfSSL | 0:9d17e4342598 | 1931 | void* RsaEncCtx; /* Rsa Public Encrypt Callback Context */ |
wolfSSL | 0:9d17e4342598 | 1932 | void* RsaDecCtx; /* Rsa Private Decrypt Callback Context */ |
wolfSSL | 0:9d17e4342598 | 1933 | #endif /* NO_RSA */ |
wolfSSL | 0:9d17e4342598 | 1934 | #endif /* HAVE_PK_CALLBACKS */ |
wolfSSL | 0:9d17e4342598 | 1935 | }; |
wolfSSL | 0:9d17e4342598 | 1936 | |
wolfSSL | 0:9d17e4342598 | 1937 | |
wolfSSL | 0:9d17e4342598 | 1938 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 1939 | int InitSSL(CYASSL*, CYASSL_CTX*); |
wolfSSL | 0:9d17e4342598 | 1940 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 1941 | void FreeSSL(CYASSL*); |
wolfSSL | 0:9d17e4342598 | 1942 | CYASSL_API void SSL_ResourceFree(CYASSL*); /* Micrium uses */ |
wolfSSL | 0:9d17e4342598 | 1943 | |
wolfSSL | 0:9d17e4342598 | 1944 | |
wolfSSL | 0:9d17e4342598 | 1945 | enum { |
wolfSSL | 0:9d17e4342598 | 1946 | IV_SZ = 32, /* max iv sz */ |
wolfSSL | 0:9d17e4342598 | 1947 | NAME_SZ = 80 /* max one line */ |
wolfSSL | 0:9d17e4342598 | 1948 | }; |
wolfSSL | 0:9d17e4342598 | 1949 | |
wolfSSL | 0:9d17e4342598 | 1950 | |
wolfSSL | 0:9d17e4342598 | 1951 | typedef struct EncryptedInfo { |
wolfSSL | 0:9d17e4342598 | 1952 | char name[NAME_SZ]; /* encryption name */ |
wolfSSL | 0:9d17e4342598 | 1953 | byte iv[IV_SZ]; /* encrypted IV */ |
wolfSSL | 0:9d17e4342598 | 1954 | word32 ivSz; /* encrypted IV size */ |
wolfSSL | 0:9d17e4342598 | 1955 | long consumed; /* tracks PEM bytes consumed */ |
wolfSSL | 0:9d17e4342598 | 1956 | byte set; /* if encryption set */ |
wolfSSL | 0:9d17e4342598 | 1957 | CYASSL_CTX* ctx; /* CTX owner */ |
wolfSSL | 0:9d17e4342598 | 1958 | } EncryptedInfo; |
wolfSSL | 0:9d17e4342598 | 1959 | |
wolfSSL | 0:9d17e4342598 | 1960 | |
wolfSSL | 0:9d17e4342598 | 1961 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 1962 | CYASSL_LOCAL int PemToDer(const unsigned char* buff, long sz, int type, |
wolfSSL | 0:9d17e4342598 | 1963 | buffer* der, void* heap, EncryptedInfo* info, |
wolfSSL | 0:9d17e4342598 | 1964 | int* eccKey); |
wolfSSL | 0:9d17e4342598 | 1965 | |
wolfSSL | 0:9d17e4342598 | 1966 | CYASSL_LOCAL int ProcessFile(CYASSL_CTX* ctx, const char* fname, int format, |
wolfSSL | 0:9d17e4342598 | 1967 | int type, CYASSL* ssl, int userChain, |
wolfSSL | 0:9d17e4342598 | 1968 | CYASSL_CRL* crl); |
wolfSSL | 0:9d17e4342598 | 1969 | #endif |
wolfSSL | 0:9d17e4342598 | 1970 | |
wolfSSL | 0:9d17e4342598 | 1971 | |
wolfSSL | 0:9d17e4342598 | 1972 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 1973 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 1974 | void InitHandShakeInfo(HandShakeInfo*); |
wolfSSL | 0:9d17e4342598 | 1975 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 1976 | void FinishHandShakeInfo(HandShakeInfo*, const CYASSL*); |
wolfSSL | 0:9d17e4342598 | 1977 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 1978 | void AddPacketName(const char*, HandShakeInfo*); |
wolfSSL | 0:9d17e4342598 | 1979 | |
wolfSSL | 0:9d17e4342598 | 1980 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 1981 | void InitTimeoutInfo(TimeoutInfo*); |
wolfSSL | 0:9d17e4342598 | 1982 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 1983 | void FreeTimeoutInfo(TimeoutInfo*, void*); |
wolfSSL | 0:9d17e4342598 | 1984 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 1985 | void AddPacketInfo(const char*, TimeoutInfo*, const byte*, int, void*); |
wolfSSL | 0:9d17e4342598 | 1986 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 1987 | void AddLateName(const char*, TimeoutInfo*); |
wolfSSL | 0:9d17e4342598 | 1988 | CYASSL_LOCAL |
wolfSSL | 0:9d17e4342598 | 1989 | void AddLateRecordHeader(const RecordLayerHeader* rl, TimeoutInfo* info); |
wolfSSL | 0:9d17e4342598 | 1990 | #endif |
wolfSSL | 0:9d17e4342598 | 1991 | |
wolfSSL | 0:9d17e4342598 | 1992 | |
wolfSSL | 0:9d17e4342598 | 1993 | /* Record Layer Header identifier from page 12 */ |
wolfSSL | 0:9d17e4342598 | 1994 | enum ContentType { |
wolfSSL | 0:9d17e4342598 | 1995 | no_type = 0, |
wolfSSL | 0:9d17e4342598 | 1996 | change_cipher_spec = 20, |
wolfSSL | 0:9d17e4342598 | 1997 | alert = 21, |
wolfSSL | 0:9d17e4342598 | 1998 | handshake = 22, |
wolfSSL | 0:9d17e4342598 | 1999 | application_data = 23 |
wolfSSL | 0:9d17e4342598 | 2000 | }; |
wolfSSL | 0:9d17e4342598 | 2001 | |
wolfSSL | 0:9d17e4342598 | 2002 | |
wolfSSL | 0:9d17e4342598 | 2003 | /* handshake header, same for each message type, pgs 20/21 */ |
wolfSSL | 0:9d17e4342598 | 2004 | typedef struct HandShakeHeader { |
wolfSSL | 0:9d17e4342598 | 2005 | byte type; |
wolfSSL | 0:9d17e4342598 | 2006 | word24 length; |
wolfSSL | 0:9d17e4342598 | 2007 | } HandShakeHeader; |
wolfSSL | 0:9d17e4342598 | 2008 | |
wolfSSL | 0:9d17e4342598 | 2009 | |
wolfSSL | 0:9d17e4342598 | 2010 | /* DTLS handshake header, same for each message type */ |
wolfSSL | 0:9d17e4342598 | 2011 | typedef struct DtlsHandShakeHeader { |
wolfSSL | 0:9d17e4342598 | 2012 | byte type; |
wolfSSL | 0:9d17e4342598 | 2013 | word24 length; |
wolfSSL | 0:9d17e4342598 | 2014 | byte message_seq[2]; /* start at 0, restransmit gets same # */ |
wolfSSL | 0:9d17e4342598 | 2015 | word24 fragment_offset; /* bytes in previous fragments */ |
wolfSSL | 0:9d17e4342598 | 2016 | word24 fragment_length; /* length of this fragment */ |
wolfSSL | 0:9d17e4342598 | 2017 | } DtlsHandShakeHeader; |
wolfSSL | 0:9d17e4342598 | 2018 | |
wolfSSL | 0:9d17e4342598 | 2019 | |
wolfSSL | 0:9d17e4342598 | 2020 | enum HandShakeType { |
wolfSSL | 0:9d17e4342598 | 2021 | no_shake = -1, |
wolfSSL | 0:9d17e4342598 | 2022 | hello_request = 0, |
wolfSSL | 0:9d17e4342598 | 2023 | client_hello = 1, |
wolfSSL | 0:9d17e4342598 | 2024 | server_hello = 2, |
wolfSSL | 0:9d17e4342598 | 2025 | hello_verify_request = 3, /* DTLS addition */ |
wolfSSL | 0:9d17e4342598 | 2026 | session_ticket = 4, |
wolfSSL | 0:9d17e4342598 | 2027 | certificate = 11, |
wolfSSL | 0:9d17e4342598 | 2028 | server_key_exchange = 12, |
wolfSSL | 0:9d17e4342598 | 2029 | certificate_request = 13, |
wolfSSL | 0:9d17e4342598 | 2030 | server_hello_done = 14, |
wolfSSL | 0:9d17e4342598 | 2031 | certificate_verify = 15, |
wolfSSL | 0:9d17e4342598 | 2032 | client_key_exchange = 16, |
wolfSSL | 0:9d17e4342598 | 2033 | finished = 20 |
wolfSSL | 0:9d17e4342598 | 2034 | }; |
wolfSSL | 0:9d17e4342598 | 2035 | |
wolfSSL | 0:9d17e4342598 | 2036 | |
wolfSSL | 0:9d17e4342598 | 2037 | static const byte client[SIZEOF_SENDER] = { 0x43, 0x4C, 0x4E, 0x54 }; |
wolfSSL | 0:9d17e4342598 | 2038 | static const byte server[SIZEOF_SENDER] = { 0x53, 0x52, 0x56, 0x52 }; |
wolfSSL | 0:9d17e4342598 | 2039 | |
wolfSSL | 0:9d17e4342598 | 2040 | static const byte tls_client[FINISHED_LABEL_SZ + 1] = "client finished"; |
wolfSSL | 0:9d17e4342598 | 2041 | static const byte tls_server[FINISHED_LABEL_SZ + 1] = "server finished"; |
wolfSSL | 0:9d17e4342598 | 2042 | |
wolfSSL | 0:9d17e4342598 | 2043 | |
wolfSSL | 0:9d17e4342598 | 2044 | /* internal functions */ |
wolfSSL | 0:9d17e4342598 | 2045 | CYASSL_LOCAL int SendChangeCipher(CYASSL*); |
wolfSSL | 0:9d17e4342598 | 2046 | CYASSL_LOCAL int SendData(CYASSL*, const void*, int); |
wolfSSL | 0:9d17e4342598 | 2047 | CYASSL_LOCAL int SendCertificate(CYASSL*); |
wolfSSL | 0:9d17e4342598 | 2048 | CYASSL_LOCAL int SendCertificateRequest(CYASSL*); |
wolfSSL | 0:9d17e4342598 | 2049 | CYASSL_LOCAL int SendServerKeyExchange(CYASSL*); |
wolfSSL | 0:9d17e4342598 | 2050 | CYASSL_LOCAL int SendBuffered(CYASSL*); |
wolfSSL | 0:9d17e4342598 | 2051 | CYASSL_LOCAL int ReceiveData(CYASSL*, byte*, int, int); |
wolfSSL | 0:9d17e4342598 | 2052 | CYASSL_LOCAL int SendFinished(CYASSL*); |
wolfSSL | 0:9d17e4342598 | 2053 | CYASSL_LOCAL int SendAlert(CYASSL*, int, int); |
wolfSSL | 0:9d17e4342598 | 2054 | CYASSL_LOCAL int ProcessReply(CYASSL*); |
wolfSSL | 0:9d17e4342598 | 2055 | |
wolfSSL | 0:9d17e4342598 | 2056 | CYASSL_LOCAL int SetCipherSpecs(CYASSL*); |
wolfSSL | 0:9d17e4342598 | 2057 | CYASSL_LOCAL int MakeMasterSecret(CYASSL*); |
wolfSSL | 0:9d17e4342598 | 2058 | |
wolfSSL | 0:9d17e4342598 | 2059 | CYASSL_LOCAL int AddSession(CYASSL*); |
wolfSSL | 0:9d17e4342598 | 2060 | CYASSL_LOCAL int DeriveKeys(CYASSL* ssl); |
wolfSSL | 0:9d17e4342598 | 2061 | CYASSL_LOCAL int StoreKeys(CYASSL* ssl, const byte* keyData); |
wolfSSL | 0:9d17e4342598 | 2062 | |
wolfSSL | 0:9d17e4342598 | 2063 | CYASSL_LOCAL int IsTLS(const CYASSL* ssl); |
wolfSSL | 0:9d17e4342598 | 2064 | CYASSL_LOCAL int IsAtLeastTLSv1_2(const CYASSL* ssl); |
wolfSSL | 0:9d17e4342598 | 2065 | |
wolfSSL | 0:9d17e4342598 | 2066 | CYASSL_LOCAL void FreeHandshakeResources(CYASSL* ssl); |
wolfSSL | 0:9d17e4342598 | 2067 | CYASSL_LOCAL void ShrinkInputBuffer(CYASSL* ssl, int forcedFree); |
wolfSSL | 0:9d17e4342598 | 2068 | CYASSL_LOCAL void ShrinkOutputBuffer(CYASSL* ssl); |
wolfSSL | 0:9d17e4342598 | 2069 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 2070 | CYASSL_LOCAL Signer* GetCA(void* cm, byte* hash); |
wolfSSL | 0:9d17e4342598 | 2071 | #ifndef NO_SKID |
wolfSSL | 0:9d17e4342598 | 2072 | CYASSL_LOCAL Signer* GetCAByName(void* cm, byte* hash); |
wolfSSL | 0:9d17e4342598 | 2073 | #endif |
wolfSSL | 0:9d17e4342598 | 2074 | #endif |
wolfSSL | 0:9d17e4342598 | 2075 | CYASSL_LOCAL int BuildTlsFinished(CYASSL* ssl, Hashes* hashes, |
wolfSSL | 0:9d17e4342598 | 2076 | const byte* sender); |
wolfSSL | 0:9d17e4342598 | 2077 | CYASSL_LOCAL void FreeArrays(CYASSL* ssl, int keep); |
wolfSSL | 0:9d17e4342598 | 2078 | CYASSL_LOCAL int CheckAvailableSize(CYASSL *ssl, int size); |
wolfSSL | 0:9d17e4342598 | 2079 | CYASSL_LOCAL int GrowInputBuffer(CYASSL* ssl, int size, int usedLength); |
wolfSSL | 0:9d17e4342598 | 2080 | |
wolfSSL | 0:9d17e4342598 | 2081 | #ifndef NO_TLS |
wolfSSL | 0:9d17e4342598 | 2082 | CYASSL_LOCAL int MakeTlsMasterSecret(CYASSL*); |
wolfSSL | 0:9d17e4342598 | 2083 | CYASSL_LOCAL int TLS_hmac(CYASSL* ssl, byte* digest, const byte* in, |
wolfSSL | 0:9d17e4342598 | 2084 | word32 sz, int content, int verify); |
wolfSSL | 0:9d17e4342598 | 2085 | #endif |
wolfSSL | 0:9d17e4342598 | 2086 | |
wolfSSL | 0:9d17e4342598 | 2087 | #ifndef NO_CYASSL_CLIENT |
wolfSSL | 0:9d17e4342598 | 2088 | CYASSL_LOCAL int SendClientHello(CYASSL*); |
wolfSSL | 0:9d17e4342598 | 2089 | CYASSL_LOCAL int SendClientKeyExchange(CYASSL*); |
wolfSSL | 0:9d17e4342598 | 2090 | CYASSL_LOCAL int SendCertificateVerify(CYASSL*); |
wolfSSL | 0:9d17e4342598 | 2091 | #endif /* NO_CYASSL_CLIENT */ |
wolfSSL | 0:9d17e4342598 | 2092 | |
wolfSSL | 0:9d17e4342598 | 2093 | #ifndef NO_CYASSL_SERVER |
wolfSSL | 0:9d17e4342598 | 2094 | CYASSL_LOCAL int SendServerHello(CYASSL*); |
wolfSSL | 0:9d17e4342598 | 2095 | CYASSL_LOCAL int SendServerHelloDone(CYASSL*); |
wolfSSL | 0:9d17e4342598 | 2096 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 2097 | CYASSL_LOCAL int SendHelloVerifyRequest(CYASSL*); |
wolfSSL | 0:9d17e4342598 | 2098 | #endif |
wolfSSL | 0:9d17e4342598 | 2099 | #endif /* NO_CYASSL_SERVER */ |
wolfSSL | 0:9d17e4342598 | 2100 | |
wolfSSL | 0:9d17e4342598 | 2101 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 2102 | CYASSL_LOCAL int DtlsPoolInit(CYASSL*); |
wolfSSL | 0:9d17e4342598 | 2103 | CYASSL_LOCAL int DtlsPoolSave(CYASSL*, const byte*, int); |
wolfSSL | 0:9d17e4342598 | 2104 | CYASSL_LOCAL int DtlsPoolTimeout(CYASSL*); |
wolfSSL | 0:9d17e4342598 | 2105 | CYASSL_LOCAL int DtlsPoolSend(CYASSL*); |
wolfSSL | 0:9d17e4342598 | 2106 | CYASSL_LOCAL void DtlsPoolReset(CYASSL*); |
wolfSSL | 0:9d17e4342598 | 2107 | |
wolfSSL | 0:9d17e4342598 | 2108 | CYASSL_LOCAL DtlsMsg* DtlsMsgNew(word32, void*); |
wolfSSL | 0:9d17e4342598 | 2109 | CYASSL_LOCAL void DtlsMsgDelete(DtlsMsg*, void*); |
wolfSSL | 0:9d17e4342598 | 2110 | CYASSL_LOCAL void DtlsMsgListDelete(DtlsMsg*, void*); |
wolfSSL | 0:9d17e4342598 | 2111 | CYASSL_LOCAL void DtlsMsgSet(DtlsMsg*, word32, const byte*, byte, |
wolfSSL | 0:9d17e4342598 | 2112 | word32, word32); |
wolfSSL | 0:9d17e4342598 | 2113 | CYASSL_LOCAL DtlsMsg* DtlsMsgFind(DtlsMsg*, word32); |
wolfSSL | 0:9d17e4342598 | 2114 | CYASSL_LOCAL DtlsMsg* DtlsMsgStore(DtlsMsg*, word32, const byte*, word32, |
wolfSSL | 0:9d17e4342598 | 2115 | byte, word32, word32, void*); |
wolfSSL | 0:9d17e4342598 | 2116 | CYASSL_LOCAL DtlsMsg* DtlsMsgInsert(DtlsMsg*, DtlsMsg*); |
wolfSSL | 0:9d17e4342598 | 2117 | #endif /* CYASSL_DTLS */ |
wolfSSL | 0:9d17e4342598 | 2118 | |
wolfSSL | 0:9d17e4342598 | 2119 | #ifndef NO_TLS |
wolfSSL | 0:9d17e4342598 | 2120 | |
wolfSSL | 0:9d17e4342598 | 2121 | |
wolfSSL | 0:9d17e4342598 | 2122 | #endif /* NO_TLS */ |
wolfSSL | 0:9d17e4342598 | 2123 | |
wolfSSL | 0:9d17e4342598 | 2124 | |
wolfSSL | 0:9d17e4342598 | 2125 | CYASSL_LOCAL word32 LowResTimer(void); |
wolfSSL | 0:9d17e4342598 | 2126 | |
wolfSSL | 0:9d17e4342598 | 2127 | CYASSL_LOCAL void InitX509Name(CYASSL_X509_NAME*, int); |
wolfSSL | 0:9d17e4342598 | 2128 | CYASSL_LOCAL void FreeX509Name(CYASSL_X509_NAME* name); |
wolfSSL | 0:9d17e4342598 | 2129 | CYASSL_LOCAL void InitX509(CYASSL_X509*, int); |
wolfSSL | 0:9d17e4342598 | 2130 | CYASSL_LOCAL void FreeX509(CYASSL_X509*); |
wolfSSL | 0:9d17e4342598 | 2131 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 2132 | CYASSL_LOCAL int CopyDecodedToX509(CYASSL_X509*, DecodedCert*); |
wolfSSL | 0:9d17e4342598 | 2133 | #endif |
wolfSSL | 0:9d17e4342598 | 2134 | |
wolfSSL | 0:9d17e4342598 | 2135 | |
wolfSSL | 0:9d17e4342598 | 2136 | #ifdef __cplusplus |
wolfSSL | 0:9d17e4342598 | 2137 | } /* extern "C" */ |
wolfSSL | 0:9d17e4342598 | 2138 | #endif |
wolfSSL | 0:9d17e4342598 | 2139 | |
wolfSSL | 0:9d17e4342598 | 2140 | #endif /* CyaSSL_INT_H */ |
wolfSSL | 0:9d17e4342598 | 2141 |