comparison libtommath/bn_mp_sqr.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_SQR_C 2 #ifdef BN_MP_SQR_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 /* computes b = a*a */ 15 /* computes b = a*a */
19 int 16 int mp_sqr(const mp_int *a, mp_int *b)
20 mp_sqr (mp_int * a, mp_int * b)
21 { 17 {
22 int res; 18 int res;
23 19
24 #ifdef BN_MP_TOOM_SQR_C 20 #ifdef BN_MP_TOOM_SQR_C
25 /* use Toom-Cook? */ 21 /* use Toom-Cook? */
26 if (a->used >= TOOM_SQR_CUTOFF) { 22 if (a->used >= TOOM_SQR_CUTOFF) {
27 res = mp_toom_sqr(a, b); 23 res = mp_toom_sqr(a, b);
28 /* Karatsuba? */ 24 /* Karatsuba? */
29 } else 25 } else
30 #endif 26 #endif
31 #ifdef BN_MP_KARATSUBA_SQR_C 27 #ifdef BN_MP_KARATSUBA_SQR_C
32 if (a->used >= KARATSUBA_SQR_CUTOFF) { 28 if (a->used >= KARATSUBA_SQR_CUTOFF) {
33 res = mp_karatsuba_sqr (a, b); 29 res = mp_karatsuba_sqr(a, b);
34 } else 30 } else
35 #endif 31 #endif
36 { 32 {
37 #ifdef BN_FAST_S_MP_SQR_C 33 #ifdef BN_FAST_S_MP_SQR_C
38 /* can we use the fast comba multiplier? */ 34 /* can we use the fast comba multiplier? */
39 if ((((a->used * 2) + 1) < MP_WARRAY) && 35 if ((((a->used * 2) + 1) < (int)MP_WARRAY) &&
40 (a->used < 36 (a->used <
41 (1 << (((sizeof(mp_word) * CHAR_BIT) - (2 * DIGIT_BIT)) - 1)))) { 37 (int)(1u << (((sizeof(mp_word) * (size_t)CHAR_BIT) - (2u * (size_t)DIGIT_BIT)) - 1u)))) {
42 res = fast_s_mp_sqr (a, b); 38 res = fast_s_mp_sqr(a, b);
43 } else 39 } else
44 #endif 40 #endif
45 { 41 {
46 #ifdef BN_S_MP_SQR_C 42 #ifdef BN_S_MP_SQR_C
47 res = s_mp_sqr (a, b); 43 res = s_mp_sqr(a, b);
48 #else 44 #else
49 res = MP_VAL; 45 res = MP_VAL;
50 #endif 46 #endif
51 } 47 }
52 } 48 }
53 b->sign = MP_ZPOS; 49 b->sign = MP_ZPOS;
54 return res; 50 return res;
55 } 51 }
56 #endif 52 #endif
57 53
58 /* ref: $Format:%D$ */ 54 /* ref: HEAD -> master, tag: v1.1.0 */
59 /* git commit: $Format:%H$ */ 55 /* git commit: 08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */
60 /* commit time: $Format:%ai$ */ 56 /* commit time: 2019-01-28 20:32:32 +0100 */