comparison libtommath/bn_mp_div_d.c @ 1437:871b18fd7065 fuzz

merge from main (libtommath/libtomcrypt/curve25510-donna updates)
author Matt Johnston <matt@ucc.asn.au>
date Sat, 24 Jun 2017 22:51:45 +0800
parents 60fc6476e044
children 8bba51a55704
comparison
equal deleted inserted replaced
1432:41dca1e5ea34 1437:871b18fd7065
1 #include <tommath.h> 1 #include <tommath_private.h>
2 #ifdef BN_MP_DIV_D_C 2 #ifdef BN_MP_DIV_D_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 static int s_is_power_of_two(mp_digit b, int *p) 18 static int s_is_power_of_two(mp_digit b, int *p)
19 { 19 {
20 int x; 20 int x;
21 21
22 for (x = 1; x < DIGIT_BIT; x++) { 22 /* fast return if no power of two */
23 if ((b == 0) || ((b & (b-1)) != 0)) {
24 return 0;
25 }
26
27 for (x = 0; x < DIGIT_BIT; x++) {
23 if (b == (((mp_digit)1)<<x)) { 28 if (b == (((mp_digit)1)<<x)) {
24 *p = x; 29 *p = x;
25 return 1; 30 return 1;
26 } 31 }
27 } 32 }
40 if (b == 0) { 45 if (b == 0) {
41 return MP_VAL; 46 return MP_VAL;
42 } 47 }
43 48
44 /* quick outs */ 49 /* quick outs */
45 if (b == 1 || mp_iszero(a) == 1) { 50 if ((b == 1) || (mp_iszero(a) == MP_YES)) {
46 if (d != NULL) { 51 if (d != NULL) {
47 *d = 0; 52 *d = 0;
48 } 53 }
49 if (c != NULL) { 54 if (c != NULL) {
50 return mp_copy(a, c); 55 return mp_copy(a, c);
103 return res; 108 return res;
104 } 109 }
105 110
106 #endif 111 #endif
107 112
108 /* $Source: /cvs/libtom/libtommath/bn_mp_div_d.c,v $ */ 113 /* $Source$ */
109 /* $Revision: 1.3 $ */ 114 /* $Revision$ */
110 /* $Date: 2006/03/31 14:18:44 $ */ 115 /* $Date$ */