comparison libtomcrypt/src/pk/asn1/der/short_integer/der_decode_short_integer.c @ 285:1b9e69c058d2

propagate from branch 'au.asn.ucc.matt.ltc.dropbear' (head 20dccfc09627970a312d77fb41dc2970b62689c3) to branch 'au.asn.ucc.matt.dropbear' (head fdf4a7a3b97ae5046139915de7e40399cceb2c01)
author Matt Johnston <matt@ucc.asn.au>
date Wed, 08 Mar 2006 13:23:58 +0000
parents
children 0cbe8f6dbf9e
comparison
equal deleted inserted replaced
281:997e6f7dc01e 285:1b9e69c058d2
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 *
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
5 *
6 * The library is free for all purposes without any express
7 * guarantee it works.
8 *
9 * Tom St Denis, [email protected], http://libtomcrypt.org
10 */
11 #include "tomcrypt.h"
12
13 /**
14 @file der_decode_short_integer.c
15 ASN.1 DER, decode an integer, Tom St Denis
16 */
17
18
19 #ifdef LTC_DER
20
21 /**
22 Read a mp_int integer
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
27 */
28 int der_decode_short_integer(const unsigned char *in, unsigned long inlen, unsigned long *num)
29 {
30 unsigned long len, x, y;
31
32 LTC_ARGCHK(num != NULL);
33 LTC_ARGCHK(in != NULL);
34
35 /* check length */
36 if (inlen < 2) {
37 return CRYPT_INVALID_PACKET;
38 }
39
40 /* check header */
41 x = 0;
42 if ((in[x++] & 0x1F) != 0x02) {
43 return CRYPT_INVALID_PACKET;
44 }
45
46 /* get the packet len */
47 len = in[x++];
48
49 if (x + len > inlen) {
50 return CRYPT_INVALID_PACKET;
51 }
52
53 /* read number */
54 y = 0;
55 while (len--) {
56 y = (y<<8) | (unsigned long)in[x++];
57 }
58 *num = y;
59
60 return CRYPT_OK;
61
62 }
63
64 #endif
65
66 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/short_integer/der_decode_short_integer.c,v $ */
67 /* $Revision: 1.4 $ */
68 /* $Date: 2005/05/23 01:04:13 $ */