iPXE
tlsfmt.h
Go to the documentation of this file.
1#ifndef _IPXE_TLSFMT_H
2#define _IPXE_TLSFMT_H
3
4/** @file
5 *
6 * TLS data formats
7 *
8 * TLS uses an ad hoc mixture of fixed-length and variable-length
9 * fields. Variable-length fields are preceded by a length field that
10 * may be one, two, or three bytes depending on the maximum length
11 * defined by the structure.
12 *
13 * To avoid open-coding a very large number of bounds checks, we
14 * define an abstraction for decomposing the component parts of a TLS
15 * data structure into a sequence of field data pointers and lengths
16 * (for variable-length fields), along with an efficient binary
17 * encoding that can describe the mapping between the decomposition
18 * and the raw data structure.
19 *
20 * A fixed-length field is described using a simple pointer to the
21 * appropriate fixed-length data type. A variable-length field is
22 * described using a cursor structure that comprises a void pointer
23 * followed by a length. TLS extensions are always variable-length
24 * and so are represented in the same way as variable-length fields.
25 *
26 * For example, the start of a ServerHello could be described using:
27 *
28 * struct tls_server_hello {
29 * uint16_t *version;
30 * struct tls_random *random;
31 * struct tls_cursor session_id;
32 * uint16_t *suite;
33 * uint8_t *compression;
34 * struct {
35 * struct tls_cursor all;
36 * struct tls_cursor renegotiation;
37 * struct tls_cursor extended_master_secret;
38 * } ext;
39 * };
40 *
41 * Note that the fixed-length fields are all typed pointers, whereas
42 * the variable-length session ID uses a TLS cursor (i.e. a void
43 * pointer and a length). Since pointer values and length values are
44 * necessarily the same size, we can meaningfully treat this
45 * descriptor structure as an array `ptrlen[]` of pointer/length
46 * values.
47 *
48 * We create a binary encoding to allow us to define the mapping
49 * between this descriptor structure and the raw TLS data structure
50 * using a static byte array constructed at build time. The same
51 * binary encoding may be used both for parsing and for building a TLS
52 * data structure.
53 *
54 * Starting at index `N=1` within the byte array `map[]`:
55 *
56 * - Interpret `map[0]` as the length of the `map[]` array. A zero
57 * array length is invalid and is treated as a fatal error.
58 *
59 * - Upon reaching the end of the mapping (i.e. `N==map[0]`),
60 * stop processing.
61 *
62 * - Interpret `map[N]` as the eight bits `llllllvv`, where:
63 *
64 * - `V = vv` is the minimal TLS version that includes this field
65 * (encoded as a delta from the lowest version currently
66 * supported by the codebase).
67 *
68 * - `L = llllll` is one plus the length of the corresponding
69 * fixed-length data structure. An empty fixed-length data
70 * structure is pointless, and so we choose a zero fixed length
71 * (i.e. `L==1`) to represent a variable-length data structure.
72 * A negative fixed length (i.e. `L==0`) is invalid and is
73 * treated as a fatal error.
74 *
75 * - For a fixed-length data structure (with `L>1`):
76 *
77 * - When parsing: store the pointer to the start of the
78 * fixed-length data as `ptrlen[N-1]`.
79 *
80 * - When building: append a copy of the data from `ptrlen[N-1]`
81 * with length `L-1`.
82 *
83 * - For a variable-length data structure (with `L==1`), interpret
84 * `map[N+1]` as the eight bits `xxxxxxnn`, where:
85 *
86 * - `N = nn` is the length of the length header that precedes the
87 * variable-length data structure. A zero-byte length header is
88 * invalid, and so we choose `N==0` to represent a field that
89 * covers all remaining data.
90 *
91 * - `X = xxxxxx` is one plus the number of TLS extension types
92 * that immediately follow `map[N+1]` and that represent
93 * extensions of interest that may be present within this field.
94 * A negative number of extensions (i.e. `X==0`) is impossible
95 * and so we choose this to represent a field that is not used
96 * to contain extensions.
97 *
98 * - When parsing: store the pointer to the start of the
99 * variable-length data as `ptrlen[N-1]`, and store the decoded
100 * length of the variable-length data as `ptrlen[N]`.
101 *
102 * - When building: append a copy of the data from `ptrlen[N-1]`
103 * (with the correct `N`-byte length header). Take the length
104 * of the variable-length data to be `X ? 0 : ptrlen[N]`
105 * (i.e. always build fields that contain extensions as being
106 * empty).
107 *
108 * - For each `1<=k<=(X-1)` in a variable-length data structure that
109 * is used to contain extensions (i.e. that has `X>0`), interpret
110 * `T = map[N+2k]:map[N+2k+1]` as the inverse of a TLS extension
111 * type (in network-endian order):
112 *
113 * - If `T==0`, then terminate processing with a fatal error.
114 *
115 * - When parsing: for each matching extension type `~T` that is
116 * found, store the pointer to the start of the extension data
117 * as `ptrlen[N+2k-1]`, and store the decoded length of the
118 * variable-length extension data as `ptrlen[N+2k]`.
119 *
120 * - When building: if `ptrlen[N+2k-1]` is set, then append a copy
121 * of the data from `ptrlen[N+2k-1]` with length `ptrlen[N+2k]`
122 * as an extension with type `~T` (with the correct extension
123 * header, and updating the length of the containing field
124 * accordingly).
125 *
126 * - Increment `N` to the next uninterpreted byte, and loop.
127 *
128 * Any parsing failure (e.g. insufficient remaining space to contain
129 * the fixed-length or variable-length structure) will be treated as a
130 * fatal error. Missing extensions of interest will not be treated as
131 * errors, and the corresponding `ptrlen` entries will be zeroed to
132 * indicate that the extension was not found. Duplicate extensions of
133 * interest will be treated as a fatal error. (Any extensions that
134 * are not of interest will be ignored, even if duplicated.)
135 *
136 * The encoding allows for fixed-length fields of up to 62 bytes.
137 * Longer fixed-length fields must be expressed as a sequence of
138 * smaller fixed-length fields.
139 *
140 * All fields must be represented using data structures that are
141 * packed and that allow for arbitrary byte alignment.
142 *
143 * A variable-length field that covers all remaining data (i.e. with
144 * `N==0`) may be used for incremental parsing, as required for the
145 * variable number of entries in structures such as a TLS extension
146 * list. If no such variable-length field exists, then any leftover
147 * data will be treated as a fatal parsing error.
148 *
149 * Up to four consecutive versions of TLS may be supported by the
150 * encoding. Experience shows that at most three versions of TLS will
151 * be supported by the codebase at any one time, and so this is likely
152 * to be sufficient in practice.
153 *
154 * The encoding is designed to allow for efficient population of the
155 * byte array using preprocessor macros (with compile-time checks to
156 * ensure that the byte array matches the descriptor structure). A
157 * missing populator macro will leave an erroneous zero byte within
158 * the byte array, and the encoding has been designed so that stray
159 * zero bytes will fail safe: `map[0]==0` is treated as a fatal error,
160 * `L==0` or `T==0` are treated as fatal errors, and `N==0` would
161 * capture all remaining data (and so cause parsing to fail on the
162 * subsequent byte).
163 *
164 */
165
166FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
167FILE_SECBOOT ( PERMITTED );
168
169#include <stdint.h>
170#include <stddef.h>
171#include <ipxe/asn1.h>
172
173/** TLS version 1.1 */
174#define TLS_VERSION_TLS_1_1 0x0302
175
176/** TLS version 1.2 */
177#define TLS_VERSION_TLS_1_2 0x0303
178
179/** TLS version 1.3 */
180#define TLS_VERSION_TLS_1_3 0x0304
181
182/** Lowest configurable supported version */
183#define TLS_VERSION_BASE TLS_VERSION_TLS_1_1
184
185/** A TLS variable-length data cursor */
187 /** Data */
188 void *data;
189 /** Length of data */
190 size_t len;
191};
192
193/** A pointer/length value */
195 /** Data pointer */
196 void *data;
197 /** Length */
198 size_t len;
199};
200
201/**
202 * Number of pointer/length values in a descriptor structure
203 *
204 * @v desc Descriptor structure name
205 * @ret count Number of pointer/length values
206 */
207#define TLS_DESCR_COUNT( desc ) \
208 ( /* Calculate count */ \
209 ( sizeof ( struct desc ) / sizeof ( union tls_ptr_len ) ) + \
210 /* Check alignment */ \
211 ( 0 * sizeof ( int[ -( sizeof ( struct desc ) % \
212 sizeof ( union tls_ptr_len ) ) ] ) ) )
213
214/**
215 * Binary encoding of a descriptor structure mapping
216 *
217 * @v desc Descriptor structure name
218 * @ret map Binary encoding of the descriptor structure mapping
219 */
220#define TLS_DESCR_MAPPING( desc ) \
221 const uint8_t desc ## _map [ 1 /* Mapping size byte */ + \
222 TLS_DESCR_COUNT ( desc ) ]
223
224/**
225 * Describe size of a descriptor mapping
226 *
227 * @v desc Descriptor stucture name
228 */
229#define TLS_MAPSZ( desc ) \
230 [0] = ( 1 /* Mapping size byte */ + TLS_DESCR_COUNT ( desc ) )
231
232/**
233 * Index of descriptor field
234 *
235 * @v desc Descriptor structure name
236 * @v field Field name within descriptor structure
237 * @ret index Index within byte array or ptr/len array
238 */
239#define TLS_INDEX( desc, field ) \
240 ( /* Skip mapping size byte */ \
241 1 + \
242 /* Index within ptr/len array */ \
243 ( offsetof ( struct desc, field ) / \
244 sizeof ( union tls_ptr_len ) ) + \
245 /* Check alignment */ \
246 ( 0 * sizeof ( int[ -( offsetof ( struct desc, field ) % \
247 sizeof ( union tls_ptr_len ) ) ] ) ) )
248
249/**
250 * Number of extensions of interest within an extension descriptor
251 *
252 * @v desc Descriptor structure name
253 * @v field Field name within descriptor structure
254 * @ret extns Number of extensions of interest within this field
255 */
256#define TLS_EXTNS( desc, field ) \
257 ( ( sizeof ( ( ( struct desc * ) NULL )->field ) - \
258 sizeof ( ( ( struct desc * ) NULL )->field.all ) ) \
259 / sizeof ( struct tls_cursor ) )
260
261/**
262 * Describe a fixed-length field
263 *
264 * @v desc Descriptor structure name
265 * @v version Minimum TLS version that includes this field
266 * @v field Field name within descriptor structure
267 */
268#define TLS_FIXED( desc, version, field ) \
269 /* Encoded `llllllvv` */ \
270 [ TLS_INDEX ( desc, field ) ] = \
271 ( ( (version) - TLS_VERSION_BASE ) + \
272 ( ( sizeof ( *( ( ( struct desc * ) NULL )->field ) ) \
273 + 1 ) << 2 ) )
274
275/**
276 * Describe a variable-length field
277 *
278 * @v desc Descriptor structure name
279 * @v version Minimum TLS version that includes this field
280 * @v field Field name within descriptor structure
281 * @v bits Number of bits used to encode field length
282 * @v extns Number of extensions of interest plus one (if any)
283 */
284#define TLS_VARIABLE( desc, version, field, bits, extns ) \
285 /* Encoded `000001vv` */ \
286 [ TLS_INDEX ( desc, field ) ] = \
287 ( ( (version) - TLS_VERSION_BASE ) + ( 1 << 2 ) ), \
288 /* Encoded `xxxxxxnn` */ \
289 [ TLS_INDEX ( desc, field ) + 1 ] = \
290 ( ( ( (bits) + 7 ) / 8 ) + ( (extns) << 2 ) )
291
292/**
293 * Describe a variable-length field that captures all remaining data
294 *
295 * @v desc Descriptor structure name
296 * @v version Minimum TLS version that includes this field
297 * @v field Field name within descriptor structure
298 */
299#define TLS_EXTRA( desc, version, field ) \
300 TLS_VARIABLE ( desc, version, field, 0, 0 )
301
302/**
303 * Describe a variable-length field with an 8-bit length
304 *
305 * @v desc Descriptor structure name
306 * @v version Minimum TLS version that includes this field
307 * @v field Field name within descriptor structure
308 */
309#define TLS_VAR08( desc, version, field ) \
310 TLS_VARIABLE ( desc, (version), field, 8, 0 )
311
312/**
313 * Describe a variable-length field with a 16-bit length
314 *
315 * @v desc Descriptor structure name
316 * @v version Minimum TLS version that includes this field
317 * @v field Field name within descriptor structure
318 */
319#define TLS_VAR16( desc, version, field ) \
320 TLS_VARIABLE ( desc, (version), field, 16, 0 )
321
322/**
323 * Describe a variable-length field with a 24-bit length
324 *
325 * @v desc Descriptor structure name
326 * @v version Minimum TLS version that includes this field
327 * @v field Field name within descriptor structure
328 */
329#define TLS_VAR24( desc, version, field ) \
330 TLS_VARIABLE ( desc, (version), field, 24, 0 )
331
332/**
333 * Describe a variable-length field containing extensions
334 *
335 * @v desc Descriptor structure name
336 * @v version Minimum TLS version that includes this field
337 * @v field Field name within descriptor structure
338 */
339#define TLS_EXT16( desc, version, field ) \
340 TLS_VARIABLE ( desc, (version), field.all, 16, \
341 ( TLS_EXTNS ( desc, field ) + 1 ) )
342
343/**
344 * Describe a variable-length field containing an extension of interest
345 *
346 * @v desc Descriptor structure name
347 * @v extension Extension type
348 * @v field Field name within descriptor structure
349 */
350#define TLS_EXTND( desc, extension, field ) \
351 [ TLS_INDEX ( desc, field ) ] = \
352 ( ( (extension) >> 8 ) ^ 0xff ), \
353 [ TLS_INDEX ( desc, field ) + 1 ] = \
354 ( ( (extension) & 0xff ) ^ 0xff )
355
356/**
357 * Interpret minimum version from an `llllllvv` byte
358 *
359 * @v byte Mapping byte
360 * @ret min Minimum TLS version that includes this field
361 */
362#define TLS_MAP_MIN( byte ) ( TLS_VERSION_BASE + ( (byte) & 0x03 ) )
363
364/**
365 * Interpret fixed length from an `llllllvv` byte
366 *
367 * @v byte Mapping byte
368 * @ret fixed Fixed length
369 */
370#define TLS_MAP_FIXED( byte ) ( ( (byte) >> 2 ) - 1 )
371
372/**
373 * Interpret number of length bytes from an `xxxxxxnn` byte
374 *
375 * @v byte Mapping byte
376 * @ret len_len Number of length bytes
377 */
378#define TLS_MAP_LEN_LEN( byte ) ( (byte) & 0x03 )
379
380/** Maximum number of length bytes */
381#define TLS_MAP_LEN_LEN_MAX 3
382
383/**
384 * Interpret number of extensions from an `xxxxxxnn` byte
385 *
386 * @v byte Mapping byte
387 * @ret extensions Number of extensions
388 */
389#define TLS_MAP_EXTENSIONS( byte ) ( ( (byte) >> 2 ) - 1 )
390
391/** Certificate descriptor */
393 /** Certificate request context */
395 /** Certificate list */
397};
398
399/** CertificateEntry descriptor */
401 /** Certificate data */
403 /** Extensions of interest */
404 struct {
405 /** All extensions */
408 /** Next certificate */
410};
411
412/** ClientHello descriptor */
414 /** Fixed portion */
415 struct {
416 /** Offered version */
418 /** Client random bytes */
420 } __attribute__ (( packed )) *a;
421 /** Session ID */
423 /** Cipher suites */
425 /** Compression methods */
427 /** Extensions of interest */
428 struct {
429 /** All extensions */
431 /** Cookie extension */
433 /** Extended master secret extension */
435 /** Maximum fragment length extension */
437 /** Supported groups extension */
439 /** Key share extension */
441 /** Server name indication extension */
443 /** Preshared key modes extension */
445 /** Record size limit extension */
447 /** Renegotiation information extension */
449 /** Signature algorithms extension */
451 /** Supported versions extension */
453 /** Session ticket extension */
456};
457
458/** ClientKeyExchange descriptor (for DHE) */
460 /** Public key */
462};
463
464/** ClientKeyExchange descriptor (for ECDHE) */
466 /** Curve point */
468};
469
470/** ClientKeyExchange descriptor (for key transport) */
472 /** Encrypted pre-master secret */
474};
475
476/** ClientKeyExchange descriptor (unified) */
478 /** ClientKeyExchange descriptor (common format) */
480 /** ClientKeyExchange descriptor (for key transport) */
482 /** ClientKeyExchange descriptor (for DHE) */
484 /** ClientKeyExchange descriptor (for ECDHE) */
486 /** Raw pointer/length array */
488};
489
490/** DigitallySigned descriptor */
492 /** Signature and hash algorithm */
493 uint16_t __attribute__ (( aligned ( 1 ) )) *sig_hash;
494 /** Signature */
496};
497
498/** Extension descriptor */
500 /** Extension type */
501 uint16_t __attribute__ (( aligned ( 1 ) )) *type;
502 /** Extension data */
504 /** Next extension */
506};
507
508/** HelloRequest descriptor */
510
511/** KeyShareClientHello descriptor */
513 /** Key share list */
515};
516
517/** KeyShareEntry descriptor */
519 /** Named group */
520 uint16_t __attribute__ (( aligned ( 1 ) )) *group;
521 /** Public key */
523 /** Next key share */
525};
526
527/** KeyShareHelloRetryRequest descriptor */
529 /** Named group */
530 uint16_t __attribute__ (( aligned ( 1 ) )) *group;
531};
532
533/** KeyShareServerHello descriptor */
535 /** Named group */
536 uint16_t __attribute__ (( aligned ( 1 ) )) *group;
537 /** Public key */
539};
540
541/** KeyShareServerHello/KeyShareHelloRetryRequest combined descriptor */
543 /** Named group (present in both) */
544 uint16_t __attribute__ (( aligned ( 1 ) )) *group;
545 /** KeyShareHelloRetryRequest descriptor */
547 /** KeyShareServerHello descriptor */
549 /** Raw pointer/length array */
551};
552
553/** MaxFragmentLength descriptor */
555 /** Maximum fragment length */
557};
558
559/** NamedGroupList descriptor */
561 /** Named group list */
563};
564
565/** NewSessionTicket descriptor */
567 /** Lifetime hint */
568 uint32_t __attribute__ (( aligned ( 1 ) )) *lifetime;
569 /** Age obfuscation */
570 uint32_t __attribute__ (( aligned ( 1 ) )) *age;
571 /** Nonce */
573 /** Ticket */
575 /** Extensions of interest */
576 struct {
577 /** All extensions */
580};
581
582/** PskKeyExchangeModes descriptor */
584 /** Mode list */
586};
587
588/** RenegotiationInfo descriptor */
590 /** Verification data from previous Finished */
592};
593
594/** ServerHello descriptor */
596 /** First fixed-length portion */
597 struct {
598 /** Selected version */
600 /** Server random bytes */
602 } __attribute__ (( packed )) *a;
603 /** Session ID */
605 /** Second fixed-length portion */
606 struct {
607 /** Selected cipher suite */
609 /** Selected compression method */
611 } __attribute__ (( packed )) *b;
612 /** Extensions of interest */
613 struct {
614 /** All extensions */
616 /** Renegotiation information extension */
618 /** Extended master secret extension */
620 /** Supported versions extension */
622 /** Key share extension */
624 /** Cookie extension */
627};
628
629/** ServerHelloDone descriptor */
631
632/** ServerKeyExchange descriptor (for DHE) */
634 /** Prime modulus */
636 /** Generator */
638 /** Public key */
640 /** Signature */
642};
643
644/** ServerKeyExchange descriptor (for ECDHE) */
646 /** Curve parameters */
647 struct {
648 /** Curve type */
650 /** Named group */
652 } __attribute__ (( packed )) *curve;
653 /** Curve point */
655 /** Signature */
657};
658
659/** ServerName descriptor */
661 /** Name type */
663 /** Host name */
665};
666
667/** ServerNameList descriptor */
669 /** Server name list */
671};
672
673/** SignatureSchemeList descriptor */
675 /** Supported signature algorithm list */
677};
678
679/** SupportedVersions descriptor (in ServerHello) */
681 /** Selected version */
682 uint16_t __attribute__ (( aligned ( 1 ) )) *selected;
683};
684
685/** SupportedVersions descriptor (in ClientHello) */
687 /** Supported version list */
689};
690
691/**
692 * Get ASN.1 cursor from TLS cursor
693 *
694 * @v cursor TLS cursor
695 * @ret asn1 ASN.1 object cursor
696 */
697static inline __attribute__ (( always_inline )) const struct asn1_cursor *
698tls_asn1 ( const struct tls_cursor *cursor ) {
699 union {
700 const struct tls_cursor tls;
701 const struct asn1_cursor asn1;
702 } *u = container_of ( cursor, typeof ( *u ), tls );
703
704 /* Sanity check */
705 build_assert ( ( ( const void * ) &u->tls.data ) == &u->asn1.data );
706 build_assert ( &u->tls.len == &u->asn1.len );
707
708 return &u->asn1;
709}
710
711extern int tls_parse_map ( const uint8_t *map, unsigned int version,
712 const struct tls_cursor *cursor,
713 union tls_ptr_len *desc );
714extern int tls_parse_opt_map ( const uint8_t *map, unsigned int version,
715 const struct tls_cursor *cursor,
716 union tls_ptr_len *desc );
717extern int tls_build_map ( const uint8_t *map, unsigned int version,
718 union tls_ptr_len *desc,
719 struct tls_cursor *cursor );
720extern int tls_size_map ( const uint8_t *map, unsigned int version,
721 union tls_ptr_len *desc,
722 struct tls_cursor *cursor );
723
724/**
725 * Parse TLS data structure
726 *
727 * @v type Descriptor structure name
728 * @v version Protocol version
729 * @v cursor Cursor containing TLS data structure
730 * @v desc Data structure descriptor to fill in
731 * @ret rc Return status code
732 */
733#define tls_parse( type, version, cursor, desc ) \
734 tls_parse_map ( type ## _map, (version), (cursor), \
735 ( ( union tls_ptr_len * ) \
736 ( (desc) == ( ( struct type * ) NULL ) ? \
737 (desc) : (desc) ) ) )
738
739/**
740 * Parse optional TLS data structure
741 *
742 * @v type Descriptor structure name
743 * @v version Protocol version
744 * @v cursor Cursor containing TLS data structure
745 * @v desc Data structure descriptor to fill in
746 * @ret rc Return status code
747 */
748#define tls_parse_opt( type, version, cursor, desc ) \
749 tls_parse_opt_map ( type ## _map, (version), (cursor), \
750 ( ( union tls_ptr_len * ) \
751 ( (desc) == ( ( struct type * ) NULL ) ? \
752 (desc) : (desc) ) ) )
753
754/**
755 * Build TLS data structure
756 *
757 * @v type Descriptor structure name
758 * @v version Protocol version
759 * @v desc Data structure descriptor to fill in
760 * @v cursor Cursor to contain TLS data structure
761 * @ret rc Return status code
762 */
763#define tls_build( type, version, desc, cursor ) \
764 tls_build_map ( type ## _map, (version), \
765 ( ( union tls_ptr_len * ) \
766 ( (desc) == ( ( struct type * ) NULL ) ? \
767 (desc) : (desc) ) ), (cursor) )
768
769/**
770 * Calculate length of TLS data structure
771 *
772 * @v type Descriptor structure name
773 * @v version Protocol version
774 * @v desc Data structure descriptor to fill in
775 * @v cursor Cursor to contain TLS data structure
776 * @ret rc Return status code
777 */
778#define tls_size( type, version, desc, cursor ) \
779 tls_size_map ( type ## _map, (version), \
780 ( ( union tls_ptr_len * ) \
781 ( (desc) == ( ( struct type * ) NULL ) ? \
782 (desc) : (desc) ) ), (cursor) )
783
811
812#endif /* _IPXE_TLSFMT_H */
typeof(acpi_finder=acpi_find)
ACPI table finder.
Definition acpi.c:48
unsigned short uint16_t
Definition stdint.h:11
unsigned int uint32_t
Definition stdint.h:12
unsigned char uint8_t
Definition stdint.h:10
ASN.1 encoding.
#define build_assert(condition)
Assert a condition at build time (after dead code elimination).
Definition assert.h:88
u32 version
Driver version.
Definition ath9k_hw.c:1985
union @104331263140136355135267063077374276003064103115 u
uint16_t ext
Extended status.
Definition ena.h:9
struct ena_llq_option desc
Descriptor counts.
Definition ena.h:9
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:921
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:951
#define __attribute__(x)
Definition compiler.h:10
static __always_inline int struct dma_mapping * map
Definition dma.h:184
#define container_of(ptr, type, field)
Get containing structure.
Definition stddef.h:36
An ASN.1 object cursor.
Definition asn1.h:21
CertificateEntry descriptor.
Definition tlsfmt.h:400
struct tls_cursor next
Next certificate.
Definition tlsfmt.h:409
struct tls_cursor all
All extensions.
Definition tlsfmt.h:406
struct tls_cursor cert
Certificate data.
Definition tlsfmt.h:402
Certificate descriptor.
Definition tlsfmt.h:392
struct tls_cursor list
Certificate list.
Definition tlsfmt.h:396
struct tls_cursor context
Certificate request context.
Definition tlsfmt.h:394
ClientHello descriptor.
Definition tlsfmt.h:413
struct tls_cursor frag
Maximum fragment length extension.
Definition tlsfmt.h:436
struct tls_cursor sigs
Signature algorithms extension.
Definition tlsfmt.h:450
struct tls_cursor cookie
Cookie extension.
Definition tlsfmt.h:432
struct tls_client_hello::@300242163101377353070067133352065270331266023376 * a
Fixed portion.
struct tls_cursor pskmodes
Preshared key modes extension.
Definition tlsfmt.h:444
struct tls_cursor keys
Key share extension.
Definition tlsfmt.h:440
struct tls_cursor groups
Supported groups extension.
Definition tlsfmt.h:438
struct tls_cursor all
All extensions.
Definition tlsfmt.h:430
uint8_t random[32]
Client random bytes.
Definition tlsfmt.h:419
struct tls_cursor reneg
Renegotiation information extension.
Definition tlsfmt.h:448
struct tls_cursor compression
Compression methods.
Definition tlsfmt.h:426
uint16_t version
Offered version.
Definition tlsfmt.h:417
struct tls_cursor record
Record size limit extension.
Definition tlsfmt.h:446
struct tls_cursor suites
Cipher suites.
Definition tlsfmt.h:424
struct tls_cursor ems
Extended master secret extension.
Definition tlsfmt.h:434
struct tls_cursor ticket
Session ticket extension.
Definition tlsfmt.h:454
struct tls_cursor supvers
Supported versions extension.
Definition tlsfmt.h:452
struct tls_cursor session_id
Session ID.
Definition tlsfmt.h:422
struct tls_cursor names
Server name indication extension.
Definition tlsfmt.h:442
ClientKeyExchange descriptor (for DHE).
Definition tlsfmt.h:459
struct tls_cursor dh_yc
Public key.
Definition tlsfmt.h:461
ClientKeyExchange descriptor (for ECDHE).
Definition tlsfmt.h:465
struct tls_cursor point
Curve point.
Definition tlsfmt.h:467
ClientKeyExchange descriptor (for key transport).
Definition tlsfmt.h:471
struct tls_cursor enc
Encrypted pre-master secret.
Definition tlsfmt.h:473
A TLS variable-length data cursor.
Definition tlsfmt.h:186
void * data
Data.
Definition tlsfmt.h:188
size_t len
Length of data.
Definition tlsfmt.h:190
DigitallySigned descriptor.
Definition tlsfmt.h:491
uint16_t * sig_hash
Signature and hash algorithm.
Definition tlsfmt.h:493
struct tls_cursor sig
Signature.
Definition tlsfmt.h:495
Extension descriptor.
Definition tlsfmt.h:499
struct tls_cursor data
Extension data.
Definition tlsfmt.h:503
struct tls_cursor next
Next extension.
Definition tlsfmt.h:505
uint16_t * type
Extension type.
Definition tlsfmt.h:501
HelloRequest descriptor.
Definition tlsfmt.h:509
KeyShareClientHello descriptor.
Definition tlsfmt.h:512
struct tls_cursor list
Key share list.
Definition tlsfmt.h:514
KeyShareEntry descriptor.
Definition tlsfmt.h:518
struct tls_cursor next
Next key share.
Definition tlsfmt.h:524
uint16_t * group
Named group.
Definition tlsfmt.h:520
struct tls_cursor public
Public key.
Definition tlsfmt.h:522
KeyShareHelloRetryRequest descriptor.
Definition tlsfmt.h:528
uint16_t * group
Named group.
Definition tlsfmt.h:530
KeyShareServerHello descriptor.
Definition tlsfmt.h:534
uint16_t * group
Named group.
Definition tlsfmt.h:536
struct tls_cursor public
Public key.
Definition tlsfmt.h:538
MaxFragmentLength descriptor.
Definition tlsfmt.h:554
uint8_t * max
Maximum fragment length.
Definition tlsfmt.h:556
NamedGroupList descriptor.
Definition tlsfmt.h:560
struct tls_cursor list
Named group list.
Definition tlsfmt.h:562
NewSessionTicket descriptor.
Definition tlsfmt.h:566
struct tls_cursor all
All extensions.
Definition tlsfmt.h:578
uint32_t * age
Age obfuscation.
Definition tlsfmt.h:570
struct tls_cursor ticket
Ticket.
Definition tlsfmt.h:574
struct tls_cursor nonce
Nonce.
Definition tlsfmt.h:572
uint32_t * lifetime
Lifetime hint.
Definition tlsfmt.h:568
PskKeyExchangeModes descriptor.
Definition tlsfmt.h:583
struct tls_cursor list
Mode list.
Definition tlsfmt.h:585
RenegotiationInfo descriptor.
Definition tlsfmt.h:589
struct tls_cursor verify
Verification data from previous Finished.
Definition tlsfmt.h:591
ServerHelloDone descriptor.
Definition tlsfmt.h:630
ServerHello descriptor.
Definition tlsfmt.h:595
struct tls_cursor key
Key share extension.
Definition tlsfmt.h:623
struct tls_cursor all
All extensions.
Definition tlsfmt.h:615
uint8_t compression
Selected compression method.
Definition tlsfmt.h:610
struct tls_cursor cookie
Cookie extension.
Definition tlsfmt.h:625
struct tls_server_hello::@161027372353017270343224204013300325065157134244 * b
Second fixed-length portion.
struct tls_cursor session_id
Session ID.
Definition tlsfmt.h:604
struct tls_cursor ems
Extended master secret extension.
Definition tlsfmt.h:619
uint8_t random[32]
Server random bytes.
Definition tlsfmt.h:601
uint16_t version
Selected version.
Definition tlsfmt.h:599
struct tls_server_hello::@103274354304025060212205334334227305117174114135 * a
First fixed-length portion.
uint16_t suite
Selected cipher suite.
Definition tlsfmt.h:608
struct tls_cursor reneg
Renegotiation information extension.
Definition tlsfmt.h:617
struct tls_cursor supver
Supported versions extension.
Definition tlsfmt.h:621
ServerKeyExchange descriptor (for DHE).
Definition tlsfmt.h:633
struct tls_cursor dsig
Signature.
Definition tlsfmt.h:641
struct tls_cursor dh_ys
Public key.
Definition tlsfmt.h:639
struct tls_cursor dh_g
Generator.
Definition tlsfmt.h:637
struct tls_cursor dh_p
Prime modulus.
Definition tlsfmt.h:635
ServerKeyExchange descriptor (for ECDHE).
Definition tlsfmt.h:645
struct tls_server_key_exchange_ecdhe::@335121145353041211061272202142307345103264367317 * curve
Curve parameters.
uint8_t type
Curve type.
Definition tlsfmt.h:649
uint16_t group
Named group.
Definition tlsfmt.h:651
struct tls_cursor dsig
Signature.
Definition tlsfmt.h:656
struct tls_cursor point
Curve point.
Definition tlsfmt.h:654
ServerNameList descriptor.
Definition tlsfmt.h:668
struct tls_cursor list
Server name list.
Definition tlsfmt.h:670
ServerName descriptor.
Definition tlsfmt.h:660
struct tls_cursor name
Host name.
Definition tlsfmt.h:664
uint8_t * type
Name type.
Definition tlsfmt.h:662
SignatureSchemeList descriptor.
Definition tlsfmt.h:674
struct tls_cursor list
Supported signature algorithm list.
Definition tlsfmt.h:676
SupportedVersions descriptor (in ServerHello).
Definition tlsfmt.h:680
uint16_t * selected
Selected version.
Definition tlsfmt.h:682
SupportedVersions descriptor (in ClientHello).
Definition tlsfmt.h:686
struct tls_cursor list
Supported version list.
Definition tlsfmt.h:688
int tls_build_map(const uint8_t *map, unsigned int version, union tls_ptr_len *desc, struct tls_cursor *cursor)
Build TLS data structure.
Definition tlsfmt.c:468
static const struct asn1_cursor * tls_asn1(const struct tls_cursor *cursor)
Get ASN.1 cursor from TLS cursor.
Definition tlsfmt.h:698
int tls_size_map(const uint8_t *map, unsigned int version, union tls_ptr_len *desc, struct tls_cursor *cursor)
Calculate length of TLS data structure.
Definition tlsfmt.c:658
#define TLS_DESCR_MAPPING(desc)
Binary encoding of a descriptor structure mapping.
Definition tlsfmt.h:220
int tls_parse_opt_map(const uint8_t *map, unsigned int version, const struct tls_cursor *cursor, union tls_ptr_len *desc)
Parse optional TLS data structure.
Definition tlsfmt.c:343
int tls_parse_map(const uint8_t *map, unsigned int version, const struct tls_cursor *cursor, union tls_ptr_len *desc)
Parse TLS data structure.
Definition tlsfmt.c:172
ClientKeyExchange descriptor (unified).
Definition tlsfmt.h:477
struct tls_client_key_exchange_ecdhe ecdhe
ClientKeyExchange descriptor (for ECDHE).
Definition tlsfmt.h:485
struct tls_cursor cursor
ClientKeyExchange descriptor (common format).
Definition tlsfmt.h:479
struct tls_client_key_exchange_pubkey pubkey
ClientKeyExchange descriptor (for key transport).
Definition tlsfmt.h:481
struct tls_client_key_exchange_dhe dhe
ClientKeyExchange descriptor (for DHE).
Definition tlsfmt.h:483
union tls_ptr_len desc[0]
Raw pointer/length array.
Definition tlsfmt.h:487
KeyShareServerHello/KeyShareHelloRetryRequest combined descriptor.
Definition tlsfmt.h:542
union tls_ptr_len desc[0]
Raw pointer/length array.
Definition tlsfmt.h:550
uint16_t * group
Named group (present in both).
Definition tlsfmt.h:544
struct tls_key_share_hello_retry_request hrr
KeyShareHelloRetryRequest descriptor.
Definition tlsfmt.h:546
struct tls_key_share_server_hello hello
KeyShareServerHello descriptor.
Definition tlsfmt.h:548
A pointer/length value.
Definition tlsfmt.h:194
size_t len
Length.
Definition tlsfmt.h:198
void * data
Data pointer.
Definition tlsfmt.h:196