comparison libtomcrypt/src/pk/asn1/der/integer/der_length_integer.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_length_integer.c 14 @file der_length_integer.c
17 17
18 18
19 #ifdef LTC_DER 19 #ifdef LTC_DER
20 /** 20 /**
21 Gets length of DER encoding of num 21 Gets length of DER encoding of num
22 @param num The mp_int to get the size of 22 @param num The int to get the size of
23 @param outlen [out] The length of the DER encoding for the given integer 23 @param outlen [out] The length of the DER encoding for the given integer
24 @return CRYPT_OK if successful 24 @return CRYPT_OK if successful
25 */ 25 */
26 int der_length_integer(mp_int *num, unsigned long *outlen) 26 int der_length_integer(void *num, unsigned long *outlen)
27 { 27 {
28 unsigned long z, len; 28 unsigned long z, len;
29 int leading_zero; 29 int leading_zero;
30 30
31 LTC_ARGCHK(num != NULL); 31 LTC_ARGCHK(num != NULL);
32 LTC_ARGCHK(outlen != NULL); 32 LTC_ARGCHK(outlen != NULL);
33 33
34 if (mp_cmp_d(num, 0) != MP_LT) { 34 if (mp_cmp_d(num, 0) != LTC_MP_LT) {
35 /* positive */ 35 /* positive */
36 36
37 /* we only need a leading zero if the msb of the first byte is one */ 37 /* we only need a leading zero if the msb of the first byte is one */
38 if ((mp_count_bits(num) & 7) == 0 || mp_iszero(num) == MP_YES) { 38 if ((mp_count_bits(num) & 7) == 0 || mp_iszero(num) == LTC_MP_YES) {
39 leading_zero = 1; 39 leading_zero = 1;
40 } else { 40 } else {
41 leading_zero = 0; 41 leading_zero = 0;
42 } 42 }
43 43
47 /* it's negative */ 47 /* it's negative */
48 /* find power of 2 that is a multiple of eight and greater than count bits */ 48 /* find power of 2 that is a multiple of eight and greater than count bits */
49 leading_zero = 0; 49 leading_zero = 0;
50 z = mp_count_bits(num); 50 z = mp_count_bits(num);
51 z = z + (8 - (z & 7)); 51 z = z + (8 - (z & 7));
52 if (((mp_cnt_lsb(num)+1)==mp_count_bits(num)) && ((mp_count_bits(num)&7)==0)) --z;
52 len = z = z >> 3; 53 len = z = z >> 3;
53 } 54 }
54 55
55 /* now we need a length */ 56 /* now we need a length */
56 if (z < 128) { 57 if (z < 128) {
75 } 76 }
76 77
77 #endif 78 #endif
78 79
79 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/integer/der_length_integer.c,v $ */ 80 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/integer/der_length_integer.c,v $ */
80 /* $Revision: 1.1 $ */ 81 /* $Revision: 1.4 $ */
81 /* $Date: 2005/05/16 15:08:11 $ */ 82 /* $Date: 2006/04/22 01:22:55 $ */