3e4a757915f3a324bff5ad7fcc5d48c1173769be
[bcm963xx.git] / userapps / opensource / sshd / libtommath / bn_mp_reduce_is_2k.c
1 /* LibTomMath, multiple-precision integer library -- Tom St Denis\r
2  *\r
3  * LibTomMath is library that provides for multiple-precision\r
4  * integer arithmetic as well as number theoretic functionality.\r
5  *\r
6  * The library is designed directly after the MPI library by\r
7  * Michael Fromberger but has been written from scratch with\r
8  * additional optimizations in place.\r
9  *\r
10  * The library is free for all purposes without any express\r
11  * guarantee it works.\r
12  *\r
13  * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org\r
14  */\r
15 #include <tommath.h>\r
16 \r
17 /* determines if mp_reduce_2k can be used */\r
18 int \r
19 mp_reduce_is_2k(mp_int *a)\r
20 {\r
21    int ix, iy;\r
22    \r
23    if (a->used == 0) {\r
24       return 0;\r
25    } else if (a->used == 1) {\r
26       return 1;\r
27    } else if (a->used > 1) {\r
28       iy = mp_count_bits(a);\r
29       for (ix = DIGIT_BIT; ix < iy; ix++) {\r
30           if ((a->dp[ix/DIGIT_BIT] & \r
31               ((mp_digit)1 << (mp_digit)(ix % DIGIT_BIT))) == 0) {\r
32              return 0;\r
33           }\r
34       }\r
35    }\r
36    return 1;\r
37 }\r
38 \r