27 #ifndef POLARSSL_SSL_H
28 #define POLARSSL_SSL_H
41 #if defined(POLARSSL_DHM_C)
45 #if defined(POLARSSL_ZLIB_SUPPORT)
49 #if defined(_MSC_VER) && !defined(inline)
50 #define inline _inline
52 #if defined(__ARMCC_VERSION) && !defined(inline)
53 #define inline __inline
60 #define POLARSSL_ERR_SSL_FEATURE_UNAVAILABLE -0x7080
61 #define POLARSSL_ERR_SSL_BAD_INPUT_DATA -0x7100
62 #define POLARSSL_ERR_SSL_INVALID_MAC -0x7180
63 #define POLARSSL_ERR_SSL_INVALID_RECORD -0x7200
64 #define POLARSSL_ERR_SSL_CONN_EOF -0x7280
65 #define POLARSSL_ERR_SSL_UNKNOWN_CIPHER -0x7300
66 #define POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN -0x7380
67 #define POLARSSL_ERR_SSL_NO_SESSION_FOUND -0x7400
68 #define POLARSSL_ERR_SSL_NO_CLIENT_CERTIFICATE -0x7480
69 #define POLARSSL_ERR_SSL_CERTIFICATE_TOO_LARGE -0x7500
70 #define POLARSSL_ERR_SSL_CERTIFICATE_REQUIRED -0x7580
71 #define POLARSSL_ERR_SSL_PRIVATE_KEY_REQUIRED -0x7600
72 #define POLARSSL_ERR_SSL_CA_CHAIN_REQUIRED -0x7680
73 #define POLARSSL_ERR_SSL_UNEXPECTED_MESSAGE -0x7700
74 #define POLARSSL_ERR_SSL_FATAL_ALERT_MESSAGE -0x7780
75 #define POLARSSL_ERR_SSL_PEER_VERIFY_FAILED -0x7800
76 #define POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY -0x7880
77 #define POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO -0x7900
78 #define POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO -0x7980
79 #define POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE -0x7A00
80 #define POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST -0x7A80
81 #define POLARSSL_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE -0x7B00
82 #define POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO_DONE -0x7B80
83 #define POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE -0x7C00
84 #define POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_DHM_RP -0x7C80
85 #define POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_DHM_CS -0x7D00
86 #define POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY -0x7D80
87 #define POLARSSL_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC -0x7E00
88 #define POLARSSL_ERR_SSL_BAD_HS_FINISHED -0x7E80
89 #define POLARSSL_ERR_SSL_MALLOC_FAILED -0x7F00
90 #define POLARSSL_ERR_SSL_HW_ACCEL_FAILED -0x7F80
91 #define POLARSSL_ERR_SSL_HW_ACCEL_FALLTHROUGH -0x6F80
92 #define POLARSSL_ERR_SSL_COMPRESSION_FAILED -0x6F00
93 #define POLARSSL_ERR_SSL_BAD_HS_PROTOCOL_VERSION -0x6E80
98 #define SSL_MAJOR_VERSION_3 3
99 #define SSL_MINOR_VERSION_0 0
100 #define SSL_MINOR_VERSION_1 1
101 #define SSL_MINOR_VERSION_2 2
102 #define SSL_MINOR_VERSION_3 3
104 #define SSL_IS_CLIENT 0
105 #define SSL_IS_SERVER 1
106 #define SSL_COMPRESS_NULL 0
107 #define SSL_COMPRESS_DEFLATE 1
109 #define SSL_VERIFY_NONE 0
110 #define SSL_VERIFY_OPTIONAL 1
111 #define SSL_VERIFY_REQUIRED 2
113 #define SSL_INITIAL_HANDSHAKE 0
114 #define SSL_RENEGOTIATION 1
116 #define SSL_LEGACY_RENEGOTIATION 0
117 #define SSL_SECURE_RENEGOTIATION 1
119 #define SSL_RENEGOTIATION_DISABLED 0
120 #define SSL_RENEGOTIATION_ENABLED 1
122 #define SSL_LEGACY_NO_RENEGOTIATION 0
123 #define SSL_LEGACY_ALLOW_RENEGOTIATION 1
124 #define SSL_LEGACY_BREAK_HANDSHAKE 2
133 #if !defined(POLARSSL_CONFIG_OPTIONS)
134 #define SSL_MAX_CONTENT_LEN 16384
143 #if defined(POLARSSL_ZLIB_SUPPORT)
144 #define SSL_COMPRESSION_ADD 1024
146 #define SSL_COMPRESSION_ADD 0
149 #define SSL_BUFFER_LEN (SSL_MAX_CONTENT_LEN + SSL_COMPRESSION_ADD + 512)
154 #define TLS_RSA_WITH_NULL_MD5 0x01
155 #define TLS_RSA_WITH_NULL_SHA 0x02
156 #define TLS_RSA_WITH_NULL_SHA256 0x3B
157 #define TLS_RSA_WITH_DES_CBC_SHA 0x09
158 #define TLS_DHE_RSA_WITH_DES_CBC_SHA 0x15
160 #define TLS_RSA_WITH_RC4_128_MD5 0x04
161 #define TLS_RSA_WITH_RC4_128_SHA 0x05
163 #define TLS_RSA_WITH_3DES_EDE_CBC_SHA 0x0A
164 #define TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA 0x16
166 #define TLS_RSA_WITH_AES_128_CBC_SHA 0x2F
167 #define TLS_DHE_RSA_WITH_AES_128_CBC_SHA 0x33
168 #define TLS_RSA_WITH_AES_256_CBC_SHA 0x35
169 #define TLS_DHE_RSA_WITH_AES_256_CBC_SHA 0x39
170 #define TLS_RSA_WITH_AES_128_CBC_SHA256 0x3C
171 #define TLS_RSA_WITH_AES_256_CBC_SHA256 0x3D
172 #define TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 0x67
173 #define TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 0x6B
175 #define TLS_RSA_WITH_CAMELLIA_128_CBC_SHA 0x41
176 #define TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA 0x45
177 #define TLS_RSA_WITH_CAMELLIA_256_CBC_SHA 0x84
178 #define TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA 0x88
179 #define TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 0xBA
180 #define TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 0xBE
181 #define TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 0xC0
182 #define TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 0xC4
184 #define TLS_RSA_WITH_AES_128_GCM_SHA256 0x9C
185 #define TLS_RSA_WITH_AES_256_GCM_SHA384 0x9D
186 #define TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 0x9E
187 #define TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 0x9F
189 #define SSL_EMPTY_RENEGOTIATION_INFO 0xFF
194 #define SSL_HASH_NONE 0
195 #define SSL_HASH_MD5 1
196 #define SSL_HASH_SHA1 2
197 #define SSL_HASH_SHA224 3
198 #define SSL_HASH_SHA256 4
199 #define SSL_HASH_SHA384 5
200 #define SSL_HASH_SHA512 6
202 #define SSL_SIG_RSA 1
207 #define SSL_CERT_TYPE_RSA_SIGN 1
212 #define SSL_MSG_CHANGE_CIPHER_SPEC 20
213 #define SSL_MSG_ALERT 21
214 #define SSL_MSG_HANDSHAKE 22
215 #define SSL_MSG_APPLICATION_DATA 23
217 #define SSL_ALERT_LEVEL_WARNING 1
218 #define SSL_ALERT_LEVEL_FATAL 2
220 #define SSL_ALERT_MSG_CLOSE_NOTIFY 0
221 #define SSL_ALERT_MSG_UNEXPECTED_MESSAGE 10
222 #define SSL_ALERT_MSG_BAD_RECORD_MAC 20
223 #define SSL_ALERT_MSG_DECRYPTION_FAILED 21
224 #define SSL_ALERT_MSG_RECORD_OVERFLOW 22
225 #define SSL_ALERT_MSG_DECOMPRESSION_FAILURE 30
226 #define SSL_ALERT_MSG_HANDSHAKE_FAILURE 40
227 #define SSL_ALERT_MSG_NO_CERT 41
228 #define SSL_ALERT_MSG_BAD_CERT 42
229 #define SSL_ALERT_MSG_UNSUPPORTED_CERT 43
230 #define SSL_ALERT_MSG_CERT_REVOKED 44
231 #define SSL_ALERT_MSG_CERT_EXPIRED 45
232 #define SSL_ALERT_MSG_CERT_UNKNOWN 46
233 #define SSL_ALERT_MSG_ILLEGAL_PARAMETER 47
234 #define SSL_ALERT_MSG_UNKNOWN_CA 48
235 #define SSL_ALERT_MSG_ACCESS_DENIED 49
236 #define SSL_ALERT_MSG_DECODE_ERROR 50
237 #define SSL_ALERT_MSG_DECRYPT_ERROR 51
238 #define SSL_ALERT_MSG_EXPORT_RESTRICTION 60
239 #define SSL_ALERT_MSG_PROTOCOL_VERSION 70
240 #define SSL_ALERT_MSG_INSUFFICIENT_SECURITY 71
241 #define SSL_ALERT_MSG_INTERNAL_ERROR 80
242 #define SSL_ALERT_MSG_USER_CANCELED 90
243 #define SSL_ALERT_MSG_NO_RENEGOTIATION 100
244 #define SSL_ALERT_MSG_UNSUPPORTED_EXT 110
245 #define SSL_ALERT_MSG_UNRECOGNIZED_NAME 112
247 #define SSL_HS_HELLO_REQUEST 0
248 #define SSL_HS_CLIENT_HELLO 1
249 #define SSL_HS_SERVER_HELLO 2
250 #define SSL_HS_CERTIFICATE 11
251 #define SSL_HS_SERVER_KEY_EXCHANGE 12
252 #define SSL_HS_CERTIFICATE_REQUEST 13
253 #define SSL_HS_SERVER_HELLO_DONE 14
254 #define SSL_HS_CERTIFICATE_VERIFY 15
255 #define SSL_HS_CLIENT_KEY_EXCHANGE 16
256 #define SSL_HS_FINISHED 20
261 #define TLS_EXT_SERVERNAME 0
262 #define TLS_EXT_SERVERNAME_HOSTNAME 0
264 #define TLS_EXT_SIG_ALG 13
266 #define TLS_EXT_RENEGOTIATION_INFO 0xFF01
274 int (*f_rng)(
void *,
unsigned char *, size_t),
275 void *p_rng,
int mode,
size_t *olen,
276 const unsigned char *input,
unsigned char *output,
277 size_t output_max_len );
279 int (*f_rng)(
void *,
unsigned char *, size_t),
void *p_rng,
280 int mode,
int hash_id,
unsigned int hashlen,
281 const unsigned char *hash,
unsigned char *sig );
323 unsigned char id[32];
355 #if defined(POLARSSL_ZLIB_SUPPORT)
356 z_stream ctx_deflate;
357 z_stream ctx_inflate;
372 #if defined(POLARSSL_DHM_C)
387 int (*
tls_prf)(
unsigned char *, size_t,
char *,
388 unsigned char *, size_t,
389 unsigned char *, size_t);
419 int (*
f_rng)(
void *,
unsigned char *, size_t);
420 void (*
f_dbg)(
void *, int,
const char *);
421 int (*
f_recv)(
void *,
unsigned char *, size_t);
422 int (*
f_send)(
void *,
const unsigned char *, size_t);
507 #if defined(POLARSSL_DHM_C)
534 #if defined(POLARSSL_SSL_HW_RECORD_ACCEL)
536 const unsigned char *key_enc,
const unsigned char *key_dec,
537 const unsigned char *iv_enc,
const unsigned char *iv_dec,
538 const unsigned char *mac_enc,
const unsigned char *mac_dec);
539 extern int (*ssl_hw_record_reset)(
ssl_context *ssl);
540 extern int (*ssl_hw_record_write)(
ssl_context *ssl);
541 extern int (*ssl_hw_record_read)(
ssl_context *ssl);
542 extern int (*ssl_hw_record_finish)(
ssl_context *ssl);
553 return ssl_default_ciphersuites;
637 int (*f_vrfy)(
void *,
x509_cert *,
int,
int *),
648 int (*f_rng)(
void *,
unsigned char *,
size_t),
659 void (*f_dbg)(
void *,
int,
const char *),
672 int (*f_recv)(
void *,
unsigned char *,
size_t),
void *p_recv,
673 int (*f_send)(
void *,
const unsigned char *,
size_t),
void *p_send );
713 int (*f_get_cache)(
void *,
ssl_session *),
void *p_get_cache,
714 int (*f_set_cache)(
void *,
const ssl_session *),
void *p_set_cache );
755 const int *ciphersuites,
756 int major,
int minor );
767 x509_crl *ca_crl,
const char *peer_cn );
808 #if defined(POLARSSL_DHM_C)
866 int (*f_sni)(
void *,
ssl_context *,
const unsigned char *,
1066 unsigned char level,
1067 unsigned char message );