iPXE
Data Structures | Macros | Functions | Variables
asn1.h File Reference

ASN.1 encoding. More...

#include <stddef.h>
#include <stdint.h>
#include <assert.h>
#include <time.h>
#include <ipxe/tables.h>

Go to the source code of this file.

Data Structures

struct  asn1_cursor
 An ASN.1 object cursor. More...
 
struct  asn1_builder
 An ASN.1 object builder. More...
 
struct  asn1_builder_header
 An ASN.1 header. More...
 
struct  asn1_algorithm
 An ASN.1 OID-identified algorithm. More...
 
struct  asn1_bit_string
 An ASN.1 bit string. More...
 

Macros

#define ASN1_MAX_LEN_LEN   ( 1 + sizeof ( size_t ) )
 Maximum (viable) length of ASN.1 length. More...
 
#define ASN1_END   0x00
 ASN.1 end. More...
 
#define ASN1_BOOLEAN   0x01
 ASN.1 boolean. More...
 
#define ASN1_INTEGER   0x02
 ASN.1 integer. More...
 
#define ASN1_BIT_STRING   0x03
 ASN.1 bit string. More...
 
#define ASN1_OCTET_STRING   0x04
 ASN.1 octet string. More...
 
#define ASN1_NULL   0x05
 ASN.1 null. More...
 
#define ASN1_OID   0x06
 ASN.1 object identifier. More...
 
#define ASN1_ENUMERATED   0x0a
 ASN.1 enumeration. More...
 
#define ASN1_UTC_TIME   0x17
 ASN.1 UTC time. More...
 
#define ASN1_GENERALIZED_TIME   0x18
 ASN.1 generalized time. More...
 
#define ASN1_SEQUENCE   0x30
 ASN.1 sequence. More...
 
#define ASN1_SET   0x31
 ASN.1 set. More...
 
#define ASN1_IMPLICIT_TAG(number)   ( 0x80 | (number) )
 ASN.1 implicit tag. More...
 
#define ASN1_EXPLICIT_TAG(number)   ( 0xa0 | (number) )
 ASN.1 explicit tag. More...
 
#define ASN1_ANY   -1U
 ASN.1 "any tag" magic value. More...
 
#define ASN1_OID_INITIAL(first, second)   ( ( (first) * 40 ) + (second) )
 Initial OID byte. More...
 
#define ASN1_OID_SINGLE(value)   ( (value) & 0x7f )
 Single-byte OID value. More...
 
#define ASN1_OID_DOUBLE(value)   ( 0x80 | ( ( (value) >> 7 ) & 0x7f ) ), ASN1_OID_SINGLE ( (value) )
 Double-byte OID value. More...
 
#define ASN1_OID_TRIPLE(value)   ( 0x80 | ( ( (value) >> 14 ) & 0x7f ) ), ASN1_OID_DOUBLE ( (value) )
 Double-byte OID value. More...
 
#define ASN1_OID_RSAENCRYPTION
 ASN.1 OID for rsaEncryption (1.2.840.113549.1.1.1) More...
 
#define ASN1_OID_MD5WITHRSAENCRYPTION
 ASN.1 OID for md5WithRSAEncryption (1.2.840.113549.1.1.4) More...
 
#define ASN1_OID_SHA1WITHRSAENCRYPTION
 ASN.1 OID for sha1WithRSAEncryption (1.2.840.113549.1.1.5) More...
 
#define ASN1_OID_SHA256WITHRSAENCRYPTION
 ASN.1 OID for sha256WithRSAEncryption (1.2.840.113549.1.1.11) More...
 
#define ASN1_OID_SHA384WITHRSAENCRYPTION
 ASN.1 OID for sha384WithRSAEncryption (1.2.840.113549.1.1.12) More...
 
#define ASN1_OID_SHA512WITHRSAENCRYPTION
 ASN.1 OID for sha512WithRSAEncryption (1.2.840.113549.1.1.13) More...
 
#define ASN1_OID_SHA224WITHRSAENCRYPTION
 ASN.1 OID for sha224WithRSAEncryption (1.2.840.113549.1.1.14) More...
 
#define ASN1_OID_MD4
 ASN.1 OID for id-md4 (1.2.840.113549.2.4) More...
 
#define ASN1_OID_MD5
 ASN.1 OID for id-md5 (1.2.840.113549.2.5) More...
 
#define ASN1_OID_SHA1
 ASN.1 OID for id-sha1 (1.3.14.3.2.26) More...
 
#define ASN1_OID_SHA256
 ASN.1 OID for id-sha256 (2.16.840.1.101.3.4.2.1) More...
 
#define ASN1_OID_SHA384
 ASN.1 OID for id-sha384 (2.16.840.1.101.3.4.2.2) More...
 
#define ASN1_OID_SHA512
 ASN.1 OID for id-sha512 (2.16.840.1.101.3.4.2.3) More...
 
#define ASN1_OID_SHA224
 ASN.1 OID for id-sha224 (2.16.840.1.101.3.4.2.4) More...
 
#define ASN1_OID_SHA512_224
 ASN.1 OID for id-sha512-224 (2.16.840.1.101.3.4.2.5) More...
 
#define ASN1_OID_SHA512_256
 ASN.1 OID for id-sha512-256 (2.16.840.1.101.3.4.2.6) More...
 
#define ASN1_OID_COMMON_NAME
 ASN.1 OID for commonName (2.5.4.3) More...
 
#define ASN1_OID_KEYUSAGE
 ASN.1 OID for id-ce-keyUsage (2.5.29.15) More...
 
#define ASN1_OID_BASICCONSTRAINTS
 ASN.1 OID for id-ce-basicConstraints (2.5.29.19) More...
 
#define ASN1_OID_EXTKEYUSAGE
 ASN.1 OID for id-ce-extKeyUsage (2.5.29.37) More...
 
#define ASN1_OID_CODESIGNING
 ASN.1 OID for id-kp-codeSigning (1.3.6.1.5.5.7.3.3) More...
 
#define ASN1_OID_SIGNEDDATA
 ASN.1 OID for pkcs-signedData (1.2.840.113549.1.7.2) More...
 
#define ASN1_OID_AUTHORITYINFOACCESS
 ASN.1 OID for id-pe-authorityInfoAccess (1.3.6.1.5.5.7.1.1) More...
 
#define ASN1_OID_OCSP
 ASN.1 OID for id-ad-ocsp (1.3.6.1.5.5.7.48.1) More...
 
#define ASN1_OID_OCSP_BASIC
 ASN.1 OID for id-pkix-ocsp-basic ( 1.3.6.1.5.5.7.48.1.1) More...
 
#define ASN1_OID_OCSPSIGNING
 ASN.1 OID for id-kp-OCSPSigning (1.3.6.1.5.5.7.3.9) More...
 
#define ASN1_OID_SUBJECTALTNAME
 ASN.1 OID for id-ce-subjectAltName (2.5.29.17) More...
 
#define ASN1_OID_CURSOR(oid_value)
 Define an ASN.1 cursor containing an OID. More...
 
#define ASN1_ALGORITHMS   __table ( struct asn1_algorithm, "asn1_algorithms" )
 ASN.1 OID-identified algorithms. More...
 
#define __asn1_algorithm   __table_entry ( ASN1_ALGORITHMS, 01 )
 Declare an ASN.1 OID-identified algorithm. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static void asn1_invalidate_cursor (struct asn1_cursor *cursor)
 Invalidate ASN.1 object cursor. More...
 
static unsigned int asn1_type (const struct asn1_cursor *cursor)
 Extract ASN.1 type. More...
 
static struct asn1_cursorasn1_built (struct asn1_builder *builder)
 Get cursor for built object. More...
 
int asn1_start (struct asn1_cursor *cursor, unsigned int type, size_t extra)
 Start parsing ASN.1 object. More...
 
int asn1_enter (struct asn1_cursor *cursor, unsigned int type)
 Enter ASN.1 object. More...
 
int asn1_skip_if_exists (struct asn1_cursor *cursor, unsigned int type)
 Skip ASN.1 object if present. More...
 
int asn1_skip (struct asn1_cursor *cursor, unsigned int type)
 Skip ASN.1 object. More...
 
int asn1_shrink (struct asn1_cursor *cursor, unsigned int type)
 Shrink ASN.1 cursor to fit object. More...
 
int asn1_enter_any (struct asn1_cursor *cursor)
 Enter ASN.1 object of any type. More...
 
int asn1_skip_any (struct asn1_cursor *cursor)
 Skip ASN.1 object of any type. More...
 
int asn1_shrink_any (struct asn1_cursor *cursor)
 Shrink ASN.1 object of any type. More...
 
int asn1_boolean (const struct asn1_cursor *cursor)
 Parse value of ASN.1 boolean. More...
 
int asn1_integer (const struct asn1_cursor *cursor, int *value)
 Parse value of ASN.1 integer. More...
 
int asn1_bit_string (const struct asn1_cursor *cursor, struct asn1_bit_string *bits)
 Parse ASN.1 bit string. More...
 
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. More...
 
int asn1_compare (const struct asn1_cursor *cursor1, const struct asn1_cursor *cursor2)
 Compare two ASN.1 objects. More...
 
int asn1_algorithm (const struct asn1_cursor *cursor, struct asn1_algorithm **algorithm)
 Parse ASN.1 OID-identified algorithm. More...
 
int asn1_pubkey_algorithm (const struct asn1_cursor *cursor, struct asn1_algorithm **algorithm)
 Parse ASN.1 OID-identified public-key algorithm. More...
 
int asn1_digest_algorithm (const struct asn1_cursor *cursor, struct asn1_algorithm **algorithm)
 Parse ASN.1 OID-identified digest algorithm. More...
 
int asn1_signature_algorithm (const struct asn1_cursor *cursor, struct asn1_algorithm **algorithm)
 Parse ASN.1 OID-identified signature algorithm. More...
 
int asn1_generalized_time (const struct asn1_cursor *cursor, time_t *time)
 Parse ASN.1 GeneralizedTime. More...
 
int asn1_grow (struct asn1_builder *builder, size_t extra)
 Grow ASN.1 builder. More...
 
int asn1_prepend_raw (struct asn1_builder *builder, const void *data, size_t len)
 Prepend raw data to ASN.1 builder. More...
 
