tls.h
Go to the documentation of this file.
1 /**
2  * @file tls.h
3  * @brief TLS (Transport Layer Security)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2022 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneSSL Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.1.4
29  **/
30 
31 #ifndef _TLS_H
32 #define _TLS_H
33 
34 //Forward declaration of TlsContext structure
35 struct _TlsContext;
36 #define TlsContext struct _TlsContext
37 
38 //Forward declaration of TlsEncryptionEngine structure
40 #define TlsEncryptionEngine struct _TlsEncryptionEngine
41 
42 //Dependencies
43 #include "os_port.h"
44 #include "core/crypto.h"
45 #include "tls_config.h"
46 #include "tls_legacy.h"
47 #include "tls13_misc.h"
48 #include "dtls_misc.h"
49 #include "mac/hmac.h"
50 #include "pkc/rsa.h"
51 #include "pkc/dsa.h"
52 #include "ecc/ecdsa.h"
53 #include "pkc/dh.h"
54 #include "ecc/ecdh.h"
55 #include "aead/gcm.h"
56 #include "pkix/x509_common.h"
57 
58 
59 /*
60  * CycloneSSL Open is licensed under GPL version 2. In particular:
61  *
62  * - If you link your program to CycloneSSL Open, the result is a derivative
63  * work that can only be distributed under the same GPL license terms.
64  *
65  * - If additions or changes to CycloneSSL Open are made, the result is a
66  * derivative work that can only be distributed under the same license terms.
67  *
68  * - The GPL license requires that you make the source code available to
69  * whoever you make the binary available to.
70  *
71  * - If you sell or distribute a hardware product that runs CycloneSSL Open,
72  * the GPL license requires you to provide public and full access to all
73  * source code on a nondiscriminatory basis.
74  *
75  * If you fully understand and accept the terms of the GPL license, then edit
76  * the os_port_config.h header and add the following directive:
77  *
78  * #define GPL_LICENSE_TERMS_ACCEPTED
79  */
80 
81 #ifndef GPL_LICENSE_TERMS_ACCEPTED
82  #error Before compiling CycloneSSL Open, you must accept the terms of the GPL license
83 #endif
84 
85 //Version string
86 #define CYCLONE_SSL_VERSION_STRING "2.1.4"
87 //Major version
88 #define CYCLONE_SSL_MAJOR_VERSION 2
89 //Minor version
90 #define CYCLONE_SSL_MINOR_VERSION 1
91 //Revision number
92 #define CYCLONE_SSL_REV_NUMBER 4
93 
94 //TLS version numbers
95 #define SSL_VERSION_3_0 0x0300
96 #define TLS_VERSION_1_0 0x0301
97 #define TLS_VERSION_1_1 0x0302
98 #define TLS_VERSION_1_2 0x0303
99 #define TLS_VERSION_1_3 0x0304
100 
101 //TLS support
102 #ifndef TLS_SUPPORT
103  #define TLS_SUPPORT ENABLED
104 #elif (TLS_SUPPORT != ENABLED && TLS_SUPPORT != DISABLED)
105  #error TLS_SUPPORT parameter is not valid
106 #endif
107 
108 //Client mode of operation
109 #ifndef TLS_CLIENT_SUPPORT
110  #define TLS_CLIENT_SUPPORT ENABLED
111 #elif (TLS_CLIENT_SUPPORT != ENABLED && TLS_CLIENT_SUPPORT != DISABLED)
112  #error TLS_CLIENT_SUPPORT parameter is not valid
113 #endif
114 
115 //Server mode of operation
116 #ifndef TLS_SERVER_SUPPORT
117  #define TLS_SERVER_SUPPORT ENABLED
118 #elif (TLS_SERVER_SUPPORT != ENABLED && TLS_SERVER_SUPPORT != DISABLED)
119  #error TLS_SERVER_SUPPORT parameter is not valid
120 #endif
121 
122 //Minimum TLS version that can be negotiated
123 #ifndef TLS_MIN_VERSION
124  #define TLS_MIN_VERSION TLS_VERSION_1_2
125 #elif (TLS_MIN_VERSION < TLS_VERSION_1_0)
126  #error TLS_MIN_VERSION parameter is not valid
127 #endif
128 
129 //Maximum TLS version that can be negotiated
130 #ifndef TLS_MAX_VERSION
131  #define TLS_MAX_VERSION TLS_VERSION_1_3
132 #elif (TLS_MAX_VERSION > TLS_VERSION_1_3 || TLS_MAX_VERSION < TLS_MIN_VERSION)
133  #error TLS_MAX_VERSION parameter is not valid
134 #endif
135 
136 //Session resumption mechanism
137 #ifndef TLS_SESSION_RESUME_SUPPORT
138  #define TLS_SESSION_RESUME_SUPPORT ENABLED
139 #elif (TLS_SESSION_RESUME_SUPPORT != ENABLED && TLS_SESSION_RESUME_SUPPORT != DISABLED)
140  #error TLS_SESSION_RESUME_SUPPORT parameter is not valid
141 #endif
142 
143 //Lifetime of session cache entries
144 #ifndef TLS_SESSION_CACHE_LIFETIME
145  #define TLS_SESSION_CACHE_LIFETIME 3600000
146 #elif (TLS_SESSION_CACHE_LIFETIME < 1000)
147  #error TLS_SESSION_CACHE_LIFETIME parameter is not valid
148 #endif
149 
150 //Session ticket mechanism
151 #ifndef TLS_TICKET_SUPPORT
152  #define TLS_TICKET_SUPPORT DISABLED
153 #elif (TLS_TICKET_SUPPORT != ENABLED && TLS_TICKET_SUPPORT != DISABLED)
154  #error TLS_TICKET_SUPPORT parameter is not valid
155 #endif
156 
157 //Maximum size for session tickets
158 #ifndef TLS_MAX_TICKET_SIZE
159  #define TLS_MAX_TICKET_SIZE 1024
160 #elif (TLS_MAX_TICKET_SIZE < 32)
161  #error TLS_MAX_TICKET_SIZE parameter is not valid
162 #endif
163 
164 //Lifetime of session tickets
165 #ifndef TLS_TICKET_LIFETIME
166  #define TLS_TICKET_LIFETIME 3600000
167 #elif (TLS_TICKET_LIFETIME < 0)
168  #error TLS_TICKET_LIFETIME parameter is not valid
169 #endif
170 
171 //SNI (Server Name Indication) extension
172 #ifndef TLS_SNI_SUPPORT
173  #define TLS_SNI_SUPPORT ENABLED
174 #elif (TLS_SNI_SUPPORT != ENABLED && TLS_SNI_SUPPORT != DISABLED)
175  #error TLS_SNI_SUPPORT parameter is not valid
176 #endif
177 
178 //Maximum Fragment Length extension
179 #ifndef TLS_MAX_FRAG_LEN_SUPPORT
180  #define TLS_MAX_FRAG_LEN_SUPPORT DISABLED
181 #elif (TLS_MAX_FRAG_LEN_SUPPORT != ENABLED && TLS_MAX_FRAG_LEN_SUPPORT != DISABLED)
182  #error TLS_MAX_FRAG_LEN_SUPPORT parameter is not valid
183 #endif
184 
185 //Record Size Limit extension
186 #ifndef TLS_RECORD_SIZE_LIMIT_SUPPORT
187  #define TLS_RECORD_SIZE_LIMIT_SUPPORT ENABLED
188 #elif (TLS_RECORD_SIZE_LIMIT_SUPPORT != ENABLED && TLS_RECORD_SIZE_LIMIT_SUPPORT != DISABLED)
189  #error TLS_RECORD_SIZE_LIMIT_SUPPORT parameter is not valid
190 #endif
191 
192 //ALPN (Application-Layer Protocol Negotiation) extension
193 #ifndef TLS_ALPN_SUPPORT
194  #define TLS_ALPN_SUPPORT DISABLED
195 #elif (TLS_ALPN_SUPPORT != ENABLED && TLS_ALPN_SUPPORT != DISABLED)
196  #error TLS_ALPN_SUPPORT parameter is not valid
197 #endif
198 
199 //Extended Master Secret extension
200 #ifndef TLS_EXT_MASTER_SECRET_SUPPORT
201  #define TLS_EXT_MASTER_SECRET_SUPPORT ENABLED
202 #elif (TLS_EXT_MASTER_SECRET_SUPPORT != ENABLED && TLS_EXT_MASTER_SECRET_SUPPORT != DISABLED)
203  #error TLS_EXT_MASTER_SECRET_SUPPORT parameter is not valid
204 #endif
205 
206 //ClientHello Padding extension
207 #ifndef TLS_CLIENT_HELLO_PADDING_SUPPORT
208  #define TLS_CLIENT_HELLO_PADDING_SUPPORT ENABLED
209 #elif (TLS_CLIENT_HELLO_PADDING_SUPPORT != ENABLED && TLS_CLIENT_HELLO_PADDING_SUPPORT != DISABLED)
210  #error TLS_CLIENT_HELLO_PADDING_SUPPORT parameter is not valid
211 #endif
212 
213 //Signature Algorithms Certificate extension
214 #ifndef TLS_SIGN_ALGOS_CERT_SUPPORT
215  #define TLS_SIGN_ALGOS_CERT_SUPPORT DISABLED
216 #elif (TLS_SIGN_ALGOS_CERT_SUPPORT != ENABLED && TLS_SIGN_ALGOS_CERT_SUPPORT != DISABLED)
217  #error TLS_SIGN_ALGOS_CERT_SUPPORT parameter is not valid
218 #endif
219 
220 //RPK (Raw Public Key) support
221 #ifndef TLS_RAW_PUBLIC_KEY_SUPPORT
222  #define TLS_RAW_PUBLIC_KEY_SUPPORT DISABLED
223 #elif (TLS_RAW_PUBLIC_KEY_SUPPORT != ENABLED && TLS_RAW_PUBLIC_KEY_SUPPORT != DISABLED)
224  #error TLS_RAW_PUBLIC_KEY_SUPPORT parameter is not valid
225 #endif
226 
227 //Secure renegotiation support
228 #ifndef TLS_SECURE_RENEGOTIATION_SUPPORT
229  #define TLS_SECURE_RENEGOTIATION_SUPPORT DISABLED
230 #elif (TLS_SECURE_RENEGOTIATION_SUPPORT != ENABLED && TLS_SECURE_RENEGOTIATION_SUPPORT != DISABLED)
231  #error TLS_SECURE_RENEGOTIATION_SUPPORT parameter is not valid
232 #endif
233 
234 //Fallback SCSV support
235 #ifndef TLS_FALLBACK_SCSV_SUPPORT
236  #define TLS_FALLBACK_SCSV_SUPPORT DISABLED
237 #elif (TLS_FALLBACK_SCSV_SUPPORT != ENABLED && TLS_FALLBACK_SCSV_SUPPORT != DISABLED)
238  #error TLS_FALLBACK_SCSV_SUPPORT parameter is not valid
239 #endif
240 
241 //ECC callback functions
242 #ifndef TLS_ECC_CALLBACK_SUPPORT
243  #define TLS_ECC_CALLBACK_SUPPORT DISABLED
244 #elif (TLS_ECC_CALLBACK_SUPPORT != ENABLED && TLS_ECC_CALLBACK_SUPPORT != DISABLED)
245  #error TLS_ECC_CALLBACK_SUPPORT parameter is not valid
246 #endif
247 
248 //Maximum number of certificates the end entity can load
249 #ifndef TLS_MAX_CERTIFICATES
250  #define TLS_MAX_CERTIFICATES 3
251 #elif (TLS_MAX_CERTIFICATES < 1)
252  #error TLS_MAX_CERTIFICATES parameter is not valid
253 #endif
254 
255 //RSA key exchange support
256 #ifndef TLS_RSA_KE_SUPPORT
257  #define TLS_RSA_KE_SUPPORT ENABLED
258 #elif (TLS_RSA_KE_SUPPORT != ENABLED && TLS_RSA_KE_SUPPORT != DISABLED)
259  #error TLS_RSA_KE_SUPPORT parameter is not valid
260 #endif
261 
262 //DHE_RSA key exchange support
263 #ifndef TLS_DHE_RSA_KE_SUPPORT
264  #define TLS_DHE_RSA_KE_SUPPORT ENABLED
265 #elif (TLS_DHE_RSA_KE_SUPPORT != ENABLED && TLS_DHE_RSA_KE_SUPPORT != DISABLED)
266  #error TLS_DHE_RSA_KE_SUPPORT parameter is not valid
267 #endif
268 
269 //DHE_DSS key exchange support
270 #ifndef TLS_DHE_DSS_KE_SUPPORT
271  #define TLS_DHE_DSS_KE_SUPPORT DISABLED
272 #elif (TLS_DHE_DSS_KE_SUPPORT != ENABLED && TLS_DHE_DSS_KE_SUPPORT != DISABLED)
273  #error TLS_DHE_DSS_KE_SUPPORT parameter is not valid
274 #endif
275 
276 //DH_anon key exchange support (insecure)
277 #ifndef TLS_DH_ANON_KE_SUPPORT
278  #define TLS_DH_ANON_KE_SUPPORT DISABLED
279 #elif (TLS_DH_ANON_KE_SUPPORT != ENABLED && TLS_DH_ANON_KE_SUPPORT != DISABLED)
280  #error TLS_DH_ANON_KE_SUPPORT parameter is not valid
281 #endif
282 
283 //ECDHE_RSA key exchange support
284 #ifndef TLS_ECDHE_RSA_KE_SUPPORT
285  #define TLS_ECDHE_RSA_KE_SUPPORT ENABLED
286 #elif (TLS_ECDHE_RSA_KE_SUPPORT != ENABLED && TLS_ECDHE_RSA_KE_SUPPORT != DISABLED)
287  #error TLS_ECDHE_RSA_KE_SUPPORT parameter is not valid
288 #endif
289 
290 //ECDHE_ECDSA key exchange support
291 #ifndef TLS_ECDHE_ECDSA_KE_SUPPORT
292  #define TLS_ECDHE_ECDSA_KE_SUPPORT ENABLED
293 #elif (TLS_ECDHE_ECDSA_KE_SUPPORT != ENABLED && TLS_ECDHE_ECDSA_KE_SUPPORT != DISABLED)
294  #error TLS_ECDHE_ECDSA_KE_SUPPORT parameter is not valid
295 #endif
296 
297 //ECDH_anon key exchange support (insecure)
298 #ifndef TLS_ECDH_ANON_KE_SUPPORT
299  #define TLS_ECDH_ANON_KE_SUPPORT DISABLED
300 #elif (TLS_ECDH_ANON_KE_SUPPORT != ENABLED && TLS_ECDH_ANON_KE_SUPPORT != DISABLED)
301  #error TLS_ECDH_ANON_KE_SUPPORT parameter is not valid
302 #endif
303 
304 //PSK key exchange support
305 #ifndef TLS_PSK_KE_SUPPORT
306  #define TLS_PSK_KE_SUPPORT DISABLED
307 #elif (TLS_PSK_KE_SUPPORT != ENABLED && TLS_PSK_KE_SUPPORT != DISABLED)
308  #error TLS_PSK_KE_SUPPORT parameter is not valid
309 #endif
310 
311 //RSA_PSK key exchange support
312 #ifndef TLS_RSA_PSK_KE_SUPPORT
313  #define TLS_RSA_PSK_KE_SUPPORT DISABLED
314 #elif (TLS_RSA_PSK_KE_SUPPORT != ENABLED && TLS_RSA_PSK_KE_SUPPORT != DISABLED)
315  #error TLS_RSA_PSK_KE_SUPPORT parameter is not valid
316 #endif
317 
318 //DHE_PSK key exchange support
319 #ifndef TLS_DHE_PSK_KE_SUPPORT
320  #define TLS_DHE_PSK_KE_SUPPORT DISABLED
321 #elif (TLS_DHE_PSK_KE_SUPPORT != ENABLED && TLS_DHE_PSK_KE_SUPPORT != DISABLED)
322  #error TLS_DHE_PSK_KE_SUPPORT parameter is not valid
323 #endif
324 
325 //ECDHE_PSK key exchange support
326 #ifndef TLS_ECDHE_PSK_KE_SUPPORT
327  #define TLS_ECDHE_PSK_KE_SUPPORT DISABLED
328 #elif (TLS_ECDHE_PSK_KE_SUPPORT != ENABLED && TLS_ECDHE_PSK_KE_SUPPORT != DISABLED)
329  #error TLS_ECDHE_PSK_KE_SUPPORT parameter is not valid
330 #endif
331 
332 //RSA signature capability
333 #ifndef TLS_RSA_SIGN_SUPPORT
334  #define TLS_RSA_SIGN_SUPPORT ENABLED
335 #elif (TLS_RSA_SIGN_SUPPORT != ENABLED && TLS_RSA_SIGN_SUPPORT != DISABLED)
336  #error TLS_RSA_SIGN_SUPPORT parameter is not valid
337 #endif
338 
339 //RSA-PSS signature capability
340 #ifndef TLS_RSA_PSS_SIGN_SUPPORT
341  #define TLS_RSA_PSS_SIGN_SUPPORT ENABLED
342 #elif (TLS_RSA_PSS_SIGN_SUPPORT != ENABLED && TLS_RSA_PSS_SIGN_SUPPORT != DISABLED)
343  #error TLS_RSA_PSS_SIGN_SUPPORT parameter is not valid
344 #endif
345 
346 //DSA signature capability
347 #ifndef TLS_DSA_SIGN_SUPPORT
348  #define TLS_DSA_SIGN_SUPPORT DISABLED
349 #elif (TLS_DSA_SIGN_SUPPORT != ENABLED && TLS_DSA_SIGN_SUPPORT != DISABLED)
350  #error TLS_DSA_SIGN_SUPPORT parameter is not valid
351 #endif
352 
353 //ECDSA signature capability
354 #ifndef TLS_ECDSA_SIGN_SUPPORT
355  #define TLS_ECDSA_SIGN_SUPPORT ENABLED
356 #elif (TLS_ECDSA_SIGN_SUPPORT != ENABLED && TLS_ECDSA_SIGN_SUPPORT != DISABLED)
357  #error TLS_ECDSA_SIGN_SUPPORT parameter is not valid
358 #endif
359 
360 //EdDSA signature capability
361 #ifndef TLS_EDDSA_SIGN_SUPPORT
362  #define TLS_EDDSA_SIGN_SUPPORT DISABLED
363 #elif (TLS_EDDSA_SIGN_SUPPORT != ENABLED && TLS_EDDSA_SIGN_SUPPORT != DISABLED)
364  #error TLS_EDDSA_SIGN_SUPPORT parameter is not valid
365 #endif
366 
367 //NULL cipher support (insecure)
368 #ifndef TLS_NULL_CIPHER_SUPPORT
369  #define TLS_NULL_CIPHER_SUPPORT DISABLED
370 #elif (TLS_NULL_CIPHER_SUPPORT != ENABLED && TLS_NULL_CIPHER_SUPPORT != DISABLED)
371  #error TLS_NULL_CIPHER_SUPPORT parameter is not valid
372 #endif
373 
374 //Stream cipher support
375 #ifndef TLS_STREAM_CIPHER_SUPPORT
376  #define TLS_STREAM_CIPHER_SUPPORT DISABLED
377 #elif (TLS_STREAM_CIPHER_SUPPORT != ENABLED && TLS_STREAM_CIPHER_SUPPORT != DISABLED)
378  #error TLS_STREAM_CIPHER_SUPPORT parameter is not valid
379 #endif
380 
381 //CBC block cipher support
382 #ifndef TLS_CBC_CIPHER_SUPPORT
383  #define TLS_CBC_CIPHER_SUPPORT ENABLED
384 #elif (TLS_CBC_CIPHER_SUPPORT != ENABLED && TLS_CBC_CIPHER_SUPPORT != DISABLED)
385  #error TLS_CBC_CIPHER_SUPPORT parameter is not valid
386 #endif
387 
388 //CCM AEAD support
389 #ifndef TLS_CCM_CIPHER_SUPPORT
390  #define TLS_CCM_CIPHER_SUPPORT DISABLED
391 #elif (TLS_CCM_CIPHER_SUPPORT != ENABLED && TLS_CCM_CIPHER_SUPPORT != DISABLED)
392  #error TLS_CCM_CIPHER_SUPPORT parameter is not valid
393 #endif
394 
395 //CCM_8 AEAD support
396 #ifndef TLS_CCM_8_CIPHER_SUPPORT
397  #define TLS_CCM_8_CIPHER_SUPPORT DISABLED
398 #elif (TLS_CCM_8_CIPHER_SUPPORT != ENABLED && TLS_CCM_8_CIPHER_SUPPORT != DISABLED)
399  #error TLS_CCM_8_CIPHER_SUPPORT parameter is not valid
400 #endif
401 
402 //GCM AEAD support
403 #ifndef TLS_GCM_CIPHER_SUPPORT
404  #define TLS_GCM_CIPHER_SUPPORT ENABLED
405 #elif (TLS_GCM_CIPHER_SUPPORT != ENABLED && TLS_GCM_CIPHER_SUPPORT != DISABLED)
406  #error TLS_GCM_CIPHER_SUPPORT parameter is not valid
407 #endif
408 
409 //ChaCha20Poly1305 AEAD support
410 #ifndef TLS_CHACHA20_POLY1305_SUPPORT
411  #define TLS_CHACHA20_POLY1305_SUPPORT DISABLED
412 #elif (TLS_CHACHA20_POLY1305_SUPPORT != ENABLED && TLS_CHACHA20_POLY1305_SUPPORT != DISABLED)
413  #error TLS_CHACHA20_POLY1305_SUPPORT parameter is not valid
414 #endif
415 
416 //RC4 cipher support (insecure)
417 #ifndef TLS_RC4_SUPPORT
418  #define TLS_RC4_SUPPORT DISABLED
419 #elif (TLS_RC4_SUPPORT != ENABLED && TLS_RC4_SUPPORT != DISABLED)
420  #error TLS_RC4_SUPPORT parameter is not valid
421 #endif
422 
423 //IDEA cipher support (insecure)
424 #ifndef TLS_IDEA_SUPPORT
425  #define TLS_IDEA_SUPPORT DISABLED
426 #elif (TLS_IDEA_SUPPORT != ENABLED && TLS_IDEA_SUPPORT != DISABLED)
427  #error TLS_IDEA_SUPPORT parameter is not valid
428 #endif
429 
430 //DES cipher support (insecure)
431 #ifndef TLS_DES_SUPPORT
432  #define TLS_DES_SUPPORT DISABLED
433 #elif (TLS_DES_SUPPORT != ENABLED && TLS_DES_SUPPORT != DISABLED)
434  #error TLS_DES_SUPPORT parameter is not valid
435 #endif
436 
437 //Triple DES cipher support (weak)
438 #ifndef TLS_3DES_SUPPORT
439  #define TLS_3DES_SUPPORT DISABLED
440 #elif (TLS_3DES_SUPPORT != ENABLED && TLS_3DES_SUPPORT != DISABLED)
441  #error TLS_3DES_SUPPORT parameter is not valid
442 #endif
443 
444 //AES 128-bit cipher support
445 #ifndef TLS_AES_128_SUPPORT
446  #define TLS_AES_128_SUPPORT ENABLED
447 #elif (TLS_AES_128_SUPPORT != ENABLED && TLS_AES_128_SUPPORT != DISABLED)
448  #error TLS_AES_128_SUPPORT parameter is not valid
449 #endif
450 
451 //AES 256-bit cipher support
452 #ifndef TLS_AES_256_SUPPORT
453  #define TLS_AES_256_SUPPORT ENABLED
454 #elif (TLS_AES_256_SUPPORT != ENABLED && TLS_AES_256_SUPPORT != DISABLED)
455  #error TLS_AES_256_SUPPORT parameter is not valid
456 #endif
457 
458 //Camellia 128-bit cipher support
459 #ifndef TLS_CAMELLIA_128_SUPPORT
460  #define TLS_CAMELLIA_128_SUPPORT DISABLED
461 #elif (TLS_CAMELLIA_128_SUPPORT != ENABLED && TLS_CAMELLIA_128_SUPPORT != DISABLED)
462  #error TLS_CAMELLIA_128_SUPPORT parameter is not valid
463 #endif
464 
465 //Camellia 256-bit cipher support
466 #ifndef TLS_CAMELLIA_256_SUPPORT
467  #define TLS_CAMELLIA_256_SUPPORT DISABLED
468 #elif (TLS_CAMELLIA_256_SUPPORT != ENABLED && TLS_CAMELLIA_256_SUPPORT != DISABLED)
469  #error TLS_CAMELLIA_256_SUPPORT parameter is not valid
470 #endif
471 
472 //ARIA 128-bit cipher support
473 #ifndef TLS_ARIA_128_SUPPORT
474  #define TLS_ARIA_128_SUPPORT DISABLED
475 #elif (TLS_ARIA_128_SUPPORT != ENABLED && TLS_ARIA_128_SUPPORT != DISABLED)
476  #error TLS_ARIA_128_SUPPORT parameter is not valid
477 #endif
478 
479 //ARIA 256-bit cipher support
480 #ifndef TLS_ARIA_256_SUPPORT
481  #define TLS_ARIA_256_SUPPORT DISABLED
482 #elif (TLS_ARIA_256_SUPPORT != ENABLED && TLS_ARIA_256_SUPPORT != DISABLED)
483  #error TLS_ARIA_256_SUPPORT parameter is not valid
484 #endif
485 
486 //SEED cipher support
487 #ifndef TLS_SEED_SUPPORT
488  #define TLS_SEED_SUPPORT DISABLED
489 #elif (TLS_SEED_SUPPORT != ENABLED && TLS_SEED_SUPPORT != DISABLED)
490  #error TLS_SEED_SUPPORT parameter is not valid
491 #endif
492 
493 //MD5 hash support (insecure)
494 #ifndef TLS_MD5_SUPPORT
495  #define TLS_MD5_SUPPORT DISABLED
496 #elif (TLS_MD5_SUPPORT != ENABLED && TLS_MD5_SUPPORT != DISABLED)
497  #error TLS_MD5_SUPPORT parameter is not valid
498 #endif
499 
500 //SHA-1 hash support (weak)
501 #ifndef TLS_SHA1_SUPPORT
502  #define TLS_SHA1_SUPPORT ENABLED
503 #elif (TLS_SHA1_SUPPORT != ENABLED && TLS_SHA1_SUPPORT != DISABLED)
504  #error TLS_SHA1_SUPPORT parameter is not valid
505 #endif
506 
507 //SHA-224 hash support (weak)
508 #ifndef TLS_SHA224_SUPPORT
509  #define TLS_SHA224_SUPPORT DISABLED
510 #elif (TLS_SHA224_SUPPORT != ENABLED && TLS_SHA224_SUPPORT != DISABLED)
511  #error TLS_SHA224_SUPPORT parameter is not valid
512 #endif
513 
514 //SHA-256 hash support
515 #ifndef TLS_SHA256_SUPPORT
516  #define TLS_SHA256_SUPPORT ENABLED
517 #elif (TLS_SHA256_SUPPORT != ENABLED && TLS_SHA256_SUPPORT != DISABLED)
518  #error TLS_SHA256_SUPPORT parameter is not valid
519 #endif
520 
521 //SHA-384 hash support
522 #ifndef TLS_SHA384_SUPPORT
523  #define TLS_SHA384_SUPPORT ENABLED
524 #elif (TLS_SHA384_SUPPORT != ENABLED && TLS_SHA384_SUPPORT != DISABLED)
525  #error TLS_SHA384_SUPPORT parameter is not valid
526 #endif
527 
528 //SHA-512 hash support
529 #ifndef TLS_SHA512_SUPPORT
530  #define TLS_SHA512_SUPPORT DISABLED
531 #elif (TLS_SHA512_SUPPORT != ENABLED && TLS_SHA512_SUPPORT != DISABLED)
532  #error TLS_SHA512_SUPPORT parameter is not valid
533 #endif
534 
535 //FFDHE key exchange mechanism
536 #ifndef TLS_FFDHE_SUPPORT
537  #define TLS_FFDHE_SUPPORT DISABLED
538 #elif (TLS_FFDHE_SUPPORT != ENABLED && TLS_FFDHE_SUPPORT != DISABLED)
539  #error TLS_FFDHE_SUPPORT parameter is not valid
540 #endif
541 
542 //ffdhe2048 group support
543 #ifndef TLS_FFDHE2048_SUPPORT
544  #define TLS_FFDHE2048_SUPPORT ENABLED
545 #elif (TLS_FFDHE2048_SUPPORT != ENABLED && TLS_FFDHE2048_SUPPORT != DISABLED)
546  #error TLS_FFDHE2048_SUPPORT parameter is not valid
547 #endif
548 
549 //ffdhe3072 group support
550 #ifndef TLS_FFDHE3072_SUPPORT
551  #define TLS_FFDHE3072_SUPPORT DISABLED
552 #elif (TLS_FFDHE3072_SUPPORT != ENABLED && TLS_FFDHE3072_SUPPORT != DISABLED)
553  #error TLS_FFDHE3072_SUPPORT parameter is not valid
554 #endif
555 
556 //ffdhe4096 group support
557 #ifndef TLS_FFDHE4096_SUPPORT
558  #define TLS_FFDHE4096_SUPPORT DISABLED
559 #elif (TLS_FFDHE4096_SUPPORT != ENABLED && TLS_FFDHE4096_SUPPORT != DISABLED)
560  #error TLS_FFDHE4096_SUPPORT parameter is not valid
561 #endif
562 
563 //secp160k1 elliptic curve support (weak)
564 #ifndef TLS_SECP160K1_SUPPORT
565  #define TLS_SECP160K1_SUPPORT DISABLED
566 #elif (TLS_SECP160K1_SUPPORT != ENABLED && TLS_SECP160K1_SUPPORT != DISABLED)
567  #error TLS_SECP160K1_SUPPORT parameter is not valid
568 #endif
569 
570 //secp160r1 elliptic curve support (weak)
571 #ifndef TLS_SECP160R1_SUPPORT
572  #define TLS_SECP160R1_SUPPORT DISABLED
573 #elif (TLS_SECP160R1_SUPPORT != ENABLED && TLS_SECP160R1_SUPPORT != DISABLED)
574  #error TLS_SECP160R1_SUPPORT parameter is not valid
575 #endif
576 
577 //secp160r2 elliptic curve support (weak)
578 #ifndef TLS_SECP160R2_SUPPORT
579  #define TLS_SECP160R2_SUPPORT DISABLED
580 #elif (TLS_SECP160R2_SUPPORT != ENABLED && TLS_SECP160R2_SUPPORT != DISABLED)
581  #error TLS_SECP160R2_SUPPORT parameter is not valid
582 #endif
583 
584 //secp192k1 elliptic curve support
585 #ifndef TLS_SECP192K1_SUPPORT
586  #define TLS_SECP192K1_SUPPORT DISABLED
587 #elif (TLS_SECP192K1_SUPPORT != ENABLED && TLS_SECP192K1_SUPPORT != DISABLED)
588  #error TLS_SECP192K1_SUPPORT parameter is not valid
589 #endif
590 
591 //secp192r1 elliptic curve support (NIST P-192)
592 #ifndef TLS_SECP192R1_SUPPORT
593  #define TLS_SECP192R1_SUPPORT DISABLED
594 #elif (TLS_SECP192R1_SUPPORT != ENABLED && TLS_SECP192R1_SUPPORT != DISABLED)
595  #error TLS_SECP192R1_SUPPORT parameter is not valid
596 #endif
597 
598 //secp224k1 elliptic curve support
599 #ifndef TLS_SECP224K1_SUPPORT
600  #define TLS_SECP224K1_SUPPORT DISABLED
601 #elif (TLS_SECP224K1_SUPPORT != ENABLED && TLS_SECP224K1_SUPPORT != DISABLED)
602  #error TLS_SECP224K1_SUPPORT parameter is not valid
603 #endif
604 
605 //secp224r1 elliptic curve support (NIST P-224)
606 #ifndef TLS_SECP224R1_SUPPORT
607  #define TLS_SECP224R1_SUPPORT DISABLED
608 #elif (TLS_SECP224R1_SUPPORT != ENABLED && TLS_SECP224R1_SUPPORT != DISABLED)
609  #error TLS_SECP224R1_SUPPORT parameter is not valid
610 #endif
611 
612 //secp256k1 elliptic curve support
613 #ifndef TLS_SECP256K1_SUPPORT
614  #define TLS_SECP256K1_SUPPORT DISABLED
615 #elif (TLS_SECP256K1_SUPPORT != ENABLED && TLS_SECP256K1_SUPPORT != DISABLED)
616  #error TLS_SECP256K1_SUPPORT parameter is not valid
617 #endif
618 
619 //secp256r1 elliptic curve support (NIST P-256)
620 #ifndef TLS_SECP256R1_SUPPORT
621  #define TLS_SECP256R1_SUPPORT ENABLED
622 #elif (TLS_SECP256R1_SUPPORT != ENABLED && TLS_SECP256R1_SUPPORT != DISABLED)
623  #error TLS_SECP256R1_SUPPORT parameter is not valid
624 #endif
625 
626 //secp384r1 elliptic curve support (NIST P-384)
627 #ifndef TLS_SECP384R1_SUPPORT
628  #define TLS_SECP384R1_SUPPORT ENABLED
629 #elif (TLS_SECP384R1_SUPPORT != ENABLED && TLS_SECP384R1_SUPPORT != DISABLED)
630  #error TLS_SECP384R1_SUPPORT parameter is not valid
631 #endif
632 
633 //secp521r1 elliptic curve support (NIST P-521)
634 #ifndef TLS_SECP521R1_SUPPORT
635  #define TLS_SECP521R1_SUPPORT DISABLED
636 #elif (TLS_SECP521R1_SUPPORT != ENABLED && TLS_SECP521R1_SUPPORT != DISABLED)
637  #error TLS_SECP521R1_SUPPORT parameter is not valid
638 #endif
639 
640 //brainpoolP256r1 elliptic curve support
641 #ifndef TLS_BRAINPOOLP256R1_SUPPORT
642  #define TLS_BRAINPOOLP256R1_SUPPORT DISABLED
643 #elif (TLS_BRAINPOOLP256R1_SUPPORT != ENABLED && TLS_BRAINPOOLP256R1_SUPPORT != DISABLED)
644  #error TLS_BRAINPOOLP256R1_SUPPORT parameter is not valid
645 #endif
646 
647 //brainpoolP384r1 elliptic curve support
648 #ifndef TLS_BRAINPOOLP384R1_SUPPORT
649  #define TLS_BRAINPOOLP384R1_SUPPORT DISABLED
650 #elif (TLS_BRAINPOOLP384R1_SUPPORT != ENABLED && TLS_BRAINPOOLP384R1_SUPPORT != DISABLED)
651  #error TLS_BRAINPOOLP384R1_SUPPORT parameter is not valid
652 #endif
653 
654 //brainpoolP512r1 elliptic curve support
655 #ifndef TLS_BRAINPOOLP512R1_SUPPORT
656  #define TLS_BRAINPOOLP512R1_SUPPORT DISABLED
657 #elif (TLS_BRAINPOOLP512R1_SUPPORT != ENABLED && TLS_BRAINPOOLP512R1_SUPPORT != DISABLED)
658  #error TLS_BRAINPOOLP512R1_SUPPORT parameter is not valid
659 #endif
660 
661 //Curve25519 elliptic curve support
662 #ifndef TLS_X25519_SUPPORT
663  #define TLS_X25519_SUPPORT DISABLED
664 #elif (TLS_X25519_SUPPORT != ENABLED && TLS_X25519_SUPPORT != DISABLED)
665  #error TLS_X25519_SUPPORT parameter is not valid
666 #endif
667 
668 //Curve448 elliptic curve support
669 #ifndef TLS_X448_SUPPORT
670  #define TLS_X448_SUPPORT DISABLED
671 #elif (TLS_X448_SUPPORT != ENABLED && TLS_X448_SUPPORT != DISABLED)
672  #error TLS_X448_SUPPORT parameter is not valid
673 #endif
674 
675 //Ed25519 elliptic curve support
676 #ifndef TLS_ED25519_SUPPORT
677  #define TLS_ED25519_SUPPORT ENABLED
678 #elif (TLS_ED25519_SUPPORT != ENABLED && TLS_ED25519_SUPPORT != DISABLED)
679  #error TLS_ED25519_SUPPORT parameter is not valid
680 #endif
681 
682 //Ed448 elliptic curve support
683 #ifndef TLS_ED448_SUPPORT
684  #define TLS_ED448_SUPPORT DISABLED
685 #elif (TLS_ED448_SUPPORT != ENABLED && TLS_ED448_SUPPORT != DISABLED)
686  #error TLS_ED448_SUPPORT parameter is not valid
687 #endif
688 
689 //Certificate key usage verification
690 #ifndef TLS_CERT_KEY_USAGE_SUPPORT
691  #define TLS_CERT_KEY_USAGE_SUPPORT ENABLED
692 #elif (TLS_CERT_KEY_USAGE_SUPPORT != ENABLED && TLS_CERT_KEY_USAGE_SUPPORT != DISABLED)
693  #error TLS_CERT_KEY_USAGE_SUPPORT parameter is not valid
694 #endif
695 
696 //Key logging (for debugging purpose only)
697 #ifndef TLS_KEY_LOG_SUPPORT
698  #define TLS_KEY_LOG_SUPPORT DISABLED
699 #elif (TLS_KEY_LOG_SUPPORT != ENABLED && TLS_KEY_LOG_SUPPORT != DISABLED)
700  #error TLS_KEY_LOG_SUPPORT parameter is not valid
701 #endif
702 
703 //Maximum acceptable length for server names
704 #ifndef TLS_MAX_SERVER_NAME_LEN
705  #define TLS_MAX_SERVER_NAME_LEN 255
706 #elif (TLS_MAX_SERVER_NAME_LEN < 1)
707  #error TLS_MAX_SERVER_NAME_LEN parameter is not valid
708 #endif
709 
710 //Minimum acceptable size for Diffie-Hellman prime modulus
711 #ifndef TLS_MIN_DH_MODULUS_SIZE
712  #define TLS_MIN_DH_MODULUS_SIZE 1024
713 #elif (TLS_MIN_DH_MODULUS_SIZE < 512)
714  #error TLS_MIN_DH_MODULUS_SIZE parameter is not valid
715 #endif
716 
717 //Maximum acceptable size for Diffie-Hellman prime modulus
718 #ifndef TLS_MAX_DH_MODULUS_SIZE
719  #define TLS_MAX_DH_MODULUS_SIZE 4096
720 #elif (TLS_MAX_DH_MODULUS_SIZE < TLS_MIN_DH_MODULUS_SIZE)
721  #error TLS_MAX_DH_MODULUS_SIZE parameter is not valid
722 #endif
723 
724 //Minimum acceptable size for RSA modulus
725 #ifndef TLS_MIN_RSA_MODULUS_SIZE
726  #define TLS_MIN_RSA_MODULUS_SIZE 1024
727 #elif (TLS_MIN_RSA_MODULUS_SIZE < 512)
728  #error TLS_MIN_RSA_MODULUS_SIZE parameter is not valid
729 #endif
730 
731 //Maximum acceptable size for RSA modulus
732 #ifndef TLS_MAX_RSA_MODULUS_SIZE
733  #define TLS_MAX_RSA_MODULUS_SIZE 4096
734 #elif (TLS_MAX_RSA_MODULUS_SIZE < TLS_MIN_RSA_MODULUS_SIZE)
735  #error TLS_MAX_RSA_MODULUS_SIZE parameter is not valid
736 #endif
737 
738 //Minimum acceptable size for DSA prime modulus
739 #ifndef TLS_MIN_DSA_MODULUS_SIZE
740  #define TLS_MIN_DSA_MODULUS_SIZE 1024
741 #elif (TLS_MIN_DSA_MODULUS_SIZE < 512)
742  #error TLS_MIN_DSA_MODULUS_SIZE parameter is not valid
743 #endif
744 
745 //Maximum acceptable size for DSA prime modulus
746 #ifndef TLS_MAX_DSA_MODULUS_SIZE
747  #define TLS_MAX_DSA_MODULUS_SIZE 4096
748 #elif (TLS_MAX_DSA_MODULUS_SIZE < TLS_MIN_DSA_MODULUS_SIZE)
749  #error TLS_MAX_DSA_MODULUS_SIZE parameter is not valid
750 #endif
751 
752 //Maximum size for premaster secret
753 #ifndef TLS_PREMASTER_SECRET_SIZE
754  #define TLS_PREMASTER_SECRET_SIZE 256
755 #elif (TLS_PREMASTER_SECRET_SIZE < 48)
756  #error TLS_PREMASTER_SECRET_SIZE parameter is not valid
757 #endif
758 
759 //Maximum number of consecutive warning alerts
760 #ifndef TLS_MAX_WARNING_ALERTS
761  #define TLS_MAX_WARNING_ALERTS 0
762 #elif (TLS_MAX_WARNING_ALERTS < 0)
763  #error TLS_MAX_WARNING_ALERTS parameter is not valid
764 #endif
765 
766 //Maximum number of consecutive empty records
767 #ifndef TLS_MAX_EMPTY_RECORDS
768  #define TLS_MAX_EMPTY_RECORDS 0
769 #elif (TLS_MAX_EMPTY_RECORDS < 0)
770  #error TLS_MAX_EMPTY_RECORDS parameter is not valid
771 #endif
772 
773 //Maximum number of consecutive ChangeCipherSpec messages
774 #ifndef TLS_MAX_CHANGE_CIPHER_SPEC_MESSAGES
775  #define TLS_MAX_CHANGE_CIPHER_SPEC_MESSAGES 0
776 #elif (TLS_MAX_CHANGE_CIPHER_SPEC_MESSAGES < 0)
777  #error TLS_MAX_CHANGE_CIPHER_SPEC_MESSAGES parameter is not valid
778 #endif
779 
780 //Maximum number of consecutive KeyUpdate messages
781 #ifndef TLS_MAX_KEY_UPDATE_MESSAGES
782  #define TLS_MAX_KEY_UPDATE_MESSAGES 0
783 #elif (TLS_MAX_KEY_UPDATE_MESSAGES < 0)
784  #error TLS_MAX_KEY_UPDATE_MESSAGES parameter is not valid
785 #endif
786 
787 //Allocate memory block
788 #ifndef tlsAllocMem
789  #define tlsAllocMem(size) osAllocMem(size)
790 #endif
791 
792 //Deallocate memory block
793 #ifndef tlsFreeMem
794  #define tlsFreeMem(p) osFreeMem(p)
795 #endif
796 
797 //Support for Diffie-Hellman?
798 #if ((TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_2) && \
799  (TLS_DH_ANON_KE_SUPPORT == ENABLED || TLS_DHE_RSA_KE_SUPPORT == ENABLED || \
800  TLS_DHE_DSS_KE_SUPPORT == ENABLED || TLS_DHE_PSK_KE_SUPPORT == ENABLED))
801  #define TLS_DH_SUPPORT ENABLED
802 #elif ((TLS_MAX_VERSION >= TLS_VERSION_1_3 && TLS_MIN_VERSION <= TLS_VERSION_1_3) && \
803  (TLS13_DHE_KE_SUPPORT == ENABLED || TLS13_PSK_DHE_KE_SUPPORT == ENABLED))
804  #define TLS_DH_SUPPORT ENABLED
805 #else
806  #define TLS_DH_SUPPORT DISABLED
807 #endif
808 
809 //Support for ECDH?
810 #if ((TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_2) && \
811  (TLS_ECDH_ANON_KE_SUPPORT == ENABLED || TLS_ECDHE_RSA_KE_SUPPORT == ENABLED || \
812  TLS_ECDHE_ECDSA_KE_SUPPORT == ENABLED || TLS_ECDHE_PSK_KE_SUPPORT == ENABLED))
813  #define TLS_ECDH_SUPPORT ENABLED
814 #elif ((TLS_MAX_VERSION >= TLS_VERSION_1_3 && TLS_MIN_VERSION <= TLS_VERSION_1_3) && \
815  (TLS13_ECDHE_KE_SUPPORT == ENABLED || TLS13_PSK_ECDHE_KE_SUPPORT == ENABLED))
816  #define TLS_ECDH_SUPPORT ENABLED
817 #else
818  #define TLS_ECDH_SUPPORT DISABLED
819 #endif
820 
821 //Support for RSA?
822 #if ((TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_2) && \
823  (TLS_RSA_SIGN_SUPPORT == ENABLED || TLS_RSA_PSS_SIGN_SUPPORT == ENABLED || \
824  TLS_RSA_KE_SUPPORT == ENABLED || TLS_DHE_RSA_KE_SUPPORT == ENABLED || \
825  TLS_ECDHE_RSA_KE_SUPPORT == ENABLED || TLS_RSA_PSK_KE_SUPPORT == ENABLED))
826  #define TLS_RSA_SUPPORT ENABLED
827 #elif ((TLS_MAX_VERSION >= TLS_VERSION_1_3 && TLS_MIN_VERSION <= TLS_VERSION_1_3) && \
828  (TLS_RSA_SIGN_SUPPORT == ENABLED || TLS_RSA_PSS_SIGN_SUPPORT == ENABLED))
829  #define TLS_RSA_SUPPORT ENABLED
830 #else
831  #define TLS_RSA_SUPPORT DISABLED
832 #endif
833 
834 //Support for PSK?
835 #if ((TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_2) && \
836  (TLS_PSK_KE_SUPPORT == ENABLED || TLS_RSA_PSK_KE_SUPPORT == ENABLED || \
837  TLS_DHE_PSK_KE_SUPPORT == ENABLED || TLS_ECDHE_PSK_KE_SUPPORT == ENABLED))
838  #define TLS_PSK_SUPPORT ENABLED
839 #elif ((TLS_MAX_VERSION >= TLS_VERSION_1_3 && TLS_MIN_VERSION <= TLS_VERSION_1_3) && \
840  (TLS13_PSK_KE_SUPPORT == ENABLED || TLS13_PSK_DHE_KE_SUPPORT == ENABLED || \
841  TLS13_PSK_ECDHE_KE_SUPPORT == ENABLED))
842  #define TLS_PSK_SUPPORT ENABLED
843 #else
844  #define TLS_PSK_SUPPORT DISABLED
845 #endif
846 
847 //Maximum size for HKDF digests
848 #if (TLS_SHA384_SUPPORT == ENABLED)
849  #define TLS_MAX_HKDF_DIGEST_SIZE 48
850 #else
851  #define TLS_MAX_HKDF_DIGEST_SIZE 32
852 #endif
853 
854 //Bind TLS to a particular socket
855 #define tlsSetSocket(context, socket) tlsSetSocketCallbacks(context, \
856  (TlsSocketSendCallback) socketSend, (TlsSocketReceiveCallback) socketReceive, \
857  (TlsSocketHandle) socket)
858 
859 //Minimum plaintext record length
860 #define TLS_MIN_RECORD_LENGTH 512
861 //Maximum plaintext record length
862 #define TLS_MAX_RECORD_LENGTH 16384
863 //Data overhead caused by record encryption
864 #define TLS_MAX_RECORD_OVERHEAD 512
865 //Size of client and server random values
866 #define TLS_RANDOM_SIZE 32
867 //Master secret size
868 #define TLS_MASTER_SECRET_SIZE 48
869 
870 //C++ guard
871 #ifdef __cplusplus
872 extern "C" {
873 #endif
874 
875 
876 /**
877  * @brief TLS transport protocols
878  **/
879 
880 typedef enum
881 {
885 
886 
887 /**
888  * @brief TLS connection end
889  **/
890 
891 typedef enum
892 {
896 
897 
898 /**
899  * @brief Client authentication mode
900  **/
901 
902 typedef enum
903 {
908 
909 
910 /**
911  * @brief Early data status
912  **/
913 
914 typedef enum
915 {
919 
920 
921 /**
922  * @brief Flags used by read and write functions
923  **/
924 
925 typedef enum
926 {
927  TLS_FLAG_PEEK = 0x0200,
933  TLS_FLAG_DELAY = 0x8000
935 
936 
937 //The TLS_FLAG_BREAK macro causes the read function to stop reading
938 //data whenever the specified break character is encountered
939 #define TLS_FLAG_BREAK(c) (TLS_FLAG_BREAK_CHAR | LSB(c))
940 
941 
942 /**
943  * @brief Content type
944  **/
945 
946 typedef enum
947 {
954  TLS_TYPE_ACK = 25 //RFC draft
956 
957 
958 /**
959  * @brief Handshake message type
960  **/
961 
962 typedef enum
963 {
985 
986 
987 /**
988  * @brief Alert level
989  **/
990 
991 typedef enum
992 {
995 } TlsAlertLevel;
996 
997 
998 /**
999  * @brief Alert description
1000  **/
1001 
1002 typedef enum
1003 {
1039 
1040 
1041 /**
1042  * @brief Compression methods
1043  **/
1044 
1045 typedef enum
1046 {
1050 
1051 
1052 /**
1053  * @brief Key exchange methods
1054  **/
1055 
1056 typedef enum
1057 {
1083 
1084 
1085 /**
1086  * @brief Certificate formats
1087  **/
1088 
1089 typedef enum
1090 {
1095 
1096 
1097 /**
1098  * @brief Certificate types
1099  **/
1100 
1101 typedef enum
1102 {
1114  TLS_CERT_RSA_PSS_SIGN = 256, //For internal use only
1115  TLS_CERT_ED25519_SIGN = 257, //For internal use only
1116  TLS_CERT_ED448_SIGN = 258 //For internal use only
1118 
1119 
1120 /**
1121  * @brief Hash algorithms
1122  **/
1123 
1124 typedef enum
1125 {
1135 
1136 
1137 /**
1138  * @brief Signature algorithms
1139  **/
1140 
1141 typedef enum
1142 {
1159  TLS_SIGN_ALGO_GOSTR34102012_512 = 65 //RFC draft
1161 
1162 
1163 /**
1164  * @brief TLS extension types
1165  **/
1166 
1167 typedef enum
1168 {
1208 
1209 
1210 /**
1211  * @brief Name type
1212  **/
1213 
1214 typedef enum
1215 {
1218 
1219 
1220 /**
1221  * @brief Maximum fragment length
1222  **/
1223 
1224 typedef enum
1225 {
1231 
1232 
1233 /**
1234  * @brief Named groups
1235  **/
1236 
1237 typedef enum
1238 {
1240  TLS_GROUP_SECT163K1 = 1, //RFC 4492
1241  TLS_GROUP_SECT163R1 = 2, //RFC 4492
1242  TLS_GROUP_SECT163R2 = 3, //RFC 4492
1243  TLS_GROUP_SECT193R1 = 4, //RFC 4492
1244  TLS_GROUP_SECT193R2 = 5, //RFC 4492
1245  TLS_GROUP_SECT233K1 = 6, //RFC 4492
1246  TLS_GROUP_SECT233R1 = 7, //RFC 4492
1247  TLS_GROUP_SECT239K1 = 8, //RFC 4492
1248  TLS_GROUP_SECT283K1 = 9, //RFC 4492
1249  TLS_GROUP_SECT283R1 = 10, //RFC 4492
1250  TLS_GROUP_SECT409K1 = 11, //RFC 4492
1251  TLS_GROUP_SECT409R1 = 12, //RFC 4492
1252  TLS_GROUP_SECT571K1 = 13, //RFC 4492
1253  TLS_GROUP_SECT571R1 = 14, //RFC 4492
1254  TLS_GROUP_SECP160K1 = 15, //RFC 4492
1255  TLS_GROUP_SECP160R1 = 16, //RFC 4492
1256  TLS_GROUP_SECP160R2 = 17, //RFC 4492
1257  TLS_GROUP_SECP192K1 = 18, //RFC 4492
1258  TLS_GROUP_SECP192R1 = 19, //RFC 4492
1259  TLS_GROUP_SECP224K1 = 20, //RFC 4492
1260  TLS_GROUP_SECP224R1 = 21, //RFC 4492
1261  TLS_GROUP_SECP256K1 = 22, //RFC 4492
1262  TLS_GROUP_SECP256R1 = 23, //RFC 4492
1263  TLS_GROUP_SECP384R1 = 24, //RFC 4492
1264  TLS_GROUP_SECP521R1 = 25, //RFC 4492
1265  TLS_GROUP_BRAINPOOLP256R1 = 26, //RFC 7027
1266  TLS_GROUP_BRAINPOOLP384R1 = 27, //RFC 7027
1267  TLS_GROUP_BRAINPOOLP512R1 = 28, //RFC 7027
1268  TLS_GROUP_ECDH_X25519 = 29, //RFC 8422
1269  TLS_GROUP_ECDH_X448 = 30, //RFC 8422
1273  TLS_GROUP_GC256A = 34, //RFC draft
1274  TLS_GROUP_GC256B = 35, //RFC draft
1275  TLS_GROUP_GC256C = 36, //RFC draft
1276  TLS_GROUP_GC256D = 37, //RFC draft
1277  TLS_GROUP_GC512A = 38, //RFC draft
1278  TLS_GROUP_GC512B = 39, //RFC draft
1279  TLS_GROUP_GC512C = 40, //RFC draft
1280  TLS_GROUP_SM2 = 41, //RFC draft
1281  TLS_GROUP_FFDHE2048 = 256, //RFC 7919
1282  TLS_GROUP_FFDHE3072 = 257, //RFC 7919
1283  TLS_GROUP_FFDHE4096 = 258, //RFC 7919
1284  TLS_GROUP_FFDHE6144 = 259, //RFC 7919
1285  TLS_GROUP_FFDHE8192 = 260, //RFC 7919
1286  TLS_GROUP_FFDHE_MAX = 511, //RFC 7919
1288  TLS_GROUP_EXPLICIT_CHAR2_CURVE = 65282 //RFC 4492
1290 
1291 
1292 /**
1293  * @brief EC point formats
1294  **/
1295 
1296 typedef enum
1297 {
1302 
1303 
1304 /**
1305  * @brief EC curve types
1306  **/
1307 
1308 typedef enum
1309 {
1314 
1315 
1316 /**
1317  * @brief TLS FSM states
1318  **/
1319 
1320 typedef enum
1321 {
1354  TLS_STATE_CLOSED = 32
1356 
1357 
1358 //CodeWarrior or Win32 compiler?
1359 #if defined(__CWCC__) || defined(_WIN32)
1360  #pragma pack(push, 1)
1361 #endif
1362 
1363 
1364 /**
1365  * @brief Sequence number
1366  **/
1367 
1368 typedef __start_packed struct
1369 {
1370  uint8_t b[8];
1372 
1373 
1374 /**
1375  * @brief Cipher suites
1376  **/
1377 
1378 typedef __start_packed struct
1379 {
1380  uint16_t length; //0-1
1381  uint16_t value[]; //2
1383 
1384 
1385 /**
1386  * @brief Compression methods
1387  **/
1388 
1389 typedef __start_packed struct
1390 {
1391  uint8_t length; //0
1392  uint8_t value[]; //1
1394 
1395 
1396 /**
1397  * @brief Signature algorithm
1398  **/
1399 
1400 typedef __start_packed struct
1401 {
1402  uint8_t hash; //0
1403  uint8_t signature; //1
1405 
1406 
1407 /**
1408  * @brief List of signature algorithms
1409  **/
1410 
1411 typedef __start_packed struct
1412 {
1413  uint16_t length; //0-1
1414  TlsSignHashAlgo value[]; //2
1416 
1417 
1418 /**
1419  * @brief List of certificates
1420  **/
1421 
1422 typedef __start_packed struct
1423 {
1424  uint8_t length[3]; //0-2
1425  uint8_t value[]; //3
1427 
1428 
1429 /**
1430  * @brief List of certificate authorities
1431  **/
1432 
1433 typedef __start_packed struct
1434 {
1435  uint16_t length; //0-1
1436  uint8_t value[]; //2
1438 
1439 
1440 /**
1441  * @brief TLS extension
1442  **/
1443 
1444 typedef __start_packed struct
1445 {
1446  uint16_t type; //0-1
1447  uint16_t length; //2-3
1448  uint8_t value[]; //4
1450 
1451 
1452 /**
1453  * @brief List of TLS extensions
1454  **/
1455 
1456 typedef __start_packed struct
1457 {
1458  uint16_t length; //0-1
1459  uint8_t value[]; //2
1461 
1462 
1463 /**
1464  * @brief List of supported versions
1465  **/
1466 
1467 typedef __start_packed struct
1468 {
1469  uint8_t length; //0
1470  uint16_t value[]; //1
1472 
1473 
1474 /**
1475  * @brief Server name
1476  **/
1477 
1478 typedef __start_packed struct
1479 {
1480  uint8_t type; //0
1481  uint16_t length; //1-2
1484 
1485 
1486 /**
1487  * @brief List of server names
1488  **/
1489 
1490 typedef __start_packed struct
1491 {
1492  uint16_t length; //0-1
1493  uint8_t value[]; //2
1495 
1496 
1497 /**
1498  * @brief Protocol name
1499  **/
1500 
1501 typedef __start_packed struct
1502 {
1503  uint8_t length; //0
1504  char_t value[]; //1
1506 
1507 
1508 /**
1509  * @brief List of protocol names
1510  **/
1511 
1512 typedef __start_packed struct
1513 {
1514  uint16_t length; //0-1
1515  uint8_t value[]; //2
1517 
1518 
1519 /**
1520  * @brief List of supported groups
1521  **/
1522 
1523 typedef __start_packed struct
1524 {
1525  uint16_t length; //0-1
1526  uint16_t value[]; //2
1528 
1529 
1530 /**
1531  * @brief List of supported EC point formats
1532  **/
1533 
1534 typedef __start_packed struct
1535 {
1536  uint8_t length; //0
1537  uint8_t value[]; //1
1539 
1540 
1541 /**
1542  * @brief List of supported certificate types
1543  **/
1544 
1545 typedef __start_packed struct
1546 {
1547  uint8_t length; //0
1548  uint8_t value[]; //1
1550 
1551 
1552 /**
1553  * @brief Renegotiated connection
1554  **/
1555 
1556 typedef __start_packed struct
1557 {
1558  uint8_t length; //0
1559  uint8_t value[]; //1
1561 
1562 
1563 /**
1564  * @brief PSK identity
1565  **/
1566 
1567 typedef __start_packed struct
1568 {
1569  uint16_t length; //0-1
1570  uint8_t value[]; //2
1572 
1573 
1574 /**
1575  * @brief PSK identity hint
1576  **/
1577 
1578 typedef __start_packed struct
1579 {
1580  uint16_t length; //0-1
1581  uint8_t value[]; //2
1583 
1584 
1585 /**
1586  * @brief Digitally-signed element (TLS 1.0 and TLS 1.1)
1587  **/
1588 
1589 typedef __start_packed struct
1590 {
1591  uint16_t length; //0-1
1592  uint8_t value[]; //2
1594 
1595 
1596 /**
1597  * @brief Digitally-signed element (TLS 1.2)
1598  **/
1599 
1600 typedef __start_packed struct
1601 {
1603  uint16_t length; //2-3
1604  uint8_t value[]; //4
1606 
1607 
1608 /**
1609  * @brief TLS record
1610  **/
1611 
1612 typedef __start_packed struct
1613 {
1614  uint8_t type; //0
1615  uint16_t version; //1-2
1616  uint16_t length; //3-4
1617  uint8_t data[]; //5
1619 
1620 
1621 /**
1622  * @brief TLS handshake message
1623  **/
1624 
1625 typedef __start_packed struct
1626 {
1627  uint8_t msgType; //0
1628  uint8_t length[3]; //1-3
1629  uint8_t data[]; //4
1631 
1632 
1633 /**
1634  * @brief HelloRequest message
1635  **/
1636 
1637 typedef void TlsHelloRequest;
1638 
1639 
1640 /**
1641  * @brief ClientHello message
1642  **/
1643 
1644 typedef __start_packed struct
1645 {
1646  uint16_t clientVersion; //0-1
1647  uint8_t random[32]; //2-33
1648  uint8_t sessionIdLen; //34
1649  uint8_t sessionId[]; //35
1651 
1652 
1653 /**
1654  * @brief ServerHello message
1655  **/
1656 
1657 typedef __start_packed struct
1658 {
1659  uint16_t serverVersion; //0-1
1660  uint8_t random[32]; //2-33
1661  uint8_t sessionIdLen; //34
1662  uint8_t sessionId[]; //35
1664 
1665 
1666 /**
1667  * @brief Certificate message
1668  **/
1669 
1670 typedef void TlsCertificate;
1671 
1672 
1673 /**
1674  * @brief ServerKeyExchange message
1675  **/
1676 
1678 
1679 
1680 /**
1681  * @brief CertificateRequest message
1682  **/
1683 
1684 typedef __start_packed struct
1685 {
1686  uint8_t certificateTypesLen; //0
1687  uint8_t certificateTypes[]; //1
1689 
1690 
1691 /**
1692  * @brief ServerHelloDone message
1693  **/
1694 
1695 typedef void TlsServerHelloDone;
1696 
1697 
1698 /**
1699  * @brief ClientKeyExchange message
1700  **/
1701 
1703 
1704 
1705 /**
1706  * @brief CertificateVerify message
1707  **/
1708 
1710 
1711 
1712 /**
1713  * @brief NewSessionTicket message
1714  **/
1715 
1716 typedef __start_packed struct
1717 {
1718  uint32_t ticketLifetimeHint; //0-3
1719  uint16_t ticketLen; //4-5
1720  uint8_t ticket[]; //6
1722 
1723 
1724 /**
1725  * @brief Finished message
1726  **/
1727 
1728 typedef void TlsFinished;
1729 
1730 
1731 /**
1732  * @brief ChangeCipherSpec message
1733  **/
1734 
1735 typedef __start_packed struct
1736 {
1737  uint8_t type; //0
1739 
1740 
1741 /**
1742  * @brief Alert message
1743  **/
1744 
1745 typedef __start_packed struct
1746 {
1747  uint8_t level; //0
1748  uint8_t description; //1
1750 
1751 
1752 /**
1753  * @brief Session state information
1754  **/
1755 
1756 typedef __start_packed struct
1757 {
1758  uint16_t version; ///<Protocol version
1759  uint16_t cipherSuite; ///<Cipher suite identifier
1760  uint8_t secret[48]; ///<Master secret
1761  systime_t ticketTimestamp; ///<Timestamp to manage ticket lifetime
1762  uint32_t ticketLifetime; ///<Lifetime of the ticket
1763 #if (TLS_EXT_MASTER_SECRET_SUPPORT == ENABLED)
1764  bool_t extendedMasterSecret; ///<Extended master secret computation
1765 #endif
1767 
1768 
1769 //CodeWarrior or Win32 compiler?
1770 #if defined(__CWCC__) || defined(_WIN32)
1771  #pragma pack(pop)
1772 #endif
1773 
1774 
1775 /**
1776  * @brief Socket handle
1777  **/
1778 
1779 typedef void *TlsSocketHandle;
1780 
1781 
1782 /**
1783  * @brief Socket send callback function
1784  **/
1785 
1787  const void *data, size_t length, size_t *written, uint_t flags);
1788 
1789 
1790 /**
1791  * @brief Socket receive callback function
1792  **/
1793 
1795  void *data, size_t size, size_t *received, uint_t flags);
1796 
1797 
1798 /**
1799  * @brief ALPN callback function
1800  **/
1801 
1802 typedef error_t (*TlsAlpnCallback)(TlsContext *context,
1803  const char_t *selectedProtocol);
1804 
1805 
1806 /**
1807  * @brief Pre-shared key callback function
1808  **/
1809 
1810 typedef error_t (*TlsPskCallback)(TlsContext *context,
1811  const uint8_t *pskIdentity, size_t pskIdentityLen);
1812 
1813 
1814 /**
1815  * @brief Certificate verification callback function
1816  **/
1817 
1819  const X509CertificateInfo *certInfo, uint_t pathLen, void *param);
1820 
1821 
1822 /**
1823  * @brief Raw public key verification callback function
1824  **/
1825 
1827  const uint8_t *rawPublicKey, size_t rawPublicKeyLen);
1828 
1829 
1830 /**
1831  * @brief Ticket encryption callback function
1832  **/
1833 
1835  const uint8_t *plaintext, size_t plaintextLen, uint8_t *ciphertext,
1836  size_t *ciphertextLen, void *param);
1837 
1838 
1839 /**
1840  * @brief Ticket decryption callback function
1841  **/
1842 
1844  const uint8_t *ciphertext, size_t ciphertextLen, uint8_t *plaintext,
1845  size_t *plaintextLen, void *param);
1846 
1847 
1848 /**
1849  * @brief ECDH key agreement callback function
1850  **/
1851 
1852 typedef error_t (*TlsEcdhCallback)(TlsContext *context);
1853 
1854 
1855 /**
1856  * @brief ECDSA signature generation callback function
1857  **/
1858 
1860  const uint8_t *digest, size_t digestLen, EcdsaSignature *signature);
1861 
1862 
1863 /**
1864  * @brief ECDSA signature verification callback function
1865  **/
1866 
1868  const uint8_t *digest, size_t digestLen, EcdsaSignature *signature);
1869 
1870 
1871 /**
1872  * @brief Key logging callback function (for debugging purpose only)
1873  **/
1874 
1875 typedef void (*TlsKeyLogCallback)(TlsContext *context, const char_t *key);
1876 
1877 
1878 /**
1879  * @brief Structure describing a cipher suite
1880  **/
1881 
1882 typedef struct
1883 {
1884  uint16_t identifier;
1885  const char_t *name;
1891  uint8_t macKeyLen;
1892  uint8_t encKeyLen;
1893  uint8_t fixedIvLen;
1894  uint8_t recordIvLen;
1895  uint8_t authTagLen;
1896  uint8_t verifyDataLen;
1898 
1899 
1900 /**
1901  * @brief TLS session state
1902  **/
1903 
1904 typedef struct
1905 {
1906  uint16_t version; ///<TLS protocol version
1907  uint16_t cipherSuite; ///<Cipher suite identifier
1908  systime_t timestamp; ///<Time stamp to manage entry lifetime
1909  uint8_t secret[48]; ///<Master secret (TLS 1.2) or ticket PSK (TLS 1.3)
1910 #if (TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_2)
1911  uint8_t sessionId[32]; ///<Session identifier
1912  size_t sessionIdLen; ///<Length of the session identifier
1913  bool_t extendedMasterSecret; ///<Extended master secret computation
1914 #endif
1915  uint8_t *ticket; ///<Session ticket
1916  size_t ticketLen; ///<Length of the session ticket
1917 #if (TLS_MAX_VERSION >= TLS_VERSION_1_3 && TLS_MIN_VERSION <= TLS_VERSION_1_3)
1918  systime_t ticketTimestamp; ///<Timestamp to manage ticket lifetime
1919  uint32_t ticketLifetime; ///<Lifetime of the ticket
1920  uint32_t ticketAgeAdd; ///<Random value used to obscure the age of the ticket
1921  TlsHashAlgo ticketHashAlgo; ///<Hash algorithm associated with the ticket
1922  char_t *ticketAlpn; ///<ALPN protocol associated with the ticket
1923  uint32_t maxEarlyDataSize; ///<Maximum amount of 0-RTT data that the client is allowed to send
1924 #endif
1925 #if (TLS_SNI_SUPPORT == ENABLED)
1926  char_t *serverName; ///<ServerName extension
1927 #endif
1928 } TlsSessionState;
1929 
1930 
1931 /**
1932  * @brief Session cache
1933  **/
1934 
1935 typedef struct
1936 {
1937  OsMutex mutex; ///<Mutex preventing simultaneous access to the cache
1938  uint_t size; ///<Maximum number of entries
1939  TlsSessionState sessions[]; ///<Cache entries
1940 } TlsCache;
1941 
1942 
1943 /**
1944  * @brief Certificate descriptor
1945  **/
1946 
1947 typedef struct
1948 {
1949  const char_t *certChain; ///<End entity certificate chain (PEM format)
1950  size_t certChainLen; ///<Length of the certificate chain
1951  const char_t *privateKey; ///<Private key (PEM format)
1952  size_t privateKeyLen; ///<Length of the private key
1953  TlsCertificateType type; ///<End entity certificate type
1954  TlsSignatureAlgo signAlgo; ///<Signature algorithm used to sign the end entity certificate
1955  TlsHashAlgo hashAlgo; ///<Hash algorithm used to sign the end entity certificate
1956  TlsNamedGroup namedCurve; ///<Named curve used to generate the EC public key
1957 } TlsCertDesc;
1958 
1959 
1960 /**
1961  * @brief Hello extensions
1962  **/
1963 
1964 typedef struct
1965 {
1966  const TlsSupportedVersionList *supportedVersionList; ///<SupportedVersions extension (ClientHello)
1967  const TlsExtension *selectedVersion; ///<SupportedVersions extension (ServerHello)
1968  const TlsServerNameList *serverNameList; ///<ServerName extension
1969  const TlsSupportedGroupList *supportedGroupList; ///<SupportedGroups extension
1970  const TlsEcPointFormatList *ecPointFormatList; ///<EcPointFormats extension
1971  const TlsSignHashAlgos *signAlgoList; ///<SignatureAlgorithms extension
1972  const TlsSignHashAlgos *certSignAlgoList; ///<SignatureAlgorithmsCert extension
1973 #if (TLS_MAX_FRAG_LEN_SUPPORT == ENABLED)
1974  const TlsExtension *maxFragLen; ///<MaxFragmentLength extension
1975 #endif
1976 #if (TLS_RECORD_SIZE_LIMIT_SUPPORT == ENABLED)
1977  const TlsExtension *recordSizeLimit; ///<RecordSizeLimit extension
1978 #endif
1979 #if (TLS_ALPN_SUPPORT == ENABLED)
1980  const TlsProtocolNameList *protocolNameList; ///<ALPN extension
1981 #endif
1982 #if (TLS_RAW_PUBLIC_KEY_SUPPORT == ENABLED)
1983  const TlsCertTypeList *clientCertTypeList; ///<ClientCertType extension
1985  const TlsCertTypeList *serverCertTypeList; ///<ServerCertType extension
1987 #endif
1988 #if (TLS_EXT_MASTER_SECRET_SUPPORT == ENABLED)
1989  const TlsExtension *extendedMasterSecret; ///<ExtendedMasterSecret extension
1990 #endif
1991 #if (TLS_TICKET_SUPPORT == ENABLED)
1992  const TlsExtension *sessionTicket; ///<SessionTicket extension
1993 #endif
1994 #if (TLS_SECURE_RENEGOTIATION_SUPPORT == ENABLED)
1995  const TlsRenegoInfo *renegoInfo; ///<RenegotiationInfo extension
1996 #endif
1997 #if (TLS_MAX_VERSION >= TLS_VERSION_1_3 && TLS_MIN_VERSION <= TLS_VERSION_1_3)
1998  const Tls13Cookie *cookie; ///<Cookie extension
1999  const Tls13KeyShareList *keyShareList; ///<KeyShare extension (ClientHello)
2000  const TlsExtension *selectedGroup; ///<KeyShare extension (HelloRetryRequest)
2001  const Tls13KeyShareEntry *serverShare; ///<KeyShare extension (ServerHello)
2002  const Tls13PskKeModeList *pskKeModeList; ///<PskKeyExchangeModes extension
2003  const Tls13PskIdentityList *identityList; ///<PreSharedKey extension (ClientHello)
2005  const TlsExtension *selectedIdentity; ///<PreSharedKey extension (ServerHello)
2006  const TlsExtension *earlyDataIndication; ///<EarlyData extension
2007 #endif
2009 
2010 
2011 /**
2012  * @brief Encryption engine
2013  **/
2014 
2016 {
2017  uint16_t version; ///<Negotiated TLS version
2018  uint8_t macKey[48]; ///<MAC key
2019  size_t macKeyLen; ///<Length of the MAC key
2020  uint8_t encKey[48]; ///<Encryption key
2021  size_t encKeyLen; ///<Length of the encryption key
2022  uint8_t iv[16]; ///<Initialization vector
2023  size_t fixedIvLen; ///<Length of the fixed part of the IV
2024  size_t recordIvLen; ///<Length of the IV
2025  size_t authTagLen; ///<Length of the authentication tag
2026  const CipherAlgo *cipherAlgo; ///<Cipher algorithm
2027  void *cipherContext; ///<Cipher context
2028  CipherMode cipherMode; ///<Cipher mode of operation
2029  const HashAlgo *hashAlgo; ///<Hash algorithm for MAC operations
2030  HmacContext *hmacContext; ///<HMAC context
2031 #if (TLS_GCM_CIPHER_SUPPORT == ENABLED)
2032  GcmContext *gcmContext; ///<GCM context
2033 #endif
2034  TlsSequenceNumber seqNum; ///<TLS sequence number
2035 #if (DTLS_SUPPORT == ENABLED)
2036  uint16_t epoch; ///<Counter value incremented on every cipher state change
2037  DtlsSequenceNumber dtlsSeqNum; ///<Record sequence number
2038 #endif
2039 #if (TLS_RECORD_SIZE_LIMIT_SUPPORT == ENABLED)
2040  size_t recordSizeLimit; ///<Maximum size of record in octets
2041 #endif
2042 };
2043 
2044 
2045 /**
2046  * @brief TLS context
2047  *
2048  * An opaque data structure that represents a TLS connection
2049  *
2050  **/
2051 
2053 {
2054  TlsState state; ///<TLS handshake finite state machine
2055  TlsTransportProtocol transportProtocol; ///<Transport protocol (stream or datagram)
2056  TlsConnectionEnd entity; ///<Client or server operation
2057 
2058  TlsSocketHandle socketHandle; ///<Socket handle
2059  TlsSocketSendCallback socketSendCallback; ///<Socket send callback function
2060  TlsSocketReceiveCallback socketReceiveCallback; ///<Socket receive callback function
2061 
2062  const PrngAlgo *prngAlgo; ///<Pseudo-random number generator to be used
2063  void *prngContext; ///<Pseudo-random number generator context
2064 
2065  const uint16_t *cipherSuites; ///<List of supported cipher suites
2066  uint_t numCipherSuites; ///<Number of cipher suites in the list
2067 
2068  const uint16_t *supportedGroups; ///<List of supported named groups
2069  uint_t numSupportedGroups; ///<Number of named groups in the list
2070 
2071  char_t *serverName; ///<Fully qualified DNS hostname of the server
2072 
2073 #if (TLS_ECC_CALLBACK_SUPPORT == ENABLED)
2077 #endif
2078 
2079  TlsCertDesc certs[TLS_MAX_CERTIFICATES]; ///<End entity certificates (PEM format)
2080  uint_t numCerts; ///<Number of certificates available
2081  const char_t *trustedCaList; ///<List of trusted CA (PEM format)
2082  size_t trustedCaListLen; ///<Number of trusted CA in the list
2083  TlsCertVerifyCallback certVerifyCallback; ///<Certificate verification callback function
2084  void *certVerifyParam; ///<Opaque pointer passed to the certificate verification callback
2085  TlsCertDesc *cert; ///<Pointer to the currently selected certificate
2086 
2087  TlsCache *cache; ///<TLS session cache
2088  uint8_t sessionId[32]; ///<Session identifier
2089  size_t sessionIdLen; ///<Length of the session identifier
2090 
2091  uint16_t clientVersion; ///<Latest version supported by the client
2092  uint16_t version; ///<Negotiated TLS version
2093  uint16_t versionMin; ///<Minimum version accepted by the implementation
2094  uint16_t versionMax; ///<Maximum version accepted by the implementation
2095 
2096  uint8_t *cookie; ///<Cookie
2097  size_t cookieLen; ///<Length of the cookie
2098 
2099  uint8_t *ticket; ///<Session ticket
2100  size_t ticketLen; ///<Length of the session ticket
2101  systime_t ticketTimestamp; ///<Timestamp to manage ticket lifetime
2102  uint32_t ticketLifetime; ///<Lifetime of the ticket
2103 
2104  TlsCipherSuiteInfo cipherSuite; ///<Negotiated cipher suite
2105  TlsKeyExchMethod keyExchMethod; ///<Key exchange method
2106  TlsSignatureAlgo signAlgo; ///<Signature algorithm to be used
2107  TlsHashAlgo signHashAlgo; ///<Hash algorithm used for signing
2108  uint16_t namedGroup; ///<ECDHE or FFDHE named group
2109 
2110  TlsCertificateType peerCertType; ///<Peer's certificate type
2111  TlsClientAuthMode clientAuthMode; ///<Client authentication mode
2112  bool_t clientCertRequested; ///<This flag tells whether the client certificate is requested
2113 
2114  bool_t resume; ///<The connection is established by resuming a session
2115  bool_t fatalAlertSent; ///<A fatal alert message has been sent
2116  bool_t fatalAlertReceived; ///<A fatal alert message has been received from the peer
2117  bool_t closeNotifySent; ///<A closure alert has been sent
2118  bool_t closeNotifyReceived; ///<A closure alert has been received from the peer
2119 
2120  uint8_t *txBuffer; ///<TX buffer
2121  size_t txBufferSize; ///<TX buffer size
2122  size_t txBufferMaxLen; ///<Maximum number of plaintext data the TX buffer can hold
2123  TlsContentType txBufferType; ///<Type of data that resides in the TX buffer
2124  size_t txBufferLen; ///<Number of bytes that are pending to be sent
2125  size_t txBufferPos; ///<Current position in TX buffer
2126  size_t txRecordLen; ///<Length of the TLS record
2127  size_t txRecordPos; ///<Current position in the TLS record
2128 
2129  uint8_t *rxBuffer; ///<RX buffer
2130  size_t rxBufferSize; ///<RX buffer size
2131  size_t rxBufferMaxLen; ///<Maximum number of plaintext data the RX buffer can hold
2132  TlsContentType rxBufferType; ///<Type of data that resides in the RX buffer
2133  size_t rxBufferLen; ///<Number of bytes available for reading
2134  size_t rxBufferPos; ///<Current position in RX buffer
2135  size_t rxRecordLen; ///<Length of the TLS record
2136  size_t rxRecordPos; ///<Current position in the TLS record
2137 
2138  uint8_t clientRandom[TLS_RANDOM_SIZE]; ///<Client random value
2139  uint8_t serverRandom[TLS_RANDOM_SIZE]; ///<Server random value
2140  uint8_t premasterSecret[TLS_PREMASTER_SECRET_SIZE]; ///<Premaster secret
2141  size_t premasterSecretLen; ///<Length of the premaster secret
2142  uint8_t clientVerifyData[64]; ///<Client verify data
2143  size_t clientVerifyDataLen; ///<Length of the client verify data
2144  uint8_t serverVerifyData[64]; ///<Server verify data
2145  size_t serverVerifyDataLen; ///<Length of the server verify data
2146 
2147  TlsEncryptionEngine encryptionEngine; ///<Encryption engine
2148  TlsEncryptionEngine decryptionEngine; ///<Decryption engine
2149 
2150 #if (TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_0)
2151  size_t txLastRecordLen; ///<Length of the previous TLS record
2152 #endif
2153 
2154 #if (TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_1)
2155  Md5Context *transcriptMd5Context; ///<MD5 context used to compute verify data
2156 #endif
2157 
2158 #if (TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_2)
2159  uint8_t masterSecret[TLS_MASTER_SECRET_SIZE]; ///<Master secret
2160  uint8_t keyBlock[192]; ///<Key material
2161  HmacContext hmacContext; ///<HMAC context
2162  Sha1Context *transcriptSha1Context; ///<SHA-1 context used to compute verify data
2163 #endif
2164 
2165 #if (TLS_MAX_VERSION >= TLS_VERSION_1_2 && TLS_MIN_VERSION <= TLS_VERSION_1_3)
2166  HashContext *transcriptHashContext; ///<Hash context used to compute verify data
2167 #endif
2168 
2169 #if (TLS_MAX_VERSION >= TLS_VERSION_1_3 && TLS_MIN_VERSION <= TLS_VERSION_1_3)
2170  uint16_t preferredGroup; ///<Preferred ECDHE or FFDHE named group
2171  systime_t clientHelloTimestamp; ///<Time at which the ClientHello message was sent
2172  bool_t updatedClientHelloReceived; ///<An updated ClientHello message has been received
2173  uint8_t *certRequestContext; ///<Certificate request context
2174  size_t certRequestContextLen; ///<Length of the certificate request context
2175  int_t selectedIdentity; ///<Selected PSK identity
2176  bool_t pskKeModeSupported; ///<PSK key establishment supported by the client
2177 
2186 
2187  uint_t newSessionTicketCount; ///<Number of NewSessionTicket messages that have been sent
2188 
2189  uint8_t ticketPsk[TLS_MAX_HKDF_DIGEST_SIZE]; ///<PSK associated with the ticket
2190  size_t ticketPskLen; ///<Length of the PSK associated with the ticket
2191  uint32_t ticketAgeAdd; ///<Random value used to obscure the age of the ticket
2192  uint32_t ticketNonce; ///<A per-ticket value that is unique across all tickets issued
2193  uint16_t ticketCipherSuite; ///<Cipher suite associated with the ticket
2194  TlsHashAlgo ticketHashAlgo; ///<Hash algorithm associated with the ticket
2195  char_t *ticketAlpn; ///<ALPN protocol associated with the ticket
2196 
2197  size_t maxEarlyDataSize; ///<Maximum amount of 0-RTT data that the client is allowed to send
2198  size_t earlyDataLen; ///<Total amount of 0-RTT data that have been sent by the client
2199  bool_t earlyDataEnabled; ///<EarlyData is enabled
2200  bool_t earlyDataRejected; ///<The 0-RTT data have been rejected by the server
2201  bool_t earlyDataExtReceived; ///<The EarlyData extension has been received
2202  TlsSequenceNumber earlyDataSeqNum; ///<Early data sequence number
2203 #endif
2204 
2205 #if (TLS_DH_SUPPORT == ENABLED)
2206  DhContext dhContext; ///<Diffie-Hellman context
2207 #endif
2208 
2209 #if (TLS_ECDH_SUPPORT == ENABLED)
2210  EcdhContext ecdhContext; ///<ECDH context
2211  bool_t ecPointFormatsExtReceived; ///<The EcPointFormats extension has been received
2212 #endif
2213 
2214 #if (TLS_RSA_SUPPORT == ENABLED)
2215  RsaPublicKey peerRsaPublicKey; ///<Peer's RSA public key
2216 #endif
2217 
2218 #if (TLS_DSA_SIGN_SUPPORT == ENABLED)
2219  DsaPublicKey peerDsaPublicKey; ///<Peer's DSA public key
2220 #endif
2221 
2222 #if (TLS_ECDSA_SIGN_SUPPORT == ENABLED || TLS_EDDSA_SIGN_SUPPORT == ENABLED)
2223  EcDomainParameters peerEcParams; ///<Peer's EC domain parameters
2224  EcPublicKey peerEcPublicKey; ///<Peer's EC public key
2225 #endif
2226 
2227 #if (TLS_PSK_SUPPORT == ENABLED)
2228  uint8_t *psk; ///<Pre-shared key
2229  size_t pskLen; ///<Length of the pre-shared key, in bytes
2230  char_t *pskIdentity; ///<PSK identity
2231  char_t *pskIdentityHint; ///<PSK identity hint
2232  TlsPskCallback pskCallback; ///<PSK callback function
2233  uint16_t pskCipherSuite; ///<Cipher suite associated with the PSK
2234  TlsHashAlgo pskHashAlgo; ///<Hash algorithm associated with the PSK
2235 #endif
2236 
2237 #if (TLS_MAX_FRAG_LEN_SUPPORT == ENABLED)
2238  size_t maxFragLen; ///<Maximum plaintext fragment length
2239  bool_t maxFragLenExtReceived; ///<The MaxFragmentLength extension has been received
2240 #endif
2241 
2242 #if (TLS_RECORD_SIZE_LIMIT_SUPPORT == ENABLED)
2243  size_t recordSizeLimit; ///<Maximum record size the peer is willing to receive
2244  bool_t recordSizeLimitExtReceived; ///<The RecordSizeLimit extension has been received
2245 #endif
2246 
2247 #if (TLS_ALPN_SUPPORT == ENABLED)
2248  bool_t unknownProtocolsAllowed; ///<Unknown ALPN protocols allowed
2249  char_t *protocolList; ///<List of supported ALPN protocols
2250  char_t *selectedProtocol; ///<Selected ALPN protocol
2251  TlsAlpnCallback alpnCallback; ///<ALPN callback function
2252 #endif
2253 
2254 #if (TLS_EXT_MASTER_SECRET_SUPPORT == ENABLED)
2255  bool_t emsExtReceived; ///<The ExtendedMasterSecret extension has been received
2256 #endif
2257 
2258 #if (TLS_RAW_PUBLIC_KEY_SUPPORT == ENABLED)
2259  TlsCertificateFormat certFormat; ///<Certificate format
2260  TlsCertificateFormat peerCertFormat; ///<Peer's certificate format
2261  TlsRpkVerifyCallback rpkVerifyCallback; ///<Raw public key verification callback function
2262  bool_t clientCertTypeExtReceived; ///<The ClientCertType extension has been received
2263  bool_t serverCertTypeExtReceived; ///<The ServerCertType extension has been received
2264 #endif
2265 
2266 #if (TLS_TICKET_SUPPORT == ENABLED)
2267  bool_t sessionTicketEnabled; ///<Session ticket mechanism enabled
2268  bool_t sessionTicketExtReceived; ///<The SessionTicket extension has been received
2269  bool_t sessionTicketExtSent; ///<The SessionTicket extension has been sent
2270  TlsTicketEncryptCallback ticketEncryptCallback; ///<Ticket encryption callback function
2271  TlsTicketDecryptCallback ticketDecryptCallback; ///<Ticket decryption callback function
2272  void *ticketParam; ///<Opaque pointer passed to the ticket callbacks
2273 #endif
2274 
2275 #if (TLS_SECURE_RENEGOTIATION_SUPPORT == ENABLED)
2276  bool_t secureRenegoEnabled; ///<Secure renegotiation enabled
2277  bool_t secureRenegoFlag; ///<Secure renegotiation flag
2278 #endif
2279 
2280 #if (TLS_FALLBACK_SCSV_SUPPORT == ENABLED)
2281  bool_t fallbackScsvEnabled; ///<Support for FALLBACK_SCSV
2282 #endif
2283 
2284 #if (TLS_KEY_LOG_SUPPORT == ENABLED)
2285  TlsKeyLogCallback keyLogCallback; ///<Key logging callback (for debugging purpose only)
2286 #endif
2287 
2288 #if (TLS_MAX_WARNING_ALERTS > 0)
2289  uint_t alertCount; ///<Count of consecutive warning alerts
2290 #endif
2291 
2292 #if (TLS_MAX_EMPTY_RECORDS > 0)
2293  uint_t emptyRecordCount; ///<Count of consecutive empty records
2294 #endif
2295 
2296 #if (TLS_MAX_CHANGE_CIPHER_SPEC_MESSAGES > 0)
2297  uint_t changeCipherSpecCount; ///<Count of consecutive ChangeCipherSpec messages
2298 #endif
2299 
2300 #if (TLS_MAX_KEY_UPDATE_MESSAGES > 0)
2301  uint_t keyUpdateCount; ///<Count of consecutive KeyUpdate messages
2302 #endif
2303 
2304 #if (DTLS_SUPPORT == ENABLED)
2305  size_t pmtu; ///<PMTU value
2306  systime_t timeout; ///<Timeout for blocking calls
2308 
2309  DtlsCookieGenerateCallback cookieGenerateCallback; ///<Cookie generation callback function
2310  DtlsCookieVerifyCallback cookieVerifyCallback; ///<Cookie verification callback function
2311  void *cookieParam; ///<Opaque pointer passed to the cookie callbacks
2312 
2313  uint_t retransmitCount; ///<Retransmission counter
2314  systime_t retransmitTimestamp; ///<Time at which the datagram was sent
2315  systime_t retransmitTimeout; ///<Retransmission timeout
2316 
2317  uint16_t txMsgSeq; ///<Send sequence number
2318  size_t txDatagramLen; ///<Length of the outgoing datagram, in bytes
2319 
2320  uint16_t rxMsgSeq; ///<Next receive sequence number
2321  size_t rxFragQueueLen; ///<Length of the reassembly queue
2322  size_t rxDatagramLen; ///<Length of the incoming datagram, in bytes
2324  uint16_t rxRecordVersion; ///<Version of the incoming record
2325 
2326 #if (DTLS_REPLAY_DETECTION_SUPPORT == ENABLED)
2327  bool_t replayDetectionEnabled; ///<Anti-replay mechanism enabled
2328  uint32_t replayWindow[(DTLS_REPLAY_WINDOW_SIZE + 31) / 32];
2329 #endif
2330 
2332 #endif
2333 };
2334 
2335 
2336 //TLS application programming interface (API)
2337 TlsContext *tlsInit(void);
2338 TlsState tlsGetState(TlsContext *context);
2339 
2341  TlsSocketSendCallback socketSendCallback,
2342  TlsSocketReceiveCallback socketReceiveCallback, TlsSocketHandle handle);
2343 
2344 error_t tlsSetVersion(TlsContext *context, uint16_t versionMin,
2345  uint16_t versionMax);
2346 
2348  TlsTransportProtocol transportProtocol);
2349 
2351 
2352 error_t tlsSetPrng(TlsContext *context, const PrngAlgo *prngAlgo,
2353  void *prngContext);
2354 
2355 error_t tlsSetServerName(TlsContext *context, const char_t *serverName);
2356 const char_t *tlsGetServerName(TlsContext *context);
2357 
2358 error_t tlsSetCache(TlsContext *context, TlsCache *cache);
2360 
2361 error_t tlsSetBufferSize(TlsContext *context, size_t txBufferSize,
2362  size_t rxBufferSize);
2363 
2364 error_t tlsSetMaxFragmentLength(TlsContext *context, size_t maxFragLen);
2365 
2366 error_t tlsSetCipherSuites(TlsContext *context, const uint16_t *cipherSuites,
2367  uint_t length);
2368 
2369 error_t tlsSetSupportedGroups(TlsContext *context, const uint16_t *groups,
2370  uint_t length);
2371 
2372 error_t tlsSetPreferredGroup(TlsContext *context, uint16_t group);
2373 
2374 error_t tlsSetDhParameters(TlsContext *context, const char_t *params,
2375  size_t length);
2376 
2377 error_t tlsSetEcdhCallback(TlsContext *context, TlsEcdhCallback ecdhCallback);
2378 
2380  TlsEcdsaSignCallback ecdsaSignCallback);
2381 
2383  TlsEcdsaVerifyCallback ecdsaVerifyCallback);
2384 
2386  TlsKeyLogCallback keyLogCallback);
2387 
2389 error_t tlsSetAlpnProtocolList(TlsContext *context, const char_t *protocolList);
2390 error_t tlsSetAlpnCallback(TlsContext *context, TlsAlpnCallback alpnCallback);
2391 const char_t *tlsGetAlpnProtocol(TlsContext *context);
2392 
2393 error_t tlsSetPsk(TlsContext *context, const uint8_t *psk, size_t length);
2394 error_t tlsSetPskIdentity(TlsContext *context, const char_t *pskIdentity);
2395 error_t tlsSetPskIdentityHint(TlsContext *context, const char_t *pskIdentityHint);
2396 error_t tlsSetPskCallback(TlsContext *context, TlsPskCallback pskCallback);
2397 
2399  TlsRpkVerifyCallback rpkVerifyCallback);
2400 
2402  const char_t *trustedCaList, size_t length);
2403 
2404 error_t tlsAddCertificate(TlsContext *context, const char_t *certChain,
2405  size_t certChainLen, const char_t *privateKey, size_t privateKeyLen);
2406 
2408  TlsCertVerifyCallback certVerifyCallback, void *param);
2409 
2412 error_t tlsEnableFallbackScsv(TlsContext *context, bool_t enabled);
2413 
2415  TlsTicketEncryptCallback ticketEncryptCallback,
2416  TlsTicketDecryptCallback ticketDecryptCallback, void *param);
2417 
2418 error_t tlsSetPmtu(TlsContext *context, size_t pmtu);
2419 error_t tlsSetTimeout(TlsContext *context, systime_t timeout);
2420 
2422  DtlsCookieGenerateCallback cookieGenerateCallback,
2423  DtlsCookieVerifyCallback cookieVerifyCallback, void *param);
2424 
2426 
2427 error_t tlsSetMaxEarlyDataSize(TlsContext *context, size_t maxEarlyDataSize);
2428 
2429 error_t tlsWriteEarlyData(TlsContext *context, const void *data,
2430  size_t length, size_t *written, uint_t flags);
2431 
2432 error_t tlsConnect(TlsContext *context);
2433 
2435 
2436 error_t tlsWrite(TlsContext *context, const void *data,
2437  size_t length, size_t *written, uint_t flags);
2438 
2439 error_t tlsRead(TlsContext *context, void *data,
2440  size_t size, size_t *received, uint_t flags);
2441 
2442 bool_t tlsIsTxReady(TlsContext *context);
2443 bool_t tlsIsRxReady(TlsContext *context);
2444 
2445 error_t tlsShutdown(TlsContext *context);
2446 error_t tlsShutdownEx(TlsContext *context, bool_t waitForCloseNotify);
2447 
2448 void tlsFree(TlsContext *context);
2449 
2451 
2452 error_t tlsSaveSessionState(const TlsContext *context,
2453  TlsSessionState *session);
2454 
2456  const TlsSessionState *session);
2457 
2458 void tlsFreeSessionState(TlsSessionState *session);
2459 
2461 void tlsFreeCache(TlsCache *cache);
2462 
2463 //C++ guard
2464 #ifdef __cplusplus
2465 }
2466 #endif
2467 
2468 #endif
signed int int_t
Definition: compiler_port.h:44
unsigned int uint_t
Definition: compiler_port.h:45
char char_t
Definition: compiler_port.h:43
int bool_t
Definition: compiler_port.h:48
General definitions for cryptographic algorithms.
CipherMode
Cipher operation modes.
Definition: crypto.h:811
Diffie-Hellman key exchange.
DSA (Digital Signature Algorithm)
DTLS (Datagram Transport Layer Security)
error_t(* DtlsCookieGenerateCallback)(TlsContext *context, const DtlsClientParameters *clientParams, uint8_t *cookie, size_t *length, void *param)
DTLS cookie generation callback function.
Definition: dtls_misc.h:235
__start_packed struct @222 DtlsSequenceNumber
Sequence number.
error_t(* DtlsCookieVerifyCallback)(TlsContext *context, const DtlsClientParameters *clientParams, const uint8_t *cookie, size_t length, void *param)
DTLS cookie verification callback function.
Definition: dtls_misc.h:244
#define DTLS_REPLAY_WINDOW_SIZE
Definition: dtls_misc.h:68
ECDH (Elliptic Curve Diffie-Hellman) key exchange.
ECDSA (Elliptic Curve Digital Signature Algorithm)
error_t
Error codes.
Definition: error.h:43
Galois/Counter Mode (GCM)
HMAC (Keyed-Hashing for Message Authentication)
__start_packed struct _Ipv4Header __end_packed
uint8_t mode
Definition: ntp_common.h:149
RTOS abstraction layer.
uint32_t systime_t
System time.
RSA public-key cryptography standard.
TLS context.
Definition: tls.h:2053
systime_t ticketTimestamp
Timestamp to manage ticket lifetime.
Definition: tls.h:2101
bool_t resume
The connection is established by resuming a session.
Definition: tls.h:2114
bool_t sessionTicketEnabled
Session ticket mechanism enabled.
Definition: tls.h:2267
size_t maxEarlyDataSize
Maximum amount of 0-RTT data that the client is allowed to send.
Definition: tls.h:2197
size_t rxFragQueueLen
Length of the reassembly queue.
Definition: tls.h:2321
size_t maxFragLen
Maximum plaintext fragment length.
Definition: tls.h:2238
size_t trustedCaListLen
Number of trusted CA in the list.
Definition: tls.h:2082
void * ticketParam
Opaque pointer passed to the ticket callbacks.
Definition: tls.h:2272
TlsPskCallback pskCallback
PSK callback function.
Definition: tls.h:2232
TlsKeyExchMethod keyExchMethod
Key exchange method.
Definition: tls.h:2105
HashContext * transcriptHashContext
Hash context used to compute verify data.
Definition: tls.h:2166
uint_t numCerts
Number of certificates available.
Definition: tls.h:2080
TlsRpkVerifyCallback rpkVerifyCallback
Raw public key verification callback function.
Definition: tls.h:2261
bool_t ecPointFormatsExtReceived
The EcPointFormats extension has been received.
Definition: tls.h:2211
uint8_t serverHsTrafficSecret[TLS_MAX_HKDF_DIGEST_SIZE]
Definition: tls.h:2181
TlsSocketHandle socketHandle
Socket handle.
Definition: tls.h:2058
bool_t sessionTicketExtReceived
The SessionTicket extension has been received.
Definition: tls.h:2268
bool_t earlyDataEnabled
EarlyData is enabled.
Definition: tls.h:2199
bool_t unknownProtocolsAllowed
Unknown ALPN protocols allowed.
Definition: tls.h:2248
uint16_t rxRecordVersion
Version of the incoming record.
Definition: tls.h:2324
bool_t sessionTicketExtSent
The SessionTicket extension has been sent.
Definition: tls.h:2269
TlsCertVerifyCallback certVerifyCallback
Certificate verification callback function.
Definition: tls.h:2083
TlsAlpnCallback alpnCallback
ALPN callback function.
Definition: tls.h:2251
uint16_t versionMax
Maximum version accepted by the implementation.
Definition: tls.h:2094
size_t ticketPskLen
Length of the PSK associated with the ticket.
Definition: tls.h:2190
void * cookieParam
Opaque pointer passed to the cookie callbacks.
Definition: tls.h:2311
size_t recordSizeLimit
Maximum record size the peer is willing to receive.
Definition: tls.h:2243
bool_t maxFragLenExtReceived
The MaxFragmentLength extension has been received.
Definition: tls.h:2239
bool_t earlyDataExtReceived
The EarlyData extension has been received.
Definition: tls.h:2201
bool_t updatedClientHelloReceived
An updated ClientHello message has been received.
Definition: tls.h:2172
uint32_t replayWindow[(DTLS_REPLAY_WINDOW_SIZE+31)/32]
Definition: tls.h:2328
uint16_t namedGroup
ECDHE or FFDHE named group.
Definition: tls.h:2108
uint16_t txMsgSeq
Send sequence number.
Definition: tls.h:2317
uint8_t clientAppTrafficSecret[TLS_MAX_HKDF_DIGEST_SIZE]
Definition: tls.h:2182
DhContext dhContext
Diffie-Hellman context.
Definition: tls.h:2206
uint8_t sessionId[32]
Session identifier.
Definition: tls.h:2088
bool_t fatalAlertSent
A fatal alert message has been sent.
Definition: tls.h:2115
char_t * pskIdentityHint
PSK identity hint.
Definition: tls.h:2231
TlsTransportProtocol transportProtocol
Transport protocol (stream or datagram)
Definition: tls.h:2055
TlsClientAuthMode clientAuthMode
Client authentication mode.
Definition: tls.h:2111
uint8_t serverAppTrafficSecret[TLS_MAX_HKDF_DIGEST_SIZE]
Definition: tls.h:2183
systime_t retransmitTimeout
Retransmission timeout.
Definition: tls.h:2315
TlsCipherSuiteInfo cipherSuite
Negotiated cipher suite.
Definition: tls.h:2104
int_t selectedIdentity
Selected PSK identity.
Definition: tls.h:2175
size_t sessionIdLen
Length of the session identifier.
Definition: tls.h:2089
TlsEcdsaSignCallback ecdsaSignCallback
Definition: tls.h:2075
TlsCache * cache
TLS session cache.
Definition: tls.h:2087
size_t pskLen
Length of the pre-shared key, in bytes.
Definition: tls.h:2229
Sha1Context * transcriptSha1Context
SHA-1 context used to compute verify data.
Definition: tls.h:2162
size_t txBufferMaxLen
Maximum number of plaintext data the TX buffer can hold.
Definition: tls.h:2122
const PrngAlgo * prngAlgo
Pseudo-random number generator to be used.
Definition: tls.h:2062
bool_t secureRenegoFlag
Secure renegotiation flag.
Definition: tls.h:2277
EcDomainParameters peerEcParams
Peer's EC domain parameters.
Definition: tls.h:2223
bool_t closeNotifyReceived
A closure alert has been received from the peer.
Definition: tls.h:2118
size_t txBufferPos
Current position in TX buffer.
Definition: tls.h:2125
uint8_t masterSecret[TLS_MASTER_SECRET_SIZE]
Master secret.
Definition: tls.h:2159
size_t certRequestContextLen
Length of the certificate request context.
Definition: tls.h:2174
TlsCertificateFormat certFormat
Certificate format.
Definition: tls.h:2259
uint16_t pskCipherSuite
Cipher suite associated with the PSK.
Definition: tls.h:2233
size_t txBufferSize
TX buffer size.
Definition: tls.h:2121
TlsEncryptionEngine decryptionEngine
Decryption engine.
Definition: tls.h:2148
size_t txBufferLen
Number of bytes that are pending to be sent.
Definition: tls.h:2124
bool_t clientCertRequested
This flag tells whether the client certificate is requested.
Definition: tls.h:2112
TlsContentType txBufferType
Type of data that resides in the TX buffer.
Definition: tls.h:2123
TlsCertificateType peerCertType
Peer's certificate type.
Definition: tls.h:2110
RsaPublicKey peerRsaPublicKey
Peer's RSA public key.
Definition: tls.h:2215
TlsContentType rxBufferType
Type of data that resides in the RX buffer.
Definition: tls.h:2132
uint16_t ticketCipherSuite
Cipher suite associated with the ticket.
Definition: tls.h:2193
uint8_t * rxBuffer
RX buffer.
Definition: tls.h:2129
bool_t recordSizeLimitExtReceived
The RecordSizeLimit extension has been received.
Definition: tls.h:2244
uint8_t * cookie
Cookie.
Definition: tls.h:2096
bool_t fallbackScsvEnabled
Support for FALLBACK_SCSV.
Definition: tls.h:2281
uint_t numSupportedGroups
Number of named groups in the list.
Definition: tls.h:2069
TlsHashAlgo signHashAlgo
Hash algorithm used for signing.
Definition: tls.h:2107
size_t ticketLen
Length of the session ticket.
Definition: tls.h:2100
char_t * pskIdentity
PSK identity.
Definition: tls.h:2230
size_t earlyDataLen
Total amount of 0-RTT data that have been sent by the client.
Definition: tls.h:2198
TlsEncryptionEngine encryptionEngine
Encryption engine.
Definition: tls.h:2147
uint8_t serverRandom[TLS_RANDOM_SIZE]
Server random value.
Definition: tls.h:2139
uint8_t exporterMasterSecret[TLS_MAX_HKDF_DIGEST_SIZE]
Definition: tls.h:2184
TlsKeyLogCallback keyLogCallback
Key logging callback (for debugging purpose only)
Definition: tls.h:2285
uint16_t preferredGroup
Preferred ECDHE or FFDHE named group.
Definition: tls.h:2170
uint8_t premasterSecret[TLS_PREMASTER_SECRET_SIZE]
Premaster secret.
Definition: tls.h:2140
bool_t replayDetectionEnabled
Anti-replay mechanism enabled.
Definition: tls.h:2327
uint16_t clientVersion
Latest version supported by the client.
Definition: tls.h:2091
uint_t retransmitCount
Retransmission counter.
Definition: tls.h:2313
char_t * selectedProtocol
Selected ALPN protocol.
Definition: tls.h:2250
TlsCertDesc * cert
Pointer to the currently selected certificate.
Definition: tls.h:2085
char_t * protocolList
List of supported ALPN protocols.
Definition: tls.h:2249
bool_t emsExtReceived
The ExtendedMasterSecret extension has been received.
Definition: tls.h:2255
uint16_t versionMin
Minimum version accepted by the implementation.
Definition: tls.h:2093
DsaPublicKey peerDsaPublicKey
Peer's DSA public key.
Definition: tls.h:2219
const char_t * trustedCaList
List of trusted CA (PEM format)
Definition: tls.h:2081
TlsCertDesc certs[TLS_MAX_CERTIFICATES]
End entity certificates (PEM format)
Definition: tls.h:2079
uint32_t ticketNonce
A per-ticket value that is unique across all tickets issued.
Definition: tls.h:2192
TlsTicketDecryptCallback ticketDecryptCallback
Ticket decryption callback function.
Definition: tls.h:2271
uint8_t serverVerifyData[64]
Server verify data.
Definition: tls.h:2144
uint8_t * txBuffer
TX buffer.
Definition: tls.h:2120
size_t txRecordLen
Length of the TLS record.
Definition: tls.h:2126
bool_t clientCertTypeExtReceived
The ClientCertType extension has been received.
Definition: tls.h:2262
size_t pmtu
PMTU value.
Definition: tls.h:2305
size_t txDatagramLen
Length of the outgoing datagram, in bytes.
Definition: tls.h:2318
uint8_t clientVerifyData[64]
Client verify data.
Definition: tls.h:2142
size_t rxBufferLen
Number of bytes available for reading.
Definition: tls.h:2133
TlsCertificateFormat peerCertFormat
Peer's certificate format.
Definition: tls.h:2260
uint8_t ticketPsk[TLS_MAX_HKDF_DIGEST_SIZE]
PSK associated with the ticket.
Definition: tls.h:2189
size_t rxBufferSize
RX buffer size.
Definition: tls.h:2130
size_t rxDatagramPos
Definition: tls.h:2323
TlsEcdsaVerifyCallback ecdsaVerifyCallback
Definition: tls.h:2076
TlsConnectionEnd entity
Client or server operation.
Definition: tls.h:2056
DtlsCookieVerifyCallback cookieVerifyCallback
Cookie verification callback function.
Definition: tls.h:2310
size_t txRecordPos
Current position in the TLS record.
Definition: tls.h:2127
TlsState state
TLS handshake finite state machine.
Definition: tls.h:2054
uint16_t version
Negotiated TLS version.
Definition: tls.h:2092
void * certVerifyParam
Opaque pointer passed to the certificate verification callback.
Definition: tls.h:2084
systime_t retransmitTimestamp
Time at which the datagram was sent.
Definition: tls.h:2314
bool_t fatalAlertReceived
A fatal alert message has been received from the peer.
Definition: tls.h:2116
systime_t timeout
Timeout for blocking calls.
Definition: tls.h:2306
size_t rxBufferPos
Current position in RX buffer.
Definition: tls.h:2134
uint8_t * ticket
Session ticket.
Definition: tls.h:2099
bool_t earlyDataRejected
The 0-RTT data have been rejected by the server.
Definition: tls.h:2200
uint8_t clientEarlyTrafficSecret[TLS_MAX_HKDF_DIGEST_SIZE]
Definition: tls.h:2179
uint8_t clientRandom[TLS_RANDOM_SIZE]
Client random value.
Definition: tls.h:2138
bool_t closeNotifySent
A closure alert has been sent.
Definition: tls.h:2117
size_t rxDatagramLen
Length of the incoming datagram, in bytes.
Definition: tls.h:2322
HmacContext hmacContext
HMAC context.
Definition: tls.h:2161
systime_t startTime
Definition: tls.h:2307
size_t serverVerifyDataLen
Length of the server verify data.
Definition: tls.h:2145
uint8_t secret[TLS_MAX_HKDF_DIGEST_SIZE]
Definition: tls.h:2178
const uint16_t * cipherSuites
List of supported cipher suites.
Definition: tls.h:2065
uint32_t ticketAgeAdd
Random value used to obscure the age of the ticket.
Definition: tls.h:2191
bool_t serverCertTypeExtReceived
The ServerCertType extension has been received.
Definition: tls.h:2263
size_t cookieLen
Length of the cookie.
Definition: tls.h:2097
EcdhContext ecdhContext
ECDH context.
Definition: tls.h:2210
char_t * ticketAlpn
ALPN protocol associated with the ticket.
Definition: tls.h:2195
size_t rxRecordLen
Length of the TLS record.
Definition: tls.h:2135
TlsEcdhCallback ecdhCallback
Definition: tls.h:2074
TlsSignatureAlgo signAlgo
Signature algorithm to be used.
Definition: tls.h:2106
TlsEncryptionEngine prevEncryptionEngine
Definition: tls.h:2331
bool_t secureRenegoEnabled
Secure renegotiation enabled.
Definition: tls.h:2276
TlsSocketReceiveCallback socketReceiveCallback
Socket receive callback function.
Definition: tls.h:2060
TlsTicketEncryptCallback ticketEncryptCallback
Ticket encryption callback function.
Definition: tls.h:2270
char_t * serverName
Fully qualified DNS hostname of the server.
Definition: tls.h:2071
TlsHashAlgo ticketHashAlgo
Hash algorithm associated with the ticket.
Definition: tls.h:2194
size_t clientVerifyDataLen
Length of the client verify data.
Definition: tls.h:2143
uint8_t resumptionMasterSecret[TLS_MAX_HKDF_DIGEST_SIZE]
Definition: tls.h:2185
uint32_t ticketLifetime
Lifetime of the ticket.
Definition: tls.h:2102
bool_t pskKeModeSupported
PSK key establishment supported by the client.
Definition: tls.h:2176
uint16_t rxMsgSeq
Next receive sequence number.
Definition: tls.h:2320
TlsHashAlgo pskHashAlgo
Hash algorithm associated with the PSK.
Definition: tls.h:2234
size_t premasterSecretLen
Length of the premaster secret.
Definition: tls.h:2141
uint_t numCipherSuites
Number of cipher suites in the list.
Definition: tls.h:2066
size_t rxBufferMaxLen
Maximum number of plaintext data the RX buffer can hold.
Definition: tls.h:2131
DtlsCookieGenerateCallback cookieGenerateCallback
Cookie generation callback function.
Definition: tls.h:2309
TlsSequenceNumber earlyDataSeqNum
Early data sequence number.
Definition: tls.h:2202
EcPublicKey peerEcPublicKey
Peer's EC public key.
Definition: tls.h:2224
uint8_t * psk
Pre-shared key.
Definition: tls.h:2228
uint8_t * certRequestContext
Certificate request context.
Definition: tls.h:2173
const uint16_t * supportedGroups
List of supported named groups.
Definition: tls.h:2068
TlsSocketSendCallback socketSendCallback
Socket send callback function.
Definition: tls.h:2059
systime_t clientHelloTimestamp
Time at which the ClientHello message was sent.
Definition: tls.h:2171
void * prngContext
Pseudo-random number generator context.
Definition: tls.h:2063
size_t rxRecordPos
Current position in the TLS record.
Definition: tls.h:2136
uint8_t keyBlock[192]
Key material.
Definition: tls.h:2160
uint8_t clientHsTrafficSecret[TLS_MAX_HKDF_DIGEST_SIZE]
Definition: tls.h:2180
uint_t newSessionTicketCount
Number of NewSessionTicket messages that have been sent.
Definition: tls.h:2187
Encryption engine.
Definition: tls.h:2016
CipherMode cipherMode
Cipher mode of operation.
Definition: tls.h:2028
GcmContext * gcmContext
GCM context.
Definition: tls.h:2032
size_t macKeyLen
Length of the MAC key.
Definition: tls.h:2019
HmacContext * hmacContext
HMAC context.
Definition: tls.h:2030
size_t recordSizeLimit
Maximum size of record in octets.
Definition: tls.h:2040
const HashAlgo * hashAlgo
Hash algorithm for MAC operations.
Definition: tls.h:2029
size_t fixedIvLen
Length of the fixed part of the IV.
Definition: tls.h:2023
uint8_t encKey[48]
Encryption key.
Definition: tls.h:2020
uint8_t iv[16]
Initialization vector.
Definition: tls.h:2022
const CipherAlgo * cipherAlgo
Cipher algorithm.
Definition: tls.h:2026
DtlsSequenceNumber dtlsSeqNum
Record sequence number.
Definition: tls.h:2037
size_t authTagLen
Length of the authentication tag.
Definition: tls.h:2025
uint16_t version
Negotiated TLS version.
Definition: tls.h:2017
TlsSequenceNumber seqNum
TLS sequence number.
Definition: tls.h:2034
void * cipherContext
Cipher context.
Definition: tls.h:2027
size_t encKeyLen
Length of the encryption key.
Definition: tls.h:2021
uint8_t macKey[48]
MAC key.
Definition: tls.h:2018
size_t recordIvLen
Length of the IV.
Definition: tls.h:2024
uint16_t epoch
Counter value incremented on every cipher state change.
Definition: tls.h:2036
Common interface for encryption algorithms.
Definition: crypto.h:874
Diffie-Hellman context.
Definition: dh.h:60
DSA public key.
Definition: dsa.h:61
EC domain parameters.
Definition: ec.h:64
EC public key.
Definition: ec.h:82
ECDH context.
Definition: ecdh.h:59
ECDSA signature.
Definition: ecdsa.h:49
GCM context.
Definition: gcm.h:48
Common interface for hash algorithms.
Definition: crypto.h:852
HMAC algorithm context.
Definition: hmac.h:54
MD5 algorithm context.
Definition: md5.h:59
Mutex object.
Common interface for pseudo-random number generators.
Definition: crypto.h:892
RSA public key.
Definition: rsa.h:50
SHA-1 algorithm context.
Definition: sha1.h:59
Session cache.
Definition: tls.h:1936
uint_t size
Maximum number of entries.
Definition: tls.h:1938
OsMutex mutex
Mutex preventing simultaneous access to the cache.
Definition: tls.h:1937
Certificate descriptor.
Definition: tls.h:1948
const char_t * privateKey
Private key (PEM format)
Definition: tls.h:1951
TlsNamedGroup namedCurve
Named curve used to generate the EC public key.
Definition: tls.h:1956
TlsHashAlgo hashAlgo
Hash algorithm used to sign the end entity certificate.
Definition: tls.h:1955
size_t privateKeyLen
Length of the private key.
Definition: tls.h:1952
size_t certChainLen
Length of the certificate chain.
Definition: tls.h:1950
const char_t * certChain
End entity certificate chain (PEM format)
Definition: tls.h:1949
TlsCertificateType type
End entity certificate type.
Definition: tls.h:1953
TlsSignatureAlgo signAlgo
Signature algorithm used to sign the end entity certificate.
Definition: tls.h:1954
Structure describing a cipher suite.
Definition: tls.h:1883
CipherMode cipherMode
Definition: tls.h:1888
TlsKeyExchMethod keyExchMethod
Definition: tls.h:1886
uint8_t recordIvLen
Definition: tls.h:1894
uint8_t verifyDataLen
Definition: tls.h:1896
uint8_t fixedIvLen
Definition: tls.h:1893
const char_t * name
Definition: tls.h:1885
const HashAlgo * hashAlgo
Definition: tls.h:1889
uint8_t macKeyLen
Definition: tls.h:1891
uint16_t identifier
Definition: tls.h:1884
const CipherAlgo * cipherAlgo
Definition: tls.h:1887
uint8_t authTagLen
Definition: tls.h:1895
uint8_t encKeyLen
Definition: tls.h:1892
const HashAlgo * prfHashAlgo
Definition: tls.h:1890
Hello extensions.
Definition: tls.h:1965
const TlsExtension * serverCertType
Definition: tls.h:1986
const TlsSupportedGroupList * supportedGroupList
SupportedGroups extension.
Definition: tls.h:1969
const Tls13KeyShareEntry * serverShare
KeyShare extension (ServerHello)
Definition: tls.h:2001
const TlsExtension * clientCertType
Definition: tls.h:1984
const TlsExtension * recordSizeLimit
RecordSizeLimit extension.
Definition: tls.h:1977
const TlsCertTypeList * serverCertTypeList
ServerCertType extension.
Definition: tls.h:1985
const TlsExtension * selectedGroup
KeyShare extension (HelloRetryRequest)
Definition: tls.h:2000
const TlsExtension * sessionTicket
SessionTicket extension.
Definition: tls.h:1992
const Tls13PskIdentityList * identityList
PreSharedKey extension (ClientHello)
Definition: tls.h:2003
const Tls13PskKeModeList * pskKeModeList
PskKeyExchangeModes extension.
Definition: tls.h:2002
const Tls13KeyShareList * keyShareList
KeyShare extension (ClientHello)
Definition: tls.h:1999
const TlsSupportedVersionList * supportedVersionList
SupportedVersions extension (ClientHello)
Definition: tls.h:1966
const Tls13PskBinderList * binderList
Definition: tls.h:2004
const Tls13Cookie * cookie
Cookie extension.
Definition: tls.h:1998
const TlsExtension * extendedMasterSecret
ExtendedMasterSecret extension.
Definition: tls.h:1989
const TlsServerNameList * serverNameList
ServerName extension.
Definition: tls.h:1968
const TlsSignHashAlgos * signAlgoList
SignatureAlgorithms extension.
Definition: tls.h:1971
const TlsExtension * earlyDataIndication
EarlyData extension.
Definition: tls.h:2006
const TlsExtension * maxFragLen
MaxFragmentLength extension.
Definition: tls.h:1974
const TlsProtocolNameList * protocolNameList
ALPN extension.
Definition: tls.h:1980
const TlsEcPointFormatList * ecPointFormatList
EcPointFormats extension.
Definition: tls.h:1970
const TlsCertTypeList * clientCertTypeList
ClientCertType extension.
Definition: tls.h:1983
const TlsExtension * selectedVersion
SupportedVersions extension (ServerHello)
Definition: tls.h:1967
const TlsRenegoInfo * renegoInfo
RenegotiationInfo extension.
Definition: tls.h:1995
const TlsExtension * selectedIdentity
PreSharedKey extension (ServerHello)
Definition: tls.h:2005
const TlsSignHashAlgos * certSignAlgoList
SignatureAlgorithmsCert extension.
Definition: tls.h:1972
TLS session state.
Definition: tls.h:1905
systime_t ticketTimestamp
Timestamp to manage ticket lifetime.
Definition: tls.h:1918
systime_t timestamp
Time stamp to manage entry lifetime.
Definition: tls.h:1908
size_t sessionIdLen
Length of the session identifier.
Definition: tls.h:1912
size_t ticketLen
Length of the session ticket.
Definition: tls.h:1916
uint32_t maxEarlyDataSize
Maximum amount of 0-RTT data that the client is allowed to send.
Definition: tls.h:1923
uint16_t version
TLS protocol version.
Definition: tls.h:1906
uint8_t * ticket
Session ticket.
Definition: tls.h:1915
uint16_t cipherSuite
Cipher suite identifier.
Definition: tls.h:1907
uint32_t ticketAgeAdd
Random value used to obscure the age of the ticket.
Definition: tls.h:1920
char_t * ticketAlpn
ALPN protocol associated with the ticket.
Definition: tls.h:1922
char_t * serverName
ServerName extension.
Definition: tls.h:1926
TlsHashAlgo ticketHashAlgo
Hash algorithm associated with the ticket.
Definition: tls.h:1921
uint32_t ticketLifetime
Lifetime of the ticket.
Definition: tls.h:1919
bool_t extendedMasterSecret
Extended master secret computation.
Definition: tls.h:1913
X.509 certificate.
Definition: x509_common.h:930
uint8_t flags
Definition: tcp.h:349
TLS 1.3 helper functions.
__start_packed struct @259 Tls13Cookie
Cookie.
__start_packed struct @266 Tls13PskBinderList
List of PSK binders.
__start_packed struct @261 Tls13KeyShareList
List of key shares.
__start_packed struct @262 Tls13PskKeModeList
List of PSK key exchange modes.
uint16_t group
Definition: tls13_misc.h:206
__start_packed struct @260 Tls13KeyShareEntry
Key share entry.
__start_packed struct @264 Tls13PskIdentityList
List of PSK identities.
systime_t ticketTimestamp
Timestamp to manage ticket lifetime.
Definition: tls.h:1761
__start_packed struct @232 TlsSignHashAlgos
List of signature algorithms.
uint8_t secret[48]
Master secret.
Definition: tls.h:1760
TlsState
TLS FSM states.
Definition: tls.h:1321
@ TLS_STATE_SERVER_CHANGE_CIPHER_SPEC
Definition: tls.h:1345
@ TLS_STATE_SERVER_CERTIFICATE
Definition: tls.h:1333
@ TLS_STATE_CLIENT_CERTIFICATE_VERIFY
Definition: tls.h:1340
@ TLS_STATE_CLOSED
Definition: tls.h:1354
@ TLS_STATE_SERVER_CHANGE_CIPHER_SPEC_2
Definition: tls.h:1346
@ TLS_STATE_SERVER_CERTIFICATE_VERIFY
Definition: tls.h:1335
@ TLS_STATE_SERVER_HELLO_2
Definition: tls.h:1329
@ TLS_STATE_HELLO_VERIFY_REQUEST
Definition: tls.h:1326
@ TLS_STATE_CLIENT_FINISHED
Definition: tls.h:1343
@ TLS_STATE_CLIENT_APP_TRAFFIC_KEYS
Definition: tls.h:1344
@ TLS_STATE_SERVER_APP_TRAFFIC_KEYS
Definition: tls.h:1349
@ TLS_STATE_SERVER_FINISHED
Definition: tls.h:1347
@ TLS_STATE_CLIENT_HELLO_2
Definition: tls.h:1324
@ TLS_STATE_KEY_UPDATE
Definition: tls.h:1351
@ TLS_STATE_SERVER_HELLO
Definition: tls.h:1328
@ TLS_STATE_EARLY_DATA
Definition: tls.h:1325
@ TLS_STATE_APPLICATION_DATA
Definition: tls.h:1352
@ TLS_STATE_SERVER_KEY_EXCHANGE
Definition: tls.h:1334
@ TLS_STATE_INIT
Definition: tls.h:1322
@ TLS_STATE_NEW_SESSION_TICKET
Definition: tls.h:1350
@ TLS_STATE_CLIENT_CHANGE_CIPHER_SPEC_2
Definition: tls.h:1342
@ TLS_STATE_HELLO_RETRY_REQUEST
Definition: tls.h:1327
@ TLS_STATE_END_OF_EARLY_DATA
Definition: tls.h:1348
@ TLS_STATE_CLOSING
Definition: tls.h:1353
@ TLS_STATE_SERVER_HELLO_3
Definition: tls.h:1330
@ TLS_STATE_SERVER_HELLO_DONE
Definition: tls.h:1337
@ TLS_STATE_CLIENT_HELLO
Definition: tls.h:1323
@ TLS_STATE_CERTIFICATE_REQUEST
Definition: tls.h:1336
@ TLS_STATE_HANDSHAKE_TRAFFIC_KEYS
Definition: tls.h:1331
@ TLS_STATE_CLIENT_KEY_EXCHANGE
Definition: tls.h:1339
@ TLS_STATE_CLIENT_CERTIFICATE
Definition: tls.h:1338
@ TLS_STATE_CLIENT_CHANGE_CIPHER_SPEC
Definition: tls.h:1341
@ TLS_STATE_ENCRYPTED_EXTENSIONS
Definition: tls.h:1332
error_t tlsSetEcdsaSignCallback(TlsContext *context, TlsEcdsaSignCallback ecdsaSignCallback)
ECDSA signature generation callback function.
Definition: tls.c:705
error_t tlsRestoreSessionState(TlsContext *context, const TlsSessionState *session)
Restore TLS session.
Definition: tls.c:2555
error_t tlsSetPskIdentity(TlsContext *context, const char_t *pskIdentity)
Set the PSK identity to be used by the client.
Definition: tls.c:975
uint8_t certificateTypesLen
Definition: tls.h:1686
error_t tlsSetTicketCallbacks(TlsContext *context, TlsTicketEncryptCallback ticketEncryptCallback, TlsTicketDecryptCallback ticketDecryptCallback, void *param)
Set ticket encryption/decryption callbacks.
Definition: tls.c:1384
error_t tlsConnect(TlsContext *context)
Initiate the TLS handshake.
Definition: tls.c:1630
uint8_t sessionId[]
Definition: tls.h:1649
TlsNameType
Name type.
Definition: tls.h:1215
@ TLS_NAME_TYPE_HOSTNAME
Definition: tls.h:1216
TlsKeyExchMethod
Key exchange methods.
Definition: tls.h:1057
@ TLS_KEY_EXCH_DHE_RSA
Definition: tls.h:1061
@ TLS_KEY_EXCH_RSA
Definition: tls.h:1059
@ TLS_KEY_EXCH_SRP_SHA
Definition: tls.h:1074
@ TLS_KEY_EXCH_ECDHE_ECDSA
Definition: tls.h:1068
@ TLS13_KEY_EXCH_PSK_DHE
Definition: tls.h:1080
@ TLS_KEY_EXCH_DHE_PSK
Definition: tls.h:1072
@ TLS_KEY_EXCH_DH_ANON
Definition: tls.h:1064
@ TLS_KEY_EXCH_DH_DSS
Definition: tls.h:1062
@ TLS_KEY_EXCH_RSA_PSK
Definition: tls.h:1071
@ TLS13_KEY_EXCH_ECDHE
Definition: tls.h:1078
@ TLS13_KEY_EXCH_PSK
Definition: tls.h:1079
@ TLS_KEY_EXCH_DH_RSA
Definition: tls.h:1060
@ TLS_KEY_EXCH_SRP_SHA_DSS
Definition: tls.h:1076
@ TLS_KEY_EXCH_SRP_SHA_RSA
Definition: tls.h:1075
@ TLS13_KEY_EXCH_DHE
Definition: tls.h:1077
@ TLS_KEY_EXCH_ECDH_ANON
Definition: tls.h:1069
@ TLS_KEY_EXCH_ECDH_ECDSA
Definition: tls.h:1067
@ TLS13_KEY_EXCH_PSK_ECDHE
Definition: tls.h:1081
@ TLS_KEY_EXCH_DHE_DSS
Definition: tls.h:1063
@ TLS_KEY_EXCH_NONE
Definition: tls.h:1058
@ TLS_KEY_EXCH_ECDHE_RSA
Definition: tls.h:1066
@ TLS_KEY_EXCH_ECDHE_PSK
Definition: tls.h:1073
@ TLS_KEY_EXCH_PSK
Definition: tls.h:1070
@ TLS_KEY_EXCH_ECDH_RSA
Definition: tls.h:1065
TlsEarlyDataStatus tlsGetEarlyDataStatus(TlsContext *context)
Check whether the server has accepted or rejected the early data.
Definition: tls.c:1678
TlsCertificateFormat
Certificate formats.
Definition: tls.h:1090
@ TLS_CERT_FORMAT_OPEN_PGP
Definition: tls.h:1092
@ TLS_CERT_FORMAT_RAW_PUBLIC_KEY
Definition: tls.h:1093
@ TLS_CERT_FORMAT_X509
Definition: tls.h:1091
error_t tlsSaveSessionState(const TlsContext *context, TlsSessionState *session)
Save TLS session.
Definition: tls.c:2486
uint8_t hash
Definition: tls.h:1402
uint8_t sessionIdLen
Definition: tls.h:1648
__start_packed struct @233 TlsCertificateList
List of certificates.
error_t tlsWrite(TlsContext *context, const void *data, size_t length, size_t *written, uint_t flags)
Send application data to the remote host using TLS.
Definition: tls.c:1721
TlsAlertDescription
Alert description.
Definition: tls.h:1003
@ TLS_ALERT_CERTIFICATE_REVOKED
Definition: tls.h:1014
@ TLS_ALERT_ACCESS_DENIED
Definition: tls.h:1019
@ TLS_ALERT_BAD_CERTIFICATE
Definition: tls.h:1012
@ TLS_ALERT_UNSUPPORTED_EXTENSION
Definition: tls.h:1030
@ TLS_ALERT_UNEXPECTED_MESSAGE
Definition: tls.h:1005
@ TLS_ALERT_NO_RENEGOTIATION
Definition: tls.h:1028
@ TLS_ALERT_USER_CANCELED
Definition: tls.h:1027
@ TLS_ALERT_BAD_CERTIFICATE_HASH_VALUE
Definition: tls.h:1034
@ TLS_ALERT_MISSING_EXTENSION
Definition: tls.h:1029
@ TLS_ALERT_DECODE_ERROR
Definition: tls.h:1020
@ TLS_ALERT_NO_CERTIFICATE
Definition: tls.h:1011
@ TLS_ALERT_NO_APPLICATION_PROTOCOL
Definition: tls.h:1037
@ TLS_ALERT_CLOSE_NOTIFY
Definition: tls.h:1004
@ TLS_ALERT_CERTIFICATE_UNKNOWN
Definition: tls.h:1016
@ TLS_ALERT_UNKNOWN_CA
Definition: tls.h:1018
@ TLS_ALERT_BAD_CERTIFICATE_STATUS_RESPONSE
Definition: tls.h:1033
@ TLS_ALERT_INAPPROPRIATE_FALLBACK
Definition: tls.h:1026
@ TLS_ALERT_CERTIFICATE_REQUIRED
Definition: tls.h:1036
@ TLS_ALERT_PROTOCOL_VERSION
Definition: tls.h:1023
@ TLS_ALERT_BAD_RECORD_MAC
Definition: tls.h:1006
@ TLS_ALERT_EXPORT_RESTRICTION
Definition: tls.h:1022
@ TLS_ALERT_CERTIFICATE_EXPIRED
Definition: tls.h:1015
@ TLS_ALERT_DECOMPRESSION_FAILURE
Definition: tls.h:1009
@ TLS_ALERT_ILLEGAL_PARAMETER
Definition: tls.h:1017
@ TLS_ALERT_HANDSHAKE_FAILURE
Definition: tls.h:1010
@ TLS_ALERT_DECRYPTION_FAILED
Definition: tls.h:1007
@ TLS_ALERT_RECORD_OVERFLOW
Definition: tls.h:1008
@ TLS_ALERT_CERTIFICATE_UNOBTAINABLE
Definition: tls.h:1031
@ TLS_ALERT_INSUFFICIENT_SECURITY
Definition: tls.h:1024
@ TLS_ALERT_UNKNOWN_PSK_IDENTITY
Definition: tls.h:1035
@ TLS_ALERT_UNSUPPORTED_CERTIFICATE
Definition: tls.h:1013
@ TLS_ALERT_INTERNAL_ERROR
Definition: tls.h:1025
@ TLS_ALERT_UNRECOGNIZED_NAME
Definition: tls.h:1032
@ TLS_ALERT_DECRYPT_ERROR
Definition: tls.h:1021
uint16_t type
Definition: tls.h:1446
error_t(* TlsCertVerifyCallback)(TlsContext *context, const X509CertificateInfo *certInfo, uint_t pathLen, void *param)
Certificate verification callback function.
Definition: tls.h:1818
error_t(* TlsEcdsaVerifyCallback)(TlsContext *context, const uint8_t *digest, size_t digestLen, EcdsaSignature *signature)
ECDSA signature verification callback function.
Definition: tls.h:1867
uint8_t certificateTypes[]
Definition: tls.h:1687
__start_packed struct @247 TlsPskIdentityHint
PSK identity hint.
__start_packed struct @258 TlsPlaintextSessionState
Session state information.
error_t tlsSetEcdhCallback(TlsContext *context, TlsEcdhCallback ecdhCallback)
Register ECDH key agreement callback function.
Definition: tls.c:679
__start_packed struct @239 TlsServerNameList
List of server names.
#define TLS_MAX_CERTIFICATES
Definition: tls.h:250
void TlsCertificateVerify
CertificateVerify message.
Definition: tls.h:1709
TlsTransportProtocol
TLS transport protocols.
Definition: tls.h:881
@ TLS_TRANSPORT_PROTOCOL_STREAM
Definition: tls.h:882
@ TLS_TRANSPORT_PROTOCOL_DATAGRAM
Definition: tls.h:883
error_t tlsAddCertificate(TlsContext *context, const char_t *certChain, size_t certChainLen, const char_t *privateKey, size_t privateKeyLen)
Import a certificate and the corresponding private key.
Definition: tls.c:1159
__start_packed struct @255 TlsNewSessionTicket
NewSessionTicket message.
TlsCompressMethod
Compression methods.
Definition: tls.h:1046
@ TLS_COMPRESSION_METHOD_DEFLATE
Definition: tls.h:1048
@ TLS_COMPRESSION_METHOD_NULL
Definition: tls.h:1047
error_t(* TlsTicketEncryptCallback)(TlsContext *context, const uint8_t *plaintext, size_t plaintextLen, uint8_t *ciphertext, size_t *ciphertextLen, void *param)
Ticket encryption callback function.
Definition: tls.h:1834
TlsCache * tlsInitCache(uint_t size)
Session cache initialization.
Definition: tls_cache.c:51
__start_packed struct @228 TlsSequenceNumber
Sequence number.
error_t(* TlsAlpnCallback)(TlsContext *context, const char_t *selectedProtocol)
ALPN callback function.
Definition: tls.h:1802
error_t(* TlsSocketSendCallback)(TlsSocketHandle handle, const void *data, size_t length, size_t *written, uint_t flags)
Socket send callback function.
Definition: tls.h:1786
TlsEarlyDataStatus
Early data status.
Definition: tls.h:915
@ TLS_EARLY_DATA_REJECTED
Definition: tls.h:916
@ TLS_EARLY_DATA_ACCEPTED
Definition: tls.h:917
__start_packed struct @238 TlsServerName
Server name.
void tlsFreeCache(TlsCache *cache)
Properly dispose a session cache.
Definition: tls_cache.c:320
error_t tlsEnableSessionTickets(TlsContext *context, bool_t enabled)
Enable session ticket mechanism.
Definition: tls.c:1304
error_t(* TlsPskCallback)(TlsContext *context, const uint8_t *pskIdentity, size_t pskIdentityLen)
Pre-shared key callback function.
Definition: tls.h:1810
__start_packed struct @234 TlsCertAuthorities
List of certificate authorities.
error_t tlsEnableReplayDetection(TlsContext *context, bool_t enabled)
Enable anti-replay mechanism (for DTLS only)
Definition: tls.c:1510
__start_packed struct @241 TlsProtocolNameList
List of protocol names.
error_t tlsSetSupportedGroups(TlsContext *context, const uint16_t *groups, uint_t length)
Specify the list of allowed ECDHE and FFDHE groups.
Definition: tls.c:596
__start_packed struct @244 TlsCertTypeList
List of supported certificate types.
error_t(* TlsSocketReceiveCallback)(TlsSocketHandle handle, void *data, size_t size, size_t *received, uint_t flags)
Socket receive callback function.
Definition: tls.h:1794
TlsEcPointFormat
EC point formats.
Definition: tls.h:1297
@ TLS_EC_POINT_FORMAT_UNCOMPRESSED
Definition: tls.h:1298
@ TLS_EC_POINT_FORMAT_ANSI_X962_COMPRESSED_CHAR2
Definition: tls.h:1300
@ TLS_EC_POINT_FORMAT_ANSI_X962_COMPRESSED_PRIME
Definition: tls.h:1299
error_t tlsSetPrng(TlsContext *context, const PrngAlgo *prngAlgo, void *prngContext)
Set the pseudo-random number generator to be used.
Definition: tls.c:339
uint8_t b[8]
Definition: tls.h:1370
error_t tlsSetCertificateVerifyCallback(TlsContext *context, TlsCertVerifyCallback certVerifyCallback, void *param)
Set certificate verification callback.
Definition: tls.c:1280
error_t tlsSetKeyLogCallback(TlsContext *context, TlsKeyLogCallback keyLogCallback)
Register key logging callback function (for debugging purpose only)
Definition: tls.c:759
bool_t tlsIsTxReady(TlsContext *context)
Check whether some data is ready for transmission.
Definition: tls.c:2092
void TlsCertificate
Certificate message.
Definition: tls.h:1670
void * TlsSocketHandle
Socket handle.
Definition: tls.h:1779
void(* TlsKeyLogCallback)(TlsContext *context, const char_t *key)
Key logging callback function (for debugging purpose only)
Definition: tls.h:1875
__start_packed struct @242 TlsSupportedGroupList
List of supported groups.
__start_packed struct @252 TlsClientHello
ClientHello message.
void TlsHelloRequest
HelloRequest message.
Definition: tls.h:1637
uint8_t data[]
Definition: tls.h:1617
TlsContext * tlsInit(void)
TLS context initialization.
Definition: tls.c:66
void TlsFinished
Finished message.
Definition: tls.h:1728
__start_packed struct @243 TlsEcPointFormatList
List of supported EC point formats.
uint8_t random[32]
Definition: tls.h:1647
uint8_t ticket[]
Definition: tls.h:1720
TlsClientAuthMode
Client authentication mode.
Definition: tls.h:903
@ TLS_CLIENT_AUTH_REQUIRED
Definition: tls.h:906
@ TLS_CLIENT_AUTH_OPTIONAL
Definition: tls.h:905
@ TLS_CLIENT_AUTH_NONE
Definition: tls.h:904
__start_packed struct @236 TlsExtensionList
List of TLS extensions.
error_t tlsSetRpkVerifyCallback(TlsContext *context, TlsRpkVerifyCallback rpkVerifyCallback)
Register the raw public key verification callback function.
Definition: tls.c:1099
uint16_t serverVersion
Definition: tls.h:1659
void TlsServerKeyExchange
ServerKeyExchange message.
Definition: tls.h:1677
error_t tlsRead(TlsContext *context, void *data, size_t size, size_t *received, uint_t flags)
Receive application data from a the remote host using TLS.
Definition: tls.c:1856
error_t tlsAllowUnknownAlpnProtocols(TlsContext *context, bool_t allowed)
Allow unknown ALPN protocols.
Definition: tls.c:786
void tlsFreeSessionState(TlsSessionState *session)
Properly dispose a session state.
Definition: tls.c:2608
__start_packed struct @257 TlsAlert
Alert message.
error_t(* TlsEcdsaSignCallback)(TlsContext *context, const uint8_t *digest, size_t digestLen, EcdsaSignature *signature)
ECDSA signature generation callback function.
Definition: tls.h:1859
TlsContentType
Content type.
Definition: tls.h:947
@ TLS_TYPE_CHANGE_CIPHER_SPEC
Definition: tls.h:949
@ TLS_TYPE_HANDSHAKE
Definition: tls.h:951
@ TLS_TYPE_NONE
Definition: tls.h:948
@ TLS_TYPE_ACK
Definition: tls.h:954
@ TLS_TYPE_APPLICATION_DATA
Definition: tls.h:952
@ TLS_TYPE_ALERT
Definition: tls.h:950
@ TLS_TYPE_HEARTBEAT
Definition: tls.h:953
char_t hostname[]
Definition: tls.h:1482
void TlsServerHelloDone
ServerHelloDone message.
Definition: tls.h:1695
error_t tlsSetPskIdentityHint(TlsContext *context, const char_t *pskIdentityHint)
Set the PSK identity hint to be used by the server.
Definition: tls.c:1024
uint8_t description
Definition: tls.h:1748
error_t tlsSetVersion(TlsContext *context, uint16_t versionMin, uint16_t versionMax)
Set minimum and maximum versions permitted.
Definition: tls.c:250
__start_packed struct @235 TlsExtension
TLS extension.
error_t tlsEnableSecureRenegotiation(TlsContext *context, bool_t enabled)
Enable secure renegotiation.
Definition: tls.c:1330
error_t tlsSetConnectionEnd(TlsContext *context, TlsConnectionEnd entity)
Set operation mode (client or server)
Definition: tls.c:313
__start_packed struct @251 TlsHandshake
TLS handshake message.
void TlsClientKeyExchange
ClientKeyExchange message.
Definition: tls.h:1702
error_t tlsSetMaxFragmentLength(TlsContext *context, size_t maxFragLen)
Set maximum fragment length.
Definition: tls.c:531
TlsExtensionType
TLS extension types.
Definition: tls.h:1168
@ TLS_EXT_PADDING
Definition: tls.h:1190
@ TLS_EXT_RENEGOTIATION_INFO
Definition: tls.h:1206
@ TLS_EXT_SIGNATURE_ALGORITHMS_CERT
Definition: tls.h:1204
@ TLS_EXT_SRP
Definition: tls.h:1181
@ TLS_EXT_HEARTBEAT
Definition: tls.h:1184
@ TLS_EXT_USE_SRTP
Definition: tls.h:1183
@ TLS_EXT_EARLY_DATA
Definition: tls.h:1197
@ TLS_EXT_TRUNCATED_HMAC
Definition: tls.h:1173
@ TLS_EXT_TRUSTED_CA_KEYS
Definition: tls.h:1172
@ TLS_EXT_CLIENT_CERTIFICATE_URL
Definition: tls.h:1171
@ TLS_EXT_USER_MAPPING
Definition: tls.h:1175
@ TLS_EXT_PRE_SHARED_KEY
Definition: tls.h:1196
@ TLS_EXT_MAX_FRAGMENT_LENGTH
Definition: tls.h:1170
@ TLS_EXT_CERTIFICATE_AUTHORITIES
Definition: tls.h:1201
@ TLS_EXT_POST_HANDSHAKE_AUTH
Definition: tls.h:1203
@ TLS_EXT_OID_FILTERS
Definition: tls.h:1202
@ TLS_EXT_SERVER_CERT_TYPE
Definition: tls.h:1189
@ TLS_EXT_CLIENT_CERT_TYPE
Definition: tls.h:1188
@ TLS_EXT_KEY_SHARE
Definition: tls.h:1205
@ TLS_EXT_ENCRYPT_THEN_MAC
Definition: tls.h:1191
@ TLS_EXT_SIGNATURE_ALGORITHMS
Definition: tls.h:1182
@ TLS_EXT_SUPPORTED_VERSIONS
Definition: tls.h:1198
@ TLS_EXT_STATUS_REQUEST
Definition: tls.h:1174
@ TLS_EXT_CLIENT_AUTHZ
Definition: tls.h:1176
@ TLS_EXT_CERT_TYPE
Definition: tls.h:1178
@ TLS_EXT_EC_POINT_FORMATS
Definition: tls.h:1180
@ TLS_EXT_RECORD_SIZE_LIMIT
Definition: tls.h:1194
@ TLS_EXT_SESSION_TICKET
Definition: tls.h:1195
@ TLS_EXT_CACHED_INFO
Definition: tls.h:1193
@ TLS_EXT_SUPPORTED_GROUPS
Definition: tls.h:1179
@ TLS_EXT_STATUS_REQUEST_V2
Definition: tls.h:1186
@ TLS_EXT_COOKIE
Definition: tls.h:1199
@ TLS_EXT_PSK_KEY_EXCHANGE_MODES
Definition: tls.h:1200
@ TLS_EXT_ALPN
Definition: tls.h:1185
@ TLS_EXT_SERVER_NAME
Definition: tls.h:1169
@ TLS_EXT_SIGNED_CERT_TIMESTAMP
Definition: tls.h:1187
@ TLS_EXT_EXTENDED_MASTER_SECRET
Definition: tls.h:1192
@ TLS_EXT_SERVER_AUTHZ
Definition: tls.h:1177
const char_t * tlsGetServerName(TlsContext *context)
Get the server name.
Definition: tls.c:415
error_t tlsSetSocketCallbacks(TlsContext *context, TlsSocketSendCallback socketSendCallback, TlsSocketReceiveCallback socketReceiveCallback, TlsSocketHandle handle)
Set socket send and receive callbacks.
Definition: tls.c:218
uint16_t clientVersion
Definition: tls.h:1646
__start_packed struct @245 TlsRenegoInfo
Renegotiated connection.
__start_packed struct @250 TlsRecord
TLS record.
#define TLS_MAX_HKDF_DIGEST_SIZE
Definition: tls.h:849
error_t tlsSetPsk(TlsContext *context, const uint8_t *psk, size_t length)
Set the pre-shared key to be used.
Definition: tls.c:914
error_t tlsSetDhParameters(TlsContext *context, const char_t *params, size_t length)
Import Diffie-Hellman parameters.
Definition: tls.c:651
TlsHashAlgo
Hash algorithms.
Definition: tls.h:1125
@ TLS_HASH_ALGO_SHA224
Definition: tls.h:1129
@ TLS_HASH_ALGO_SHA384
Definition: tls.h:1131
@ TLS_HASH_ALGO_NONE
Definition: tls.h:1126
@ TLS_HASH_ALGO_SHA256
Definition: tls.h:1130
@ TLS_HASH_ALGO_SHA512
Definition: tls.h:1132
@ TLS_HASH_ALGO_MD5
Definition: tls.h:1127
@ TLS_HASH_ALGO_INTRINSIC
Definition: tls.h:1133
@ TLS_HASH_ALGO_SHA1
Definition: tls.h:1128
TlsCertificateType
Certificate types.
Definition: tls.h:1102
@ TLS_CERT_ED448_SIGN
Definition: tls.h:1116
@ TLS_CERT_DSS_EPHEMERAL_DH
Definition: tls.h:1109
@ TLS_CERT_RSA_FIXED_DH
Definition: tls.h:1106
@ TLS_CERT_ECDSA_FIXED_ECDH
Definition: tls.h:1113
@ TLS_CERT_RSA_SIGN
Definition: tls.h:1104
@ TLS_CERT_DSS_FIXED_DH
Definition: tls.h:1107
@ TLS_CERT_DSS_SIGN
Definition: tls.h:1105
@ TLS_CERT_ED25519_SIGN
Definition: tls.h:1115
@ TLS_CERT_RSA_PSS_SIGN
Definition: tls.h:1114
@ TLS_CERT_ECDSA_SIGN
Definition: tls.h:1111
@ TLS_CERT_RSA_EPHEMERAL_DH
Definition: tls.h:1108
@ TLS_CERT_RSA_FIXED_ECDH
Definition: tls.h:1112
@ TLS_CERT_FORTEZZA_DMS
Definition: tls.h:1110
@ TLS_CERT_NONE
Definition: tls.h:1103
TlsMaxFragmentLength
Maximum fragment length.
Definition: tls.h:1225
@ TLS_MAX_FRAGMENT_LENGTH_512
Definition: tls.h:1226
@ TLS_MAX_FRAGMENT_LENGTH_4096
Definition: tls.h:1229
@ TLS_MAX_FRAGMENT_LENGTH_2048
Definition: tls.h:1228
@ TLS_MAX_FRAGMENT_LENGTH_1024
Definition: tls.h:1227
__start_packed struct @254 TlsCertificateRequest
CertificateRequest message.
uint8_t msgType
Definition: tls.h:1627
const char_t * tlsGetAlpnProtocol(TlsContext *context)
Get the name of the selected ALPN protocol.
Definition: tls.c:886
uint16_t ticketLen
Definition: tls.h:1719
error_t tlsSetPmtu(TlsContext *context, size_t pmtu)
Set PMTU value (for DTLS only)
Definition: tls.c:1416
error_t tlsShutdownEx(TlsContext *context, bool_t waitForCloseNotify)
Gracefully close TLS session.
Definition: tls.c:2183
error_t tlsEnableFallbackScsv(TlsContext *context, bool_t enabled)
Perform fallback retry (for clients only)
Definition: tls.c:1356
error_t(* TlsTicketDecryptCallback)(TlsContext *context, const uint8_t *ciphertext, size_t ciphertextLen, uint8_t *plaintext, size_t *plaintextLen, void *param)
Ticket decryption callback function.
Definition: tls.h:1843
error_t tlsSetTrustedCaList(TlsContext *context, const char_t *trustedCaList, size_t length)
Import a trusted CA list.
Definition: tls.c:1127
error_t tlsSetEcdsaVerifyCallback(TlsContext *context, TlsEcdsaVerifyCallback ecdsaVerifyCallback)
Register ECDSA signature verification callback function.
Definition: tls.c:732
__start_packed struct @237 TlsSupportedVersionList
List of supported versions.
__start_packed struct @253 TlsServerHello
ServerHello message.
#define TLS_RANDOM_SIZE
Definition: tls.h:866
TlsFlags
Flags used by read and write functions.
Definition: tls.h:926
@ TLS_FLAG_BREAK_CRLF
Definition: tls.h:930
@ TLS_FLAG_WAIT_ALL
Definition: tls.h:928
@ TLS_FLAG_WAIT_ACK
Definition: tls.h:931
@ TLS_FLAG_NO_DELAY
Definition: tls.h:932
@ TLS_FLAG_DELAY
Definition: tls.h:933
@ TLS_FLAG_PEEK
Definition: tls.h:927
@ TLS_FLAG_BREAK_CHAR
Definition: tls.h:929
error_t tlsSetServerName(TlsContext *context, const char_t *serverName)
Set the server name.
Definition: tls.c:367
error_t(* TlsRpkVerifyCallback)(TlsContext *context, const uint8_t *rawPublicKey, size_t rawPublicKeyLen)
Raw public key verification callback function.
Definition: tls.h:1826
uint16_t length
Definition: tls.h:1380
#define TLS_PREMASTER_SECRET_SIZE
Definition: tls.h:754
uint16_t version
Protocol version.
Definition: tls.h:1615
TlsState tlsGetState(TlsContext *context)
Retrieve current state.
Definition: tls.c:194
uint8_t level
Definition: tls.h:1747
TlsSignatureAlgo
Signature algorithms.
Definition: tls.h:1142
@ TLS_SIGN_ALGO_ECDSA_BRAINPOOLP512R1_TLS13_SHA512
Definition: tls.h:1157
@ TLS_SIGN_ALGO_RSA_PSS_PSS_SHA512
Definition: tls.h:1154
@ TLS_SIGN_ALGO_ECDSA_BRAINPOOLP256R1_TLS13_SHA256
Definition: tls.h:1155
@ TLS_SIGN_ALGO_GOSTR34102012_512
Definition: tls.h:1159
@ TLS_SIGN_ALGO_ECDSA
Definition: tls.h:1146
@ TLS_SIGN_ALGO_RSA_PSS_RSAE_SHA512
Definition: tls.h:1149
@ TLS_SIGN_ALGO_ECDSA_BRAINPOOLP384R1_TLS13_SHA384
Definition: tls.h:1156
@ TLS_SIGN_ALGO_ED448
Definition: tls.h:1151
@ TLS_SIGN_ALGO_RSA
Definition: tls.h:1144
@ TLS_SIGN_ALGO_DSA
Definition: tls.h:1145
@ TLS_SIGN_ALGO_RSA_PSS_PSS_SHA256
Definition: tls.h:1152
@ TLS_SIGN_ALGO_ANONYMOUS
Definition: tls.h:1143
@ TLS_SIGN_ALGO_ED25519
Definition: tls.h:1150
@ TLS_SIGN_ALGO_RSA_PSS_RSAE_SHA256
Definition: tls.h:1147
@ TLS_SIGN_ALGO_RSA_PSS_PSS_SHA384
Definition: tls.h:1153
@ TLS_SIGN_ALGO_GOSTR34102012_256
Definition: tls.h:1158
@ TLS_SIGN_ALGO_RSA_PSS_RSAE_SHA384
Definition: tls.h:1148
TlsSignHashAlgo algorithm
Definition: tls.h:1602
error_t tlsWriteEarlyData(TlsContext *context, const void *data, size_t length, size_t *written, uint_t flags)
Send early data to the remote TLS server.
Definition: tls.c:1567
#define TlsContext
Definition: tls.h:36
error_t tlsSetBufferSize(TlsContext *context, size_t txBufferSize, size_t rxBufferSize)
Set TLS buffer size.
Definition: tls.c:483
error_t tlsSetPreferredGroup(TlsContext *context, uint16_t group)
Specify the preferred ECDHE or FFDHE group.
Definition: tls.c:623
uint16_t cipherSuite
Cipher suite identifier.
Definition: tls.h:1759
error_t tlsSetCookieCallbacks(TlsContext *context, DtlsCookieGenerateCallback cookieGenerateCallback, DtlsCookieVerifyCallback cookieVerifyCallback, void *param)
Set cookie generation/verification callbacks (for DTLS only)
Definition: tls.c:1474
TlsAlertLevel
Alert level.
Definition: tls.h:992
@ TLS_ALERT_LEVEL_WARNING
Definition: tls.h:993
@ TLS_ALERT_LEVEL_FATAL
Definition: tls.h:994
TlsConnectionEnd
TLS connection end.
Definition: tls.h:892
@ TLS_CONNECTION_END_SERVER
Definition: tls.h:894
@ TLS_CONNECTION_END_CLIENT
Definition: tls.h:893
error_t(* TlsEcdhCallback)(TlsContext *context)
ECDH key agreement callback function.
Definition: tls.h:1852
__start_packed struct @231 TlsSignHashAlgo
Signature algorithm.
__start_packed struct @230 TlsCompressMethods
Compression methods.
__start_packed struct @249 Tls12DigitalSignature
Digitally-signed element (TLS 1.2)
uint16_t value[]
Definition: tls.h:1381
#define TlsEncryptionEngine
Definition: tls.h:40
__start_packed struct @240 TlsProtocolName
Protocol name.
__start_packed struct @246 TlsPskIdentity
PSK identity.
error_t tlsSetCipherSuites(TlsContext *context, const uint16_t *cipherSuites, uint_t length)
Specify the list of allowed cipher suites.
Definition: tls.c:567
#define TLS_MASTER_SECRET_SIZE
Definition: tls.h:868
bool_t tlsIsRxReady(TlsContext *context)
Check whether some data is available in the receive buffer.
Definition: tls.c:2125
TlsNamedGroup
Named groups.
Definition: tls.h:1238
@ TLS_GROUP_FFDHE6144
Definition: tls.h:1284
@ TLS_GROUP_SECT233K1
Definition: tls.h:1245
@ TLS_GROUP_BRAINPOOLP384R1_TLS13
Definition: tls.h:1271
@ TLS_GROUP_FFDHE4096
Definition: tls.h:1283
@ TLS_GROUP_SECP192R1
Definition: tls.h:1258
@ TLS_GROUP_SECP521R1
Definition: tls.h:1264
@ TLS_GROUP_SECP160R2
Definition: tls.h:1256
@ TLS_GROUP_SECT163K1
Definition: tls.h:1240
@ TLS_GROUP_GC512C
Definition: tls.h:1279
@ TLS_GROUP_BRAINPOOLP512R1_TLS13
Definition: tls.h:1272
@ TLS_GROUP_GC256D
Definition: tls.h:1276
@ TLS_GROUP_SECT283K1
Definition: tls.h:1248
@ TLS_GROUP_GC256A
Definition: tls.h:1273
@ TLS_GROUP_SECT193R2
Definition: tls.h:1244
@ TLS_GROUP_SECT193R1
Definition: tls.h:1243
@ TLS_GROUP_SECP256R1
Definition: tls.h:1262
@ TLS_GROUP_SECP384R1
Definition: tls.h:1263
@ TLS_GROUP_SECP160R1
Definition: tls.h:1255
@ TLS_GROUP_SECP256K1
Definition: tls.h:1261
@ TLS_GROUP_SECT283R1
Definition: tls.h:1249
@ TLS_GROUP_BRAINPOOLP512R1
Definition: tls.h:1267
@ TLS_GROUP_SECT409R1
Definition: tls.h:1251
@ TLS_GROUP_SECT233R1
Definition: tls.h:1246
@ TLS_GROUP_GC512A
Definition: tls.h:1277
@ TLS_GROUP_FFDHE8192
Definition: tls.h:1285
@ TLS_GROUP_FFDHE2048
Definition: tls.h:1281
@ TLS_GROUP_SECT163R1
Definition: tls.h:1241
@ TLS_GROUP_SECT239K1
Definition: tls.h:1247
@ TLS_GROUP_FFDHE3072
Definition: tls.h:1282
@ TLS_GROUP_BRAINPOOLP256R1_TLS13
Definition: tls.h:1270
@ TLS_GROUP_ECDH_X448
Definition: tls.h:1269
@ TLS_GROUP_BRAINPOOLP256R1
Definition: tls.h:1265
@ TLS_GROUP_EXPLICIT_CHAR2_CURVE
Definition: tls.h:1288
@ TLS_GROUP_SECT571R1
Definition: tls.h:1253
@ TLS_GROUP_SECP160K1
Definition: tls.h:1254
@ TLS_GROUP_SECP224K1
Definition: tls.h:1259
@ TLS_GROUP_ECDH_X25519
Definition: tls.h:1268
@ TLS_GROUP_SECT163R2
Definition: tls.h:1242
@ TLS_GROUP_SECT571K1
Definition: tls.h:1252
@ TLS_GROUP_GC512B
Definition: tls.h:1278
@ TLS_GROUP_EXPLICIT_PRIME_CURVE
Definition: tls.h:1287
@ TLS_GROUP_GC256B
Definition: tls.h:1274
@ TLS_GROUP_SECP192K1
Definition: tls.h:1257
@ TLS_GROUP_FFDHE_MAX
Definition: tls.h:1286
@ TLS_GROUP_NONE
Definition: tls.h:1239
@ TLS_GROUP_SECT409K1
Definition: tls.h:1250
@ TLS_GROUP_BRAINPOOLP384R1
Definition: tls.h:1266
@ TLS_GROUP_SECP224R1
Definition: tls.h:1260
@ TLS_GROUP_GC256C
Definition: tls.h:1275
@ TLS_GROUP_SM2
Definition: tls.h:1280
error_t tlsSetClientAuthMode(TlsContext *context, TlsClientAuthMode mode)
Set client authentication mode (for servers only)
Definition: tls.c:461
error_t tlsShutdown(TlsContext *context)
Gracefully close TLS session.
Definition: tls.c:2170
error_t tlsSetCache(TlsContext *context, TlsCache *cache)
Set session cache.
Definition: tls.c:440
uint32_t ticketLifetime
Lifetime of the ticket.
Definition: tls.h:1762
TlsMessageType
Handshake message type.
Definition: tls.h:963
@ TLS_TYPE_SERVER_HELLO
Definition: tls.h:966
@ TLS_TYPE_CLIENT_HELLO
Definition: tls.h:965
@ TLS_TYPE_CERTIFICATE_VERIFY
Definition: tls.h:976
@ TLS_TYPE_SUPPLEMENTAL_DATA
Definition: tls.h:981
@ TLS_TYPE_MESSAGE_HASH
Definition: tls.h:983
@ TLS_TYPE_END_OF_EARLY_DATA
Definition: tls.h:969
@ TLS_TYPE_SERVER_HELLO_DONE
Definition: tls.h:975
@ TLS_TYPE_SERVER_KEY_EXCHANGE
Definition: tls.h:973
@ TLS_TYPE_FINISHED
Definition: tls.h:978
@ TLS_TYPE_HELLO_REQUEST
Definition: tls.h:964
@ TLS_TYPE_CERTIFICATE_URL
Definition: tls.h:979
@ TLS_TYPE_CERTIFICATE
Definition: tls.h:972
@ TLS_TYPE_KEY_UPDATE
Definition: tls.h:982
@ TLS_TYPE_CERTIFICATE_STATUS
Definition: tls.h:980
@ TLS_TYPE_CLIENT_KEY_EXCHANGE
Definition: tls.h:977
@ TLS_TYPE_ENCRYPTED_EXTENSIONS
Definition: tls.h:971
@ TLS_TYPE_HELLO_VERIFY_REQUEST
Definition: tls.h:967
@ TLS_TYPE_NEW_SESSION_TICKET
Definition: tls.h:968
@ TLS_TYPE_CERTIFICATE_REQUEST
Definition: tls.h:974
@ TLS_TYPE_HELLO_RETRY_REQUEST
Definition: tls.h:970
error_t tlsInitSessionState(TlsSessionState *session)
Initialize session state.
Definition: tls.c:2465
void tlsFree(TlsContext *context)
Release TLS context.
Definition: tls.c:2330
__start_packed struct @248 TlsDigitalSignature
Digitally-signed element (TLS 1.0 and TLS 1.1)
__start_packed struct @229 TlsCipherSuites
Cipher suites.
uint32_t ticketLifetimeHint
Definition: tls.h:1718
error_t tlsSetTimeout(TlsContext *context, systime_t timeout)
Set timeout for blocking calls (for DTLS only)
Definition: tls.c:1446
uint8_t signature
Definition: tls.h:1403
bool_t extendedMasterSecret
Extended master secret computation.
Definition: tls.h:1764
__start_packed struct @256 TlsChangeCipherSpec
ChangeCipherSpec message.
TlsEcCurveType
EC curve types.
Definition: tls.h:1309
@ TLS_EC_CURVE_TYPE_NAMED_CURVE
Definition: tls.h:1312
@ TLS_EC_CURVE_TYPE_EXPLICIT_PRIME
Definition: tls.h:1310
@ TLS_EC_CURVE_TYPE_EXPLICIT_CHAR2
Definition: tls.h:1311
error_t tlsSetAlpnProtocolList(TlsContext *context, const char_t *protocolList)
Set the list of supported ALPN protocols.
Definition: tls.c:812
error_t tlsSetMaxEarlyDataSize(TlsContext *context, size_t maxEarlyDataSize)
Send the maximum amount of 0-RTT data the server can accept.
Definition: tls.c:1538
error_t tlsSetPskCallback(TlsContext *context, TlsPskCallback pskCallback)
Register PSK callback function.
Definition: tls.c:1073
error_t tlsSetTransportProtocol(TlsContext *context, TlsTransportProtocol transportProtocol)
Set the transport protocol to be used.
Definition: tls.c:284
error_t tlsSetAlpnCallback(TlsContext *context, TlsAlpnCallback alpnCallback)
Register ALPN callback function.
Definition: tls.c:861
Legacy definitions.
Generic hash algorithm context.
X.509 common definitions.