Re: questions about ASN.1
- From: "Tom St Denis" <tomstdenis@xxxxxxxxx>
- Date: 24 Nov 2006 09:32:56 -0800
yawnmoth wrote:
In programming, a serialized object is one that has been turned into a
string - a string that can be saved in a database, in a *.txt file, or
whatever. Is ASN.1 basically just a serialization technique?
Also, wikipedia.org provides an example of a ASN.1 using DER:
http://en.wikipedia.org/wiki/Asn.1#Example_encoded_in_DER
The first byte represents SEQUENCE and the second byte represents the
length of everything else. How does at ASN.1 decoder know that just
one byte is being used? If I had 256 bytes of data, the length would
be two bytes (0x01, 0x00). How would an ASN.1 decoder know this?
Lengths are encoded in one of two ways.
Short) The length is less than 128 and encoded literally e.g. 0x20
would represent 32 bytes
Long) The length is longer than 127 and encoded in two steps. First
you encode the # of bytes required for the length. Say L = 0x4DC1 then
you need 2 bytes for the len, so that's done by OR'ing 128 to the # of
bytes in the length, in this case 128 | 2 = 0x82. Then store the
length.
0x82 0x4D C1
would represent the length 0x4DC1
in DER rules you trim leading zeroes and ALWAYS use the short method if
the length is less than 128.
In BER rules you may choose to use short or long for lengths less than
128 bytes (and you can insert leading zeroes).
The first byte of any ASN.1 object is the TYPE.
0x10 == SEQUENCE and you typically OR 0x20 to indicate it's
constructed. So sequence is almost always 0x30
so a sequence of 32 bytes would be
0x30 0x20
followed by the bytes of the contents of the sequence. E.g.
SEQUENCE { NULL } would be
0x30 0x02 -- SEQUENCE
0x05 0x00 -- NULL
(iirc...)
Hint, OpenSSL has an ASN1 decoder that will nicely print out binary
blobs in text format so you can see the elements.
Also, LibTomCrypt supports a fairly handy ASN1 DER set of
encoder/decoders.
Tom
.
- References:
- questions about ASN.1
- From: yawnmoth
- questions about ASN.1
- Prev by Date: Re: Interesting paper: On the Power of Simple Branch Prediction Analysis
- Next by Date: Re: Comaprison between MD5 and SHA
- Previous by thread: questions about ASN.1
- Next by thread: Re: questions about ASN.1
- Index(es):
Relevant Pages
|