int asn1_prepend (struct asn1_builder *builder, unsigned int type, const void *data, size_t len)
 Prepend data to ASN.1 builder. More...
 
int asn1_wrap (struct asn1_builder *builder, unsigned int type)
 Wrap ASN.1 builder. More...
 

Variables

struct asn1_algorithm rsa_encryption_algorithm __asn1_algorithm
 "md4" OID-identified algorithm More...
 

Detailed Description

ASN.1 encoding.

Definition in file asn1.h.

Macro Definition Documentation

◆ ASN1_MAX_LEN_LEN

#define ASN1_MAX_LEN_LEN   ( 1 + sizeof ( size_t ) )

Maximum (viable) length of ASN.1 length.

While in theory unlimited, this length is sufficient to contain a size_t.

Definition at line 44 of file asn1.h.

◆ ASN1_END

#define ASN1_END   0x00

ASN.1 end.

Definition at line 55 of file asn1.h.

◆ ASN1_BOOLEAN

#define ASN1_BOOLEAN   0x01

ASN.1 boolean.

Definition at line 58 of file asn1.h.

◆ ASN1_INTEGER

#define ASN1_INTEGER   0x02

ASN.1 integer.

Definition at line 61 of file asn1.h.

◆ ASN1_BIT_STRING

#define ASN1_BIT_STRING   0x03

ASN.1 bit string.

Definition at line 64 of file asn1.h.

◆ ASN1_OCTET_STRING

#define ASN1_OCTET_STRING   0x04

ASN.1 octet string.

Definition at line 67 of file asn1.h.

◆ ASN1_NULL

#define ASN1_NULL   0x05

ASN.1 null.

Definition at line 70 of file asn1.h.

◆ ASN1_OID

#define ASN1_OID   0x06

ASN.1 object identifier.

Definition at line 73 of file asn1.h.

◆ ASN1_ENUMERATED

#define ASN1_ENUMERATED   0x0a

ASN.1 enumeration.

Definition at line 76 of file asn1.h.

◆ ASN1_UTC_TIME

#define ASN1_UTC_TIME   0x17

ASN.1 UTC time.

Definition at line 79 of file asn1.h.

◆ ASN1_GENERALIZED_TIME

#define ASN1_GENERALIZED_TIME   0x18

ASN.1 generalized time.

Definition at line 82 of file asn1.h.

◆ ASN1_SEQUENCE

#define ASN1_SEQUENCE   0x30

ASN.1 sequence.

Definition at line 85 of file asn1.h.

◆ ASN1_SET

#define ASN1_SET   0x31

ASN.1 set.

Definition at line 88 of file asn1.h.

◆ ASN1_IMPLICIT_TAG

#define ASN1_IMPLICIT_TAG (   number)    ( 0x80 | (number) )

ASN.1 implicit tag.

Definition at line 91 of file asn1.h.

◆ ASN1_EXPLICIT_TAG

#define ASN1_EXPLICIT_TAG (   number)    ( 0xa0 | (number) )

ASN.1 explicit tag.

Definition at line 94 of file asn1.h.

◆ ASN1_ANY

#define ASN1_ANY   -1U

ASN.1 "any tag" magic value.

Definition at line 97 of file asn1.h.

◆ ASN1_OID_INITIAL

#define ASN1_OID_INITIAL (   first,
  second 
)    ( ( (first) * 40 ) + (second) )

Initial OID byte.

Definition at line 100 of file asn1.h.

◆ ASN1_OID_SINGLE

#define ASN1_OID_SINGLE (   value)    ( (value) & 0x7f )

Single-byte OID value.

Valid for values up to 127

Definition at line 106 of file asn1.h.

◆ ASN1_OID_DOUBLE

#define ASN1_OID_DOUBLE (   value)    ( 0x80 | ( ( (value) >> 7 ) & 0x7f ) ), ASN1_OID_SINGLE ( (value) )

Double-byte OID value.

Valid for values up to 16383

Definition at line 112 of file asn1.h.

◆ ASN1_OID_TRIPLE

#define ASN1_OID_TRIPLE (   value)    ( 0x80 | ( ( (value) >> 14 ) & 0x7f ) ), ASN1_OID_DOUBLE ( (value) )

Double-byte OID value.

Valid for values up to 2097151

Definition at line 119 of file asn1.h.

◆ ASN1_OID_RSAENCRYPTION

#define ASN1_OID_RSAENCRYPTION
Value:
ASN1_OID_INITIAL ( 1, 2 ), ASN1_OID_DOUBLE ( 840 ), \
ASN1_OID_TRIPLE ( 113549 ), ASN1_OID_SINGLE ( 1 ), \
ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 1 )
#define ASN1_OID_DOUBLE(value)
Double-byte OID value.
Definition: asn1.h:112
#define ASN1_OID_SINGLE(value)
Single-byte OID value.
Definition: asn1.h:106
#define ASN1_OID_INITIAL(first, second)
Initial OID byte.
Definition: asn1.h:100

ASN.1 OID for rsaEncryption (1.2.840.113549.1.1.1)

Definition at line 123 of file asn1.h.

◆ ASN1_OID_MD5WITHRSAENCRYPTION

#define ASN1_OID_MD5WITHRSAENCRYPTION
Value:
ASN1_OID_INITIAL ( 1, 2 ), ASN1_OID_DOUBLE ( 840 ), \
ASN1_OID_TRIPLE ( 113549 ), ASN1_OID_SINGLE ( 1 ), \
ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 4 )
#define ASN1_OID_DOUBLE(value)
Double-byte OID value.
Definition: asn1.h:112
#define ASN1_OID_SINGLE(value)
Single-byte OID value.
Definition: asn1.h:106
#define ASN1_OID_INITIAL(first, second)
Initial OID byte.
Definition: asn1.h:100

ASN.1 OID for md5WithRSAEncryption (1.2.840.113549.1.1.4)

Definition at line 129 of file asn1.h.

◆ ASN1_OID_SHA1WITHRSAENCRYPTION

#define ASN1_OID_SHA1WITHRSAENCRYPTION
Value:
ASN1_OID_INITIAL ( 1, 2 ), ASN1_OID_DOUBLE ( 840 ), \
ASN1_OID_TRIPLE ( 113549 ), ASN1_OID_SINGLE ( 1 ), \
ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 5 )
#define ASN1_OID_DOUBLE(value)
Double-byte OID value.
Definition: asn1.h:112
#define ASN1_OID_SINGLE(value)
Single-byte OID value.
Definition: asn1.h:106
#define ASN1_OID_INITIAL(first, second)
Initial OID byte.
Definition: asn1.h:100

ASN.1 OID for sha1WithRSAEncryption (1.2.840.113549.1.1.5)

Definition at line 135 of file asn1.h.

◆ ASN1_OID_SHA256WITHRSAENCRYPTION

#define ASN1_OID_SHA256WITHRSAENCRYPTION
Value:
ASN1_OID_INITIAL ( 1, 2 ), ASN1_OID_DOUBLE ( 840 ), \
ASN1_OID_TRIPLE ( 113549 ), ASN1_OID_SINGLE ( 1 ), \
ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 11 )
#define ASN1_OID_DOUBLE(value)
Double-byte OID value.
Definition: asn1.h:112
#define ASN1_OID_SINGLE(value)
Single-byte OID value.
Definition: asn1.h:106
#define ASN1_OID_INITIAL(first, second)
Initial OID byte.
Definition: asn1.h:100

ASN.1 OID for sha256WithRSAEncryption (1.2.840.113549.1.1.11)

Definition at line 141 of file asn1.h.

◆ ASN1_OID_SHA384WITHRSAENCRYPTION

#define ASN1_OID_SHA384WITHRSAENCRYPTION
Value:
ASN1_OID_INITIAL ( 1, 2 ), ASN1_OID_DOUBLE ( 840 ), \
ASN1_OID_TRIPLE ( 113549 ), ASN1_OID_SINGLE ( 1 ), \
ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 12 )
#define ASN1_OID_DOUBLE(value)
Double-byte OID value.
Definition: asn1.h:112
#define ASN1_OID_SINGLE(value)
Single-byte OID value.
Definition: asn1.h:106
#define ASN1_OID_INITIAL(first, second)
Initial OID byte.
Definition: asn1.h:100

ASN.1 OID for sha384WithRSAEncryption (1.2.840.113549.1.1.12)

Definition at line 147 of file asn1.h.

◆ ASN1_OID_SHA512WITHRSAENCRYPTION

#define ASN1_OID_SHA512WITHRSAENCRYPTION
Value:
ASN1_OID_INITIAL ( 1, 2 ), ASN1_OID_DOUBLE ( 840 ), \
ASN1_OID_TRIPLE ( 113549 ), ASN1_OID_SINGLE ( 1 ), \
ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 13 )
#define ASN1_OID_DOUBLE(value)
Double-byte OID value.
Definition: asn1.h:112
#define ASN1_OID_SINGLE(value)
Single-byte OID value.
Definition: asn1.h:106
#define ASN1_OID_INITIAL(first, second)
Initial OID byte.
Definition: asn1.h:100

ASN.1 OID for sha512WithRSAEncryption (1.2.840.113549.1.1.13)

Definition at line 153 of file asn1.h.

◆ ASN1_OID_SHA224WITHRSAENCRYPTION

#define ASN1_OID_SHA224WITHRSAENCRYPTION
Value:
ASN1_OID_INITIAL ( 1, 2 ), ASN1_OID_DOUBLE ( 840 ), \
ASN1_OID_TRIPLE ( 113549 ), ASN1_OID_SINGLE ( 1 ), \
ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 14 )
#define ASN1_OID_DOUBLE(value)
Double-byte OID value.
Definition: asn1.h:112
#define ASN1_OID_SINGLE(value)
Single-byte OID value.
Definition: asn1.h:106
#define ASN1_OID_INITIAL(first, second)
Initial OID byte.
Definition: asn1.h:100

ASN.1 OID for sha224WithRSAEncryption (1.2.840.113549.1.1.14)

Definition at line 159 of file asn1.h.

◆ ASN1_OID_MD4

