comparison libtomcrypt/src/pk/asn1/der/bit/der_decode_bit_string.c @ 382:0cbe8f6dbf9e

propagate from branch 'au.asn.ucc.matt.ltc.dropbear' (head 2af22fb4e878750b88f80f90d439b316d229796f) to branch 'au.asn.ucc.matt.dropbear' (head 02c413252c90e9de8e03d91e9939dde3029f5c0a)
author Matt Johnston <matt@ucc.asn.au>
date Thu, 11 Jan 2007 02:41:05 +0000
parents 1b9e69c058d2
children f849a5ca2efc
comparison
equal deleted inserted replaced
379:b66a00272a90 382:0cbe8f6dbf9e
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 $ */