Mercurial > dropbear
comparison libtomcrypt/src/pk/asn1/der/bit/der_decode_bit_string.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_bit_string.c | 14 @file der_decode_bit_string.c |
49 x = 1; | 49 x = 1; |
50 | 50 |
51 /* get the length of the data */ | 51 /* get the length of the data */ |
52 if (in[x] & 0x80) { | 52 if (in[x] & 0x80) { |
53 /* long format get number of length bytes */ | 53 /* long format get number of length bytes */ |
54 y = in[x++] & 127; | 54 y = in[x++] & 0x7F; |
55 | 55 |
56 /* invalid if 0 or > 2 */ | 56 /* invalid if 0 or > 2 */ |
57 if (y == 0 || y > 2) { | 57 if (y == 0 || y > 2) { |
58 return CRYPT_INVALID_PACKET; | 58 return CRYPT_INVALID_PACKET; |
59 } | 59 } |
63 while (y--) { | 63 while (y--) { |
64 dlen = (dlen << 8) | (unsigned long)in[x++]; | 64 dlen = (dlen << 8) | (unsigned long)in[x++]; |
65 } | 65 } |
66 } else { | 66 } else { |
67 /* short format */ | 67 /* short format */ |
68 dlen = in[x++] & 127; | 68 dlen = in[x++] & 0x7F; |
69 } | 69 } |
70 | 70 |
71 /* is the data len too long or too short? */ | 71 /* is the data len too long or too short? */ |
72 if ((dlen == 0) || (dlen + x > inlen)) { | 72 if ((dlen == 0) || (dlen + x > inlen)) { |
73 return CRYPT_INVALID_PACKET; | 73 return CRYPT_INVALID_PACKET; |
76 /* get padding count */ | 76 /* get padding count */ |
77 blen = ((dlen - 1) << 3) - (in[x++] & 7); | 77 blen = ((dlen - 1) << 3) - (in[x++] & 7); |
78 | 78 |
79 /* too many bits? */ | 79 /* too many bits? */ |
80 if (blen > *outlen) { | 80 if (blen > *outlen) { |
81 *outlen = blen; | |
81 return CRYPT_BUFFER_OVERFLOW; | 82 return CRYPT_BUFFER_OVERFLOW; |
82 } | 83 } |
83 | 84 |
84 /* decode/store the bits */ | 85 /* decode/store the bits */ |
85 for (y = 0; y < blen; y++) { | 86 for (y = 0; y < blen; y++) { |
95 } | 96 } |
96 | 97 |
97 #endif | 98 #endif |
98 | 99 |
99 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/bit/der_decode_bit_string.c,v $ */ | 100 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/bit/der_decode_bit_string.c,v $ */ |
100 /* $Revision: 1.1 $ */ | 101 /* $Revision: 1.4 $ */ |
101 /* $Date: 2005/05/16 15:08:11 $ */ | 102 /* $Date: 2006/06/16 21:53:41 $ */ |