Re: questions about ASN.1




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

.



Relevant Pages

  • Re: Compressing a list of integers
    ... For the linearly increasing sequence these ... Here you will encode integers not via the fixed length of s bits (which ... can trade off some compression optimality for speed by breaking ... 106 bits of arithmetic precision. ...
    (comp.compression)
  • Optimal encoding of monotonic integer sequences
    ... For the linearly increasing sequence these ... Here you will encode integers not via the fixed length of s bits (which ... can trade off some compression optimality for speed by breaking ...
    (sci.math)
  • Re: An Inflationary Account - #6 - Entropy as missing information
    ... before the molecules begin exchanging hydrogen atoms). ... The trick is to use a variable number of bits to encode ... Word Sequence ... encoding is simple if you use random methods can you reproduce your origna message from the encoded bits? ...
    (talk.origins)
  • Re: EXPLICIT vs IMPLICIT tags in ASN.1
    ... could be a SEQUENCE or two mandatory INTEGERs or something? ... STRING when it can be arbitrarily overwritten? ... bits (the header bytes encode how many bits are significant in the last ... The default tag is the one which is conventionally attached to ...
    (sci.crypt)
  • Re: AJAX in prototype.js vs ISO-8859-1
    ... that it doesn't correctly encode ISO-8859-1 éèà ... ... After some test it doesn't work on IE or Firefox but escape() did. ... specification and that specification defines strings as a sequence of Unicode characters and defines how encodeURIComponent works on them. ... Each character that needs to be encoded is replaced by an escape sequence of its UTF-8 representation so ...
    (comp.lang.javascript)