comparison src/pk/asn1/der/short_integer/der_decode_short_integer.c @ 209:39d5d58461d6 libtomcrypt-orig LTC_1.05

Import of libtomcrypt 1.05
author Matt Johnston <matt@ucc.asn.au>
date Wed, 06 Jul 2005 03:53:40 +0000
parents
children d5faf4814ddb
comparison
equal deleted inserted replaced
191:1c15b283127b 209:39d5d58461d6
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 $ */