comparison libtommath/bn_mp_radix_size.c @ 1439:8d24733026c5 coverity

merge
author Matt Johnston <matt@ucc.asn.au>
date Sat, 24 Jun 2017 23:33:16 +0800
parents 60fc6476e044
children 8bba51a55704
comparison
equal deleted inserted replaced
1400:238a439670f5 1439:8d24733026c5
1 #include <tommath.h> 1 #include <tommath_private.h>
2 #ifdef BN_MP_RADIX_SIZE_C 2 #ifdef BN_MP_RADIX_SIZE_C
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis 3 /* LibTomMath, multiple-precision integer library -- Tom St Denis
4 * 4 *
5 * LibTomMath is a library that provides multiple-precision 5 * LibTomMath is a library that provides multiple-precision
6 * integer arithmetic as well as number theoretic functionality. 6 * integer arithmetic as well as number theoretic functionality.
10 * additional optimizations in place. 10 * additional optimizations in place.
11 * 11 *
12 * The library is free for all purposes without any express 12 * The library is free for all purposes without any express
13 * guarantee it works. 13 * guarantee it works.
14 * 14 *
15 * Tom St Denis, [email protected], http://math.libtomcrypt.com 15 * Tom St Denis, [email protected], http://libtom.org
16 */ 16 */
17 17
18 /* returns size of ASCII reprensentation */ 18 /* returns size of ASCII reprensentation */
19 int mp_radix_size (mp_int * a, int radix, int *size) 19 int mp_radix_size (mp_int * a, int radix, int *size)
20 { 20 {
22 mp_int t; 22 mp_int t;
23 mp_digit d; 23 mp_digit d;
24 24
25 *size = 0; 25 *size = 0;
26 26
27 /* special case for binary */
28 if (radix == 2) {
29 *size = mp_count_bits (a) + (a->sign == MP_NEG ? 1 : 0) + 1;
30 return MP_OKAY;
31 }
32
33 /* make sure the radix is in range */ 27 /* make sure the radix is in range */
34 if (radix < 2 || radix > 64) { 28 if ((radix < 2) || (radix > 64)) {
35 return MP_VAL; 29 return MP_VAL;
36 } 30 }
37 31
38 if (mp_iszero(a) == MP_YES) { 32 if (mp_iszero(a) == MP_YES) {
39 *size = 2; 33 *size = 2;
34 return MP_OKAY;
35 }
36
37 /* special case for binary */
38 if (radix == 2) {
39 *size = mp_count_bits (a) + ((a->sign == MP_NEG) ? 1 : 0) + 1;
40 return MP_OKAY; 40 return MP_OKAY;
41 } 41 }
42 42
43 /* digs is the digit count */ 43 /* digs is the digit count */
44 digs = 0; 44 digs = 0;
71 return MP_OKAY; 71 return MP_OKAY;
72 } 72 }
73 73
74 #endif 74 #endif
75 75
76 /* $Source: /cvs/libtom/libtommath/bn_mp_radix_size.c,v $ */ 76 /* $Source$ */
77 /* $Revision: 1.4 $ */ 77 /* $Revision$ */
78 /* $Date: 2006/03/31 14:18:44 $ */ 78 /* $Date$ */