Mercurial > dropbear
comparison libtomcrypt/src/pk/asn1/der/bit/der_decode_bit_string.c @ 478:d4f32c3443ac dbclient-netcat-alike
propagate from branch 'au.asn.ucc.matt.dropbear' (head f21045c791002d81fc6b8dde6537ea481e513eb2)
to branch 'au.asn.ucc.matt.dropbear.dbclient-netcat-alike' (head d1f69334581dc4c35f9ca16aa5355074c9dd315d)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sun, 14 Sep 2008 06:47:51 +0000 |
parents | 0cbe8f6dbf9e |
children | f849a5ca2efc |
comparison
equal
deleted
inserted
replaced
296:6b41e2cbf071 | 478:d4f32c3443ac |
---|---|
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 $ */ |