ASN.1 integers are encoded as two's complement numbers. This means that the most significant bit of a positive number must be zero and the most significant bit of a negative integer must be set to one. Additionally prepended 0x00 octets for positive and 0xFF octets for negative numbers, respectively are discarded. Here are some examples I used in my ASN.1 lecture a couple of years back
http://www.strongsec.com/zhw/KSy_ASN1.pdf (slide 22) BER coding of two‘s complement integers • -129: 1111 1111 0111 1111 = 02 02 FF 7F • -128: 1111 1111 1000 0000 = 02 01 80 • -127: 1111 1111 1000 0001 = 02 01 81 • -1: 1111 1111 1111 1111 = 02 01 FF • 0: 0000 0000 0000 0000 = 02 00 • 1: 0000 0000 0000 0001 = 02 01 01 • 127: 0000 0000 0111 1111 = 02 01 7F • 128: 0000 0000 1000 0000 = 02 02 00 80 • 129: 0000 0000 1000 0001 = 02 02 00 81 Best regards Andreas Alessandro Premoli wrote: > Ludovic Rousseau ha scritto: >> Do we have ASN.1 experts on this list? > > Yes. You are right, these are the rules: > > If the contents octets of an integer value encoding consist of more than > one octet, then the bits of the first octet and bit 8 of the second octet: > a) shall not all be ones; and > b) shall not all be zero. > NOTE – These rules ensure that an integer value is always encoded in the > smallest possible number of octets. > > The correct encodings of 128 and -128 are: > > (128) 02:02:00:80 > (-128) 02:01:80 > > Anything else is wrong. > > -- > Alessandro Premoli ====================================================================== Andreas Steffen [EMAIL PROTECTED] strongSwan - the Linux VPN Solution! www.strongswan.org Institute for Internet Technologies and Applications University of Applied Sciences Rapperswil CH-8640 Rapperswil (Switzerland) ===========================================================[ITA-HSR]== _______________________________________________ opensc-devel mailing list opensc-devel@lists.opensc-project.org http://www.opensc-project.org/mailman/listinfo/opensc-devel