118#define EINVAL_ASN1_EMPTY \
119 __einfo_error ( EINFO_EINVAL_ASN1_EMPTY )
120#define EINFO_EINVAL_ASN1_EMPTY \
121 __einfo_uniqify ( EINFO_EINVAL, 0x01, "Empty or underlength cursor" )
122#define EINVAL_ASN1_LEN_LEN \
123 __einfo_error ( EINFO_EINVAL_ASN1_LEN_LEN )
124#define EINFO_EINVAL_ASN1_LEN_LEN \
125 __einfo_uniqify ( EINFO_EINVAL, 0x02, "Length field overruns cursor" )
126#define EINVAL_ASN1_LEN \
127 __einfo_error ( EINFO_EINVAL_ASN1_LEN )
128#define EINFO_EINVAL_ASN1_LEN \
129 __einfo_uniqify ( EINFO_EINVAL, 0x03, "Field overruns cursor" )
130#define EINVAL_ASN1_BOOLEAN \
131 __einfo_error ( EINFO_EINVAL_ASN1_BOOLEAN )
132#define EINFO_EINVAL_ASN1_BOOLEAN \
133 __einfo_uniqify ( EINFO_EINVAL, 0x04, "Invalid boolean" )
134#define EINVAL_ASN1_INTEGER \
135 __einfo_error ( EINFO_EINVAL_ASN1_INTEGER )
136#define EINFO_EINVAL_ASN1_INTEGER \
137 __einfo_uniqify ( EINFO_EINVAL, 0x04, "Invalid integer" )
138#define EINVAL_ASN1_TIME \
139 __einfo_error ( EINFO_EINVAL_ASN1_TIME )
140#define EINFO_EINVAL_ASN1_TIME \
141 __einfo_uniqify ( EINFO_EINVAL, 0x05, "Invalid time" )
142#define EINVAL_ASN1_ALGORITHM \
143 __einfo_error ( EINFO_EINVAL_ASN1_ALGORITHM )
144#define EINFO_EINVAL_ASN1_ALGORITHM \
145 __einfo_uniqify ( EINFO_EINVAL, 0x06, "Invalid algorithm" )
146#define EINVAL_BIT_STRING \
147 __einfo_error ( EINFO_EINVAL_BIT_STRING )
148#define EINFO_EINVAL_BIT_STRING \
149 __einfo_uniqify ( EINFO_EINVAL, 0x07, "Invalid bit string" )
150#define ENOTSUP_ALGORITHM \
151 __einfo_error ( EINFO_ENOTSUP_ALGORITHM )
152#define EINFO_ENOTSUP_ALGORITHM \
153 __einfo_uniqify ( EINFO_ENOTSUP, 0x01, "Unsupported algorithm" )
154#define ENOTSUP_HIGH \
155 __einfo_error ( EINFO_ENOTSUP_HIGH )
156#define EINFO_ENOTSUP_HIGH \
157 __einfo_uniqify ( EINFO_ENOTSUP, 0x02, "Unsupported high tag number" )
158#define ENOTTY_ALGORITHM \
159 __einfo_error ( EINFO_ENOTTY_ALGORITHM )
160#define EINFO_ENOTTY_ALGORITHM \
161 __einfo_uniqify ( EINFO_ENOTTY, 0x01, "Inappropriate algorithm" )
180 unsigned int len_len;
185 if ( cursor->
len < 2 ) {
187 DBGC ( cursor,
"ASN1 %p too short\n", cursor );
194 DBGC ( cursor,
"ASN1 %p has unsupported high tag number\n",
202 DBGC ( cursor,
"ASN1 %p type mismatch (expected %d, got %d)\n",
211 if ( len_len & 0x80 ) {
212 len_len = ( len_len & 0x7f );
218 if ( ( len_len == 0 ) || ( cursor->
len < len_len ) ) {
219 DBGC ( cursor,
"ASN1 %p bad length field length %d (min 0, "
220 "max %zd)\n", cursor, len_len, cursor->
len );
226 for (
len = 0 ; len_len ; len_len-- ) {
227 high_byte = (
len >> ( 8 * (
sizeof (
len ) - 1 ) ) );
229 DBGC ( cursor,
"ASN1 %p unrepresentable length\n",
239 if ( ( cursor->
len <
len ) || ( ( (
int )
len ) < 0 ) ) {
240 DBGC ( cursor,
"ASN1 %p bad length %d (min 0, max %zd)\n",
241 cursor,
len, cursor->
len );
272 if ( ( (
size_t )
len ) <= cursor->
len )
275 DBGC ( cursor,
"ASN1 %p entered object type %02x (len %x)\n",
306 DBGC ( cursor,
"ASN1 %p skipped object type %02x (len %x)\n",
352 memcpy ( &temp, cursor,
sizeof ( temp ) );
409 unsigned int unused_bits;
417 if ( cursor->
len < sizeof ( *bit_string ) ) {
418 DBGC ( cursor,
"ASN1 %p invalid bit string:\n", cursor );
423 bit_string = cursor->
data;
424 last = ( cursor->
data + cursor->
len - 1 );
425 cursor->
data = &bit_string->data;
427 unused_bits = bit_string->unused;
430 if ( ( unused_bits >= 8 ) ||
431 ( ( unused_bits > 0 ) && ( cursor->
len == 0 ) ) ||
432 ( ( *last & ( 0xffU >> ( 8 - unused_bits ) ) ) != 0 ) ) {
433 DBGC ( cursor,
"ASN1 %p invalid bit string:\n", cursor );
442 }
else if ( unused_bits ) {
443 DBGC ( cursor,
"ASN1 %p invalid integral bit string:\n",
468 if ( ! cursor->
len ) {
469 DBGC ( cursor,
"ASN1 %p empty unsigned integer\n", cursor );
477 DBGC ( cursor,
"ASN1 %p negative unsigned integer:\n",
485 while ( ( cursor->
len > 1 ) && ( msb == 0x00 ) ) {
507 memcpy ( &contents, cursor,
sizeof ( contents ) );
509 if ( contents.
len != sizeof ( *
boolean ) )
513 boolean = contents.
data;
514 return boolean->value;
530 memcpy ( &contents, cursor,
sizeof ( contents ) );
533 if ( contents.
len < 1 )
542 while ( contents.
len ) {
543 high_byte = ( (*value) >> ( 8 * (
sizeof ( *value ) - 1 ) ) );
544 if ( ( high_byte != 0x00 ) && ( high_byte != 0xff ) ) {
545 DBGC ( cursor,
"ASN1 %p integer overflow\n", cursor );
570 difference = ( cursor2->
len - cursor1->
len );
571 return ( difference ? difference :
609 memcpy ( &contents, cursor,
sizeof ( contents ) );
614 memcpy ( params, &contents,
sizeof ( *params ) );
620 DBGC ( cursor,
"ASN1 %p cannot locate algorithm OID:\n",
629 DBGC ( cursor,
"ASN1 %p unrecognised algorithm:\n", cursor );
635 if ( params && (*algorithm)->parse &&
636 ( (
rc = (*algorithm)->parse ( *
algorithm, params ) ) != 0 ) ) {
637 DBGC ( cursor,
"ASN1 %p cannot parse %s parameters: %s\n",
638 cursor, (*algorithm)->name,
strerror (
rc ) );
661 if ( ! (*algorithm)->pubkey ) {
662 DBGC ( cursor,
"ASN1 %p algorithm %s is not a public-key "
663 "algorithm:\n", cursor, (*algorithm)->name );
687 if ( ! (*algorithm)->digest ) {
688 DBGC ( cursor,
"ASN1 %p algorithm %s is not a digest "
689 "algorithm:\n", cursor, (*algorithm)->name );
715 if ( ! (*algorithm)->cipher ) {
716 DBGC ( cursor,
"ASN1 %p algorithm %s is not a cipher "
717 "algorithm:\n", cursor, (*algorithm)->name );
741 if ( ! (*algorithm)->pubkey ) {
742 DBGC ( cursor,
"ASN1 %p algorithm %s is not a signature "
743 "algorithm:\n", cursor, (*algorithm)->name );
749 if ( ! (*algorithm)->digest ) {
750 DBGC ( cursor,
"ASN1 %p algorithm %s is not a signature "
751 "algorithm:\n", cursor, (*algorithm)->name );
779 if ( ( wrapper ==
NULL ) ||
781 memcpy ( &curve, cursor,
sizeof ( curve ) );
788 DBGC ( cursor,
"ASN1 %p unrecognised EC algorithm:\n",
795 if ( ! (*algorithm)->curve ) {
796 DBGC ( cursor,
"ASN1 %p algorithm %s is not an elliptic curve "
797 "algorithm:\n", cursor, (*algorithm)->name );
824 if ( actual != expected ) {
825 DBGC ( cursor,
"ASN1 %p algorithm %s does not match %s\n",
826 cursor, actual->
name, expected->
name );
887 unsigned int have_century;
910 memcpy ( &contents, cursor,
sizeof ( contents ) );
920 DBGC ( cursor,
"ASN1 %p invalid time type %02x\n",
928 DBGC ( cursor,
"ASN1 %p cannot locate %s time:\n", cursor,
935 memset ( &pairs, 0,
sizeof ( pairs ) );
937 remaining = contents.
len;
938 for ( i = ( have_century ? 0 : 1 ) ; i <
sizeof ( pairs.raw ) ; i++ ) {
939 if ( remaining < 2 ) {
943 if ( i == (
sizeof ( pairs.raw ) - 1 ) )
945 DBGC ( cursor,
"ASN1 %p invalid time:\n", cursor );
952 DBGC ( cursor,
"ASN1 %p invalid time:\n", cursor );
956 pairs.raw[i] = ( ( 10 * ( tens -
'0' ) ) + ( units -
'0' ) );
962 if ( ! have_century )
963 pairs.named.century = ( ( pairs.named.year >= 50 ) ? 19 : 20 );
966 if ( ( remaining != 1 ) || (
data[0] !=
'Z' ) ) {
967 DBGC ( cursor,
"ASN1 %p invalid time:\n", cursor );
973 tm.
tm_year = ( ( ( pairs.named.century - 19 ) * 100 ) +
975 tm.
tm_mon = ( pairs.named.month - 1 );
996 unsigned int type,
size_t len ) {
997 unsigned int header_len = 2;
998 unsigned int len_len = 0;
1006 for ( temp =
len ; temp ; temp >>= 8 )
1008 header->length[0] = ( 0x80 | len_len );
1009 header_len += len_len;
1010 for ( temp =
len ; temp ; temp >>= 8 )
1011 header->length[len_len--] = ( temp & 0xff );
1041 if ( builder->
len && ! builder->
data )
1045 new_len = ( builder->
len +
extra );
1052 builder->
data =
new;
1056 builder->
len = new_len;
1093 const void *
data,
size_t len ) {
1128 if ( (
rc =
asn1_grow ( builder, header_len ) ) != 0 )
1164 DBGC (
image,
"IMAGE %s could not extract ASN.1 object: %s\n",
#define NULL
NULL pointer (VOID *).
typeof(acpi_finder=acpi_find)
ACPI table finder.
struct arbelprm_rc_send_wqe rc
pseudo_bit_t value[0x00020]
int asn1_cipher_algorithm(const struct asn1_cursor *cursor, struct asn1_algorithm **algorithm, struct asn1_cursor *params)
Parse ASN.1 OID-identified cipher algorithm.
#define EINVAL_ASN1_LEN_LEN
int asn1_prepend(struct asn1_builder *builder, unsigned int type, const void *data, size_t len)
Prepend data to ASN.1 builder.
int asn1_prepend_raw(struct asn1_builder *builder, const void *data, size_t len)
Prepend raw data to ASN.1 builder.
int asn1_enter_unsigned(struct asn1_cursor *cursor)
Enter ASN.1 unsigned integer.
#define EINVAL_ASN1_BOOLEAN
#define EINVAL_ASN1_INTEGER
#define EINVAL_BIT_STRING
int asn1_skip_any(struct asn1_cursor *cursor)
Skip ASN.1 object of any type.
int asn1_check_algorithm(const struct asn1_cursor *cursor, struct asn1_algorithm *expected, struct asn1_cursor *params)
Check ASN.1 OID-identified algorithm.
int asn1_generalized_time(const struct asn1_cursor *cursor, time_t *time)
Parse ASN.1 GeneralizedTime.
int asn1_boolean(const struct asn1_cursor *cursor)
Parse value of ASN.1 boolean.
int asn1_digest_algorithm(const struct asn1_cursor *cursor, struct asn1_algorithm **algorithm)
Parse ASN.1 OID-identified digest algorithm.
#define EINVAL_ASN1_EMPTY
static size_t asn1_header(struct asn1_builder_header *header, unsigned int type, size_t len)
Construct ASN.1 header.
int asn1_curve_algorithm(const struct asn1_cursor *cursor, struct asn1_algorithm *wrapper, struct asn1_algorithm **algorithm)
Parse ASN.1 OID-identified elliptic curve algorithm.
int asn1_grow(struct asn1_builder *builder, size_t extra)
Grow ASN.1 builder.
int asn1_enter(struct asn1_cursor *cursor, unsigned int type)
Enter ASN.1 object.
int asn1_enter_any(struct asn1_cursor *cursor)
Enter ASN.1 object of any type.
int image_asn1(struct image *image, size_t offset, struct asn1_cursor **cursor)
Extract ASN.1 object from image.
size_t asn1_header_len(size_t len)
Calculate ASN.1 header length.
#define ENOTSUP_ALGORITHM
int asn1_parse_cbc(struct asn1_algorithm *algorithm, struct asn1_cursor *params)
Parse ASN.1 CBC cipher parameters.
int asn1_skip(struct asn1_cursor *cursor, unsigned int type)
Skip ASN.1 object.
int asn1_pubkey_algorithm(const struct asn1_cursor *cursor, struct asn1_algorithm **algorithm)
Parse ASN.1 OID-identified public-key algorithm.
#define EINVAL_ASN1_ALGORITHM
int asn1_enter_bits(struct asn1_cursor *cursor, unsigned int *unused)
Enter ASN.1 bit string.
static struct asn1_algorithm * asn1_find_algorithm(const struct asn1_cursor *cursor)
Identify ASN.1 algorithm by OID.
static int asn1_start(struct asn1_cursor *cursor, unsigned int type)
Start parsing ASN.1 object.
int asn1_shrink_any(struct asn1_cursor *cursor)
Shrink ASN.1 object of any type.
int asn1_algorithm(const struct asn1_cursor *cursor, struct asn1_algorithm **algorithm, struct asn1_cursor *params)
Parse ASN.1 OID-identified algorithm.
int asn1_integer(const struct asn1_cursor *cursor, int *value)
Parse value of ASN.1 integer.
int asn1_compare(const struct asn1_cursor *cursor1, const struct asn1_cursor *cursor2)
Compare two ASN.1 objects.
int asn1_signature_algorithm(const struct asn1_cursor *cursor, struct asn1_algorithm **algorithm)
Parse ASN.1 OID-identified signature algorithm.
int asn1_parse_gcm(struct asn1_algorithm *algorithm __unused, struct asn1_cursor *params)
Parse ASN.1 GCM cipher parameters.
int asn1_wrap(struct asn1_builder *builder, unsigned int type)
Wrap ASN.1 builder.
int asn1_shrink(struct asn1_cursor *cursor, unsigned int type)
Shrink ASN.1 cursor to fit object.
int asn1_skip_if_exists(struct asn1_cursor *cursor, unsigned int type)
Skip ASN.1 object if present.
#define ASN1_INTEGER
ASN.1 integer.
#define ASN1_BIT_STRING
ASN.1 bit string.
#define ASN1_HIGH
ASN.1 high tag number.
#define ASN1_ANY
ASN.1 "any tag" magic value.
#define ASN1_OID
ASN.1 object identifier.
static void asn1_invalidate_cursor(struct asn1_cursor *cursor)
Invalidate ASN.1 object cursor.
#define ASN1_ALGORITHMS
ASN.1 OID-identified algorithms.
#define ASN1_BOOLEAN
ASN.1 boolean.
#define ASN1_SEQUENCE
ASN.1 sequence.
#define ASN1_UTC_TIME
ASN.1 UTC time.
#define ASN1_GENERALIZED_TIME
ASN.1 generalized time.
#define ASN1_OCTET_STRING
ASN.1 octet string.
static unsigned int asn1_type(const struct asn1_cursor *cursor)
Extract ASN.1 type.
#define assert(condition)
Assert a condition at run-time.
uint16_t offset
Offset to command line.
static int isdigit(int character)
Check if character is a decimal digit.
uint32_t next
Next descriptor address.
uint32_t type
Operating system type.
uint8_t data[48]
Additional event data.
struct ena_llq_option header
Header locations.
#define __unused
Declare a variable or data structure as unused.
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
#define REQUIRE_OBJECT(object)
Require an object.
#define ENXIO
No such device or address.
#define EINVAL
Invalid argument.
#define ENOMEM
Not enough space.
#define ENOTSUP
Operation not supported.
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
#define REQUIRING_SYMBOL(symbol)
Specify the file's requiring symbol.
u16 algorithm
Authentication algorithm (Open System or Shared Key).
uint8_t extra
Signature extra byte.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * memset(void *dest, int character, size_t len) __nonnull
void * memmove(void *dest, const void *src, size_t len) __nonnull
int64_t time_t
Seconds since the Epoch.
void * realloc(void *old_ptr, size_t new_size)
Reallocate memory.
void zfree(void *ptr)
Clear and free memory.
uint32_t end
Ending offset.
#define offsetof(type, field)
Get offset of a field within a structure.
char * strerror(int errno)
Retrieve string representation of error number.
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
An ASN.1 OID-identified algorithm.
size_t len
Length of data.
const void * data
Start of data.
size_t len
Length of data.
size_t blocksize
Block size.
int(* asn1)(struct image *image, size_t offset, struct asn1_cursor **cursor)
Extract ASN.1 object from image.
struct image_type * type
Image type, if known.
int tm_mon
Month of year [0,11].
int tm_year
Years since 1900.
int tm_sec
Seconds [0,60].
int tm_mday
Day of month [1,31].
int tm_min
Minutes [0,59].
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
time_t mktime(struct tm *tm)
Calculate seconds since the Epoch.
uint8_t month
Month (BCD).
uint8_t century
Century (BCD).