#define ASN1_OID_MD4
Value:
ASN1_OID_INITIAL ( 1, 2 ), ASN1_OID_DOUBLE ( 840 ), \
ASN1_OID_TRIPLE ( 113549 ), ASN1_OID_SINGLE ( 2 ), \
ASN1_OID_SINGLE ( 4 )
#define ASN1_OID_DOUBLE(value)
Double-byte OID value.
Definition: asn1.h:112
#define ASN1_OID_SINGLE(value)
Single-byte OID value.
Definition: asn1.h:106
#define ASN1_OID_INITIAL(first, second)
Initial OID byte.
Definition: asn1.h:100

ASN.1 OID for id-md4 (1.2.840.113549.2.4)

Definition at line 165 of file asn1.h.

◆ ASN1_OID_MD5

#define ASN1_OID_MD5
Value:
ASN1_OID_INITIAL ( 1, 2 ), ASN1_OID_DOUBLE ( 840 ), \
ASN1_OID_TRIPLE ( 113549 ), ASN1_OID_SINGLE ( 2 ), \
ASN1_OID_SINGLE ( 5 )
#define ASN1_OID_DOUBLE(value)
Double-byte OID value.
Definition: asn1.h:112
#define ASN1_OID_SINGLE(value)
Single-byte OID value.
Definition: asn1.h:106
#define ASN1_OID_INITIAL(first, second)
Initial OID byte.
Definition: asn1.h:100

ASN.1 OID for id-md5 (1.2.840.113549.2.5)

Definition at line 171 of file asn1.h.

◆ ASN1_OID_SHA1

#define ASN1_OID_SHA1
Value:
ASN1_OID_INITIAL ( 1, 3 ), ASN1_OID_SINGLE ( 14 ), \
ASN1_OID_SINGLE ( 3 ), ASN1_OID_SINGLE ( 2 ), \
ASN1_OID_SINGLE ( 26 )
#define ASN1_OID_SINGLE(value)
Single-byte OID value.
Definition: asn1.h:106
#define ASN1_OID_INITIAL(first, second)
Initial OID byte.
Definition: asn1.h:100

ASN.1 OID for id-sha1 (1.3.14.3.2.26)

Definition at line 177 of file asn1.h.

◆ ASN1_OID_SHA256

#define ASN1_OID_SHA256
Value:
ASN1_OID_INITIAL ( 2, 16 ), ASN1_OID_DOUBLE ( 840 ), \
ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 101 ), \
ASN1_OID_SINGLE ( 3 ), ASN1_OID_SINGLE ( 4 ), \
ASN1_OID_SINGLE ( 2 ), ASN1_OID_SINGLE ( 1 )
#define ASN1_OID_DOUBLE(value)
Double-byte OID value.
Definition: asn1.h:112
#define ASN1_OID_SINGLE(value)
Single-byte OID value.
Definition: asn1.h:106
#define ASN1_OID_INITIAL(first, second)
Initial OID byte.
Definition: asn1.h:100

ASN.1 OID for id-sha256 (2.16.840.1.101.3.4.2.1)

Definition at line 183 of file asn1.h.

◆ ASN1_OID_SHA384

#define ASN1_OID_SHA384
Value:
ASN1_OID_INITIAL ( 2, 16 ), ASN1_OID_DOUBLE ( 840 ), \
ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 101 ), \
ASN1_OID_SINGLE ( 3 ), ASN1_OID_SINGLE ( 4 ), \
ASN1_OID_SINGLE ( 2 ), ASN1_OID_SINGLE ( 2 )
#define ASN1_OID_DOUBLE(value)
Double-byte OID value.
Definition: asn1.h:112
#define ASN1_OID_SINGLE(value)
Single-byte OID value.
Definition: asn1.h:106
#define ASN1_OID_INITIAL(first, second)
Initial OID byte.
Definition: asn1.h:100

ASN.1 OID for id-sha384 (2.16.840.1.101.3.4.2.2)

Definition at line 190 of file asn1.h.

◆ ASN1_OID_SHA512

#define ASN1_OID_SHA512
Value:
ASN1_OID_INITIAL ( 2, 16 ), ASN1_OID_DOUBLE ( 840 ), \
ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 101 ), \
ASN1_OID_SINGLE ( 3 ), ASN1_OID_SINGLE ( 4 ), \
ASN1_OID_SINGLE ( 2 ), ASN1_OID_SINGLE ( 3 )
#define ASN1_OID_DOUBLE(value)
Double-byte OID value.
Definition: asn1.h:112
#define ASN1_OID_SINGLE(value)
Single-byte OID value.
Definition: asn1.h:106
#define ASN1_OID_INITIAL(first, second)
Initial OID byte.
Definition: asn1.h:100

ASN.1 OID for id-sha512 (2.16.840.1.101.3.4.2.3)

Definition at line 197 of file asn1.h.

◆ ASN1_OID_SHA224

#define ASN1_OID_SHA224
Value:
ASN1_OID_INITIAL ( 2, 16 ), ASN1_OID_DOUBLE ( 840 ), \
ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 101 ), \
ASN1_OID_SINGLE ( 3 ), ASN1_OID_SINGLE ( 4 ), \
ASN1_OID_SINGLE ( 2 ), ASN1_OID_SINGLE ( 4 )
#define ASN1_OID_DOUBLE(value)
Double-byte OID value.
Definition: asn1.h:112
#define ASN1_OID_SINGLE(value)
Single-byte OID value.
Definition: asn1.h:106
#define ASN1_OID_INITIAL(first, second)
Initial OID byte.
Definition: asn1.h:100

ASN.1 OID for id-sha224 (2.16.840.1.101.3.4.2.4)

Definition at line 204 of file asn1.h.

◆ ASN1_OID_SHA512_224

#define ASN1_OID_SHA512_224
Value:
ASN1_OID_INITIAL ( 2, 16 ), ASN1_OID_DOUBLE ( 840 ), \
ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 101 ), \
ASN1_OID_SINGLE ( 3 ), ASN1_OID_SINGLE ( 4 ), \
ASN1_OID_SINGLE ( 2 ), ASN1_OID_SINGLE ( 5 )
#define ASN1_OID_DOUBLE(value)
Double-byte OID value.
Definition: asn1.h:112
#define ASN1_OID_SINGLE(value)
Single-byte OID value.
Definition: asn1.h:106
#define ASN1_OID_INITIAL(first, second)
Initial OID byte.
Definition: asn1.h:100

ASN.1 OID for id-sha512-224 (2.16.840.1.101.3.4.2.5)

Definition at line 211 of file asn1.h.

◆ ASN1_OID_SHA512_256

#define ASN1_OID_SHA512_256
Value:
ASN1_OID_INITIAL ( 2, 16 ), ASN1_OID_DOUBLE ( 840 ), \
ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 101 ), \
ASN1_OID_SINGLE ( 3 ), ASN1_OID_SINGLE ( 4 ), \
ASN1_OID_SINGLE ( 2 ), ASN1_OID_SINGLE ( 6 )
#define ASN1_OID_DOUBLE(value)
Double-byte OID value.
Definition: asn1.h:112
#define ASN1_OID_SINGLE(value)
Single-byte OID value.
Definition: asn1.h:106
#define ASN1_OID_INITIAL(first, second)
Initial OID byte.
Definition: asn1.h:100

ASN.1 OID for id-sha512-256 (2.16.840.1.101.3.4.2.6)

Definition at line 218 of file asn1.h.

◆ ASN1_OID_COMMON_NAME

#define ASN1_OID_COMMON_NAME
Value:
ASN1_OID_SINGLE ( 3 )
#define ASN1_OID_SINGLE(value)
Single-byte OID value.
Definition: asn1.h:106
#define ASN1_OID_INITIAL(first, second)
Initial OID byte.
Definition: asn1.h:100

ASN.1 OID for commonName (2.5.4.3)

Definition at line 225 of file asn1.h.

◆ ASN1_OID_KEYUSAGE

#define ASN1_OID_KEYUSAGE
Value:
ASN1_OID_INITIAL ( 2, 5 ), ASN1_OID_SINGLE ( 29 ), \
ASN1_OID_SINGLE ( 15 )
#define ASN1_OID_SINGLE(value)
Single-byte OID value.
Definition: asn1.h:106
#define ASN1_OID_INITIAL(first, second)
Initial OID byte.
Definition: asn1.h:100

ASN.1 OID for id-ce-keyUsage (2.5.29.15)

Definition at line 230 of file asn1.h.

◆ ASN1_OID_BASICCONSTRAINTS

#define ASN1_OID_BASICCONSTRAINTS
Value:
ASN1_OID_INITIAL ( 2, 5 ), ASN1_OID_SINGLE ( 29 ), \
ASN1_OID_SINGLE ( 19 )
#define ASN1_OID_SINGLE(value)
Single-byte OID value.
Definition: asn1.h:106
#define ASN1_OID_INITIAL(first, second)
Initial OID byte.
Definition: asn1.h:100

ASN.1 OID for id-ce-basicConstraints (2.5.29.19)

Definition at line 235 of file asn1.h.

◆ ASN1_OID_EXTKEYUSAGE

#define ASN1_OID_EXTKEYUSAGE
Value:
ASN1_OID_INITIAL ( 2, 5 ), ASN1_OID_SINGLE ( 29 ), \
ASN1_OID_SINGLE ( 37 )
#define ASN1_OID_SINGLE(value)
Single-byte OID value.
Definition: asn1.h:106
#define ASN1_OID_INITIAL(first, second)
Initial OID byte.
Definition: asn1.h:100

ASN.1 OID for id-ce-extKeyUsage (2.5.29.37)

Definition at line 240 of file asn1.h.

◆ ASN1_OID_CODESIGNING

#define ASN1_OID_CODESIGNING
Value:
ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 5 ), \
ASN1_OID_SINGLE ( 5 ), ASN1_OID_SINGLE ( 7 ), \
ASN1_OID_SINGLE ( 3 ), ASN1_OID_SINGLE ( 3 )
#define ASN1_OID_SINGLE(value)
Single-byte OID value.
Definition: asn1.h:106
#define ASN1_OID_INITIAL(first, second)
Initial OID byte.
Definition: asn1.h:100

ASN.1 OID for id-kp-codeSigning (1.3.6.1.5.5.7.3.3)

Definition at line 245 of file asn1.h.

◆ ASN1_OID_SIGNEDDATA

