diff --git a/src/ltc/headers/tomcrypt_pk.h b/src/ltc/headers/tomcrypt_pk.h index 08c7d24..038c4bd 100644 --- a/src/ltc/headers/tomcrypt_pk.h +++ b/src/ltc/headers/tomcrypt_pk.h @@ -486,7 +486,7 @@ /** Flag used to indicate optional items in ASN.1 sequences */ int optional; /** Flag used to indicate context specific tags on ASN.1 sequence items */ - int tag; + unsigned char tag; /** prev/next entry in the list */ struct ltc_asn1_list_ *prev, *next, *child, *parent; } ltc_asn1_list; diff --git a/src/ltc/pk/asn1/der/sequence/der_decode_sequence_ex.c b/src/ltc/pk/asn1/der/sequence/der_decode_sequence_ex.c index 966064a..f135170 100644 --- a/src/ltc/pk/asn1/der/sequence/der_decode_sequence_ex.c +++ b/src/ltc/pk/asn1/der/sequence/der_decode_sequence_ex.c @@ -91,6 +91,20 @@ if (type == LTC_ASN1_EOL) { break; + } + + /* handle context specific tags - just skip the tag + len bytes */ + z = 0; + if (list[i].tag > 0 && list[i].tag == in[x + z++]) { + if (in[x+z] & 0x80) { + y = in[x + z++] & 0x7F; + if (y == 0 || y > 2) { return CRYPT_INVALID_PACKET; } + z += y; + } else { + z++; + } + x += z; + inlen -= z; } switch (type) {