Mercurial > dropbear
comparison src/pk/asn1/der/integer/der_decode_integer.c @ 380:d5faf4814ddb libtomcrypt-orig libtomcrypt-1.16
Update to LibTomCrypt 1.16
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 11 Jan 2007 02:22:00 +0000 |
parents | 59400faa4b44 |
children |
comparison
equal
deleted
inserted
replaced
280:59400faa4b44 | 380:d5faf4814ddb |
---|---|
4 * algorithms in a highly modular and flexible manner. | 4 * algorithms in a highly modular and flexible manner. |
5 * | 5 * |
6 * The library is free for all purposes without any express | 6 * The library is free for all purposes without any express |
7 * guarantee it works. | 7 * guarantee it works. |
8 * | 8 * |
9 * Tom St Denis, [email protected], http://libtomcrypt.org | 9 * Tom St Denis, [email protected], http://libtomcrypt.com |
10 */ | 10 */ |
11 #include "tomcrypt.h" | 11 #include "tomcrypt.h" |
12 | 12 |
13 /** | 13 /** |
14 @file der_decode_integer.c | 14 @file der_decode_integer.c |
23 @param in The DER encoded data | 23 @param in The DER encoded data |
24 @param inlen Size of DER encoded data | 24 @param inlen Size of DER encoded data |
25 @param num The first mp_int to decode | 25 @param num The first mp_int to decode |
26 @return CRYPT_OK if successful | 26 @return CRYPT_OK if successful |
27 */ | 27 */ |
28 int der_decode_integer(const unsigned char *in, unsigned long inlen, mp_int *num) | 28 int der_decode_integer(const unsigned char *in, unsigned long inlen, void *num) |
29 { | 29 { |
30 unsigned long x, y, z; | 30 unsigned long x, y, z; |
31 int err; | 31 int err; |
32 | 32 |
33 LTC_ARGCHK(num != NULL); | 33 LTC_ARGCHK(num != NULL); |
54 if (x + z > inlen) { | 54 if (x + z > inlen) { |
55 return CRYPT_INVALID_PACKET; | 55 return CRYPT_INVALID_PACKET; |
56 } | 56 } |
57 | 57 |
58 /* no so read it */ | 58 /* no so read it */ |
59 if ((err = mpi_to_ltc_error(mp_read_unsigned_bin(num, (unsigned char *)in + x, z))) != CRYPT_OK) { | 59 if ((err = mp_read_unsigned_bin(num, (unsigned char *)in + x, z)) != CRYPT_OK) { |
60 return err; | 60 return err; |
61 } | 61 } |
62 } else { | 62 } else { |
63 /* long form */ | 63 /* long form */ |
64 z &= 0x7F; | 64 z &= 0x7F; |
78 if ((x + y) > inlen) { | 78 if ((x + y) > inlen) { |
79 return CRYPT_INVALID_PACKET; | 79 return CRYPT_INVALID_PACKET; |
80 } | 80 } |
81 | 81 |
82 /* no so read it */ | 82 /* no so read it */ |
83 if ((err = mpi_to_ltc_error(mp_read_unsigned_bin(num, (unsigned char *)in + x, y))) != CRYPT_OK) { | 83 if ((err = mp_read_unsigned_bin(num, (unsigned char *)in + x, y)) != CRYPT_OK) { |
84 return err; | 84 return err; |
85 } | 85 } |
86 } | 86 } |
87 | 87 |
88 /* see if it's negative */ | 88 /* see if it's negative */ |
89 if (in[x] & 0x80) { | 89 if (in[x] & 0x80) { |
90 mp_int tmp; | 90 void *tmp; |
91 if (mp_init(&tmp) != MP_OKAY) { | 91 if (mp_init(&tmp) != CRYPT_OK) { |
92 return CRYPT_MEM; | 92 return CRYPT_MEM; |
93 } | 93 } |
94 | 94 |
95 if (mp_2expt(&tmp, mp_count_bits(num)) != MP_OKAY || mp_sub(num, &tmp, num) != MP_OKAY) { | 95 if (mp_2expt(tmp, mp_count_bits(num)) != CRYPT_OK || mp_sub(num, tmp, num) != CRYPT_OK) { |
96 mp_clear(&tmp); | 96 mp_clear(tmp); |
97 return CRYPT_MEM; | 97 return CRYPT_MEM; |
98 } | 98 } |
99 mp_clear(&tmp); | 99 mp_clear(tmp); |
100 } | 100 } |
101 | 101 |
102 return CRYPT_OK; | 102 return CRYPT_OK; |
103 | 103 |
104 } | 104 } |
105 | 105 |
106 #endif | 106 #endif |
107 | 107 |
108 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/integer/der_decode_integer.c,v $ */ | 108 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/integer/der_decode_integer.c,v $ */ |
109 /* $Revision: 1.2 $ */ | 109 /* $Revision: 1.4 $ */ |
110 /* $Date: 2005/06/01 00:06:05 $ */ | 110 /* $Date: 2006/03/31 14:15:35 $ */ |