#define ASN1_OID_SIGNEDDATA
Value:
ASN1_OID_INITIAL ( 1, 2 ), ASN1_OID_DOUBLE ( 840 ), \
ASN1_OID_TRIPLE ( 113549 ), ASN1_OID_SINGLE ( 1 ), \
ASN1_OID_SINGLE ( 7 ), ASN1_OID_SINGLE ( 2 )
#define ASN1_OID_DOUBLE(value)
Double-byte OID value.
Definition: asn1.h:112
#define ASN1_OID_SINGLE(value)
Single-byte OID value.
Definition: asn1.h:106
#define ASN1_OID_INITIAL(first, second)
Initial OID byte.
Definition: asn1.h:100

ASN.1 OID for pkcs-signedData (1.2.840.113549.1.7.2)

Definition at line 252 of file asn1.h.

◆ ASN1_OID_AUTHORITYINFOACCESS

#define ASN1_OID_AUTHORITYINFOACCESS
Value:
ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 5 ), \
ASN1_OID_SINGLE ( 5 ), ASN1_OID_SINGLE ( 7 ), \
ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 1 )
#define ASN1_OID_SINGLE(value)
Single-byte OID value.
Definition: asn1.h:106
#define ASN1_OID_INITIAL(first, second)
Initial OID byte.
Definition: asn1.h:100

ASN.1 OID for id-pe-authorityInfoAccess (1.3.6.1.5.5.7.1.1)

Definition at line 258 of file asn1.h.

◆ ASN1_OID_OCSP

#define ASN1_OID_OCSP
Value:
ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 5 ), \
ASN1_OID_SINGLE ( 5 ), ASN1_OID_SINGLE ( 7 ), \
ASN1_OID_SINGLE ( 48 ), ASN1_OID_SINGLE ( 1 )
#define ASN1_OID_SINGLE(value)
Single-byte OID value.
Definition: asn1.h:106
#define ASN1_OID_INITIAL(first, second)
Initial OID byte.
Definition: asn1.h:100

ASN.1 OID for id-ad-ocsp (1.3.6.1.5.5.7.48.1)

Definition at line 265 of file asn1.h.

◆ ASN1_OID_OCSP_BASIC

#define ASN1_OID_OCSP_BASIC
Value:
ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 5 ), \
ASN1_OID_SINGLE ( 5 ), ASN1_OID_SINGLE ( 7 ), \
ASN1_OID_SINGLE ( 48 ), ASN1_OID_SINGLE ( 1 ), \
ASN1_OID_SINGLE ( 1 )
#define ASN1_OID_SINGLE(value)
Single-byte OID value.
Definition: asn1.h:106
#define ASN1_OID_INITIAL(first, second)
Initial OID byte.
Definition: asn1.h:100

ASN.1 OID for id-pkix-ocsp-basic ( 1.3.6.1.5.5.7.48.1.1)

Definition at line 272 of file asn1.h.

◆ ASN1_OID_OCSPSIGNING

#define ASN1_OID_OCSPSIGNING
Value:
ASN1_OID_SINGLE ( 1 ), ASN1_OID_SINGLE ( 5 ), \
ASN1_OID_SINGLE ( 5 ), ASN1_OID_SINGLE ( 7 ), \
ASN1_OID_SINGLE ( 3 ), ASN1_OID_SINGLE ( 9 )
#define ASN1_OID_SINGLE(value)
Single-byte OID value.
Definition: asn1.h:106
#define ASN1_OID_INITIAL(first, second)
Initial OID byte.
Definition: asn1.h:100

ASN.1 OID for id-kp-OCSPSigning (1.3.6.1.5.5.7.3.9)

Definition at line 280 of file asn1.h.

◆ ASN1_OID_SUBJECTALTNAME

#define ASN1_OID_SUBJECTALTNAME
Value:
ASN1_OID_INITIAL ( 2, 5 ), ASN1_OID_SINGLE ( 29 ), \
ASN1_OID_SINGLE ( 17 )
#define ASN1_OID_SINGLE(value)
Single-byte OID value.
Definition: asn1.h:106
#define ASN1_OID_INITIAL(first, second)
Initial OID byte.
Definition: asn1.h:100

ASN.1 OID for id-ce-subjectAltName (2.5.29.17)

Definition at line 287 of file asn1.h.

◆ ASN1_OID_CURSOR

#define ASN1_OID_CURSOR (   oid_value)
Value:
{ \
.data = oid_value, \
.len = sizeof ( oid_value ), \
}

Define an ASN.1 cursor containing an OID.

Definition at line 292 of file asn1.h.

◆ ASN1_ALGORITHMS

#define ASN1_ALGORITHMS   __table ( struct asn1_algorithm, "asn1_algorithms" )

ASN.1 OID-identified algorithms.

Definition at line 310 of file asn1.h.

◆ __asn1_algorithm

struct asn1_algorithm oid_sha512_256_algorithm __asn1_algorithm   __table_entry ( ASN1_ALGORITHMS, 01 )

Declare an ASN.1 OID-identified algorithm.

Definition at line 313 of file asn1.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ asn1_invalidate_cursor()

static void asn1_invalidate_cursor ( struct asn1_cursor cursor)
inlinestatic

Invalidate ASN.1 object cursor.

Parameters
cursorASN.1 object cursor

Definition at line 354 of file asn1.h.

354  {
355  cursor->len = 0;
356 }
size_t len
Length of data.
Definition: asn1.h:23

References asn1_cursor::len.

Referenced by asn1_enter(), asn1_shrink(), and asn1_skip().

◆ asn1_type()

static unsigned int asn1_type ( const struct asn1_cursor cursor)
inlinestatic

Extract ASN.1 type.

Parameters
cursorASN.1 object cursor
Return values
typeType, or ASN1_END if cursor is invalid

Definition at line 365 of file asn1.h.

365  {
366  const uint8_t *type = cursor->data;
367 
368  return ( ( cursor->len >= sizeof ( *type ) ) ? *type : ASN1_END );
369 }
#define ASN1_END
ASN.1 end.
Definition: asn1.h:55
uint8_t type
Type.
Definition: ena.h:16
const void * data
Start of data.
Definition: asn1.h:21
size_t len
Length of data.
Definition: asn1.h:23
unsigned char uint8_t
Definition: stdint.h:10

References ASN1_END, asn1_cursor::data, asn1_cursor::len, and type.

Referenced by asn1_generalized_time(), asn1_start(), ocsp_parse_basic_response(), ocsp_parse_responder_id(), ocsp_parse_responses(), rsa_parse_mod_exp(), x509_check_alt_name(), x509_parse_basic_constraints(), x509_parse_extension(), and x509_parse_tbscertificate().

◆ asn1_built()

static struct asn1_cursor* asn1_built ( struct asn1_builder builder)
inlinestatic

Get cursor for built object.

Parameters
builderASN.1 object builder
Return values
cursorASN.1 object cursor

Definition at line 378 of file asn1.h.

378  {
379  union {
380  struct asn1_builder builder;
381  struct asn1_cursor cursor;
382  } *u = container_of ( builder, typeof ( *u ), builder );
383 
384  /* Sanity check */
385  linker_assert ( ( ( const void * ) &u->builder.data ) ==
386  &u->cursor.data, asn1_builder_cursor_data_mismatch );
387  linker_assert ( &u->builder.len == &u->cursor.len,
388  asn1_builder_cursor_len_mismatch );
389 
390  return &u->cursor;
391 }
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
An ASN.1 object builder.
Definition: asn1.h:27
union @17 u
#define linker_assert(condition, error_symbol)
Assert a condition at link-time.
Definition: assert.h:68
An ASN.1 object cursor.
Definition: asn1.h:19

References container_of, linker_assert, and u.

◆ asn1_start()

int asn1_start ( struct asn1_cursor cursor,
unsigned int  type,
size_t  extra 
)

Start parsing ASN.1 object.

Parameters
cursorASN.1 object cursor
typeExpected type, or ASN1_ANY
extraAdditional length not present within partial cursor
Return values
lenLength of object body, or negative error

The object cursor will be updated to point to the start of the object body (i.e. the first byte following the length byte(s)), and the length of the object body (i.e. the number of bytes until the following object tag, if any) is returned.

Definition at line 98 of file asn1.c.

98  {
99  unsigned int len_len;
100  unsigned int len;
101 
102  /* Sanity check */
103  if ( cursor->len < 2 /* Tag byte and first length byte */ ) {
104  if ( cursor->len )
105  DBGC ( cursor, "ASN1 %p too short\n", cursor );
106  return -EINVAL_ASN1_EMPTY;
107  }
108 
109  /* Check the tag byte */
110  if ( ( type != ASN1_ANY ) && ( type != asn1_type ( cursor ) ) ) {
111  DBGC ( cursor, "ASN1 %p type mismatch (expected %d, got %d)\n",
112  cursor, type, *( ( uint8_t * ) cursor->data ) );
113  return -ENXIO;
114  }
115  cursor->data++;
116  cursor->len--;
117 
118  /* Extract length of the length field and sanity check */
119  len_len = *( ( uint8_t * ) cursor->data );
120  if ( len_len & 0x80 ) {
121  len_len = ( len_len & 0x7f );
122  cursor->data++;
123  cursor->len--;
124  } else {
125  len_len = 1;
126  }
127  if ( cursor->len < len_len ) {
128  DBGC ( cursor, "ASN1 %p bad length field length %d (max "
129  "%zd)\n", cursor, len_len, cursor->len );
130  return -EINVAL_ASN1_LEN_LEN;
131  }
132 
133  /* Extract the length and sanity check */
134  for ( len = 0 ; len_len ; len_len-- ) {
135  len <<= 8;
136  len |= *( ( uint8_t * ) cursor->data );
137  cursor->data++;
138  cursor->len--;
139  }
140  if ( ( cursor->len + extra ) < len ) {
141  DBGC ( cursor, "ASN1 %p bad length %d (max %zd)\n",
142  cursor, len, ( cursor->len + extra ) );
143  return -EINVAL_ASN1_LEN;
144  }
145 
146  return len;
147 }
#define EINVAL_ASN1_LEN_LEN
Definition: asn1.c:48
uint8_t type
Type.
Definition: ena.h:16
const void * data
Start of data.
Definition: asn1.h:21
#define DBGC(...)
Definition: compiler.h:505
#define EINVAL_ASN1_LEN
Definition: asn1.c:52
static unsigned int asn1_type(const struct asn1_cursor *cursor)
Extract ASN.1 type.
Definition: asn1.h:365
#define ASN1_ANY
ASN.1 "any tag" magic value.
Definition: asn1.h:97
size_t len
Length of data.
Definition: asn1.h:23
unsigned char uint8_t
Definition: stdint.h:10
#define ENXIO
No such device or address.
Definition: errno.h:599
uint32_t len
Length.
Definition: ena.h:14
#define EINVAL_ASN1_EMPTY
Definition: asn1.c:44

