Mercurial > dropbear
comparison libtomcrypt/src/pk/asn1/der/bit/der_length_bit_string.c @ 1511:5916af64acd4 fuzz
merge from main
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 17 Feb 2018 19:29:51 +0800 |
parents | 6dba84798cd5 |
children |
comparison
equal
deleted
inserted
replaced
1457:32f990cc96b1 | 1511:5916af64acd4 |
---|---|
3 * LibTomCrypt is a library that provides various cryptographic | 3 * LibTomCrypt is a library that provides various cryptographic |
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 * | |
9 * Tom St Denis, [email protected], http://libtom.org | |
10 */ | 8 */ |
11 #include "tomcrypt.h" | 9 #include "tomcrypt.h" |
12 | 10 |
13 /** | 11 /** |
14 @file der_length_bit_string.c | 12 @file der_length_bit_string.c |
15 ASN.1 DER, get length of BIT STRING, Tom St Denis | 13 ASN.1 DER, get length of BIT STRING, Tom St Denis |
16 */ | 14 */ |
17 | 15 |
18 #ifdef LTC_DER | 16 #ifdef LTC_DER |
19 /** | 17 /** |
20 Gets length of DER encoding of BIT STRING | 18 Gets length of DER encoding of BIT STRING |
21 @param nbits The number of bits in the string to encode | 19 @param nbits The number of bits in the string to encode |
22 @param outlen [out] The length of the DER encoding for the given string | 20 @param outlen [out] The length of the DER encoding for the given string |
23 @return CRYPT_OK if successful | 21 @return CRYPT_OK if successful |
24 */ | 22 */ |
25 int der_length_bit_string(unsigned long nbits, unsigned long *outlen) | 23 int der_length_bit_string(unsigned long nbits, unsigned long *outlen) |
27 unsigned long nbytes; | 25 unsigned long nbytes; |
28 LTC_ARGCHK(outlen != NULL); | 26 LTC_ARGCHK(outlen != NULL); |
29 | 27 |
30 /* get the number of the bytes */ | 28 /* get the number of the bytes */ |
31 nbytes = (nbits >> 3) + ((nbits & 7) ? 1 : 0) + 1; | 29 nbytes = (nbits >> 3) + ((nbits & 7) ? 1 : 0) + 1; |
32 | 30 |
33 if (nbytes < 128) { | 31 if (nbytes < 128) { |
34 /* 03 LL PP DD DD DD ... */ | 32 /* 03 LL PP DD DD DD ... */ |
35 *outlen = 2 + nbytes; | 33 *outlen = 2 + nbytes; |
36 } else if (nbytes < 256) { | 34 } else if (nbytes < 256) { |
37 /* 03 81 LL PP DD DD DD ... */ | 35 /* 03 81 LL PP DD DD DD ... */ |
47 } | 45 } |
48 | 46 |
49 #endif | 47 #endif |
50 | 48 |
51 | 49 |
52 /* $Source$ */ | 50 /* ref: $Format:%D$ */ |
53 /* $Revision$ */ | 51 /* git commit: $Format:%H$ */ |
54 /* $Date$ */ | 52 /* commit time: $Format:%ai$ */ |