Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASN.1 SEQUENCE (OF) real tag value

Tags:

asn.1

ber

I am finding a lot of contradicting information regarding the tag value for the SEQUENCE (OF) ASN.1 datatype:

Wikipedia claims it is both 0x10 and 0x30:

http://en.wikipedia.org/wiki/Abstract_Syntax_Notation_One -> 0x30

http://en.wikipedia.org/wiki/Basic_Encoding_Rules -> 0x10

According to Microsoft it is 0x30:

http://msdn.microsoft.com/en-us/library/windows/desktop/bb540799%28v=VS.85%29.aspx

And in the Bouncycastle sources one can find:

public const int Sequence = 0x10;

So it is basically a tie between 0x10 and 0x30. Do you know that the real value is or am I missing something?

like image 287
Krassi Avatar asked Oct 15 '11 13:10

Krassi


People also ask

What is SEQUENCE in ASN 1?

In ASN. 1, an ordered list of elements (or components) comprises a SEQUENCE. Using SEQUENCE, you can create a new type built from an arbitrary series of elements. Each element must identify its type, either by specifying a type name or by actually defining the element's type inline.

What is ASN tag?

Specifying Tags Note that ASN. 1 tags can be used to identify a type as well as a field (for example, if some components of a SEQUENCE type are optional, tags can be used to detect whether the optional components are absent or present).

What is ASN format?

ASN. 1, or Abstract Syntax Notation One, is an International Standards Organization (ISO) data representation format used to achieve interoperability between platforms.

Are ASN 1 primitive data types?

Primitive types within ASN. 1 are those types that are not constructed or cannot be broken down into more primitive types. They correspond to the normal data types encountered in many programming and data definition languages.


1 Answers

A BER encoded "tag" is made up of several bit fields:

---------------------------------
| 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
---------------------------------
|Class  |P/C| Tag Number        |
---------------------------------
  • The tag number for a Sequence(in the Universal Class) is 0x10.
  • A sequence is a Constructed type, making the P/C bit 1
  • Universal Class is 0
  • This makes the entire octet 0x30

Note that there's many ways to encode a sequence in BER/DER/CER, it depends on the exact ASN.1 used. e.g. some protocol might override the class and specify a sequence as Application Specific class, and/or it might specify its own Tag Number if Implicit tagging is used.

You can read the BER encoding spec here

like image 173
nos Avatar answered Jan 01 '23 23:01

nos