References ASN1_ANY, asn1_type(), asn1_cursor::data, DBGC, EINVAL_ASN1_EMPTY, EINVAL_ASN1_LEN, EINVAL_ASN1_LEN_LEN, ENXIO, len, asn1_cursor::len, and type.

Referenced by asn1_enter(), asn1_shrink(), asn1_skip_if_exists(), and der_probe().

◆ asn1_enter()

int asn1_enter ( struct asn1_cursor cursor,
unsigned int  type 
)

Enter ASN.1 object.

Parameters
cursorASN.1 object cursor
typeExpected type, or ASN1_ANY
Return values
rcReturn status code

The object cursor will be updated to point to the body of the current ASN.1 object. If any error occurs, the object cursor will be invalidated.

Definition at line 160 of file asn1.c.

160  {
161  int len;
162 
163  len = asn1_start ( cursor, type, 0 );
164  if ( len < 0 ) {
165  asn1_invalidate_cursor ( cursor );
166  return len;
167  }
168 
169  cursor->len = len;
170  DBGC ( cursor, "ASN1 %p entered object type %02x (len %x)\n",
171  cursor, type, len );
172 
173  return 0;
174 }
uint8_t type
Type.
Definition: ena.h:16
#define DBGC(...)
Definition: compiler.h:505
int asn1_start(struct asn1_cursor *cursor, unsigned int type, size_t extra)
Start parsing ASN.1 object.
Definition: asn1.c:98
size_t len
Length of data.
Definition: asn1.h:23
static void asn1_invalidate_cursor(struct asn1_cursor *cursor)
Invalidate ASN.1 object cursor.
Definition: asn1.h:354
uint32_t len
Length.
Definition: ena.h:14

References asn1_invalidate_cursor(), asn1_start(), DBGC, len, asn1_cursor::len, and type.

Referenced by asn1_algorithm(), asn1_bit_string(), asn1_boolean(), asn1_enter_any(), asn1_generalized_time(), asn1_integer(), cms_parse(), cms_parse_certificates(), cms_parse_content_type(), cms_parse_signature_value(), cms_parse_signer_identifier(), cms_parse_signer_info(), ocsp_compare_responder_key_hash(), ocsp_parse_basic_response(), ocsp_parse_cert_id(), ocsp_parse_certs(), ocsp_parse_response(), ocsp_parse_response_bytes(), ocsp_parse_response_status(), ocsp_parse_response_type(), ocsp_parse_responses(), ocsp_parse_tbs_response_data(), ocsp_request(), rsa_parse_integer(), rsa_parse_mod_exp(), validator_append(), x509_parse(), x509_parse_access_description(), x509_parse_authority_info_access(), x509_parse_basic_constraints(), x509_parse_common_name(), x509_parse_extended_key_usage(), x509_parse_extension(), x509_parse_extensions(), x509_parse_key_purpose(), x509_parse_ocsp(), x509_parse_public_key(), x509_parse_subject_alt_name(), x509_parse_tbscertificate(), x509_parse_validity(), and x509_parse_version().

◆ asn1_skip_if_exists()

int asn1_skip_if_exists ( struct asn1_cursor cursor,
unsigned int  type 
)

Skip ASN.1 object if present.

Parameters
cursorASN.1 object cursor
typeExpected type, or ASN1_ANY
Return values
rcReturn status code

The object cursor will be updated to point to the next ASN.1 object. If any error occurs, the object cursor will not be modified.

Definition at line 187 of file asn1.c.

187  {
188  int len;
189 
190  len = asn1_start ( cursor, type, 0 );
191  if ( len < 0 )
192  return len;
193 
194  cursor->data += len;
195  cursor->len -= len;
196  DBGC ( cursor, "ASN1 %p skipped object type %02x (len %x)\n",
197  cursor, type, len );
198 
199  if ( ! cursor->len ) {
200  DBGC ( cursor, "ASN1 %p reached end of object\n", cursor );
201  return -ENOENT;
202  }
203 
204  return 0;
205 }
uint8_t type
Type.
Definition: ena.h:16
const void * data
Start of data.
Definition: asn1.h:21
#define DBGC(...)
Definition: compiler.h:505
#define ENOENT
No such file or directory.
Definition: errno.h:514
int asn1_start(struct asn1_cursor *cursor, unsigned int type, size_t extra)
Start parsing ASN.1 object.
Definition: asn1.c:98
size_t len
Length of data.
Definition: asn1.h:23
uint32_t len
Length.
Definition: ena.h:14

References asn1_start(), asn1_cursor::data, DBGC, ENOENT, len, asn1_cursor::len, and type.

Referenced by asn1_skip(), cms_parse(), cms_parse_signer_info(), and ocsp_parse_tbs_response_data().

◆ asn1_skip()

int asn1_skip ( struct asn1_cursor cursor,
unsigned int  type 
)

Skip ASN.1 object.

Parameters
cursorASN.1 object cursor
typeExpected type, or ASN1_ANY
Return values
rcReturn status code

The object cursor will be updated to point to the next ASN.1 object. If any error occurs, the object cursor will be invalidated.

Definition at line 218 of file asn1.c.

