24 #ifndef MBEDTLS_SSL_INTERNAL_H 25 #define MBEDTLS_SSL_INTERNAL_H 30 #if defined(MBEDTLS_MD5_C) 34 #if defined(MBEDTLS_SHA1_C) 38 #if defined(MBEDTLS_SHA256_C) 42 #if defined(MBEDTLS_SHA512_C) 46 #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) 50 #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \ 51 !defined(inline) && !defined(__cplusplus) 52 #define inline __inline 56 #define MBEDTLS_SSL_MIN_MAJOR_VERSION MBEDTLS_SSL_MAJOR_VERSION_3 58 #if defined(MBEDTLS_SSL_PROTO_SSL3) 59 #define MBEDTLS_SSL_MIN_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_0 61 #if defined(MBEDTLS_SSL_PROTO_TLS1) 62 #define MBEDTLS_SSL_MIN_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_1 64 #if defined(MBEDTLS_SSL_PROTO_TLS1_1) 65 #define MBEDTLS_SSL_MIN_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_2 67 #if defined(MBEDTLS_SSL_PROTO_TLS1_2) 68 #define MBEDTLS_SSL_MIN_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_3 74 #define MBEDTLS_SSL_MIN_VALID_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_1 75 #define MBEDTLS_SSL_MIN_VALID_MAJOR_VERSION MBEDTLS_SSL_MAJOR_VERSION_3 78 #define MBEDTLS_SSL_MAX_MAJOR_VERSION MBEDTLS_SSL_MAJOR_VERSION_3 80 #if defined(MBEDTLS_SSL_PROTO_TLS1_2) 81 #define MBEDTLS_SSL_MAX_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_3 83 #if defined(MBEDTLS_SSL_PROTO_TLS1_1) 84 #define MBEDTLS_SSL_MAX_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_2 86 #if defined(MBEDTLS_SSL_PROTO_TLS1) 87 #define MBEDTLS_SSL_MAX_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_1 89 #if defined(MBEDTLS_SSL_PROTO_SSL3) 90 #define MBEDTLS_SSL_MAX_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_0 97 #if defined(MBEDTLS_ECP_RESTARTABLE) && \ 98 defined(MBEDTLS_SSL_CLI_C) && \ 99 defined(MBEDTLS_SSL_PROTO_TLS1_2) && \ 100 defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) 101 #define MBEDTLS_SSL__ECP_RESTARTABLE 104 #define MBEDTLS_SSL_INITIAL_HANDSHAKE 0 105 #define MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS 1 106 #define MBEDTLS_SSL_RENEGOTIATION_DONE 2 107 #define MBEDTLS_SSL_RENEGOTIATION_PENDING 3 117 #define MBEDTLS_SSL_RETRANS_PREPARING 0 118 #define MBEDTLS_SSL_RETRANS_SENDING 1 119 #define MBEDTLS_SSL_RETRANS_WAITING 2 120 #define MBEDTLS_SSL_RETRANS_FINISHED 3 128 #if defined(MBEDTLS_ZLIB_SUPPORT) 129 #define MBEDTLS_SSL_COMPRESSION_ADD 1024 131 #define MBEDTLS_SSL_COMPRESSION_ADD 0 134 #if defined(MBEDTLS_ARC4_C) || defined(MBEDTLS_CIPHER_MODE_CBC) 136 #if defined(MBEDTLS_SHA512_C) 137 #define MBEDTLS_SSL_MAC_ADD 48 138 #elif defined(MBEDTLS_SHA256_C) 139 #define MBEDTLS_SSL_MAC_ADD 32 141 #define MBEDTLS_SSL_MAC_ADD 20 145 #define MBEDTLS_SSL_MAC_ADD 16 148 #if defined(MBEDTLS_CIPHER_MODE_CBC) 149 #define MBEDTLS_SSL_PADDING_ADD 256 151 #define MBEDTLS_SSL_PADDING_ADD 0 154 #define MBEDTLS_SSL_PAYLOAD_OVERHEAD ( MBEDTLS_SSL_COMPRESSION_ADD + \ 155 MBEDTLS_MAX_IV_LENGTH + \ 156 MBEDTLS_SSL_MAC_ADD + \ 157 MBEDTLS_SSL_PADDING_ADD \ 160 #define MBEDTLS_SSL_IN_PAYLOAD_LEN ( MBEDTLS_SSL_PAYLOAD_OVERHEAD + \ 161 ( MBEDTLS_SSL_IN_CONTENT_LEN ) ) 163 #define MBEDTLS_SSL_OUT_PAYLOAD_LEN ( MBEDTLS_SSL_PAYLOAD_OVERHEAD + \ 164 ( MBEDTLS_SSL_OUT_CONTENT_LEN ) ) 167 #define MBEDTLS_SSL_MAX_BUFFERED_HS 4 173 #define MBEDTLS_TLS_EXT_ADV_CONTENT_LEN ( \ 174 (MBEDTLS_SSL_IN_CONTENT_LEN > MBEDTLS_SSL_OUT_CONTENT_LEN) \ 175 ? ( MBEDTLS_SSL_OUT_CONTENT_LEN ) \ 176 : ( MBEDTLS_SSL_IN_CONTENT_LEN ) \ 183 #if MBEDTLS_SSL_MAX_CONTENT_LEN > 16384 184 #error "Bad configuration - record content too large." 187 #if MBEDTLS_SSL_IN_CONTENT_LEN > MBEDTLS_SSL_MAX_CONTENT_LEN 188 #error "Bad configuration - incoming record content should not be larger than MBEDTLS_SSL_MAX_CONTENT_LEN." 191 #if MBEDTLS_SSL_OUT_CONTENT_LEN > MBEDTLS_SSL_MAX_CONTENT_LEN 192 #error "Bad configuration - outgoing record content should not be larger than MBEDTLS_SSL_MAX_CONTENT_LEN." 195 #if MBEDTLS_SSL_IN_PAYLOAD_LEN > MBEDTLS_SSL_MAX_CONTENT_LEN + 2048 196 #error "Bad configuration - incoming protected record payload too large." 199 #if MBEDTLS_SSL_OUT_PAYLOAD_LEN > MBEDTLS_SSL_MAX_CONTENT_LEN + 2048 200 #error "Bad configuration - outgoing protected record payload too large." 208 #define MBEDTLS_SSL_HEADER_LEN 13 210 #define MBEDTLS_SSL_IN_BUFFER_LEN \ 211 ( ( MBEDTLS_SSL_HEADER_LEN ) + ( MBEDTLS_SSL_IN_PAYLOAD_LEN ) ) 213 #define MBEDTLS_SSL_OUT_BUFFER_LEN \ 214 ( ( MBEDTLS_SSL_HEADER_LEN ) + ( MBEDTLS_SSL_OUT_PAYLOAD_LEN ) ) 216 #ifdef MBEDTLS_ZLIB_SUPPORT 218 #define MBEDTLS_SSL_COMPRESS_BUFFER_LEN ( \ 219 ( MBEDTLS_SSL_IN_BUFFER_LEN > MBEDTLS_SSL_OUT_BUFFER_LEN ) \ 220 ? MBEDTLS_SSL_IN_BUFFER_LEN \ 221 : MBEDTLS_SSL_OUT_BUFFER_LEN \ 230 #define MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS_PRESENT (1 << 0) 231 #define MBEDTLS_TLS_EXT_ECJPAKE_KKPP_OK (1 << 1) 237 #if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \ 238 defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED) 264 #if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \ 265 defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED) 268 #if defined(MBEDTLS_DHM_C) 271 #if defined(MBEDTLS_ECDH_C) 274 #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) 276 #if defined(MBEDTLS_SSL_CLI_C) 277 unsigned char *ecjpake_cache;
278 size_t ecjpake_cache_len;
281 #if defined(MBEDTLS_ECDH_C) || defined(MBEDTLS_ECDSA_C) || \ 282 defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) 285 #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED) 289 #if defined(MBEDTLS_X509_CRT_PARSE_C) 290 mbedtls_ssl_key_cert *key_cert;
291 #if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION) 293 mbedtls_ssl_key_cert *sni_key_cert;
298 #if defined(MBEDTLS_SSL__ECP_RESTARTABLE) 304 ssl_ecrs_ske_start_processing,
305 ssl_ecrs_cke_ecdh_calc_secret,
306 ssl_ecrs_crt_vrfy_sign,
310 #if defined(MBEDTLS_SSL_PROTO_DTLS) 311 unsigned int out_msg_seq;
312 unsigned int in_msg_seq;
314 unsigned char *verify_cookie;
316 unsigned char verify_cookie_len;
319 uint32_t retransmit_timeout;
320 unsigned char retransmit_state;
321 mbedtls_ssl_flight_item *flight;
322 mbedtls_ssl_flight_item *cur_msg;
323 unsigned char *cur_msg_p;
324 unsigned int in_flight_start_seq;
328 unsigned char alt_out_ctr[8];
333 size_t total_bytes_buffered;
341 unsigned is_valid : 1;
342 unsigned is_fragmented : 1;
343 unsigned is_complete : 1;
363 #if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \ 364 defined(MBEDTLS_SSL_PROTO_TLS1_1) 368 #if defined(MBEDTLS_SSL_PROTO_TLS1_2) 369 #if defined(MBEDTLS_SHA256_C) 372 #if defined(MBEDTLS_SHA512_C) 380 int (*
tls_prf)(
const unsigned char *, size_t,
const char *,
381 const unsigned char *, size_t,
382 unsigned char *, size_t);
395 #if defined(MBEDTLS_SSL_SESSION_TICKETS) 396 int new_session_ticket;
398 #if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET) 402 #if defined(MBEDTLS_SSL_ASYNC_PRIVATE) 403 unsigned int async_in_progress : 1;
406 #if defined(MBEDTLS_SSL_ASYNC_PRIVATE) 412 void *user_async_ctx;
438 #if defined(MBEDTLS_SSL_PROTO_SSL3) 440 unsigned char mac_enc[20];
441 unsigned char mac_dec[20];
453 #if defined(MBEDTLS_ZLIB_SUPPORT) 454 z_stream ctx_deflate;
455 z_stream ctx_inflate;
459 #if defined(MBEDTLS_X509_CRT_PARSE_C) 463 struct mbedtls_ssl_key_cert
467 mbedtls_ssl_key_cert *next;
471 #if defined(MBEDTLS_SSL_PROTO_DTLS) 475 struct mbedtls_ssl_flight_item
480 mbedtls_ssl_flight_item *next;
484 #if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \ 485 defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED) 613 unsigned update_hs_digest );
632 #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED) 636 #if defined(MBEDTLS_PK_C) 646 #if defined(MBEDTLS_ECP_C) 650 #if defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED) 655 #if defined(MBEDTLS_X509_CRT_PARSE_C) 658 mbedtls_ssl_key_cert *key_cert;
663 key_cert = ssl->
conf->key_cert;
665 return( key_cert == NULL ? NULL : key_cert->key );
670 mbedtls_ssl_key_cert *key_cert;
675 key_cert = ssl->
conf->key_cert;
677 return( key_cert == NULL ? NULL : key_cert->cert );
696 unsigned char ver[2] );
698 const unsigned char ver[2] );
702 #if defined(MBEDTLS_SSL_PROTO_DTLS) 713 #if defined(MBEDTLS_SSL_PROTO_DTLS) 722 #if defined(MBEDTLS_SSL_PROTO_DTLS) 730 #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY) 736 static inline int mbedtls_ssl_safer_memcmp(
const void *a,
const void *b,
size_t n )
739 volatile const unsigned char *A = (
volatile const unsigned char *) a;
740 volatile const unsigned char *B = (
volatile const unsigned char *) b;
741 volatile unsigned char diff = 0;
743 for( i = 0; i < n; i++ )
748 unsigned char x = A[i], y = B[i];
755 #if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \ 756 defined(MBEDTLS_SSL_PROTO_TLS1_1) 758 unsigned char *output,
759 unsigned char *data,
size_t data_len );
763 #if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || \ 764 defined(MBEDTLS_SSL_PROTO_TLS1_2) 766 unsigned char *hash,
size_t *hashlen,
767 unsigned char *data,
size_t data_len,
void mbedtls_ssl_handshake_free(mbedtls_ssl_context *ssl)
Free referenced items in an SSL handshake context and clear memory.
unsigned int transport
Definition: ssl.h:981
int mbedtls_ssl_parse_finished(mbedtls_ssl_context *ssl)
unsigned char mbedtls_ssl_hash_from_md_alg(int md)
Public key container.
Definition: pk.h:130
void(* update_checksum)(mbedtls_ssl_context *, const unsigned char *, size_t)
Definition: ssl_internal.h:377
void mbedtls_ssl_read_version(int *major, int *minor, int transport, const unsigned char ver[2])
int mbedtls_ssl_handshake_server_step(mbedtls_ssl_context *ssl)
unsigned char randbytes[64]
Definition: ssl_internal.h:386
int mbedtls_ssl_write_change_cipher_spec(mbedtls_ssl_context *ssl)
struct mbedtls_ssl_sig_hash_set_t mbedtls_ssl_sig_hash_set_t
Definition: ssl.h:566
int mbedtls_ssl_write_finished(mbedtls_ssl_context *ssl)
Definition: x509_crl.h:70
int mbedtls_ssl_set_calc_verify_md(mbedtls_ssl_context *ssl, int md)
mbedtls_pk_type_t
Public key types.
Definition: pk.h:78
int mbedtls_ssl_handle_message_type(mbedtls_ssl_context *ssl)
int mbedtls_ssl_parse_certificate(mbedtls_ssl_context *ssl)
#define MBEDTLS_SSL_TRANSPORT_DATAGRAM
Definition: ssl.h:137
int mbedtls_ssl_derive_keys(mbedtls_ssl_context *ssl)
int max_major_ver
Definition: ssl_internal.h:391
Definition: ssl_internal.h:258
int mbedtls_ssl_prepare_handshake_record(mbedtls_ssl_context *ssl)
int mbedtls_ssl_fetch_input(mbedtls_ssl_context *ssl, size_t nb_want)
mbedtls_ssl_handshake_params * handshake
Definition: ssl.h:1059
void mbedtls_ssl_update_handshake_status(mbedtls_ssl_context *ssl)
void mbedtls_ssl_transform_free(mbedtls_ssl_transform *transform)
Free referenced items in an SSL transform context and clear memory.
The SHA-512 context structure.
Definition: sha512.h:57
struct mbedtls_ssl_hs_buffer mbedtls_ssl_hs_buffer
Definition: ssl_internal.h:416
#define MBEDTLS_SSL_MAX_BUFFERED_HS
Definition: ssl_internal.h:167
void mbedtls_x509_crt_restart_ctx
Definition: x509_crt.h:199
mbedtls_md_type_t mbedtls_ssl_md_alg_from_hash(unsigned char hash)
void(* calc_verify)(mbedtls_ssl_context *, unsigned char *)
Definition: ssl_internal.h:378
int mbedtls_ssl_send_fatal_handshake_failure(mbedtls_ssl_context *ssl)
mbedtls_key_exchange_type_t
Definition: ssl_ciphersuites.h:286
int mbedtls_ssl_read_record(mbedtls_ssl_context *ssl, unsigned update_hs_digest)
Update record layer.
This file contains an abstraction interface for use with the cipher primitives provided by the librar...
size_t pmslen
Definition: ssl_internal.h:384
mbedtls_ecp_group_id
Definition: ecp.h:71
int mbedtls_ssl_write_record(mbedtls_ssl_context *ssl, uint8_t force_flush)
The DHM context structure.
Definition: dhm.h:102
const mbedtls_ssl_config * conf
Definition: ssl.h:1024
The SHA-256 context structure.
Definition: sha256.h:58
The ECDH context structure.
Definition: ecdh.h:104
int mbedtls_ssl_write_certificate(mbedtls_ssl_context *ssl)
int resume
Definition: ssl_internal.h:390
int cli_exts
Definition: ssl_internal.h:393
This structure is used for storing ciphersuite information.
Definition: ssl_ciphersuites.h:385
#define MBEDTLS_PREMASTER_SIZE
Definition: ssl.h:416
int mbedtls_ssl_write_handshake_msg(mbedtls_ssl_context *ssl)
int mbedtls_ssl_parse_change_cipher_spec(mbedtls_ssl_context *ssl)
void mbedtls_ssl_write_version(int major, int minor, int transport, unsigned char ver[2])
This file contains SHA-1 definitions and functions.
int mbedtls_ssl_flush_output(mbedtls_ssl_context *ssl)
MD5 context structure.
Definition: md5.h:59
void mbedtls_ssl_optimize_checksum(mbedtls_ssl_context *ssl, const mbedtls_ssl_ciphersuite_t *ciphersuite_info)
void mbedtls_ssl_reset_checksum(mbedtls_ssl_context *ssl)
Definition: x509_crt.h:53
The SHA-1 context structure.
Definition: sha1.h:63
This file contains SHA-384 and SHA-512 definitions and functions.
int mbedtls_ssl_handshake_client_step(mbedtls_ssl_context *ssl)
unsigned char premaster[MBEDTLS_PREMASTER_SIZE]
Definition: ssl_internal.h:387
void mbedtls_ssl_handshake_wrapup(mbedtls_ssl_context *ssl)
void(* calc_finished)(mbedtls_ssl_context *, unsigned char *, int)
Definition: ssl_internal.h:379
int max_minor_ver
Definition: ssl_internal.h:392
int(* tls_prf)(const unsigned char *, size_t, const char *, const unsigned char *, size_t, unsigned char *, size_t)
Definition: ssl_internal.h:380
mbedtls_md_type_t
Supported message digests.
Definition: md.h:58
#define md
Definition: compat-1.3.h:1982
MD5 message digest algorithm (hash function)
This file contains SHA-224 and SHA-256 definitions and functions.