From: Clifford Heath Date: 2003-06-02T13:22:55+09:00 Subject: Re: What is BER compression? (was RCR: unpack/pack Bignum) Dan Sugalski wrote: > It's an old format for storing indefinite precision integers. > Google says it's used as part of the ASN1 stuff as well. BER = Basic Encoding Rules. The term comes from ISO networking, all the protocols of which are defined in terms of protocol data units (messages) defined in ASN.1. ASN.1 then requires choice of one of the sets of encoding rules (BER, DER, XER, PER, etc) to turn a possibly large, composite and unknown-length data value into an unambiguous bitstream. Sort-of like what the funky XMLschema folk have re-invented, but better - at least it doesn't cause contortions like those required for XML signatures :-) The BER format described by Sam isn't BER for an integer, but is rather an encoding that BER uses internally to encode positive integers used in OIDs and tag numbers. BER for an integer includes a tag (0x02), a length, and the data bytes. The length is either a length byte < 0x80, or the length of a multi-byte length field (or-ed with 0x80) and that number of bytes. The signed twos-complement byte-extended integer then follows. Unsigned integers need a leading zero, so to represent 128 takes two data bytes. BTW, because BER allows more than one way to encode some things, which is not good for cryptographic signatures, DER (Distinguished Encoding Rules) limit things to exactly one alternative in each case. No contortions required... PER (Packed Encoding Rules) specify a minimum-possible encoding length for a given ASN.1, and XER (XML Encoding Rules) specifies a maximum-length encoding :-))). Or close :-P ASN.1 is not dead. It's perhaps nobbled though by being too powerful, because of the preponderance of incompetent, poorly designed and overpriced tools available for it. Clifford Heath.