24 #ifndef POLARSSL_SSL_H
25 #define POLARSSL_SSL_H
27 #if !defined(POLARSSL_CONFIG_FILE)
30 #include POLARSSL_CONFIG_FILE
34 #if !defined(POLARSSL_SSL_DISABLE_RENEGOTIATION)
35 #define POLARSSL_SSL_RENEGOTIATION
44 #if defined(POLARSSL_MD5_C)
48 #if defined(POLARSSL_SHA1_C)
52 #if defined(POLARSSL_SHA256_C)
56 #if defined(POLARSSL_SHA512_C)
61 #if defined(POLARSSL_AES_C)
65 #if defined(POLARSSL_X509_CRT_PARSE_C)
70 #if defined(POLARSSL_DHM_C)
74 #if defined(POLARSSL_ECDH_C)
78 #if defined(POLARSSL_ZLIB_SUPPORT)
82 #if defined(POLARSSL_HAVE_TIME)
87 #if defined(POLARSSL_KEY_EXCHANGE_PSK_ENABLED) || \
88 defined(POLARSSL_KEY_EXCHANGE_RSA_PSK_ENABLED) || \
89 defined(POLARSSL_KEY_EXCHANGE_DHE_PSK_ENABLED) || \
90 defined(POLARSSL_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
91 #define POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED
94 #if defined(POLARSSL_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
95 defined(POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
96 defined(POLARSSL_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
97 #define POLARSSL_KEY_EXCHANGE__SOME__ECDHE_ENABLED
100 #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
101 !defined(inline) && !defined(__cplusplus)
102 #define inline __inline
108 #define POLARSSL_ERR_SSL_FEATURE_UNAVAILABLE -0x7080
109 #define POLARSSL_ERR_SSL_BAD_INPUT_DATA -0x7100
110 #define POLARSSL_ERR_SSL_INVALID_MAC -0x7180
111 #define POLARSSL_ERR_SSL_INVALID_RECORD -0x7200
112 #define POLARSSL_ERR_SSL_CONN_EOF -0x7280
113 #define POLARSSL_ERR_SSL_UNKNOWN_CIPHER -0x7300
114 #define POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN -0x7380
115 #define POLARSSL_ERR_SSL_NO_RNG -0x7400
116 #define POLARSSL_ERR_SSL_NO_CLIENT_CERTIFICATE -0x7480
117 #define POLARSSL_ERR_SSL_CERTIFICATE_TOO_LARGE -0x7500
118 #define POLARSSL_ERR_SSL_CERTIFICATE_REQUIRED -0x7580
119 #define POLARSSL_ERR_SSL_PRIVATE_KEY_REQUIRED -0x7600
120 #define POLARSSL_ERR_SSL_CA_CHAIN_REQUIRED -0x7680
121 #define POLARSSL_ERR_SSL_UNEXPECTED_MESSAGE -0x7700
122 #define POLARSSL_ERR_SSL_FATAL_ALERT_MESSAGE -0x7780
123 #define POLARSSL_ERR_SSL_PEER_VERIFY_FAILED -0x7800
124 #define POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY -0x7880
125 #define POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO -0x7900
126 #define POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO -0x7980
127 #define POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE -0x7A00
128 #define POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST -0x7A80
129 #define POLARSSL_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE -0x7B00
130 #define POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO_DONE -0x7B80
131 #define POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE -0x7C00
132 #define POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP -0x7C80
133 #define POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS -0x7D00
134 #define POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY -0x7D80
135 #define POLARSSL_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC -0x7E00
136 #define POLARSSL_ERR_SSL_BAD_HS_FINISHED -0x7E80
137 #define POLARSSL_ERR_SSL_MALLOC_FAILED -0x7F00
138 #define POLARSSL_ERR_SSL_HW_ACCEL_FAILED -0x7F80
139 #define POLARSSL_ERR_SSL_HW_ACCEL_FALLTHROUGH -0x6F80
140 #define POLARSSL_ERR_SSL_COMPRESSION_FAILED -0x6F00
141 #define POLARSSL_ERR_SSL_BAD_HS_PROTOCOL_VERSION -0x6E80
142 #define POLARSSL_ERR_SSL_BAD_HS_NEW_SESSION_TICKET -0x6E00
143 #define POLARSSL_ERR_SSL_SESSION_TICKET_EXPIRED -0x6D80
144 #define POLARSSL_ERR_SSL_PK_TYPE_MISMATCH -0x6D00
145 #define POLARSSL_ERR_SSL_UNKNOWN_IDENTITY -0x6C80
146 #define POLARSSL_ERR_SSL_INTERNAL_ERROR -0x6C00
147 #define POLARSSL_ERR_SSL_COUNTER_WRAPPING -0x6B80
148 #define POLARSSL_ERR_SSL_WAITING_SERVER_HELLO_RENEGO -0x6B00
149 #define POLARSSL_ERR_SSL_NO_USABLE_CIPHERSUITE -0x6A80
154 #define SSL_MAJOR_VERSION_3 3
155 #define SSL_MINOR_VERSION_0 0
156 #define SSL_MINOR_VERSION_1 1
157 #define SSL_MINOR_VERSION_2 2
158 #define SSL_MINOR_VERSION_3 3
161 #define SSL_MIN_MAJOR_VERSION SSL_MAJOR_VERSION_3
163 #if defined(POLARSSL_SSL_PROTO_SSL3)
164 #define SSL_MIN_MINOR_VERSION SSL_MINOR_VERSION_0
166 #if defined(POLARSSL_SSL_PROTO_TLS1)
167 #define SSL_MIN_MINOR_VERSION SSL_MINOR_VERSION_1
169 #if defined(POLARSSL_SSL_PROTO_TLS1_1)
170 #define SSL_MIN_MINOR_VERSION SSL_MINOR_VERSION_2
172 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
173 #define SSL_MIN_MINOR_VERSION SSL_MINOR_VERSION_3
180 #define SSL_MAX_MAJOR_VERSION SSL_MAJOR_VERSION_3
182 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
183 #define SSL_MAX_MINOR_VERSION SSL_MINOR_VERSION_3
185 #if defined(POLARSSL_SSL_PROTO_TLS1_1)
186 #define SSL_MAX_MINOR_VERSION SSL_MINOR_VERSION_2
188 #if defined(POLARSSL_SSL_PROTO_TLS1)
189 #define SSL_MAX_MINOR_VERSION SSL_MINOR_VERSION_1
191 #if defined(POLARSSL_SSL_PROTO_SSL3)
192 #define SSL_MAX_MINOR_VERSION SSL_MINOR_VERSION_0
198 #define SSL_MAX_HOST_NAME_LEN 255
202 #define SSL_MAX_FRAG_LEN_NONE 0
203 #define SSL_MAX_FRAG_LEN_512 1
204 #define SSL_MAX_FRAG_LEN_1024 2
205 #define SSL_MAX_FRAG_LEN_2048 3
206 #define SSL_MAX_FRAG_LEN_4096 4
207 #define SSL_MAX_FRAG_LEN_INVALID 5
209 #define SSL_IS_CLIENT 0
210 #define SSL_IS_SERVER 1
212 #define SSL_IS_NOT_FALLBACK 0
213 #define SSL_IS_FALLBACK 1
215 #define SSL_EXTENDED_MS_DISABLED 0
216 #define SSL_EXTENDED_MS_ENABLED 1
218 #define SSL_ETM_DISABLED 0
219 #define SSL_ETM_ENABLED 1
221 #define SSL_COMPRESS_NULL 0
222 #define SSL_COMPRESS_DEFLATE 1
224 #define SSL_VERIFY_NONE 0
225 #define SSL_VERIFY_OPTIONAL 1
226 #define SSL_VERIFY_REQUIRED 2
228 #define SSL_INITIAL_HANDSHAKE 0
229 #define SSL_RENEGOTIATION 1
230 #define SSL_RENEGOTIATION_DONE 2
231 #define SSL_RENEGOTIATION_PENDING 3
233 #define SSL_LEGACY_RENEGOTIATION 0
234 #define SSL_SECURE_RENEGOTIATION 1
236 #define SSL_RENEGOTIATION_DISABLED 0
237 #define SSL_RENEGOTIATION_ENABLED 1
239 #define SSL_RENEGOTIATION_NOT_ENFORCED -1
240 #define SSL_RENEGO_MAX_RECORDS_DEFAULT 16
242 #define SSL_LEGACY_NO_RENEGOTIATION 0
243 #define SSL_LEGACY_ALLOW_RENEGOTIATION 1
244 #define SSL_LEGACY_BREAK_HANDSHAKE 2
246 #define SSL_TRUNC_HMAC_DISABLED 0
247 #define SSL_TRUNC_HMAC_ENABLED 1
248 #define SSL_TRUNCATED_HMAC_LEN 10
250 #define SSL_SESSION_TICKETS_DISABLED 0
251 #define SSL_SESSION_TICKETS_ENABLED 1
253 #define SSL_CBC_RECORD_SPLITTING_DISABLED -1
254 #define SSL_CBC_RECORD_SPLITTING_ENABLED 0
256 #define SSL_ARC4_ENABLED 0
257 #define SSL_ARC4_DISABLED 1
267 #if !defined(SSL_DEFAULT_TICKET_LIFETIME)
268 #define SSL_DEFAULT_TICKET_LIFETIME 86400
280 #if !defined(SSL_MAX_CONTENT_LEN)
281 #define SSL_MAX_CONTENT_LEN 16384
289 #if !defined(SSL_MIN_DHM_BYTES)
290 #define SSL_MIN_DHM_BYTES 128
300 #if defined(POLARSSL_ZLIB_SUPPORT)
301 #define SSL_COMPRESSION_ADD 1024
303 #define SSL_COMPRESSION_ADD 0
306 #if defined(POLARSSL_RC4_C) || defined(POLARSSL_CIPHER_MODE_CBC)
308 #if defined(POLARSSL_SHA512_C)
309 #define SSL_MAC_ADD 48
310 #elif defined(POLARSSL_SHA256_C)
311 #define SSL_MAC_ADD 32
313 #define SSL_MAC_ADD 20
317 #define SSL_MAC_ADD 16
320 #if defined(POLARSSL_CIPHER_MODE_CBC)
321 #define SSL_PADDING_ADD 256
323 #define SSL_PADDING_ADD 0
326 #define SSL_BUFFER_LEN ( SSL_MAX_CONTENT_LEN \
327 + SSL_COMPRESSION_ADD \
336 #if defined(POLARSSL_SSL_PROTO_SSL3)
337 #define SSL_VERIFY_DATA_MAX_LEN 36
339 #define SSL_VERIFY_DATA_MAX_LEN 12
345 #define SSL_EMPTY_RENEGOTIATION_INFO 0xFF
346 #define SSL_FALLBACK_SCSV 0x5600
352 #define SSL_HASH_NONE 0
353 #define SSL_HASH_MD5 1
354 #define SSL_HASH_SHA1 2
355 #define SSL_HASH_SHA224 3
356 #define SSL_HASH_SHA256 4
357 #define SSL_HASH_SHA384 5
358 #define SSL_HASH_SHA512 6
360 #define SSL_SIG_ANON 0
361 #define SSL_SIG_RSA 1
362 #define SSL_SIG_ECDSA 3
368 #define SSL_CERT_TYPE_RSA_SIGN 1
369 #define SSL_CERT_TYPE_ECDSA_SIGN 64
374 #define SSL_MSG_CHANGE_CIPHER_SPEC 20
375 #define SSL_MSG_ALERT 21
376 #define SSL_MSG_HANDSHAKE 22
377 #define SSL_MSG_APPLICATION_DATA 23
379 #define SSL_ALERT_LEVEL_WARNING 1
380 #define SSL_ALERT_LEVEL_FATAL 2
382 #define SSL_ALERT_MSG_CLOSE_NOTIFY 0
383 #define SSL_ALERT_MSG_UNEXPECTED_MESSAGE 10
384 #define SSL_ALERT_MSG_BAD_RECORD_MAC 20
385 #define SSL_ALERT_MSG_DECRYPTION_FAILED 21
386 #define SSL_ALERT_MSG_RECORD_OVERFLOW 22
387 #define SSL_ALERT_MSG_DECOMPRESSION_FAILURE 30
388 #define SSL_ALERT_MSG_HANDSHAKE_FAILURE 40
389 #define SSL_ALERT_MSG_NO_CERT 41
390 #define SSL_ALERT_MSG_BAD_CERT 42
391 #define SSL_ALERT_MSG_UNSUPPORTED_CERT 43
392 #define SSL_ALERT_MSG_CERT_REVOKED 44
393 #define SSL_ALERT_MSG_CERT_EXPIRED 45
394 #define SSL_ALERT_MSG_CERT_UNKNOWN 46
395 #define SSL_ALERT_MSG_ILLEGAL_PARAMETER 47
396 #define SSL_ALERT_MSG_UNKNOWN_CA 48
397 #define SSL_ALERT_MSG_ACCESS_DENIED 49
398 #define SSL_ALERT_MSG_DECODE_ERROR 50
399 #define SSL_ALERT_MSG_DECRYPT_ERROR 51
400 #define SSL_ALERT_MSG_EXPORT_RESTRICTION 60
401 #define SSL_ALERT_MSG_PROTOCOL_VERSION 70
402 #define SSL_ALERT_MSG_INSUFFICIENT_SECURITY 71
403 #define SSL_ALERT_MSG_INTERNAL_ERROR 80
404 #define SSL_ALERT_MSG_INAPROPRIATE_FALLBACK 86
405 #define SSL_ALERT_MSG_USER_CANCELED 90
406 #define SSL_ALERT_MSG_NO_RENEGOTIATION 100
407 #define SSL_ALERT_MSG_UNSUPPORTED_EXT 110
408 #define SSL_ALERT_MSG_UNRECOGNIZED_NAME 112
409 #define SSL_ALERT_MSG_UNKNOWN_PSK_IDENTITY 115
410 #define SSL_ALERT_MSG_NO_APPLICATION_PROTOCOL 120
412 #define SSL_HS_HELLO_REQUEST 0
413 #define SSL_HS_CLIENT_HELLO 1
414 #define SSL_HS_SERVER_HELLO 2
415 #define SSL_HS_NEW_SESSION_TICKET 4
416 #define SSL_HS_CERTIFICATE 11
417 #define SSL_HS_SERVER_KEY_EXCHANGE 12
418 #define SSL_HS_CERTIFICATE_REQUEST 13
419 #define SSL_HS_SERVER_HELLO_DONE 14
420 #define SSL_HS_CERTIFICATE_VERIFY 15
421 #define SSL_HS_CLIENT_KEY_EXCHANGE 16
422 #define SSL_HS_FINISHED 20
427 #define TLS_EXT_SERVERNAME 0
428 #define TLS_EXT_SERVERNAME_HOSTNAME 0
430 #define TLS_EXT_MAX_FRAGMENT_LENGTH 1
432 #define TLS_EXT_TRUNCATED_HMAC 4
434 #define TLS_EXT_SUPPORTED_ELLIPTIC_CURVES 10
435 #define TLS_EXT_SUPPORTED_POINT_FORMATS 11
437 #define TLS_EXT_SIG_ALG 13
439 #define TLS_EXT_ALPN 16
441 #define TLS_EXT_ENCRYPT_THEN_MAC 22
442 #define TLS_EXT_EXTENDED_MASTER_SECRET 0x0017
444 #define TLS_EXT_SESSION_TICKET 35
446 #define TLS_EXT_RENEGOTIATION_INFO 0xFF01
453 #define TLS_EXT_SUPPORTED_POINT_FORMATS_PRESENT (1 << 0)
458 #if !defined(POLARSSL_PSK_MAX_LEN)
459 #define POLARSSL_PSK_MAX_LEN 32
465 #if defined(POLARSSL_KEY_EXCHANGE_RSA_ENABLED)
468 #if defined(POLARSSL_KEY_EXCHANGE_DHE_RSA_ENABLED)
471 #if defined(POLARSSL_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
472 defined(POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
473 defined(POLARSSL_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
474 defined(POLARSSL_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
477 #if defined(POLARSSL_KEY_EXCHANGE_PSK_ENABLED)
480 #if defined(POLARSSL_KEY_EXCHANGE_DHE_PSK_ENABLED)
484 #if defined(POLARSSL_KEY_EXCHANGE_RSA_PSK_ENABLED)
487 #if defined(POLARSSL_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
493 #define POLARSSL_PREMASTER_SIZE sizeof( union _ssl_premaster_secret )
504 const unsigned char *input,
unsigned char *output,
505 size_t output_max_len );
507 int (*f_rng)(
void *,
unsigned char *, size_t),
void *p_rng,
508 int mode,
md_type_t md_alg,
unsigned int hashlen,
509 const unsigned char *hash,
unsigned char *sig );
542 #if defined(POLARSSL_SSL_SESSION_TICKETS)
545 #if defined(POLARSSL_X509_CRT_PARSE_C)
554 #if defined(POLARSSL_HAVE_TIME)
560 unsigned char id[32];
563 #if defined(POLARSSL_X509_CRT_PARSE_C)
568 #if defined(POLARSSL_SSL_SESSION_TICKETS)
574 #if defined(POLARSSL_SSL_MAX_FRAGMENT_LENGTH)
578 #if defined(POLARSSL_SSL_TRUNCATED_HMAC)
582 #if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
607 #if defined(POLARSSL_SSL_PROTO_SSL3)
609 unsigned char mac_enc[20];
610 unsigned char mac_dec[20];
622 #if defined(POLARSSL_ZLIB_SUPPORT)
623 z_stream ctx_deflate;
624 z_stream ctx_inflate;
639 #if defined(POLARSSL_DHM_C)
642 #if defined(POLARSSL_ECDH_C)
645 #if defined(POLARSSL_ECDH_C) || defined(POLARSSL_ECDSA_C)
648 #if defined(POLARSSL_X509_CRT_PARSE_C)
656 #if defined(POLARSSL_SSL_SERVER_NAME_INDICATION)
664 #if defined(POLARSSL_SSL_PROTO_SSL3) || defined(POLARSSL_SSL_PROTO_TLS1) || \
665 defined(POLARSSL_SSL_PROTO_TLS1_1)
669 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
670 #if defined(POLARSSL_SHA256_C)
673 #if defined(POLARSSL_SHA512_C)
681 int (*
tls_prf)(
const unsigned char *, size_t,
const char *,
682 const unsigned char *, size_t,
683 unsigned char *, size_t);
696 #if defined(POLARSSL_SSL_SESSION_TICKETS)
699 #if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
704 #if defined(POLARSSL_SSL_SESSION_TICKETS)
717 #if defined(POLARSSL_X509_CRT_PARSE_C)
737 #if defined(POLARSSL_SSL_RENEGOTIATION)
749 #if defined(POLARSSL_SSL_FALLBACK_SCSV) && defined(POLARSSL_SSL_CLI_C)
752 #if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
755 #if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
763 int (*
f_rng)(
void *,
unsigned char *, size_t);
764 void (*
f_dbg)(
void *, int,
const char *);
765 int (*
f_recv)(
void *,
unsigned char *, size_t);
766 int (*
f_send)(
void *,
const unsigned char *, size_t);
778 #if defined(POLARSSL_SSL_SERVER_NAME_INDICATION)
783 #if defined(POLARSSL_X509_CRT_PARSE_C)
788 #if defined(POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED)
789 int (*
f_psk)(
void *, ssl_context *,
const unsigned char *, size_t);
841 #if defined(POLARSSL_ZLIB_SUPPORT)
842 unsigned char *compress_buf;
844 #if defined(POLARSSL_SSL_MAX_FRAGMENT_LENGTH)
847 #if defined(POLARSSL_SSL_CBC_RECORD_SPLITTING)
855 #if defined(POLARSSL_X509_CRT_PARSE_C)
866 #if defined(POLARSSL_SSL_SESSION_TICKETS)
877 #if defined(POLARSSL_SSL_RENEGOTIATION)
885 #if defined(POLARSSL_SSL_SET_CURVES)
888 #if defined(POLARSSL_SSL_TRUNCATED_HMAC)
891 #if defined(POLARSSL_SSL_SESSION_TICKETS)
896 #if defined(POLARSSL_DHM_C)
901 #if defined(POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED)
911 #if defined(POLARSSL_SSL_SERVER_NAME_INDICATION)
919 #if defined(POLARSSL_SSL_ALPN)
932 #if defined(POLARSSL_SSL_RENEGOTIATION)
939 #if defined(POLARSSL_SSL_HW_RECORD_ACCEL)
941 #define SSL_CHANNEL_OUTBOUND 0
942 #define SSL_CHANNEL_INBOUND 1
945 const unsigned char *key_enc,
const unsigned char *key_dec,
947 const unsigned char *iv_enc,
const unsigned char *iv_dec,
949 const unsigned char *mac_enc,
const unsigned char *mac_dec,
951 extern int (*ssl_hw_record_activate)(
ssl_context *ssl,
int direction);
952 extern int (*ssl_hw_record_reset)(
ssl_context *ssl);
953 extern int (*ssl_hw_record_write)(
ssl_context *ssl);
954 extern int (*ssl_hw_record_read)(
ssl_context *ssl);
955 extern int (*ssl_hw_record_finish)(
ssl_context *ssl);
1045 #if defined(POLARSSL_X509_CRT_PARSE_C)
1058 int (*f_vrfy)(
void *,
x509_crt *,
int,
int *),
1070 int (*f_rng)(
void *,
unsigned char *,
size_t),
1081 void (*f_dbg)(
void *,
int,
const char *),
1094 int (*f_recv)(
void *,
unsigned char *,
size_t),
void *p_recv,
1095 int (*f_send)(
void *,
const unsigned char *,
size_t),
void *p_send );
1097 #if defined(POLARSSL_SSL_SRV_C)
1137 int (*f_get_cache)(
void *,
ssl_session *),
void *p_get_cache,
1138 int (*f_set_cache)(
void *,
const ssl_session *),
void *p_set_cache );
1141 #if defined(POLARSSL_SSL_CLI_C)
1190 const int *ciphersuites,
1191 int major,
int minor );
1193 #if defined(POLARSSL_X509_CRT_PARSE_C)
1203 x509_crl *ca_crl,
const char *peer_cn );
1226 #if ! defined(POLARSSL_DEPRECATED_REMOVED)
1227 #if defined(POLARSSL_DEPRECATED_WARNING)
1228 #define DEPRECATED __attribute__((deprecated))
1232 #if defined(POLARSSL_RSA_C)
1285 #if defined(POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED)
1299 const unsigned char *psk_identity,
size_t psk_identity_len );
1322 int (*f_psk)(
void *,
ssl_context *,
const unsigned char *,
1327 #if defined(POLARSSL_DHM_C)
1353 #if defined(POLARSSL_SSL_SET_CURVES)
1375 #if defined(POLARSSL_SSL_SERVER_NAME_INDICATION)
1408 int (*f_sni)(
void *,
ssl_context *,
const unsigned char *,
1413 #if defined(POLARSSL_SSL_ALPN)
1471 #if defined(POLARSSL_SSL_FALLBACK_SCSV) && defined(POLARSSL_SSL_CLI_C)
1494 #if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
1509 #if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
1539 #if defined(POLARSSL_SSL_MAX_FRAGMENT_LENGTH)
1558 #if defined(POLARSSL_SSL_TRUNCATED_HMAC)
1573 #if defined(POLARSSL_SSL_CBC_RECORD_SPLITTING)
1588 #if defined(POLARSSL_SSL_SESSION_TICKETS)
1617 #if defined(POLARSSL_SSL_RENEGOTIATION)
1663 #if defined(POLARSSL_SSL_RENEGOTIATION)
1712 const unsigned char period[8] );
1755 #if defined(POLARSSL_X509_CRT_PARSE_C)
1773 #if defined(POLARSSL_SSL_CLI_C)
1817 #if defined(POLARSSL_SSL_RENEGOTIATION)
1874 unsigned char level,
1875 unsigned char message );
1954 #if defined(POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED)
1958 #if defined(POLARSSL_PK_C)
1965 #if defined(POLARSSL_SSL_SET_CURVES)
1969 #if defined(POLARSSL_X509_CRT_PARSE_C)
2001 const unsigned char *A = (
const unsigned char *) a;
2002 const unsigned char *B = (
const unsigned char *) b;
2003 unsigned char diff = 0;
2005 for( i = 0; i < n; i++ )
2006 diff |= A[i] ^ B[i];
const ecp_curve_info ** curves
int ssl_send_alert_message(ssl_context *ssl, unsigned char level, unsigned char message)
Send an alert message.
void(* f_dbg)(void *, int, const char *)
int(* f_rng)(void *, unsigned char *, size_t)
sha256_context fin_sha256
#define POLARSSL_PREMASTER_SIZE
pk_type_t ssl_pk_alg_from_sig(unsigned char sig)
Network communication functions.
#define POLARSSL_MPI_MAX_SIZE
Maximum number of bytes for usable MPIs.
int ssl_set_truncated_hmac(ssl_context *ssl, int truncate)
Activate negotiation of truncated HMAC (Default: SSL_TRUNC_HMAC_DISABLED on client, SSL_TRUNC_HMAC_ENABLED on server.)
ssl_transform * transform_out
void ssl_set_cbc_record_splitting(ssl_context *ssl, char split)
Enable / Disable 1/n-1 record splitting (Default: SSL_CBC_RECORD_SPLITTING_ENABLED) ...
int(* f_sni)(void *, ssl_context *, const unsigned char *, size_t)
void(* calc_verify)(ssl_context *, unsigned char *)
int ssl_check_cert_usage(const x509_crt *cert, const ssl_ciphersuite_t *ciphersuite, int cert_endpoint, int *flags)
void ssl_set_extended_master_secret(ssl_context *ssl, char ems)
Enable or disable Extended Master Secret negotiation.
Elliptic curves over GF(p)
ssl_session * session_negotiate
void ssl_legacy_renegotiation(ssl_context *ssl, int allow_legacy)
Prevent or allow legacy renegotiation.
int ssl_parse_certificate(ssl_context *ssl)
void ssl_set_dbg(ssl_context *ssl, void(*f_dbg)(void *, int, const char *), void *p_dbg)
Set the debug callback.
ssl_key_cert * sni_key_cert
int ssl_set_session_tickets(ssl_context *ssl, int use_tickets)
Enable / Disable session tickets (Default: SSL_SESSION_TICKETS_ENABLED on client, SSL_SESSION_TICKETS...
void ssl_set_verify(ssl_context *ssl, int(*f_vrfy)(void *, x509_crt *, int, int *), void *p_vrfy)
Set the verification callback (Optional).
ssl_transform * transform_in
const int * ciphersuite_list[4]
int ssl_parse_finished(ssl_context *ssl)
unsigned char premaster[POLARSSL_PREMASTER_SIZE]
void ssl_session_free(ssl_session *session)
Free referenced items in an SSL session including the peer certificate and clear memory.
int ssl_write_finished(ssl_context *ssl)
Configuration options (set of defines)
unsigned char _pms_dhe_psk[4+POLARSSL_MPI_MAX_SIZE+POLARSSL_PSK_MAX_LEN]
ssl_transform * transform
void ssl_handshake_wrapup(ssl_context *ssl)
int(* f_send)(void *, const unsigned char *, size_t)
int ssl_set_dh_param_ctx(ssl_context *ssl, dhm_context *dhm_ctx)
Set the Diffie-Hellman public P and G values, read from existing context (server-side only) ...
sha512_context fin_sha512
int ssl_handshake_server_step(ssl_context *ssl)
SSL Ciphersuites for mbed TLS.
int(* tls_prf)(const unsigned char *, size_t, const char *, const unsigned char *, size_t, unsigned char *, size_t)
unsigned char mac_key[16]
void ssl_set_max_version(ssl_context *ssl, int major, int minor)
Set the maximum supported version sent from the client side and/or accepted at the server side (Defau...
Multi-precision integer library.
void ssl_set_ciphersuites_for_version(ssl_context *ssl, const int *ciphersuites, int major, int minor)
Set the list of allowed ciphersuites and the preference order for a specific version of the protocol...
void ssl_set_encrypt_then_mac(ssl_context *ssl, char etm)
Enable or disable Encrypt-then-MAC (Default: SSL_ETM_ENABLED)
int ssl_init(ssl_context *ssl)
Initialize an SSL context (An individual SSL context is not thread-safe)
int ssl_get_ciphersuite_id(const char *ciphersuite_name)
Return the ID of the ciphersuite associated with the given name.
int ssl_set_psk(ssl_context *ssl, const unsigned char *psk, size_t psk_len, const unsigned char *psk_identity, size_t psk_identity_len)
Set the Pre Shared Key (PSK) and the identity name connected to it.
char peer_verify_data[SSL_VERIFY_DATA_MAX_LEN]
void ssl_set_psk_cb(ssl_context *ssl, int(*f_psk)(void *, ssl_context *, const unsigned char *, size_t), void *p_psk)
Set the PSK callback (server-side only) (Optional).
int ssl_get_session(const ssl_context *ssl, ssl_session *session)
Save session in order to resume it later (client-side only) Session data is copied to presented sessi...
const char * ssl_get_alpn_protocol(const ssl_context *ssl)
Get the name of the negotiated Application Layer Protocol.
ssl_handshake_params * handshake
void(* update_checksum)(ssl_context *, const unsigned char *, size_t)
int ssl_write_certificate(ssl_context *ssl)
size_t(* rsa_key_len_func)(void *ctx)
#define POLARSSL_PSK_MAX_LEN
Container for an X.509 certificate.
unsigned char renego_period[8]
const char * ssl_get_ciphersuite(const ssl_context *ssl)
Return the name of the current ciphersuite.
const char * ssl_get_version(const ssl_context *ssl)
Return the current SSL version (SSLv3/TLSv1/etc)
void ssl_set_renegotiation(ssl_context *ssl, int renegotiation)
Enable / Disable renegotiation support for connection when initiated by peer (Default: SSL_RENEGOTIAT...
unsigned char _pms_dhm[POLARSSL_MPI_MAX_SIZE]
ssl_key_cert * key_cert
Current key/cert or key/cert list.
static x509_crt * ssl_own_cert(ssl_context *ssl)
int ssl_set_max_frag_len(ssl_context *ssl, unsigned char mfl_code)
Set the maximum fragment length to emit and/or negotiate (Default: SSL_MAX_CONTENT_LEN, usually 2^14 bytes) (Server: set maximum fragment length to emit, usually negotiated by the client during handshake (Client: set maximum fragment length to emit and negotiate with the server during handshake)
SHA-512 context structure.
int ssl_handshake_client_step(ssl_context *ssl)
unsigned char _pms_ecdhe_psk[4+POLARSSL_ECP_MAX_BYTES+POLARSSL_PSK_MAX_LEN]
void ssl_set_fallback(ssl_context *ssl, char fallback)
Set the fallback flag (client-side only).
int ssl_set_own_cert(ssl_context *ssl, x509_crt *own_cert, pk_context *pk_key)
Set own certificate chain and private key.
void ssl_set_endpoint(ssl_context *ssl, int endpoint)
Set the current endpoint type.
void ssl_set_ciphersuites(ssl_context *ssl, const int *ciphersuites)
Set the list of allowed ciphersuites and the preference order.
Curve information for use by other modules.
int ssl_set_own_cert_alt(ssl_context *ssl, x509_crt *own_cert, void *rsa_key, rsa_decrypt_func rsa_decrypt, rsa_sign_func rsa_sign, rsa_key_len_func rsa_key_len) DEPRECATED
Set own certificate and external RSA private key and handling callbacks, such as the PKCS#11 wrappers...
void ssl_set_rng(ssl_context *ssl, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Set the random number generator callback.
void ssl_set_bio(ssl_context *ssl, int(*f_recv)(void *, unsigned char *, size_t), void *p_recv, int(*f_send)(void *, const unsigned char *, size_t), void *p_send)
Set the underlying BIO read and write callbacks.
void ssl_free(ssl_context *ssl)
Free referenced items in an SSL context and clear memory.
unsigned char _pms_rsa[48]
unsigned char ssl_sig_from_pk(pk_context *pk)
void ssl_handshake_free(ssl_handshake_params *handshake)
Free referenced items in an SSL handshake context and clear memory.
int ssl_flush_output(ssl_context *ssl)
int ssl_handshake(ssl_context *ssl)
Perform the SSL handshake.
void ssl_set_min_version(ssl_context *ssl, int major, int minor)
Set the minimum accepted SSL/TLS protocol version (Default: SSL_MIN_MAJOR_VERSION, SSL_MIN_MINOR_VERSION)
Diffie-Hellman-Merkle key exchange.
X.509 certificate parsing and writing.
int(* rsa_sign_func)(void *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, md_type_t md_alg, unsigned int hashlen, const unsigned char *hash, unsigned char *sig)
int ssl_set_hostname(ssl_context *ssl, const char *hostname)
Set hostname for ServerName TLS extension (client-side only)
int ssl_handshake_step(ssl_context *ssl)
Perform a single step of the SSL handshake.
pk_type_t
Public key types.
unsigned char _pms_ecdh[POLARSSL_ECP_MAX_BYTES]
int ssl_parse_change_cipher_spec(ssl_context *ssl)
Elliptic curve Diffie-Hellman.
#define POLARSSL_ECP_MAX_BYTES
This structure is used for storing ciphersuite information.
int ssl_close_notify(ssl_context *ssl)
Notify the peer that the connection is being closed.
const x509_crt * ssl_get_peer_cert(const ssl_context *ssl)
Return the peer certificate from the current connection.
void ssl_set_session_cache(ssl_context *ssl, int(*f_get_cache)(void *, ssl_session *), void *p_get_cache, int(*f_set_cache)(void *, const ssl_session *), void *p_set_cache)
Set the session cache callbacks (server-side only) If not set, no session resuming is done (except if...
size_t ssl_get_bytes_avail(const ssl_context *ssl)
Return the number of data bytes available to read.
void ssl_set_arc4_support(ssl_context *ssl, char arc4)
Disable or enable support for RC4 (Default: SSL_ARC4_ENABLED)
int ssl_set_session(ssl_context *ssl, const ssl_session *session)
Request resumption of session (client-side only) Session data is copied from presented session struct...
int allow_legacy_renegotiation
ssl_session * session_out
void ssl_set_renegotiation_period(ssl_context *ssl, const unsigned char period[8])
Set record counter threshold for periodic renegotiation.
unsigned char _pms_psk[4+2 *POLARSSL_PSK_MAX_LEN]
void(* calc_finished)(ssl_context *, unsigned char *, int)
int ssl_read_record(ssl_context *ssl)
ecp_group_id
Domain parameters (curve, subgroup and generator) identifiers.
int ssl_set_dh_param(ssl_context *ssl, const char *dhm_P, const char *dhm_G)
Set the Diffie-Hellman public P and G values, read as hexadecimal strings (server-side only) (Default...
int(* f_vrfy)(void *, x509_crt *, int, int *)
void ssl_set_session_ticket_lifetime(ssl_context *ssl, int lifetime)
Set session ticket lifetime (server only) (Default: SSL_DEFAULT_TICKET_LIFETIME (86400 secs / 1 day))...
SHA-1 cryptographic hash function.
int ssl_get_verify_result(const ssl_context *ssl)
Return the result of the certificate verification.
X.509 certificate revocation list parsing.
int ssl_session_reset(ssl_context *ssl)
Reset an already initialized SSL context for re-use while retaining application-set variables...
void ssl_session_init(ssl_session *session)
Initialize SSL session structure.
Certificate revocation list structure.
const int * ssl_list_ciphersuites(void)
Returns the list of ciphersuites supported by the SSL/TLS module.
SHA-384 and SHA-512 cryptographic hash function.
ssl_transform * transform_negotiate
int ssl_set_alpn_protocols(ssl_context *ssl, const char **protos)
Set the supported Application Layer Protocols.
unsigned char _pms_rsa_psk[52+POLARSSL_PSK_MAX_LEN]
void ssl_set_renegotiation_enforced(ssl_context *ssl, int max_records)
Enforce requested renegotiation.
int disable_renegotiation
int ssl_write_change_cipher_spec(ssl_context *ssl)
int(* f_get_cache)(void *, ssl_session *)
int ssl_derive_keys(ssl_context *ssl)
void ssl_set_authmode(ssl_context *ssl, int authmode)
Set the certificate verification mode.
static pk_context * ssl_own_key(ssl_context *ssl)
int(* f_set_cache)(void *, const ssl_session *)
SHA-256 context structure.
int ssl_psk_derive_premaster(ssl_context *ssl, key_exchange_type_t key_ex)
static int safer_memcmp(const void *a, const void *b, size_t n)
int ssl_send_fatal_handshake_failure(ssl_context *ssl)
ssl_ticket_keys * ticket_keys
int ssl_read(ssl_context *ssl, unsigned char *buf, size_t len)
Read at most 'len' application data bytes.
void ssl_transform_free(ssl_transform *transform)
Free referenced items in an SSL transform context and clear memory.
unsigned char * psk_identity
const char * ssl_get_ciphersuite_name(const int ciphersuite_id)
Return the name of the ciphersuite associated with the given ID.
MD5 message digest algorithm (hash function)
int ssl_renegotiate(ssl_context *ssl)
Initiate an SSL renegotiation on the running connection.
SHA-224 and SHA-256 cryptographic hash function.
int(* f_recv)(void *, unsigned char *, size_t)
unsigned char key_name[16]
int ssl_write(ssl_context *ssl, const unsigned char *buf, size_t len)
Write exactly 'len' application data bytes.
#define SSL_VERIFY_DATA_MAX_LEN
void ssl_set_ca_chain(ssl_context *ssl, x509_crt *ca_chain, x509_crl *ca_crl, const char *peer_cn)
Set the data required to verify peer certificate.
void ssl_set_sni(ssl_context *ssl, int(*f_sni)(void *, ssl_context *, const unsigned char *, size_t), void *p_sni)
Set server side ServerName TLS extension callback (optional, server-side only).
int ssl_fetch_input(ssl_context *ssl, size_t nb_want)
int(* f_psk)(void *, ssl_context *, const unsigned char *, size_t)
int ssl_write_record(ssl_context *ssl)
unsigned char randbytes[64]
char own_verify_data[SSL_VERIFY_DATA_MAX_LEN]
int(* rsa_decrypt_func)(void *ctx, int mode, size_t *olen, const unsigned char *input, unsigned char *output, size_t output_max_len)
Generic message digest context.
void ssl_optimize_checksum(ssl_context *ssl, const ssl_ciphersuite_t *ciphersuite_info)
int ssl_set_own_cert_rsa(ssl_context *ssl, x509_crt *own_cert, rsa_context *rsa_key) DEPRECATED
Set own certificate chain and private RSA key.
md_type_t ssl_md_alg_from_hash(unsigned char hash)