Mercurial > dropbear
comparison libtommath/bn_mp_sqr.c @ 1692:1051e4eea25a
Update LibTomMath to 1.2.0 (#84)
* update C files
* update other files
* update headers
* update makefiles
* remove mp_set/get_double()
* use ltm 1.2.0 API
* update ltm_desc
* use bundled tommath if system-tommath is too old
* XMALLOC etc. were changed to MP_MALLOC etc.
author | Steffen Jaeckel <s@jaeckel.eu> |
---|---|
date | Tue, 26 May 2020 17:36:47 +0200 |
parents | f52919ffd3b1 |
children |
comparison
equal
deleted
inserted
replaced
1691:2d3745d58843 | 1692:1051e4eea25a |
---|---|
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 /* SPDX-License-Identifier: Unlicense */ |
5 * LibTomMath is a library that provides multiple-precision | |
6 * integer arithmetic as well as number theoretic functionality. | |
7 * | |
8 * The library was designed directly after the MPI library by | |
9 * Michael Fromberger but has been written from scratch with | |
10 * additional optimizations in place. | |
11 * | |
12 * SPDX-License-Identifier: Unlicense | |
13 */ | |
14 | 5 |
15 /* computes b = a*a */ | 6 /* computes b = a*a */ |
16 int mp_sqr(const mp_int *a, mp_int *b) | 7 mp_err mp_sqr(const mp_int *a, mp_int *b) |
17 { | 8 { |
18 int res; | 9 mp_err err; |
19 | 10 if (MP_HAS(S_MP_TOOM_SQR) && /* use Toom-Cook? */ |
20 #ifdef BN_MP_TOOM_SQR_C | 11 (a->used >= MP_TOOM_SQR_CUTOFF)) { |
21 /* use Toom-Cook? */ | 12 err = s_mp_toom_sqr(a, b); |
22 if (a->used >= TOOM_SQR_CUTOFF) { | 13 } else if (MP_HAS(S_MP_KARATSUBA_SQR) && /* Karatsuba? */ |
23 res = mp_toom_sqr(a, b); | 14 (a->used >= MP_KARATSUBA_SQR_CUTOFF)) { |
24 /* Karatsuba? */ | 15 err = s_mp_karatsuba_sqr(a, b); |
25 } else | 16 } else if (MP_HAS(S_MP_SQR_FAST) && /* can we use the fast comba multiplier? */ |
26 #endif | 17 (((a->used * 2) + 1) < MP_WARRAY) && |
27 #ifdef BN_MP_KARATSUBA_SQR_C | 18 (a->used < (MP_MAXFAST / 2))) { |
28 if (a->used >= KARATSUBA_SQR_CUTOFF) { | 19 err = s_mp_sqr_fast(a, b); |
29 res = mp_karatsuba_sqr(a, b); | 20 } else if (MP_HAS(S_MP_SQR)) { |
30 } else | 21 err = s_mp_sqr(a, b); |
31 #endif | 22 } else { |
32 { | 23 err = MP_VAL; |
33 #ifdef BN_FAST_S_MP_SQR_C | 24 } |
34 /* can we use the fast comba multiplier? */ | |
35 if ((((a->used * 2) + 1) < (int)MP_WARRAY) && | |
36 (a->used < | |
37 (int)(1u << (((sizeof(mp_word) * (size_t)CHAR_BIT) - (2u * (size_t)DIGIT_BIT)) - 1u)))) { | |
38 res = fast_s_mp_sqr(a, b); | |
39 } else | |
40 #endif | |
41 { | |
42 #ifdef BN_S_MP_SQR_C | |
43 res = s_mp_sqr(a, b); | |
44 #else | |
45 res = MP_VAL; | |
46 #endif | |
47 } | |
48 } | |
49 b->sign = MP_ZPOS; | 25 b->sign = MP_ZPOS; |
50 return res; | 26 return err; |
51 } | 27 } |
52 #endif | 28 #endif |
53 | |
54 /* ref: HEAD -> master, tag: v1.1.0 */ | |
55 /* git commit: 08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */ | |
56 /* commit time: 2019-01-28 20:32:32 +0100 */ |