27 #ifndef POLARSSL_SSL_H
28 #define POLARSSL_SSL_H
36 #if defined(POLARSSL_MD5_C)
40 #if defined(POLARSSL_SHA1_C)
44 #if defined(POLARSSL_SHA256_C)
48 #if defined(POLARSSL_SHA512_C)
53 #if defined(POLARSSL_AES_C)
57 #if defined(POLARSSL_X509_CRT_PARSE_C)
62 #if defined(POLARSSL_DHM_C)
66 #if defined(POLARSSL_ECDH_C)
70 #if defined(POLARSSL_ZLIB_SUPPORT)
74 #if defined(POLARSSL_HAVE_TIME)
79 #if defined(POLARSSL_KEY_EXCHANGE_PSK_ENABLED) || \
80 defined(POLARSSL_KEY_EXCHANGE_RSA_PSK_ENABLED) || \
81 defined(POLARSSL_KEY_EXCHANGE_DHE_PSK_ENABLED) || \
82 defined(POLARSSL_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
83 #define POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED
86 #if defined(_MSC_VER) && !defined(inline)
87 #define inline _inline
89 #if defined(__ARMCC_VERSION) && !defined(inline)
90 #define inline __inline
97 #define POLARSSL_ERR_SSL_FEATURE_UNAVAILABLE -0x7080
98 #define POLARSSL_ERR_SSL_BAD_INPUT_DATA -0x7100
99 #define POLARSSL_ERR_SSL_INVALID_MAC -0x7180
100 #define POLARSSL_ERR_SSL_INVALID_RECORD -0x7200
101 #define POLARSSL_ERR_SSL_CONN_EOF -0x7280
102 #define POLARSSL_ERR_SSL_UNKNOWN_CIPHER -0x7300
103 #define POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN -0x7380
104 #define POLARSSL_ERR_SSL_NO_SESSION_FOUND -0x7400
105 #define POLARSSL_ERR_SSL_NO_CLIENT_CERTIFICATE -0x7480
106 #define POLARSSL_ERR_SSL_CERTIFICATE_TOO_LARGE -0x7500
107 #define POLARSSL_ERR_SSL_CERTIFICATE_REQUIRED -0x7580
108 #define POLARSSL_ERR_SSL_PRIVATE_KEY_REQUIRED -0x7600
109 #define POLARSSL_ERR_SSL_CA_CHAIN_REQUIRED -0x7680
110 #define POLARSSL_ERR_SSL_UNEXPECTED_MESSAGE -0x7700
111 #define POLARSSL_ERR_SSL_FATAL_ALERT_MESSAGE -0x7780
112 #define POLARSSL_ERR_SSL_PEER_VERIFY_FAILED -0x7800
113 #define POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY -0x7880
114 #define POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO -0x7900
115 #define POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO -0x7980
116 #define POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE -0x7A00
117 #define POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST -0x7A80
118 #define POLARSSL_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE -0x7B00
119 #define POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO_DONE -0x7B80
120 #define POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE -0x7C00
121 #define POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP -0x7C80
122 #define POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS -0x7D00
123 #define POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY -0x7D80
124 #define POLARSSL_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC -0x7E00
125 #define POLARSSL_ERR_SSL_BAD_HS_FINISHED -0x7E80
126 #define POLARSSL_ERR_SSL_MALLOC_FAILED -0x7F00
127 #define POLARSSL_ERR_SSL_HW_ACCEL_FAILED -0x7F80
128 #define POLARSSL_ERR_SSL_HW_ACCEL_FALLTHROUGH -0x6F80
129 #define POLARSSL_ERR_SSL_COMPRESSION_FAILED -0x6F00
130 #define POLARSSL_ERR_SSL_BAD_HS_PROTOCOL_VERSION -0x6E80
131 #define POLARSSL_ERR_SSL_BAD_HS_NEW_SESSION_TICKET -0x6E00
132 #define POLARSSL_ERR_SSL_SESSION_TICKET_EXPIRED -0x6D80
133 #define POLARSSL_ERR_SSL_PK_TYPE_MISMATCH -0x6D00
134 #define POLARSSL_ERR_SSL_UNKNOWN_IDENTITY -0x6C80
139 #define SSL_MAJOR_VERSION_3 3
140 #define SSL_MINOR_VERSION_0 0
141 #define SSL_MINOR_VERSION_1 1
142 #define SSL_MINOR_VERSION_2 2
143 #define SSL_MINOR_VERSION_3 3
146 #define SSL_MIN_MAJOR_VERSION SSL_MAJOR_VERSION_3
148 #if defined(POLARSSL_SSL_PROTO_SSL3)
149 #define SSL_MIN_MINOR_VERSION SSL_MINOR_VERSION_0
151 #if defined(POLARSSL_SSL_PROTO_TLS1)
152 #define SSL_MIN_MINOR_VERSION SSL_MINOR_VERSION_1
154 #if defined(POLARSSL_SSL_PROTO_TLS1_1)
155 #define SSL_MIN_MINOR_VERSION SSL_MINOR_VERSION_2
157 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
158 #define SSL_MIN_MINOR_VERSION SSL_MINOR_VERSION_3
165 #define SSL_MAX_MAJOR_VERSION SSL_MAJOR_VERSION_3
167 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
168 #define SSL_MAX_MINOR_VERSION SSL_MINOR_VERSION_3
170 #if defined(POLARSSL_SSL_PROTO_TLS1_1)
171 #define SSL_MAX_MINOR_VERSION SSL_MINOR_VERSION_2
173 #if defined(POLARSSL_SSL_PROTO_TLS1)
174 #define SSL_MAX_MINOR_VERSION SSL_MINOR_VERSION_1
176 #if defined(POLARSSL_SSL_PROTO_SSL3)
177 #define SSL_MAX_MINOR_VERSION SSL_MINOR_VERSION_0
185 #define SSL_MAX_FRAG_LEN_NONE 0
186 #define SSL_MAX_FRAG_LEN_512 1
187 #define SSL_MAX_FRAG_LEN_1024 2
188 #define SSL_MAX_FRAG_LEN_2048 3
189 #define SSL_MAX_FRAG_LEN_4096 4
190 #define SSL_MAX_FRAG_LEN_INVALID 5
192 #define SSL_IS_CLIENT 0
193 #define SSL_IS_SERVER 1
194 #define SSL_COMPRESS_NULL 0
195 #define SSL_COMPRESS_DEFLATE 1
197 #define SSL_VERIFY_NONE 0
198 #define SSL_VERIFY_OPTIONAL 1
199 #define SSL_VERIFY_REQUIRED 2
201 #define SSL_INITIAL_HANDSHAKE 0
202 #define SSL_RENEGOTIATION 1
204 #define SSL_LEGACY_RENEGOTIATION 0
205 #define SSL_SECURE_RENEGOTIATION 1
207 #define SSL_RENEGOTIATION_DISABLED 0
208 #define SSL_RENEGOTIATION_ENABLED 1
210 #define SSL_LEGACY_NO_RENEGOTIATION 0
211 #define SSL_LEGACY_ALLOW_RENEGOTIATION 1
212 #define SSL_LEGACY_BREAK_HANDSHAKE 2
214 #define SSL_TRUNC_HMAC_DISABLED 0
215 #define SSL_TRUNC_HMAC_ENABLED 1
216 #define SSL_TRUNCATED_HMAC_LEN 10
218 #define SSL_SESSION_TICKETS_DISABLED 0
219 #define SSL_SESSION_TICKETS_ENABLED 1
221 #if !defined(POLARSSL_CONFIG_OPTIONS)
222 #define SSL_DEFAULT_TICKET_LIFETIME 86400
232 #if !defined(POLARSSL_CONFIG_OPTIONS)
233 #define SSL_MAX_CONTENT_LEN 16384
242 #if defined(POLARSSL_ZLIB_SUPPORT)
243 #define SSL_COMPRESSION_ADD 1024
245 #define SSL_COMPRESSION_ADD 0
248 #define SSL_BUFFER_LEN (SSL_MAX_CONTENT_LEN + SSL_COMPRESSION_ADD + 512)
250 #define SSL_EMPTY_RENEGOTIATION_INFO 0xFF
256 #define SSL_HASH_NONE 0
257 #define SSL_HASH_MD5 1
258 #define SSL_HASH_SHA1 2
259 #define SSL_HASH_SHA224 3
260 #define SSL_HASH_SHA256 4
261 #define SSL_HASH_SHA384 5
262 #define SSL_HASH_SHA512 6
264 #define SSL_SIG_ANON 0
265 #define SSL_SIG_RSA 1
266 #define SSL_SIG_ECDSA 3
272 #define SSL_CERT_TYPE_RSA_SIGN 1
273 #define SSL_CERT_TYPE_ECDSA_SIGN 64
278 #define SSL_MSG_CHANGE_CIPHER_SPEC 20
279 #define SSL_MSG_ALERT 21
280 #define SSL_MSG_HANDSHAKE 22
281 #define SSL_MSG_APPLICATION_DATA 23
283 #define SSL_ALERT_LEVEL_WARNING 1
284 #define SSL_ALERT_LEVEL_FATAL 2
286 #define SSL_ALERT_MSG_CLOSE_NOTIFY 0
287 #define SSL_ALERT_MSG_UNEXPECTED_MESSAGE 10
288 #define SSL_ALERT_MSG_BAD_RECORD_MAC 20
289 #define SSL_ALERT_MSG_DECRYPTION_FAILED 21
290 #define SSL_ALERT_MSG_RECORD_OVERFLOW 22
291 #define SSL_ALERT_MSG_DECOMPRESSION_FAILURE 30
292 #define SSL_ALERT_MSG_HANDSHAKE_FAILURE 40
293 #define SSL_ALERT_MSG_NO_CERT 41
294 #define SSL_ALERT_MSG_BAD_CERT 42
295 #define SSL_ALERT_MSG_UNSUPPORTED_CERT 43
296 #define SSL_ALERT_MSG_CERT_REVOKED 44
297 #define SSL_ALERT_MSG_CERT_EXPIRED 45
298 #define SSL_ALERT_MSG_CERT_UNKNOWN 46
299 #define SSL_ALERT_MSG_ILLEGAL_PARAMETER 47
300 #define SSL_ALERT_MSG_UNKNOWN_CA 48
301 #define SSL_ALERT_MSG_ACCESS_DENIED 49
302 #define SSL_ALERT_MSG_DECODE_ERROR 50
303 #define SSL_ALERT_MSG_DECRYPT_ERROR 51
304 #define SSL_ALERT_MSG_EXPORT_RESTRICTION 60
305 #define SSL_ALERT_MSG_PROTOCOL_VERSION 70
306 #define SSL_ALERT_MSG_INSUFFICIENT_SECURITY 71
307 #define SSL_ALERT_MSG_INTERNAL_ERROR 80
308 #define SSL_ALERT_MSG_USER_CANCELED 90
309 #define SSL_ALERT_MSG_NO_RENEGOTIATION 100
310 #define SSL_ALERT_MSG_UNSUPPORTED_EXT 110
311 #define SSL_ALERT_MSG_UNRECOGNIZED_NAME 112
312 #define SSL_ALERT_MSG_UNKNOWN_PSK_IDENTITY 115
314 #define SSL_HS_HELLO_REQUEST 0
315 #define SSL_HS_CLIENT_HELLO 1
316 #define SSL_HS_SERVER_HELLO 2
317 #define SSL_HS_NEW_SESSION_TICKET 4
318 #define SSL_HS_CERTIFICATE 11
319 #define SSL_HS_SERVER_KEY_EXCHANGE 12
320 #define SSL_HS_CERTIFICATE_REQUEST 13
321 #define SSL_HS_SERVER_HELLO_DONE 14
322 #define SSL_HS_CERTIFICATE_VERIFY 15
323 #define SSL_HS_CLIENT_KEY_EXCHANGE 16
324 #define SSL_HS_FINISHED 20
329 #define TLS_EXT_SERVERNAME 0
330 #define TLS_EXT_SERVERNAME_HOSTNAME 0
332 #define TLS_EXT_MAX_FRAGMENT_LENGTH 1
334 #define TLS_EXT_TRUNCATED_HMAC 4
336 #define TLS_EXT_SUPPORTED_ELLIPTIC_CURVES 10
337 #define TLS_EXT_SUPPORTED_POINT_FORMATS 11
339 #define TLS_EXT_SIG_ALG 13
341 #define TLS_EXT_SESSION_TICKET 35
343 #define TLS_EXT_RENEGOTIATION_INFO 0xFF01
348 #if !defined(POLARSSL_MPI_MAX_SIZE)
349 #define POLARSSL_PREMASTER_SIZE 512
351 #define POLARSSL_PREMASTER_SIZE POLARSSL_MPI_MAX_SIZE
363 const unsigned char *input,
unsigned char *output,
364 size_t output_max_len );
366 int (*f_rng)(
void *,
unsigned char *, size_t),
void *p_rng,
367 int mode,
int hash_id,
unsigned int hashlen,
368 const unsigned char *hash,
unsigned char *sig );
401 #if defined(POLARSSL_SSL_SESSION_TICKETS)
404 #if defined(POLARSSL_X509_CRT_PARSE_C)
413 #if defined(POLARSSL_HAVE_TIME)
419 unsigned char id[32];
422 #if defined(POLARSSL_X509_CRT_PARSE_C)
427 #if defined(POLARSSL_SSL_SESSION_TICKETS)
433 #if defined(POLARSSL_SSL_MAX_FRAGMENT_LENGTH)
437 #if defined(POLARSSL_SSL_TRUNCATED_HMAC)
462 #if defined(POLARSSL_SSL_PROTO_SSL3)
477 #if defined(POLARSSL_ZLIB_SUPPORT)
478 z_stream ctx_deflate;
479 z_stream ctx_inflate;
494 #if defined(POLARSSL_DHM_C)
497 #if defined(POLARSSL_ECDH_C)
500 #if defined(POLARSSL_ECDH_C) || defined(POLARSSL_ECDSA_C)
503 #if defined(POLARSSL_X509_CRT_PARSE_C)
511 #if defined(POLARSSL_SSL_SERVER_NAME_INDICATION)
519 #if defined(POLARSSL_SSL_PROTO_SSL3) || defined(POLARSSL_SSL_PROTO_TLS1) || \
520 defined(POLARSSL_SSL_PROTO_TLS1_1)
524 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
525 #if defined(POLARSSL_SHA256_C)
528 #if defined(POLARSSL_SHA512_C)
536 int (*
tls_prf)(
const unsigned char *, size_t,
const char *,
537 const unsigned char *, size_t,
538 unsigned char *, size_t);
550 #if defined(POLARSSL_SSL_SESSION_TICKETS)
555 #if defined(POLARSSL_SSL_SESSION_TICKETS)
568 #if defined(POLARSSL_X509_CRT_PARSE_C)
600 int (*
f_rng)(
void *,
unsigned char *, size_t);
601 void (*
f_dbg)(
void *, int,
const char *);
602 int (*
f_recv)(
void *,
unsigned char *, size_t);
603 int (*
f_send)(
void *,
const unsigned char *, size_t);
615 #if defined(POLARSSL_SSL_SERVER_NAME_INDICATION)
620 #if defined(POLARSSL_X509_CRT_PARSE_C)
625 #if defined(POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED)
678 #if defined(POLARSSL_ZLIB_SUPPORT)
679 unsigned char *compress_buf;
681 #if defined(POLARSSL_SSL_MAX_FRAGMENT_LENGTH)
688 #if defined(POLARSSL_X509_CRT_PARSE_C)
699 #if defined(POLARSSL_SSL_SESSION_TICKETS)
713 #if defined(POLARSSL_SSL_TRUNCATED_HMAC)
716 #if defined(POLARSSL_SSL_SESSION_TICKETS)
721 #if defined(POLARSSL_DHM_C)
726 #if defined(POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED)
736 #if defined(POLARSSL_SSL_SERVER_NAME_INDICATION)
754 #if defined(POLARSSL_SSL_HW_RECORD_ACCEL)
756 #define SSL_CHANNEL_OUTBOUND 0
757 #define SSL_CHANNEL_INBOUND 1
760 const unsigned char *key_enc,
const unsigned char *key_dec,
762 const unsigned char *iv_enc,
const unsigned char *iv_dec,
764 const unsigned char *mac_enc,
const unsigned char *mac_dec,
766 extern int (*ssl_hw_record_activate)(
ssl_context *ssl,
int direction);
767 extern int (*ssl_hw_record_reset)(
ssl_context *ssl);
768 extern int (*ssl_hw_record_write)(
ssl_context *ssl);
769 extern int (*ssl_hw_record_read)(
ssl_context *ssl);
770 extern int (*ssl_hw_record_finish)(
ssl_context *ssl);
854 #if defined(POLARSSL_X509_CRT_PARSE_C)
867 int (*f_vrfy)(
void *,
x509_crt *,
int,
int *),
879 int (*f_rng)(
void *,
unsigned char *,
size_t),
890 void (*f_dbg)(
void *,
int,
const char *),
903 int (*f_recv)(
void *,
unsigned char *,
size_t),
void *p_recv,
904 int (*f_send)(
void *,
const unsigned char *,
size_t),
void *p_send );
944 int (*f_get_cache)(
void *,
ssl_session *),
void *p_get_cache,
945 int (*f_set_cache)(
void *,
const ssl_session *),
void *p_set_cache );
986 const int *ciphersuites,
987 int major,
int minor );
989 #if defined(POLARSSL_X509_CRT_PARSE_C)
999 x509_crl *ca_crl,
const char *peer_cn );
1022 #if defined(POLARSSL_RSA_C)
1068 #if defined(POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED)
1082 const unsigned char *psk_identity,
size_t psk_identity_len );
1105 int (*f_psk)(
void *,
ssl_context *,
const unsigned char *,
1110 #if defined(POLARSSL_DHM_C)
1136 #if defined(POLARSSL_SSL_SERVER_NAME_INDICATION)
1169 int (*f_sni)(
void *,
ssl_context *,
const unsigned char *,
1207 #if defined(POLARSSL_SSL_MAX_FRAGMENT_LENGTH)
1226 #if defined(POLARSSL_SSL_TRUNCATED_HMAC)
1241 #if defined(POLARSSL_SSL_SESSION_TICKETS)
1354 #if defined(POLARSSL_X509_CRT_PARSE_C)
1462 unsigned char level,
1463 unsigned char message );
1534 #if defined(POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED)
1538 #if defined(POLARSSL_PK_C)
1545 #if defined(POLARSSL_X509_CRT_PARSE_C)