Mercurial > dropbear
comparison libtomcrypt/src/pk/asn1/der/integer/der_decode_integer.c @ 398:59c7938af2bd
merge of '1250b8af44b62d8f4fe0f8d9fc7e7a1cc34e7e1c'
and '7f8670ac3bb975f40967f3979d09d2199b7e90c8'
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 03 Feb 2007 08:20:30 +0000 |
parents | 0cbe8f6dbf9e |
children | f849a5ca2efc |
comparison
equal
deleted
inserted
replaced
396:e7c1a77d2921 | 398:59c7938af2bd |
---|---|
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 $ */ |