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
126 #define SSL_MAX_CONTENT_LEN 16384
134 #if defined(POLARSSL_ZLIB_SUPPORT)
135 #define SSL_COMPRESSION_ADD 1024
137 #define SSL_COMPRESSION_ADD 0
140 #define SSL_BUFFER_LEN (SSL_MAX_CONTENT_LEN + SSL_COMPRESSION_ADD + 512)
145 #define TLS_RSA_WITH_NULL_MD5 0x01
146 #define TLS_RSA_WITH_NULL_SHA 0x02
147 #define TLS_RSA_WITH_NULL_SHA256 0x3B
148 #define TLS_RSA_WITH_DES_CBC_SHA 0x09
149 #define TLS_DHE_RSA_WITH_DES_CBC_SHA 0x15
151 #define TLS_RSA_WITH_RC4_128_MD5 0x04
152 #define TLS_RSA_WITH_RC4_128_SHA 0x05
154 #define TLS_RSA_WITH_3DES_EDE_CBC_SHA 0x0A
155 #define TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA 0x16
157 #define TLS_RSA_WITH_AES_128_CBC_SHA 0x2F
158 #define TLS_DHE_RSA_WITH_AES_128_CBC_SHA 0x33
159 #define TLS_RSA_WITH_AES_256_CBC_SHA 0x35
160 #define TLS_DHE_RSA_WITH_AES_256_CBC_SHA 0x39
161 #define TLS_RSA_WITH_AES_128_CBC_SHA256 0x3C
162 #define TLS_RSA_WITH_AES_256_CBC_SHA256 0x3D
163 #define TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 0x67
164 #define TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 0x6B
166 #define TLS_RSA_WITH_CAMELLIA_128_CBC_SHA 0x41
167 #define TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA 0x45
168 #define TLS_RSA_WITH_CAMELLIA_256_CBC_SHA 0x84
169 #define TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA 0x88
170 #define TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 0xBA
171 #define TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 0xBE
172 #define TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 0xC0
173 #define TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 0xC4
175 #define TLS_RSA_WITH_AES_128_GCM_SHA256 0x9C
176 #define TLS_RSA_WITH_AES_256_GCM_SHA384 0x9D
177 #define TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 0x9E
178 #define TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 0x9F
180 #define SSL_EMPTY_RENEGOTIATION_INFO 0xFF
185 #define SSL_HASH_NONE 0
186 #define SSL_HASH_MD5 1
187 #define SSL_HASH_SHA1 2
188 #define SSL_HASH_SHA224 3
189 #define SSL_HASH_SHA256 4
190 #define SSL_HASH_SHA384 5
191 #define SSL_HASH_SHA512 6
193 #define SSL_SIG_RSA 1
198 #define SSL_CERT_TYPE_RSA_SIGN 1
203 #define SSL_MSG_CHANGE_CIPHER_SPEC 20
204 #define SSL_MSG_ALERT 21
205 #define SSL_MSG_HANDSHAKE 22
206 #define SSL_MSG_APPLICATION_DATA 23
208 #define SSL_ALERT_LEVEL_WARNING 1
209 #define SSL_ALERT_LEVEL_FATAL 2
211 #define SSL_ALERT_MSG_CLOSE_NOTIFY 0
212 #define SSL_ALERT_MSG_UNEXPECTED_MESSAGE 10
213 #define SSL_ALERT_MSG_BAD_RECORD_MAC 20
214 #define SSL_ALERT_MSG_DECRYPTION_FAILED 21
215 #define SSL_ALERT_MSG_RECORD_OVERFLOW 22
216 #define SSL_ALERT_MSG_DECOMPRESSION_FAILURE 30
217 #define SSL_ALERT_MSG_HANDSHAKE_FAILURE 40
218 #define SSL_ALERT_MSG_NO_CERT 41
219 #define SSL_ALERT_MSG_BAD_CERT 42
220 #define SSL_ALERT_MSG_UNSUPPORTED_CERT 43
221 #define SSL_ALERT_MSG_CERT_REVOKED 44
222 #define SSL_ALERT_MSG_CERT_EXPIRED 45
223 #define SSL_ALERT_MSG_CERT_UNKNOWN 46
224 #define SSL_ALERT_MSG_ILLEGAL_PARAMETER 47
225 #define SSL_ALERT_MSG_UNKNOWN_CA 48
226 #define SSL_ALERT_MSG_ACCESS_DENIED 49
227 #define SSL_ALERT_MSG_DECODE_ERROR 50
228 #define SSL_ALERT_MSG_DECRYPT_ERROR 51
229 #define SSL_ALERT_MSG_EXPORT_RESTRICTION 60
230 #define SSL_ALERT_MSG_PROTOCOL_VERSION 70
231 #define SSL_ALERT_MSG_INSUFFICIENT_SECURITY 71
232 #define SSL_ALERT_MSG_INTERNAL_ERROR 80
233 #define SSL_ALERT_MSG_USER_CANCELED 90
234 #define SSL_ALERT_MSG_NO_RENEGOTIATION 100
235 #define SSL_ALERT_MSG_UNSUPPORTED_EXT 110
236 #define SSL_ALERT_MSG_UNRECOGNIZED_NAME 112
238 #define SSL_HS_HELLO_REQUEST 0
239 #define SSL_HS_CLIENT_HELLO 1
240 #define SSL_HS_SERVER_HELLO 2
241 #define SSL_HS_CERTIFICATE 11
242 #define SSL_HS_SERVER_KEY_EXCHANGE 12
243 #define SSL_HS_CERTIFICATE_REQUEST 13
244 #define SSL_HS_SERVER_HELLO_DONE 14
245 #define SSL_HS_CERTIFICATE_VERIFY 15
246 #define SSL_HS_CLIENT_KEY_EXCHANGE 16
247 #define SSL_HS_FINISHED 20
252 #define TLS_EXT_SERVERNAME 0
253 #define TLS_EXT_SERVERNAME_HOSTNAME 0
255 #define TLS_EXT_SIG_ALG 13
257 #define TLS_EXT_RENEGOTIATION_INFO 0xFF01
265 const unsigned char *input,
unsigned char *output,
266 size_t output_max_len );
268 int (*f_rng)(
void *,
unsigned char *, size_t),
void *p_rng,
269 int mode,
int hash_id,
unsigned int hashlen,
270 const unsigned char *hash,
unsigned char *sig );
312 unsigned char id[32];
344 #if defined(POLARSSL_ZLIB_SUPPORT)
345 z_stream ctx_deflate;
346 z_stream ctx_inflate;
361 #if defined(POLARSSL_DHM_C)
376 int (*
tls_prf)(
unsigned char *, size_t,
char *,
377 unsigned char *, size_t,
378 unsigned char *, size_t);
408 int (*
f_rng)(
void *,
unsigned char *, size_t);
409 void (*
f_dbg)(
void *, int,
const char *);
410 int (*
f_recv)(
void *,
unsigned char *, size_t);
411 int (*
f_send)(
void *,
const unsigned char *, size_t);
496 #if defined(POLARSSL_DHM_C)
523 #if defined(POLARSSL_SSL_HW_RECORD_ACCEL)
525 const unsigned char *key_enc,
const unsigned char *key_dec,
526 const unsigned char *iv_enc,
const unsigned char *iv_dec,
527 const unsigned char *mac_enc,
const unsigned char *mac_dec);
528 extern int (*ssl_hw_record_reset)(
ssl_context *ssl);
529 extern int (*ssl_hw_record_write)(
ssl_context *ssl);
530 extern int (*ssl_hw_record_read)(
ssl_context *ssl);
531 extern int (*ssl_hw_record_finish)(
ssl_context *ssl);
542 return ssl_default_ciphersuites;
626 int (*f_vrfy)(
void *,
x509_cert *,
int,
int *),
637 int (*f_rng)(
void *,
unsigned char *,
size_t),
648 void (*f_dbg)(
void *,
int,
const char *),
661 int (*f_recv)(
void *,
unsigned char *,
size_t),
void *p_recv,
662 int (*f_send)(
void *,
const unsigned char *,
size_t),
void *p_send );
702 int (*f_get_cache)(
void *,
ssl_session *),
void *p_get_cache,
703 int (*f_set_cache)(
void *,
const ssl_session *),
void *p_set_cache );
744 const int *ciphersuites,
745 int major,
int minor );
756 x509_crl *ca_crl,
const char *peer_cn );
797 #if defined(POLARSSL_DHM_C)
855 int (*f_sni)(
void *,
ssl_context *,
const unsigned char *,
1055 unsigned char level,
1056 unsigned char message );