1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
6 * The library is free for all purposes without any express
9 * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
14 @file der_decode_short_integer.c
15 ASN.1 DER, decode an integer, Tom St Denis
23 @param in The DER encoded data
24 @param inlen Size of data
25 @param num [out] The integer to decode
26 @return CRYPT_OK if successful
28 int der_decode_short_integer(const unsigned char *in, unsigned long inlen, unsigned long *num)
30 unsigned long len, x, y;
32 LTC_ARGCHK(num != NULL);
33 LTC_ARGCHK(in != NULL);
37 return CRYPT_INVALID_PACKET;
42 if ((in[x++] & 0x1F) != 0x02) {
43 return CRYPT_INVALID_PACKET;
46 /* get the packet len */
49 if (x + len > inlen) {
50 return CRYPT_INVALID_PACKET;
56 y = (y<<8) | (unsigned long)in[x++];
66 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/short_integer/der_decode_short_integer.c,v $ */
67 /* $Revision: 1.6 $ */
68 /* $Date: 2006/03/31 14:15:35 $ */