wolfSSL SSL/TLS library, support up to TLS1.3

Dependents:   CyaSSL-Twitter-OAuth4Tw Example-client-tls-cert TwitterReader TweetTest ... more

Committer:
wolfSSL
Date:
Fri Jun 26 00:39:20 2015 +0000
Revision:
0:d92f9d21154c
Child:
1:e27310ce7654
wolfSSL 3.6.0

Who changed what in which revision?

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