Mercurial > dropbear
comparison libtomcrypt/src/pk/asn1/der/integer/der_length_integer.c @ 1471:6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 09 Feb 2018 21:44:05 +0800 |
parents | f849a5ca2efc |
children |
comparison
equal
deleted
inserted
replaced
1470:8bba51a55704 | 1471:6dba84798cd5 |
---|---|
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_integer.c | 12 @file der_length_integer.c |
16 */ | 14 */ |
17 | 15 |
18 | 16 |
19 #ifdef LTC_DER | 17 #ifdef LTC_DER |
20 /** | 18 /** |
21 Gets length of DER encoding of num | 19 Gets length of DER encoding of num |
22 @param num The int to get the size of | 20 @param num The int to get the size of |
23 @param outlen [out] The length of the DER encoding for the given integer | 21 @param outlen [out] The length of the DER encoding for the given integer |
24 @return CRYPT_OK if successful | 22 @return CRYPT_OK if successful |
25 */ | 23 */ |
26 int der_length_integer(void *num, unsigned long *outlen) | 24 int der_length_integer(void *num, unsigned long *outlen) |
27 { | 25 { |
44 /* size for bignum */ | 42 /* size for bignum */ |
45 z = len = leading_zero + mp_unsigned_bin_size(num); | 43 z = len = leading_zero + mp_unsigned_bin_size(num); |
46 } else { | 44 } else { |
47 /* it's negative */ | 45 /* it's negative */ |
48 /* find power of 2 that is a multiple of eight and greater than count bits */ | 46 /* find power of 2 that is a multiple of eight and greater than count bits */ |
49 leading_zero = 0; | |
50 z = mp_count_bits(num); | 47 z = mp_count_bits(num); |
51 z = z + (8 - (z & 7)); | 48 z = z + (8 - (z & 7)); |
52 if (((mp_cnt_lsb(num)+1)==mp_count_bits(num)) && ((mp_count_bits(num)&7)==0)) --z; | 49 if (((mp_cnt_lsb(num)+1)==mp_count_bits(num)) && ((mp_count_bits(num)&7)==0)) --z; |
53 len = z = z >> 3; | 50 len = z = z >> 3; |
54 } | 51 } |
69 | 66 |
70 /* we need a 0x02 to indicate it's INTEGER */ | 67 /* we need a 0x02 to indicate it's INTEGER */ |
71 ++len; | 68 ++len; |
72 | 69 |
73 /* return length */ | 70 /* return length */ |
74 *outlen = len; | 71 *outlen = len; |
75 return CRYPT_OK; | 72 return CRYPT_OK; |
76 } | 73 } |
77 | 74 |
78 #endif | 75 #endif |
79 | 76 |
80 /* $Source$ */ | 77 /* ref: $Format:%D$ */ |
81 /* $Revision$ */ | 78 /* git commit: $Format:%H$ */ |
82 /* $Date$ */ | 79 /* commit time: $Format:%ai$ */ |