218  {
219  int rc;
220 
221  if ( ( rc = asn1_skip_if_exists ( cursor, type ) ) != 0 ) {
222  asn1_invalidate_cursor ( cursor );
223  return rc;
224  }
225 
226  return 0;
227 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t type
Type.
Definition: ena.h:16
static void asn1_invalidate_cursor(struct asn1_cursor *cursor)
Invalidate ASN.1 object cursor.
Definition: asn1.h:354
int asn1_skip_if_exists(struct asn1_cursor *cursor, unsigned int type)
Skip ASN.1 object if present.
Definition: asn1.c:187

References asn1_invalidate_cursor(), asn1_skip_if_exists(), rc, and type.

Referenced by asn1_skip_any(), cms_parse(), cms_parse_signer_info(), ocsp_parse_cert_id(), ocsp_request(), and rsa_parse_mod_exp().

◆ asn1_shrink()

int asn1_shrink ( struct asn1_cursor cursor,
unsigned int  type 
)

Shrink ASN.1 cursor to fit object.

Parameters
cursorASN.1 object cursor
typeExpected type, or ASN1_ANY
Return values
rcReturn status code

The object cursor will be shrunk to contain only the current ASN.1 object. If any error occurs, the object cursor will be invalidated.

Definition at line 240 of file asn1.c.

240  {
241  struct asn1_cursor temp;
242  const void *end;
243  int len;
244 
245  /* Find end of object */
246  memcpy ( &temp, cursor, sizeof ( temp ) );
247  len = asn1_start ( &temp, type, 0 );
248  if ( len < 0 ) {
249  asn1_invalidate_cursor ( cursor );
250  return len;
251  }
252  end = ( temp.data + len );
253 
254  /* Shrink original cursor to contain only its first object */
255  cursor->len = ( end - cursor->data );
256 
257  return 0;
258 }
uint8_t type
Type.
Definition: ena.h:16
const void * data
Start of data.
Definition: asn1.h:21
int asn1_start(struct asn1_cursor *cursor, unsigned int type, size_t extra)
Start parsing ASN.1 object.
Definition: asn1.c:98
size_t len
Length of data.
Definition: asn1.h:23
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static void asn1_invalidate_cursor(struct asn1_cursor *cursor)
Invalidate ASN.1 object cursor.
Definition: asn1.h:354
uint32_t len
Length.
Definition: ena.h:14
uint32_t end
Ending offset.
Definition: netvsc.h:18
An ASN.1 object cursor.
Definition: asn1.h:19

References asn1_invalidate_cursor(), asn1_start(), asn1_cursor::data, end, len, asn1_cursor::len, memcpy(), and type.

Referenced by asn1_shrink_any(), cms_parse_signer_identifier(), ocsp_parse_cert_id(), x509_parse_issuer(), and x509_parse_serial().

◆ asn1_enter_any()

int asn1_enter_any ( struct asn1_cursor cursor)

Enter ASN.1 object of any type.

Parameters
cursorASN.1 object cursor
Return values
rcReturn status code

Definition at line 266 of file asn1.c.

266  {
267  return asn1_enter ( cursor, ASN1_ANY );
268 }
int asn1_enter(struct asn1_cursor *cursor, unsigned int type)
Enter ASN.1 object.
Definition: asn1.c:160
#define ASN1_ANY
ASN.1 "any tag" magic value.
Definition: asn1.h:97

References ASN1_ANY, and asn1_enter().

Referenced by ocsp_parse_responder_id(), x509_check_alt_name(), and x509_parse_common_name().

◆ asn1_skip_any()

int asn1_skip_any ( struct asn1_cursor cursor)

◆ asn1_shrink_any()

int asn1_shrink_any ( struct asn1_cursor cursor)

Shrink ASN.1 object of any type.

Parameters
cursorASN.1 object cursor
Return values
rcReturn status code

Definition at line 286 of file asn1.c.

286  {
287  return asn1_shrink ( cursor, ASN1_ANY );
288 }
#define ASN1_ANY
ASN.1 "any tag" magic value.
Definition: asn1.h:97
int asn1_shrink(struct asn1_cursor *cursor, unsigned int type)
Shrink ASN.1 cursor to fit object.
Definition: asn1.c:240

References ASN1_ANY, and asn1_shrink().

Referenced by cms_signature(), ocsp_parse_tbs_response_data(), x509_certificate(), x509_parse_public_key(), x509_parse_subject(), and x509_parse_tbscertificate().

◆ asn1_boolean()

int asn1_boolean ( const struct asn1_cursor cursor)

Parse value of ASN.1 boolean.

Parameters
cursorASN.1 object cursor
Return values
valueValue, or negative error

Definition at line 296 of file asn1.c.

296  {
297  struct asn1_cursor contents;
298  const struct {
299  uint8_t value;
300  } __attribute__ (( packed )) *boolean;
301 
302  /* Enter boolean */
303  memcpy ( &contents, cursor, sizeof ( contents ) );
304  asn1_enter ( &contents, ASN1_BOOLEAN );
305  if ( contents.len != sizeof ( *boolean ) )
306  return -EINVAL_ASN1_BOOLEAN;
307 
308  /* Extract value */
309  boolean = contents.data;
310  return boolean->value;
311 }
#define __attribute__(x)
Definition: compiler.h:10
int asn1_enter(struct asn1_cursor *cursor, unsigned int type)
Enter ASN.1 object.
Definition: asn1.c:160
#define ASN1_BOOLEAN
ASN.1 boolean.
Definition: asn1.h:58
void * memcpy(void *dest, const void *src, size_t len) __nonnull
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
unsigned char uint8_t
Definition: stdint.h:10
#define EINVAL_ASN1_BOOLEAN
Definition: asn1.c:56
An ASN.1 object cursor.
Definition: asn1.h:19

References __attribute__, ASN1_BOOLEAN, asn1_enter(), asn1_cursor::data, EINVAL_ASN1_BOOLEAN, asn1_cursor::len, memcpy(), and value.

Referenced by x509_parse_basic_constraints(), and x509_parse_extension().

◆ asn1_integer()

int asn1_integer ( const struct asn1_cursor cursor,
int *  value 
)

Parse value of ASN.1 integer.

Parameters
cursorASN.1 object cursor
valueValue to fill in
Return values
rcReturn status code

Definition at line 320 of file asn1.c.

320  {
321  struct asn1_cursor contents;
322  uint8_t high_byte;
323  int rc;
324 
325  /* Enter integer */
326  memcpy ( &contents, cursor, sizeof ( contents ) );
327  if ( ( rc = asn1_enter ( &contents, ASN1_INTEGER ) ) != 0 )
328  return rc;
329  if ( contents.len < 1 )
330  return -EINVAL_ASN1_INTEGER;
331 
332  /* Initialise value according to sign byte */
333  *value = *( ( int8_t * ) contents.data );
334  contents.data++;
335  contents.len--;
336 
337  /* Process value */
338  while ( contents.len ) {
339  high_byte = ( (*value) >> ( 8 * ( sizeof ( *value ) - 1 ) ) );
340  if ( ( high_byte != 0x00 ) && ( high_byte != 0xff ) ) {
341  DBGC ( cursor, "ASN1 %p integer overflow\n", cursor );
342  return -EINVAL_ASN1_INTEGER;
343  }
344  *value = ( ( *value << 8 ) | *( ( uint8_t * ) contents.data ) );
345  contents.data++;
346  contents.len--;
347  }
348 
349  return 0;
350 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int asn1_enter(struct asn1_cursor *cursor, unsigned int type)
Enter ASN.1 object.
Definition: asn1.c:160
#define DBGC(...)
Definition: compiler.h:505
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define EINVAL_ASN1_INTEGER
Definition: asn1.c:60
signed char int8_t
Definition: stdint.h:15
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
unsigned char uint8_t
Definition: stdint.h:10
#define ASN1_INTEGER
ASN.1 integer.
Definition: asn1.h:61
An ASN.1 object cursor.
Definition: asn1.h:19

References asn1_enter(), ASN1_INTEGER, asn1_cursor::data, DBGC, EINVAL_ASN1_INTEGER, asn1_cursor::len, memcpy(), rc, and value.

Referenced by x509_parse_basic_constraints(), and x509_parse_version().

◆ asn1_bit_string()

int asn1_bit_string ( const struct asn1_cursor cursor,
struct asn1_bit_string bits 
)

Parse ASN.1 bit string.

Parameters
cursorASN.1 cursor
bitsBit string to fill in
Return values
rcReturn status code

Definition at line 359 of file asn1.c.

360  {
361  struct asn1_cursor contents;
362  const struct {
363  uint8_t unused;
364  uint8_t data[0];
365  } __attribute__ (( packed )) *bit_string;
366  size_t len;
367  unsigned int unused;
368  uint8_t unused_mask;
369  const uint8_t *last;
370  int rc;
371 
372  /* Enter bit string */
373  memcpy ( &contents, cursor, sizeof ( contents ) );
374  if ( ( rc = asn1_enter ( &contents, ASN1_BIT_STRING ) ) != 0 ) {
375  DBGC ( cursor, "ASN1 %p cannot locate bit string:\n", cursor );
376  DBGC_HDA ( cursor, 0, cursor->data, cursor->len );
377  return rc;
378  }
379 
380  /* Validity checks */
381  if ( contents.len < sizeof ( *bit_string ) ) {
382  DBGC ( cursor, "ASN1 %p invalid bit string:\n", cursor );
383  DBGC_HDA ( cursor, 0, cursor->data, cursor->len );
384  return -EINVAL_BIT_STRING;
385  }
386  bit_string = contents.data;
387  len = ( contents.len - offsetof ( typeof ( *bit_string ), data ) );
388  unused = bit_string->unused;
389  unused_mask = ( 0xff >> ( 8 - unused ) );
390  last = ( bit_string->data + len - 1 );
391  if ( ( unused >= 8 ) ||
392  ( ( unused > 0 ) && ( len == 0 ) ) ||
393  ( ( *last & unused_mask ) != 0 ) ) {
394  DBGC ( cursor, "ASN1 %p invalid bit string:\n", cursor );
395  DBGC_HDA ( cursor, 0, cursor->data, cursor->len );
396  return -EINVAL_BIT_STRING;
397  }
398 
399  /* Populate bit string */
400  bits->data = &bit_string->data;
401  bits->len = len;
402  bits->unused = unused;
403 
404  return 0;
405 }
#define __attribute__(x)
Definition: compiler.h:10
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EINVAL_BIT_STRING
Definition: asn1.c:72
int asn1_enter(struct asn1_cursor *cursor, unsigned int type)
Enter ASN.1 object.
Definition: asn1.c:160
const void * data
Start of data.
Definition: asn1.h:21
#define DBGC(...)
Definition: compiler.h:505
#define offsetof(type, field)
Get offset of a field within a structure.
Definition: stddef.h:24
size_t len
Length of data.
Definition: asn1.h:23
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define DBGC_HDA(...)
Definition: compiler.h:506
unsigned char uint8_t
Definition: stdint.h:10
uint32_t last
Length to read in last segment, or zero.
Definition: pccrc.h:30
static volatile void * bits
Definition: bitops.h:27
uint32_t len
Length.
Definition: ena.h:14
uint8_t unused[32]
Unused.
Definition: eltorito.h:15
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
An ASN.1 object cursor.
Definition: asn1.h:19
#define ASN1_BIT_STRING
ASN.1 bit string.
Definition: asn1.h:64

References __attribute__, ASN1_BIT_STRING, asn1_enter(), bits, data, asn1_cursor::data, DBGC, DBGC_HDA, EINVAL_BIT_STRING, last, len, asn1_cursor::len, memcpy(), offsetof, rc, and unused.

◆ asn1_integral_bit_string()

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.

Parameters
cursorASN.1 cursor
bitsBit string to fill in
Return values
rcReturn status code

Definition at line 414 of file asn1.c.

415  {
416  int rc;
417 
418  /* Parse bit string */
419  if ( ( rc = asn1_bit_string ( cursor, bits ) ) != 0 )
420  return rc;
421 
422  /* Check that there are no unused bits at end of string */
423  if ( bits->unused ) {
424  DBGC ( cursor, "ASN1 %p invalid integral bit string:\n",
425  cursor );
426  DBGC_HDA ( cursor, 0, cursor->data, cursor->len );
427  return -EINVAL_BIT_STRING;
428  }
429 
430  return 0;
431 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EINVAL_BIT_STRING
Definition: asn1.c:72
const void * data
Start of data.
Definition: asn1.h:21
#define DBGC(...)
Definition: compiler.h:505
size_t len
Length of data.
Definition: asn1.h:23
#define DBGC_HDA(...)
Definition: compiler.h:506
static volatile void * bits
Definition: bitops.h:27
An ASN.1 bit string.
Definition: asn1.h:339

References bits, asn1_cursor::data, DBGC, DBGC_HDA, EINVAL_BIT_STRING, asn1_cursor::len, and rc.

Referenced by ocsp_parse_basic_response(), rsa_parse_mod_exp(), and x509_parse().

◆ asn1_compare()

int asn1_compare ( const struct asn1_cursor cursor1,
const struct asn1_cursor cursor2 
)

Compare two ASN.1 objects.

Parameters
cursor1ASN.1 object cursor
cursor2ASN.1 object cursor
Return values
differenceDifference as returned by memcmp()

Note that invalid and empty cursors will compare as equal with each other.

Definition at line 443 of file asn1.c.

444  {
445  int difference;
446 
447  difference = ( cursor2->len - cursor1->len );
448  return ( difference ? difference :
449  memcmp ( cursor1->data, cursor2->data, cursor1->len ) );
450 }
const void * data
Start of data.
Definition: asn1.h:21
size_t len
Length of data.
Definition: asn1.h:23
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:113

References asn1_cursor::data, asn1_cursor::len, and memcmp().

Referenced by asn1_find_algorithm(), certstore_find(), cms_find_issuer_serial(), cms_parse_content_type(), ocsp_compare_responder_name(), ocsp_parse_cert_id(), ocsp_parse_response_type(), rsa_match(), validator_step(), x509_check_issuer(), x509_find_access_method(), x509_find_extension(), x509_find_subject(), x509_parse_common_name(), and x509_parse_key_purpose().

◆ asn1_algorithm()

int asn1_algorithm ( const struct asn1_cursor cursor,
struct asn1_algorithm **  algorithm 
)

Parse ASN.1 OID-identified algorithm.

Parameters
cursorASN.1 object cursor
Return values
algorithmAlgorithm
rcReturn status code

Definition at line 478 of file asn1.c.

479  {
480  struct asn1_cursor contents;
481  int rc;
482 
483  /* Enter signatureAlgorithm */
484  memcpy ( &contents, cursor, sizeof ( contents ) );
485  asn1_enter ( &contents, ASN1_SEQUENCE );
486 
487  /* Enter algorithm */
488  if ( ( rc = asn1_enter ( &contents, ASN1_OID ) ) != 0 ) {
489  DBGC ( cursor, "ASN1 %p cannot locate algorithm OID:\n",
490  cursor );
491  DBGC_HDA ( cursor, 0, cursor->data, cursor->len );
492  return -EINVAL_ASN1_ALGORITHM;
493  }
494 
495  /* Identify algorithm */
496  *algorithm = asn1_find_algorithm ( &contents );
497  if ( ! *algorithm ) {
498  DBGC ( cursor, "ASN1 %p unrecognised algorithm:\n", cursor );
499  DBGC_HDA ( cursor, 0, cursor->data, cursor->len );
500  return -ENOTSUP_ALGORITHM;
501  }
502 
503  return 0;
504 }
#define EINVAL_ASN1_ALGORITHM
Definition: asn1.c:68
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int asn1_enter(struct asn1_cursor *cursor, unsigned int type)
Enter ASN.1 object.
Definition: asn1.c:160
const void * data
Start of data.
Definition: asn1.h:21
#define DBGC(...)
Definition: compiler.h:505
size_t len
Length of data.
Definition: asn1.h:23
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define DBGC_HDA(...)
Definition: compiler.h:506
#define ASN1_SEQUENCE
ASN.1 sequence.
Definition: asn1.h:85
u16 algorithm
Authentication algorithm (Open System or Shared Key)
Definition: ieee80211.h:1030
static struct asn1_algorithm * asn1_find_algorithm(const struct asn1_cursor *cursor)
Identify ASN.1 algorithm by OID.
Definition: asn1.c:460
#define ASN1_OID
ASN.1 object identifier.
Definition: asn1.h:73
#define ENOTSUP_ALGORITHM
Definition: asn1.c:76
An ASN.1 object cursor.
Definition: asn1.h:19

References algorithm, asn1_enter(), asn1_find_algorithm(), ASN1_OID, ASN1_SEQUENCE, asn1_cursor::data, DBGC, DBGC_HDA, EINVAL_ASN1_ALGORITHM, ENOTSUP_ALGORITHM, asn1_cursor::len, memcpy(), and rc.

◆ asn1_pubkey_algorithm()

int asn1_pubkey_algorithm ( const struct asn1_cursor cursor,
struct asn1_algorithm **  algorithm 
)

Parse ASN.1 OID-identified public-key algorithm.

Parameters
cursorASN.1 object cursor
Return values
algorithmAlgorithm
rcReturn status code

Definition at line 513 of file asn1.c.

514  {
515  int rc;
516 
517  /* Parse algorithm */
518  if ( ( rc = asn1_algorithm ( cursor, algorithm ) ) != 0 )
519  return rc;
520 
521  /* Check algorithm has a public key */
522  if ( ! (*algorithm)->pubkey ) {
523  DBGC ( cursor, "ASN1 %p algorithm %s is not a public-key "
524  "algorithm:\n", cursor, (*algorithm)->name );
525  DBGC_HDA ( cursor, 0, cursor->data, cursor->len );
526  return -ENOTTY_ALGORITHM;
527  }
528 
529  return 0;
530 }
An ASN.1 OID-identified algorithm.
Definition: asn1.h:298
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define ENOTTY_ALGORITHM
Definition: asn1.c:80
const void * data
Start of data.
Definition: asn1.h:21
#define DBGC(...)
Definition: compiler.h:505
size_t len
Length of data.
Definition: asn1.h:23
#define DBGC_HDA(...)
Definition: compiler.h:506
u16 algorithm
Authentication algorithm (Open System or Shared Key)
Definition: ieee80211.h:1030

References algorithm, asn1_cursor::data, DBGC, DBGC_HDA, ENOTTY_ALGORITHM, asn1_cursor::len, and rc.

Referenced by cms_parse_signature_algorithm(), and x509_parse_public_key().

◆ asn1_digest_algorithm()

int asn1_digest_algorithm ( const struct asn1_cursor cursor,
struct asn1_algorithm **  algorithm 
)

Parse ASN.1 OID-identified digest algorithm.

Parameters
cursorASN.1 object cursor
Return values
algorithmAlgorithm
rcReturn status code

Definition at line 539 of file asn1.c.

540  {
541  int rc;
542 
543  /* Parse algorithm */
544  if ( ( rc = asn1_algorithm ( cursor, algorithm ) ) != 0 )
545  return rc;
546 
547  /* Check algorithm has a digest */
548  if ( ! (*algorithm)->digest ) {
549  DBGC ( cursor, "ASN1 %p algorithm %s is not a digest "
550  "algorithm:\n", cursor, (*algorithm)->name );
551  DBGC_HDA ( cursor, 0, cursor->data, cursor->len );
552  return -ENOTTY_ALGORITHM;
553  }
554 
555  return 0;
556 }
An ASN.1 OID-identified algorithm.
Definition: asn1.h:298
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define ENOTTY_ALGORITHM
Definition: asn1.c:80
const void * data
Start of data.
Definition: asn1.h:21
#define DBGC(...)
Definition: compiler.h:505
size_t len
Length of data.
Definition: asn1.h:23
#define DBGC_HDA(...)
Definition: compiler.h:506
u16 algorithm
Authentication algorithm (Open System or Shared Key)
Definition: ieee80211.h:1030

References algorithm, asn1_cursor::data, DBGC, DBGC_HDA, ENOTTY_ALGORITHM, asn1_cursor::len, and rc.

Referenced by cms_parse_digest_algorithm().

◆ asn1_signature_algorithm()

int asn1_signature_algorithm ( const struct asn1_cursor cursor,
struct asn1_algorithm **  algorithm 
)

Parse ASN.1 OID-identified signature algorithm.

Parameters
cursorASN.1 object cursor
Return values
algorithmAlgorithm
rcReturn status code

Definition at line 565 of file asn1.c.

566  {
567  int rc;
568 
569  /* Parse algorithm */
570  if ( ( rc = asn1_algorithm ( cursor, algorithm ) ) != 0 )
571  return rc;
572 
573  /* Check algorithm has a public key */
574  if ( ! (*algorithm)->pubkey ) {
575  DBGC ( cursor, "ASN1 %p algorithm %s is not a signature "
576  "algorithm:\n", cursor, (*algorithm)->name );
577  DBGC_HDA ( cursor, 0, cursor->data, cursor->len );
578  return -ENOTTY_ALGORITHM;
579  }
580 
581  /* Check algorithm has a digest */
582  if ( ! (*algorithm)->digest ) {
583  DBGC ( cursor, "ASN1 %p algorithm %s is not a signature "
584  "algorithm:\n", cursor, (*algorithm)->name );
585  DBGC_HDA ( cursor, 0, cursor->data, cursor->len );
586  return -ENOTTY_ALGORITHM;
587  }
588 
589  return 0;
590 }
An ASN.1 OID-identified algorithm.
Definition: asn1.h:298
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define ENOTTY_ALGORITHM
Definition: asn1.c:80
const void * data
Start of data.
Definition: asn1.h:21
#define DBGC(...)
Definition: compiler.h:505
size_t len
Length of data.
Definition: asn1.h:23
#define DBGC_HDA(...)
Definition: compiler.h:506
u16 algorithm
Authentication algorithm (Open System or Shared Key)
Definition: ieee80211.h:1030

References algorithm, asn1_cursor::data, DBGC, DBGC_HDA, ENOTTY_ALGORITHM, asn1_cursor::len, and rc.

Referenced by ocsp_parse_basic_response(), x509_parse(), and x509_parse_tbscertificate().

◆ asn1_generalized_time()

int asn1_generalized_time ( const struct asn1_cursor cursor,
time_t time 
)

Parse ASN.1 GeneralizedTime.

Parameters
cursorASN.1 cursor
timeTime to fill in
Return values
rcReturn status code

RFC 5280 section 4.1.2.5 places several restrictions on the allowed formats for UTCTime and GeneralizedTime, and mandates the interpretation of centuryless year values.

Definition at line 603 of file asn1.c.

603  {
604  struct asn1_cursor contents;
605  unsigned int have_century;
606  unsigned int type;
607  union {
608  struct {
609  uint8_t century;
610  uint8_t year;
611  uint8_t month;
612  uint8_t day;
613  uint8_t hour;
614  uint8_t minute;
615  uint8_t second;
616  } __attribute__ (( packed )) named;
617  uint8_t raw[7];
618  } pairs;
619  struct tm tm;
620  const uint8_t *data;
621  size_t remaining;
622  unsigned int tens;
623  unsigned int units;
624  unsigned int i;
625  int rc;
626 
627  /* Determine time format utcTime/generalizedTime */
628  memcpy ( &contents, cursor, sizeof ( contents ) );
629  type = asn1_type ( &contents );
630  switch ( type ) {
631  case ASN1_UTC_TIME:
632  have_century = 0;
633  break;
635  have_century = 1;
636  break;
637  default:
638  DBGC ( cursor, "ASN1 %p invalid time type %02x\n",
639  cursor, type );
640  DBGC_HDA ( cursor, 0, cursor->data, cursor->len );
641  return -EINVAL_ASN1_TIME;
642  }
643 
644  /* Enter utcTime/generalizedTime */
645  if ( ( rc = asn1_enter ( &contents, type ) ) != 0 ) {
646  DBGC ( cursor, "ASN1 %p cannot locate %s time:\n", cursor,
647  ( ( type == ASN1_UTC_TIME ) ? "UTC" : "generalized" ) );
648  DBGC_HDA ( cursor, 0, cursor->data, cursor->len );
649  return rc;
650  }
651 
652  /* Parse digit string a pair at a time */
653  memset ( &pairs, 0, sizeof ( pairs ) );
654  data = contents.data;
655  remaining = contents.len;
656  for ( i = ( have_century ? 0 : 1 ) ; i < sizeof ( pairs.raw ) ; i++ ) {
657  if ( remaining < 2 ) {
658  /* Some certificates violate the X.509 RFC by
659  * omitting the "seconds" value.
660  */
661  if ( i == ( sizeof ( pairs.raw ) - 1 ) )
662  break;
663  DBGC ( cursor, "ASN1 %p invalid time:\n", cursor );
664  DBGC_HDA ( cursor, 0, cursor->data, cursor->len );
665  return -EINVAL_ASN1_TIME;
666  }
667  tens = data[0];
668  units = data[1];
669  if ( ! ( isdigit ( tens ) && isdigit ( units ) ) ) {
670  DBGC ( cursor, "ASN1 %p invalid time:\n", cursor );
671  DBGC_HDA ( cursor, 0, cursor->data, cursor->len );
672  return -EINVAL_ASN1_TIME;
673  }
674  pairs.raw[i] = ( ( 10 * ( tens - '0' ) ) + ( units - '0' ) );
675  data += 2;
676  remaining -= 2;
677  }
678 
679  /* Determine century if applicable */
680  if ( ! have_century )
681  pairs.named.century = ( ( pairs.named.year >= 50 ) ? 19 : 20 );
682 
683  /* Check for trailing "Z" */
684  if ( ( remaining != 1 ) || ( data[0] != 'Z' ) ) {
685  DBGC ( cursor, "ASN1 %p invalid time:\n", cursor );
686  DBGC_HDA ( cursor, 0, cursor->data, cursor->len );
687  return -EINVAL_ASN1_TIME;
688  }
689 
690  /* Fill in time */
691  tm.tm_year = ( ( ( pairs.named.century - 19 ) * 100 ) +
692  pairs.named.year );
693  tm.tm_mon = ( pairs.named.month - 1 );
694  tm.tm_mday = pairs.named.day;
695  tm.tm_hour = pairs.named.hour;
696  tm.tm_min = pairs.named.minute;
697  tm.tm_sec = pairs.named.second;
698 
699  /* Convert to seconds since the Epoch */
700  *time = mktime ( &tm );
701 
702  return 0;
703 }
#define __attribute__(x)
Definition: compiler.h:10
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int tm_min
Minutes [0,59].
Definition: time.h:19
#define EINVAL_ASN1_TIME
Definition: asn1.c:64
int asn1_enter(struct asn1_cursor *cursor, unsigned int type)
Enter ASN.1 object.
Definition: asn1.c:160
static __always_inline int off_t userptr_t second
Definition: efi_uaccess.h:80
uint8_t type
Type.
Definition: ena.h:16
int tm_mday
Day of month [1,31].
Definition: time.h:23
const void * data
Start of data.
Definition: asn1.h:21
#define DBGC(...)
Definition: compiler.h:505
int tm_year
Years since 1900.
Definition: time.h:27
static unsigned int asn1_type(const struct asn1_cursor *cursor)
Extract ASN.1 type.
Definition: asn1.h:365
size_t len
Length of data.
Definition: asn1.h:23
static int isdigit(int character)
Check if character is a decimal digit.
Definition: ctype.h:18
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define DBGC_HDA(...)
Definition: compiler.h:506
int tm_mon
Month of year [0,11].
Definition: time.h:25
time_t mktime(struct tm *tm)
Calculate seconds since the Epoch.
Definition: time.c:117
#define ASN1_GENERALIZED_TIME
ASN.1 generalized time.
Definition: asn1.h:82
unsigned char uint8_t
Definition: stdint.h:10
Broken-down time.
Definition: time.h:15
int tm_sec
Seconds [0,60].
Definition: time.h:17
__be32 raw[7]
Definition: CIB_PRM.h:28
#define ASN1_UTC_TIME
ASN.1 UTC time.
Definition: asn1.h:79
int tm_hour
Hour [0,23].
Definition: time.h:21
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
uint64_t time
Current time.
Definition: ntlm.h:20
An ASN.1 object cursor.
Definition: asn1.h:19
void * memset(void *dest, int character, size_t len) __nonnull

References __attribute__, asn1_enter(), ASN1_GENERALIZED_TIME, asn1_type(), ASN1_UTC_TIME, data, asn1_cursor::data, DBGC, DBGC_HDA, EINVAL_ASN1_TIME, isdigit(), asn1_cursor::len, memcpy(), memset(), mktime(), raw, rc, second, time, tm::tm_hour, tm::tm_mday, tm::tm_min, tm::tm_mon, tm::tm_sec, tm::tm_year, and type.

Referenced by ocsp_parse_responses(), and x509_parse_validity().

◆ asn1_grow()

int asn1_grow ( struct asn1_builder builder,
size_t  extra 
)

Grow ASN.1 builder.

Parameters
builderASN.1 builder
extraExtra space to prepend
Return values
rcReturn status code

Definition at line 742 of file asn1.c.

742  {
743  size_t new_len;
744  void *new;
745 
746  /* As with the ASN1 parsing functions, make errors permanent */
747  if ( builder->len && ! builder->data )
748  return -ENOMEM;
749 
750  /* Reallocate data buffer */
751  new_len = ( builder->len + extra );
752  new = realloc ( builder->data, new_len );
753  if ( ! new ) {
754  free ( builder->data );
755  builder->data = NULL;
756  return -ENOMEM;
757  }
758  builder->data = new;
759 
760  /* Move existing data to end of buffer */
761  memmove ( ( builder->data + extra ), builder->data, builder->len );
762  builder->len = new_len;
763 
764  return 0;
765 }
void * data
Data.
Definition: asn1.h:34
#define ENOMEM
Not enough space.
Definition: errno.h:534
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * memmove(void *dest, const void *src, size_t len) __nonnull
void * realloc(void *old_ptr, size_t new_size)
Reallocate memory.
Definition: malloc.c:521
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
size_t len
Length of data.
Definition: asn1.h:36

References asn1_builder::data, ENOMEM, free, asn1_builder::len, memmove(), NULL, and realloc().

Referenced by asn1_prepend(), asn1_prepend_raw(), and asn1_wrap().

◆ asn1_prepend_raw()

int asn1_prepend_raw ( struct asn1_builder builder,
const void *  data,
size_t  len 
)

Prepend raw data to ASN.1 builder.

Parameters
builderASN.1 builder
dataData to prepend
lenLength of data to prepend
Return values
rcReturn status code

Definition at line 775 of file asn1.c.

776  {
777  int rc;
778 
779  /* Grow buffer */
780  if ( ( rc = asn1_grow ( builder, len ) ) != 0 )
781  return rc;
782 
783  /* Populate data buffer */
784  memcpy ( builder->data, data, len );
785 
786  return 0;
787 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void * data
Data.
Definition: asn1.h:34
void * memcpy(void *dest, const void *src, size_t len) __nonnull
int asn1_grow(struct asn1_builder *builder, size_t extra)
Grow ASN.1 builder.
Definition: asn1.c:742
uint32_t len
Length.
Definition: ena.h:14
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12

References asn1_grow(), data, asn1_builder::data, len, memcpy(), and rc.

Referenced by ocsp_request().

◆ asn1_prepend()

int asn1_prepend ( struct asn1_builder builder,
unsigned int  type,
const void *  data,
size_t  len 
)

Prepend data to ASN.1 builder.

Parameters
builderASN.1 builder
typeType
dataData to prepend
lenLength of data to prepend
Return values
rcReturn status code

Definition at line 798 of file asn1.c.

799  {
801  size_t header_len;
802  int rc;
803 
804  /* Construct header */
805  header_len = asn1_header ( &header, type, len );
806 
807  /* Grow buffer */
808  if ( ( rc = asn1_grow ( builder, header_len + len ) ) != 0 )
809  return rc;
810 
811  /* Populate data buffer */
812  memcpy ( builder->data, &header, header_len );
813  memcpy ( ( builder->data + header_len ), data, len );
814 
815  return 0;
816 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void * data
Data.
Definition: asn1.h:34
uint8_t type
Type.
Definition: ena.h:16
void * memcpy(void *dest, const void *src, size_t len) __nonnull
int asn1_grow(struct asn1_builder *builder, size_t extra)
Grow ASN.1 builder.
Definition: asn1.c:742
static size_t asn1_header(struct asn1_builder_header *header, unsigned int type, size_t len)
Construct ASN.1 header.
Definition: asn1.c:713
An ASN.1 header.
Definition: asn1.h:47
uint32_t len
Length.
Definition: ena.h:14
struct ena_aq_header header
Header.
Definition: ena.h:12
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12

References asn1_grow(), asn1_header(), data, asn1_builder::data, header, len, memcpy(), rc, and type.

Referenced by ocsp_request().

◆ asn1_wrap()

int asn1_wrap ( struct asn1_builder builder,
unsigned int  type 
)

Wrap ASN.1 builder.

Parameters
builderASN.1 builder
typeType
Return values
rcReturn status code

Definition at line 825 of file asn1.c.

825  {
827  size_t header_len;
828  int rc;
829 
830  /* Construct header */
831  header_len = asn1_header ( &header, type, builder->len );
832 
833  /* Grow buffer */
834  if ( ( rc = asn1_grow ( builder, header_len ) ) != 0 )
835  return rc;
836 
837  /* Populate data buffer */
838  memcpy ( builder->data, &header, header_len );
839 
840  return 0;
841 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void * data
Data.
Definition: asn1.h:34
uint8_t type
Type.
Definition: ena.h:16
void * memcpy(void *dest, const void *src, size_t len) __nonnull
int asn1_grow(struct asn1_builder *builder, size_t extra)
Grow ASN.1 builder.
Definition: asn1.c:742
static size_t asn1_header(struct asn1_builder_header *header, unsigned int type, size_t len)
Construct ASN.1 header.
Definition: asn1.c:713
An ASN.1 header.
Definition: asn1.h:47
struct ena_aq_header header
Header.
Definition: ena.h:12
size_t len
Length of data.
Definition: asn1.h:36

References asn1_grow(), asn1_header(), asn1_builder::data, header, asn1_builder::len, memcpy(), rc, and type.

Referenced by ocsp_request().

Variable Documentation

◆ __asn1_algorithm

struct asn1_algorithm oid_sha512_256_algorithm __asn1_algorithm

"md4" OID-identified algorithm

"md4" OID-identified algorithm

Definition at line 317 of file asn1.h.