iPXE
asn1.h
Go to the documentation of this file.
1 #ifndef _IPXE_ASN1_H
2 #define _IPXE_ASN1_H
3 
4 /** @file
5  *
6  * ASN.1 encoding
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 
12 #include <stddef.h>
13 #include <stdint.h>
14 #include <stdarg.h>
15 #include <assert.h>
16 #include <time.h>
17 #include <ipxe/tables.h>
18 
19 /** An ASN.1 object cursor */
20 struct asn1_cursor {
21  /** Start of data */
22  const void *data;
23  /** Length of data */
24  size_t len;
25 };
26 
27 /** An ASN.1 object builder */
28 struct asn1_builder {
29  /** Data
30  *
31  * This is always dynamically allocated. If @c data is NULL
32  * while @len is non-zero, this indicates that a memory
33  * allocation error has occurred during the building process.
34  */
35  void *data;
36  /** Length of data */
37  size_t len;
38 };
39 
40 /** Maximum (viable) length of ASN.1 length
41  *
42  * While in theory unlimited, this length is sufficient to contain a
43  * size_t.
44  */
45 #define ASN1_MAX_LEN_LEN ( 1 + sizeof ( size_t ) )
46 
47 /** An ASN.1 header */
49  /** Type */
51  /** Length (encoded) */
53 } __attribute__ (( packed ));
54 
55 /** ASN.1 end */
56 #define ASN1_END 0x00
57 
58 /** ASN.1 boolean */
59 #define ASN1_BOOLEAN 0x01
60 
61 /** ASN.1 integer */
62 #define ASN1_INTEGER 0x02
63 
64 /** ASN.1 bit string */
65 #define ASN1_BIT_STRING 0x03
66 
67 /** ASN.1 octet string */
68 #define ASN1_OCTET_STRING 0x04
69 
70 /** ASN.1 null */
71 #define ASN1_NULL 0x05
72 
73 /** ASN.1 object identifier */
74 #define ASN1_OID 0x06
75 
76 /** ASN.1 enumeration */
77 #define ASN1_ENUMERATED 0x0a
78 
79 /** ASN.1 UTF-8 string */
80 #define ASN1_UTF8_STRING 0x0c
81 
82 /** ASN.1 UTC time */
83 #define ASN1_UTC_TIME 0x17
84 
85 /** ASN.1 generalized time */
86 #define ASN1_GENERALIZED_TIME 0x18
87 
88 /** ASN.1 sequence */
89 #define ASN1_SEQUENCE 0x30
90 
91 /** ASN.1 set */
92 #define ASN1_SET 0x31
93 
94 /** ASN.1 implicit tag */
95 #define ASN1_IMPLICIT_TAG( number) ( 0x80 | (number) )
96 
97 /** ASN.1 explicit tag */
98 #define ASN1_EXPLICIT_TAG( number) ( 0xa0 | (number) )
99 
100 /** ASN.1 "any tag" magic value */
101 #define ASN1_ANY -1U
102 
103 /** Construct a short ASN.1 value */
104 #define ASN1_SHORT( tag, ... ) \
105  (tag), VA_ARG_COUNT ( __VA_ARGS__ ), __VA_ARGS__
106 
107 /** Initial OID byte */
108 #define ASN1_OID_INITIAL( first, second ) ( ( (first) * 40 ) + (second) )
109 
110 /** Single-byte OID value
111  *
112  * Valid for values up to 127
113  */
114 #define ASN1_OID_SINGLE( value ) ( (value) & 0x7f )
115 
116 /** Double-byte OID value
117  *
118  * Valid for values up to 16383
119  */
120 #define ASN1_OID_DOUBLE( value ) \
121  ( 0x80 | ( ( (value) >> 7 ) & 0x7f ) ), ASN1_OID_SINGLE ( (value) )
122 
123 /** Double-byte OID value
124  *
125  * Valid for values up to 2097151
126  */
127 #define ASN1_OID_TRIPLE( value ) \
128  ( 0x80 | ( ( (value) >> 14 ) & 0x7f ) ), ASN1_OID_DOUBLE ( (value) )
129 
130 /** ASN.1 OID for rsaEncryption (1.2.840.113549.1.1.1) */
131 #define ASN1_OID_RSAENCRYPTION \
132  ASN1_OID_INITIAL ( 1, 2 ), ASN1_OID_DOUBLE ( 840 ), \
133  ASN1_OID_TRIPLE ( 113549 ), ASN1_OID_SINGLE ( 1 ), \
134  ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 1 )
135 
136 /** ASN.1 OID for md5WithRSAEncryption (1.2.840.113549.1.1.4) */
137 #define ASN1_OID_MD5WITHRSAENCRYPTION \
138  ASN1_OID_INITIAL ( 1, 2 ), ASN1_OID_DOUBLE ( 840 ), \
139  ASN1_OID_TRIPLE ( 113549 ), ASN1_OID_SINGLE ( 1 ), \
140  ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 4 )
141 
142 /** ASN.1 OID for sha1WithRSAEncryption (1.2.840.113549.1.1.5) */
143 #define ASN1_OID_SHA1WITHRSAENCRYPTION \
144  ASN1_OID_INITIAL ( 1, 2 ), ASN1_OID_DOUBLE ( 840 ), \
145  ASN1_OID_TRIPLE ( 113549 ), ASN1_OID_SINGLE ( 1 ), \
146  ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 5 )
147 
148 /** ASN.1 OID for sha256WithRSAEncryption (1.2.840.113549.1.1.11) */
149 #define ASN1_OID_SHA256WITHRSAENCRYPTION \
150  ASN1_OID_INITIAL ( 1, 2 ), ASN1_OID_DOUBLE ( 840 ), \
151  ASN1_OID_TRIPLE ( 113549 ), ASN1_OID_SINGLE ( 1 ), \
152  ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 11 )
153 
154 /** ASN.1 OID for sha384WithRSAEncryption (1.2.840.113549.1.1.12) */
155 #define ASN1_OID_SHA384WITHRSAENCRYPTION \
156  ASN1_OID_INITIAL ( 1, 2 ), ASN1_OID_DOUBLE ( 840 ), \
157  ASN1_OID_TRIPLE ( 113549 ), ASN1_OID_SINGLE ( 1 ), \
158  ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 12 )
159 
160 /** ASN.1 OID for sha512WithRSAEncryption (1.2.840.113549.1.1.13) */
161 #define ASN1_OID_SHA512WITHRSAENCRYPTION \
162  ASN1_OID_INITIAL ( 1, 2 ), ASN1_OID_DOUBLE ( 840 ), \
163  ASN1_OID_TRIPLE ( 113549 ), ASN1_OID_SINGLE ( 1 ), \
164  ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 13 )
165 
166 /** ASN.1 OID for sha224WithRSAEncryption (1.2.840.113549.1.1.14) */
167 #define ASN1_OID_SHA224WITHRSAENCRYPTION \
168  ASN1_OID_INITIAL ( 1, 2 ), ASN1_OID_DOUBLE ( 840 ), \
169  ASN1_OID_TRIPLE ( 113549 ), ASN1_OID_SINGLE ( 1 ), \
170  ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 14 )
171 
172 /** ASN.1 OID for id-md4 (1.2.840.113549.2.4) */
173 #define ASN1_OID_MD4 \
174  ASN1_OID_INITIAL ( 1, 2 ), ASN1_OID_DOUBLE ( 840 ), \
175  ASN1_OID_TRIPLE ( 113549 ), ASN1_OID_SINGLE ( 2 ), \
176  ASN1_OID_SINGLE ( 4 )
177 
178 /** ASN.1 OID for id-md5 (1.2.840.113549.2.5) */
179 #define ASN1_OID_MD5 \
180  ASN1_OID_INITIAL ( 1, 2 ), ASN1_OID_DOUBLE ( 840 ), \
181  ASN1_OID_TRIPLE ( 113549 ), ASN1_OID_SINGLE ( 2 ), \
182  ASN1_OID_SINGLE ( 5 )
183 
184 /** ASN.1 OID for id-sha1 (1.3.14.3.2.26) */
185 #define ASN1_OID_SHA1 \
186  ASN1_OID_INITIAL ( 1, 3 ), ASN1_OID_SINGLE ( 14 ), \
187  ASN1_OID_SINGLE ( 3 ), ASN1_OID_SINGLE ( 2 ), \
188  ASN1_OID_SINGLE ( 26 )
189 
190 /** ASN.1 OID for id-x25519 (1.3.101.110) */
191 #define ASN1_OID_X25519 \
192  ASN1_OID_INITIAL ( 1, 3 ), ASN1_OID_SINGLE ( 101 ), \
193  ASN1_OID_SINGLE ( 110 )
194 
195 /** ASN.1 OID for id-sha256 (2.16.840.1.101.3.4.2.1) */
196 #define ASN1_OID_SHA256 \
197  ASN1_OID_INITIAL ( 2, 16 ), ASN1_OID_DOUBLE ( 840 ), \
198  ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 101 ), \
199  ASN1_OID_SINGLE ( 3 ), ASN1_OID_SINGLE ( 4 ), \
200  ASN1_OID_SINGLE ( 2 ), ASN1_OID_SINGLE ( 1 )
201 
202 /** ASN.1 OID for id-sha384 (2.16.840.1.101.3.4.2.2) */
203 #define ASN1_OID_SHA384 \
204  ASN1_OID_INITIAL ( 2, 16 ), ASN1_OID_DOUBLE ( 840 ), \
205  ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 101 ), \
206  ASN1_OID_SINGLE ( 3 ), ASN1_OID_SINGLE ( 4 ), \
207  ASN1_OID_SINGLE ( 2 ), ASN1_OID_SINGLE ( 2 )
208 
209 /** ASN.1 OID for id-sha512 (2.16.840.1.101.3.4.2.3) */
210 #define ASN1_OID_SHA512 \
211  ASN1_OID_INITIAL ( 2, 16 ), ASN1_OID_DOUBLE ( 840 ), \
212  ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 101 ), \
213  ASN1_OID_SINGLE ( 3 ), ASN1_OID_SINGLE ( 4 ), \
214  ASN1_OID_SINGLE ( 2 ), ASN1_OID_SINGLE ( 3 )
215 
216 /** ASN.1 OID for id-sha224 (2.16.840.1.101.3.4.2.4) */
217 #define ASN1_OID_SHA224 \
218  ASN1_OID_INITIAL ( 2, 16 ), ASN1_OID_DOUBLE ( 840 ), \
219  ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 101 ), \
220  ASN1_OID_SINGLE ( 3 ), ASN1_OID_SINGLE ( 4 ), \
221  ASN1_OID_SINGLE ( 2 ), ASN1_OID_SINGLE ( 4 )
222 
223 /** ASN.1 OID for id-sha512-224 (2.16.840.1.101.3.4.2.5) */
224 #define ASN1_OID_SHA512_224 \
225  ASN1_OID_INITIAL ( 2, 16 ), ASN1_OID_DOUBLE ( 840 ), \
226  ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 101 ), \
227  ASN1_OID_SINGLE ( 3 ), ASN1_OID_SINGLE ( 4 ), \
228  ASN1_OID_SINGLE ( 2 ), ASN1_OID_SINGLE ( 5 )
229 
230 /** ASN.1 OID for id-sha512-256 (2.16.840.1.101.3.4.2.6) */
231 #define ASN1_OID_SHA512_256 \
232  ASN1_OID_INITIAL ( 2, 16 ), ASN1_OID_DOUBLE ( 840 ), \
233  ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 101 ), \
234  ASN1_OID_SINGLE ( 3 ), ASN1_OID_SINGLE ( 4 ), \
235  ASN1_OID_SINGLE ( 2 ), ASN1_OID_SINGLE ( 6 )
236 
237 /** ASN.1 OID for commonName (2.5.4.3) */
238 #define ASN1_OID_COMMON_NAME \
239  ASN1_OID_INITIAL ( 2, 5 ), ASN1_OID_SINGLE ( 4 ), \
240  ASN1_OID_SINGLE ( 3 )
241 
242 /** ASN.1 OID for id-ce-keyUsage (2.5.29.15) */
243 #define ASN1_OID_KEYUSAGE \
244  ASN1_OID_INITIAL ( 2, 5 ), ASN1_OID_SINGLE ( 29 ), \
245  ASN1_OID_SINGLE ( 15 )
246 
247 /** ASN.1 OID for id-ce-basicConstraints (2.5.29.19) */
248 #define ASN1_OID_BASICCONSTRAINTS \
249  ASN1_OID_INITIAL ( 2, 5 ), ASN1_OID_SINGLE ( 29 ), \
250  ASN1_OID_SINGLE ( 19 )
251 
252 /** ASN.1 OID for id-ce-extKeyUsage (2.5.29.37) */
253 #define ASN1_OID_EXTKEYUSAGE \
254  ASN1_OID_INITIAL ( 2, 5 ), ASN1_OID_SINGLE ( 29 ), \
255  ASN1_OID_SINGLE ( 37 )
256 
257 /** ASN.1 OID for id-kp-codeSigning (1.3.6.1.5.5.7.3.3) */
258 #define ASN1_OID_CODESIGNING \
259  ASN1_OID_INITIAL ( 1, 3 ), ASN1_OID_SINGLE ( 6 ), \
260  ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 5 ), \
261  ASN1_OID_SINGLE ( 5 ), ASN1_OID_SINGLE ( 7 ), \
262  ASN1_OID_SINGLE ( 3 ), ASN1_OID_SINGLE ( 3 )
263 
264 /** ASN.1 OID for pkcs-signedData (1.2.840.113549.1.7.2) */
265 #define ASN1_OID_SIGNEDDATA \
266  ASN1_OID_INITIAL ( 1, 2 ), ASN1_OID_DOUBLE ( 840 ), \
267  ASN1_OID_TRIPLE ( 113549 ), ASN1_OID_SINGLE ( 1 ), \
268  ASN1_OID_SINGLE ( 7 ), ASN1_OID_SINGLE ( 2 )
269 
270 /** ASN.1 OID for id-pe-authorityInfoAccess (1.3.6.1.5.5.7.1.1) */
271 #define ASN1_OID_AUTHORITYINFOACCESS \
272  ASN1_OID_INITIAL ( 1, 3 ), ASN1_OID_SINGLE ( 6 ), \
273  ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 5 ), \
274  ASN1_OID_SINGLE ( 5 ), ASN1_OID_SINGLE ( 7 ), \
275  ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 1 )
276 
277 /** ASN.1 OID for id-ad-ocsp (1.3.6.1.5.5.7.48.1) */
278 #define ASN1_OID_OCSP \
279  ASN1_OID_INITIAL ( 1, 3 ), ASN1_OID_SINGLE ( 6 ), \
280  ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 5 ), \
281  ASN1_OID_SINGLE ( 5 ), ASN1_OID_SINGLE ( 7 ), \
282  ASN1_OID_SINGLE ( 48 ), ASN1_OID_SINGLE ( 1 )
283 
284 /** ASN.1 OID for id-pkix-ocsp-basic ( 1.3.6.1.5.5.7.48.1.1) */
285 #define ASN1_OID_OCSP_BASIC \
286  ASN1_OID_INITIAL ( 1, 3 ), ASN1_OID_SINGLE ( 6 ), \
287  ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 5 ), \
288  ASN1_OID_SINGLE ( 5 ), ASN1_OID_SINGLE ( 7 ), \
289  ASN1_OID_SINGLE ( 48 ), ASN1_OID_SINGLE ( 1 ), \
290  ASN1_OID_SINGLE ( 1 )
291 
292 /** ASN.1 OID for id-kp-OCSPSigning (1.3.6.1.5.5.7.3.9) */
293 #define ASN1_OID_OCSPSIGNING \
294  ASN1_OID_INITIAL ( 1, 3 ), ASN1_OID_SINGLE ( 6 ), \
295  ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 5 ), \
296  ASN1_OID_SINGLE ( 5 ), ASN1_OID_SINGLE ( 7 ), \
297  ASN1_OID_SINGLE ( 3 ), ASN1_OID_SINGLE ( 9 )
298 
299 /** ASN.1 OID for id-ce-subjectAltName (2.5.29.17) */
300 #define ASN1_OID_SUBJECTALTNAME \
301  ASN1_OID_INITIAL ( 2, 5 ), ASN1_OID_SINGLE ( 29 ), \
302  ASN1_OID_SINGLE ( 17 )
303 
304 /** Define an ASN.1 cursor for a static value */
305 #define ASN1_CURSOR( value ) { \
306  .data = value, \
307  .len = sizeof ( value ), \
308  }
309 
310 /** An ASN.1 OID-identified algorithm */
312  /** Name */
313  const char *name;
314  /** Object identifier */
315  struct asn1_cursor oid;
316  /** Public-key algorithm (if applicable) */
318  /** Digest algorithm (if applicable) */
320  /** Elliptic curve (if applicable) */
322 };
323 
324 /** ASN.1 OID-identified algorithms */
325 #define ASN1_ALGORITHMS __table ( struct asn1_algorithm, "asn1_algorithms" )
326 
327 /** Declare an ASN.1 OID-identified algorithm */
328 #define __asn1_algorithm __table_entry ( ASN1_ALGORITHMS, 01 )
329 
330 /* ASN.1 OID-identified algorithms */
331 extern struct asn1_algorithm rsa_encryption_algorithm __asn1_algorithm;
332 extern struct asn1_algorithm md5_with_rsa_encryption_algorithm __asn1_algorithm;
333 extern struct asn1_algorithm
334 sha1_with_rsa_encryption_algorithm __asn1_algorithm;
335 extern struct asn1_algorithm
336 sha256_with_rsa_encryption_algorithm __asn1_algorithm;
337 extern struct asn1_algorithm
338 sha384_with_rsa_encryption_algorithm __asn1_algorithm;
339 extern struct asn1_algorithm
340 sha512_with_rsa_encryption_algorithm __asn1_algorithm;
341 extern struct asn1_algorithm
342 sha224_with_rsa_encryption_algorithm __asn1_algorithm;
343 extern struct asn1_algorithm oid_md4_algorithm __asn1_algorithm;
344 extern struct asn1_algorithm oid_md5_algorithm __asn1_algorithm;
345 extern struct asn1_algorithm oid_sha1_algorithm __asn1_algorithm;
346 extern struct asn1_algorithm oid_sha256_algorithm __asn1_algorithm;
347 extern struct asn1_algorithm oid_sha384_algorithm __asn1_algorithm;
348 extern struct asn1_algorithm oid_sha512_algorithm __asn1_algorithm;
349 extern struct asn1_algorithm oid_sha224_algorithm __asn1_algorithm;
350 extern struct asn1_algorithm oid_sha512_224_algorithm __asn1_algorithm;
351 extern struct asn1_algorithm oid_sha512_256_algorithm __asn1_algorithm;
352 
353 /** An ASN.1 bit string */
355  /** Data */
356  const void *data;
357  /** Length */
358  size_t len;
359  /** Unused bits at end of data */
360  unsigned int unused;
361 } __attribute__ (( packed ));
362 
363 /**
364  * Invalidate ASN.1 object cursor
365  *
366  * @v cursor ASN.1 object cursor
367  */
368 static inline __attribute__ (( always_inline )) void
370  cursor->len = 0;
371 }
372 
373 /**
374  * Extract ASN.1 type
375  *
376  * @v cursor ASN.1 object cursor
377  * @ret type Type, or ASN1_END if cursor is invalid
378  */
379 static inline __attribute__ (( always_inline )) unsigned int
380 asn1_type ( const struct asn1_cursor *cursor ) {
381  const uint8_t *type = cursor->data;
382 
383  return ( ( cursor->len >= sizeof ( *type ) ) ? *type : ASN1_END );
384 }
385 
386 /**
387  * Get cursor for built object
388  *
389  * @v builder ASN.1 object builder
390  * @ret cursor ASN.1 object cursor
391  */
392 static inline __attribute__ (( always_inline )) struct asn1_cursor *
393 asn1_built ( struct asn1_builder *builder ) {
394  union {
395  struct asn1_builder builder;
396  struct asn1_cursor cursor;
397  } *u = container_of ( builder, typeof ( *u ), builder );
398 
399  /* Sanity check */
400  build_assert ( ( ( const void * ) &u->builder.data ) ==
401  &u->cursor.data );
402  build_assert ( &u->builder.len == &u->cursor.len );
403 
404  return &u->cursor;
405 }
406 
407 extern int asn1_start ( struct asn1_cursor *cursor, unsigned int type,
408  size_t extra );
409 extern int asn1_enter ( struct asn1_cursor *cursor, unsigned int type );
410 extern int asn1_skip_if_exists ( struct asn1_cursor *cursor,
411  unsigned int type );
412 extern int asn1_skip ( struct asn1_cursor *cursor, unsigned int type );
413 extern int asn1_shrink ( struct asn1_cursor *cursor, unsigned int type );
414 extern int asn1_enter_any ( struct asn1_cursor *cursor );
415 extern int asn1_skip_any ( struct asn1_cursor *cursor );
416 extern int asn1_shrink_any ( struct asn1_cursor *cursor );
417 extern int asn1_boolean ( const struct asn1_cursor *cursor );
418 extern int asn1_integer ( const struct asn1_cursor *cursor, int *value );
419 extern int asn1_bit_string ( const struct asn1_cursor *cursor,
420  struct asn1_bit_string *bits );
421 extern int asn1_integral_bit_string ( const struct asn1_cursor *cursor,
422  struct asn1_bit_string *bits );
423 extern int asn1_compare ( const struct asn1_cursor *cursor1,
424  const struct asn1_cursor *cursor2 );
425 extern int asn1_algorithm ( const struct asn1_cursor *cursor,
426  struct asn1_algorithm **algorithm );
427 extern int asn1_pubkey_algorithm ( const struct asn1_cursor *cursor,
428  struct asn1_algorithm **algorithm );
429 extern int asn1_digest_algorithm ( const struct asn1_cursor *cursor,
430  struct asn1_algorithm **algorithm );
431 extern int asn1_signature_algorithm ( const struct asn1_cursor *cursor,
432  struct asn1_algorithm **algorithm );
433 extern int asn1_check_algorithm ( const struct asn1_cursor *cursor,
434  struct asn1_algorithm *expected );
435 extern int asn1_generalized_time ( const struct asn1_cursor *cursor,
436  time_t *time );
437 extern int asn1_grow ( struct asn1_builder *builder, size_t extra );
438 extern int asn1_prepend_raw ( struct asn1_builder *builder, const void *data,
439  size_t len );
440 extern int asn1_prepend ( struct asn1_builder *builder, unsigned int type,
441  const void *data, size_t len );
442 extern int asn1_wrap ( struct asn1_builder *builder, unsigned int type );
443 
444 #endif /* _IPXE_ASN1_H */
#define __attribute__(x)
Definition: compiler.h:10
const void * data
Data.
Definition: asn1.h:356
An ASN.1 OID-identified algorithm.
Definition: asn1.h:311
void * data
Data.
Definition: asn1.h:35
uint8_t extra
Signature extra byte.
Definition: smbios.h:17
int asn1_digest_algorithm(const struct asn1_cursor *cursor, struct asn1_algorithm **algorithm)
Parse ASN.1 OID-identified digest algorithm.
Definition: asn1.c:539
int asn1_generalized_time(const struct asn1_cursor *cursor, time_t *time)
Parse ASN.1 GeneralizedTime.
Definition: asn1.c:629
#define ASN1_END
ASN.1 end.
Definition: asn1.h:56
int asn1_boolean(const struct asn1_cursor *cursor)
Parse value of ASN.1 boolean.
Definition: asn1.c:296
const void * data
Start of data.
Definition: asn1.h:22
int asn1_skip(struct asn1_cursor *cursor, unsigned int type)
Skip ASN.1 object.
Definition: asn1.c:218
#define __asn1_algorithm
Declare an ASN.1 OID-identified algorithm.
Definition: asn1.h:328
int asn1_prepend_raw(struct asn1_builder *builder, const void *data, size_t len)
Prepend raw data to ASN.1 builder.
Definition: asn1.c:801
int asn1_enter(struct asn1_cursor *cursor, unsigned int type)
Enter ASN.1 object.
Definition: asn1.c:160
uint8_t length[ASN1_MAX_LEN_LEN]
Length (encoded)
Definition: asn1.h:52
static unsigned int asn1_type(const struct asn1_cursor *cursor)
Extract ASN.1 type.
Definition: asn1.h:380
int asn1_integral_bit_string(const struct asn1_cursor *cursor, struct asn1_bit_string *bits)
Parse ASN.1 bit string that must be an integral number of bytes.
Definition: asn1.c:414
uint8_t type
Type.
Definition: asn1.h:50
int asn1_shrink(struct asn1_cursor *cursor, unsigned int type)
Shrink ASN.1 cursor to fit object.
Definition: asn1.c:240
size_t len
Length of data.
Definition: asn1.h:24
int asn1_skip_if_exists(struct asn1_cursor *cursor, unsigned int type)
Skip ASN.1 object if present.
Definition: asn1.c:187
struct pubkey_algorithm * pubkey
Public-key algorithm (if applicable)
Definition: asn1.h:317
int asn1_shrink_any(struct asn1_cursor *cursor)
Shrink ASN.1 object of any type.
Definition: asn1.c:286
int asn1_prepend(struct asn1_builder *builder, unsigned int type, const void *data, size_t len)
Prepend data to ASN.1 builder.
Definition: asn1.c:824
Assertions.
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
int asn1_pubkey_algorithm(const struct asn1_cursor *cursor, struct asn1_algorithm **algorithm)
Parse ASN.1 OID-identified public-key algorithm.
Definition: asn1.c:513
#define build_assert(condition)
Assert a condition at build time (after dead code elimination)
Definition: assert.h:76
#define ASN1_MAX_LEN_LEN
Maximum (viable) length of ASN.1 length.
Definition: asn1.h:45
int asn1_compare(const struct asn1_cursor *cursor1, const struct asn1_cursor *cursor2)
Compare two ASN.1 objects.
Definition: asn1.c:443
unsigned int unused
Unused bits at end of data.
Definition: asn1.h:360
int asn1_wrap(struct asn1_builder *builder, unsigned int type)
Wrap ASN.1 builder.
Definition: asn1.c:851
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
int asn1_signature_algorithm(const struct asn1_cursor *cursor, struct asn1_algorithm **algorithm)
Parse ASN.1 OID-identified signature algorithm.
Definition: asn1.c:565
static void asn1_invalidate_cursor(struct asn1_cursor *cursor)
Invalidate ASN.1 object cursor.
Definition: asn1.h:369
size_t len
Length.
Definition: asn1.h:358
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
struct elliptic_curve * curve
Elliptic curve (if applicable)
Definition: asn1.h:321
An ASN.1 object builder.
Definition: asn1.h:28
int asn1_bit_string(const struct asn1_cursor *cursor, struct asn1_bit_string *bits)
Parse ASN.1 bit string.
Definition: asn1.c:359
unsigned char uint8_t
Definition: stdint.h:10
struct asn1_cursor oid
Object identifier.
Definition: asn1.h:315
int asn1_integer(const struct asn1_cursor *cursor, int *value)
Parse value of ASN.1 integer.
Definition: asn1.c:320
int asn1_check_algorithm(const struct asn1_cursor *cursor, struct asn1_algorithm *expected)
Check ASN.1 OID-identified algorithm.
Definition: asn1.c:599
int asn1_start(struct asn1_cursor *cursor, unsigned int type, size_t extra)
Start parsing ASN.1 object.
Definition: asn1.c:98
int asn1_skip_any(struct asn1_cursor *cursor)
Skip ASN.1 object of any type.
Definition: asn1.c:276
An ASN.1 header.
Definition: asn1.h:48
u16 algorithm
Authentication algorithm (Open System or Shared Key)
Definition: ieee80211.h:1030
const char * name
Name.
Definition: asn1.h:313
An elliptic curve.
Definition: crypto.h:199
static volatile void * bits
Definition: bitops.h:27
uint32_t len
Length.
Definition: ena.h:14
uint32_t type
Operating system type.
Definition: ena.h:12
struct digest_algorithm * digest
Digest algorithm (if applicable)
Definition: asn1.h:319
int asn1_grow(struct asn1_builder *builder, size_t extra)
Grow ASN.1 builder.
Definition: asn1.c:768
int asn1_algorithm(const struct asn1_cursor *cursor, struct asn1_algorithm **algorithm)
Parse ASN.1 OID-identified algorithm.
Definition: asn1.c:478
A message digest algorithm.
Definition: crypto.h:17
union @17 u
uint8_t data[48]
Additional event data.
Definition: ena.h:22
Linker tables.
static struct asn1_cursor * asn1_built(struct asn1_builder *builder)
Get cursor for built object.
Definition: asn1.h:393
typeof(acpi_finder=acpi_find)
ACPI table finder.
Definition: acpi.c:45
int64_t time_t
Seconds since the Epoch.
Definition: time.h:18
Time source.
uint64_t time
Current time.
Definition: ntlm.h:20
size_t len
Length of data.
Definition: asn1.h:37
An ASN.1 object cursor.
Definition: asn1.h:20
A public key algorithm.
Definition: crypto.h:120
An ASN.1 bit string.
Definition: asn1.h:354
int asn1_enter_any(struct asn1_cursor *cursor)
Enter ASN.1 object of any type.
Definition: asn1.c:266