Mercurial > dropbear
comparison libtommath/bn_mp_reduce_is_2k.c @ 1655:f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
* make key-generation compliant to FIPS 186.4
* fix includes in tommath_class.h
* update fuzzcorpus instead of error-out
* fixup fuzzing make-targets
* update Makefile.in
* apply necessary patches to ltm sources
* clean-up not required ltm files
* update to vanilla ltm 1.1.0
this already only contains the required files
* remove set/get double
author | Steffen Jaeckel <s_jaeckel@gmx.de> |
---|---|
date | Mon, 16 Sep 2019 15:50:38 +0200 |
parents | 8bba51a55704 |
children | 1051e4eea25a |
comparison
equal
deleted
inserted
replaced
1654:cc0fc5131c5c | 1655:f52919ffd3b1 |
---|---|
1 #include <tommath_private.h> | 1 #include "tommath_private.h" |
2 #ifdef BN_MP_REDUCE_IS_2K_C | 2 #ifdef BN_MP_REDUCE_IS_2K_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. |
7 * | 7 * |
8 * The library was designed directly after the MPI library by | 8 * The library was designed directly after the MPI library by |
9 * Michael Fromberger but has been written from scratch with | 9 * Michael Fromberger but has been written from scratch with |
10 * additional optimizations in place. | 10 * additional optimizations in place. |
11 * | 11 * |
12 * The library is free for all purposes without any express | 12 * SPDX-License-Identifier: Unlicense |
13 * guarantee it works. | |
14 * | |
15 * Tom St Denis, [email protected], http://libtom.org | |
16 */ | 13 */ |
17 | 14 |
18 /* determines if mp_reduce_2k can be used */ | 15 /* determines if mp_reduce_2k can be used */ |
19 int mp_reduce_is_2k(mp_int *a) | 16 int mp_reduce_is_2k(const mp_int *a) |
20 { | 17 { |
21 int ix, iy, iw; | 18 int ix, iy, iw; |
22 mp_digit iz; | 19 mp_digit iz; |
23 | 20 |
24 if (a->used == 0) { | 21 if (a->used == 0) { |
25 return MP_NO; | 22 return MP_NO; |
26 } else if (a->used == 1) { | 23 } else if (a->used == 1) { |
27 return MP_YES; | 24 return MP_YES; |
28 } else if (a->used > 1) { | 25 } else if (a->used > 1) { |
29 iy = mp_count_bits(a); | 26 iy = mp_count_bits(a); |
30 iz = 1; | 27 iz = 1; |
31 iw = 1; | 28 iw = 1; |
32 | 29 |
33 /* Test every bit from the second digit up, must be 1 */ | 30 /* Test every bit from the second digit up, must be 1 */ |
34 for (ix = DIGIT_BIT; ix < iy; ix++) { | 31 for (ix = DIGIT_BIT; ix < iy; ix++) { |
35 if ((a->dp[iw] & iz) == 0) { | 32 if ((a->dp[iw] & iz) == 0u) { |
36 return MP_NO; | 33 return MP_NO; |
37 } | 34 } |
38 iz <<= 1; | 35 iz <<= 1; |
39 if (iz > (mp_digit)MP_MASK) { | 36 if (iz > (mp_digit)MP_MASK) { |
40 ++iw; | 37 ++iw; |
41 iz = 1; | 38 iz = 1; |
42 } | 39 } |
43 } | 40 } |
44 } | 41 } |
45 return MP_YES; | 42 return MP_YES; |
46 } | 43 } |
47 | 44 |
48 #endif | 45 #endif |
49 | 46 |
50 /* ref: $Format:%D$ */ | 47 /* ref: HEAD -> master, tag: v1.1.0 */ |
51 /* git commit: $Format:%H$ */ | 48 /* git commit: 08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */ |
52 /* commit time: $Format:%ai$ */ | 49 /* commit time: 2019-01-28 20:32:32 +0100 */ |