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
12 @file der_decode_short_integer.c
13 ASN.1 DER, decode an integer, Tom St Denis
21 @param in The DER encoded data
22 @param inlen Size of data
23 @param num [out] The integer to decode
24 @return CRYPT_OK if successful
26 int der_decode_short_integer(const unsigned char *in, unsigned long inlen, unsigned long *num)
28 unsigned long len, x, y;
30 LTC_ARGCHK(num != NULL);
31 LTC_ARGCHK(in != NULL);
35 return CRYPT_INVALID_PACKET;
40 if ((in[x++] & 0x1F) != 0x02) {
41 return CRYPT_INVALID_PACKET;
44 /* get the packet len */
47 if (x + len > inlen) {
48 return CRYPT_INVALID_PACKET;
54 y = (y<<8) | (unsigned long)in[x++];
64 /* ref: $Format:%D$ */
65 /* git commit: $Format:%H$ */
66 /* commit time: $Format:%ai$ */