Line data Source code
1 : #include "tommath_private.h"
2 : #ifdef BN_MP_SQR_C
3 : /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 : /* SPDX-License-Identifier: Unlicense */
5 :
6 : /* computes b = a*a */
7 236608 : mp_err mp_sqr(const mp_int *a, mp_int *b)
8 : {
9 : mp_err err;
10 236608 : if (MP_HAS(S_MP_TOOM_SQR) && /* use Toom-Cook? */
11 236608 : (a->used >= MP_TOOM_SQR_CUTOFF)) {
12 0 : err = s_mp_toom_sqr(a, b);
13 236608 : } else if (MP_HAS(S_MP_KARATSUBA_SQR) && /* Karatsuba? */
14 236608 : (a->used >= MP_KARATSUBA_SQR_CUTOFF)) {
15 0 : err = s_mp_karatsuba_sqr(a, b);
16 236608 : } else if (MP_HAS(S_MP_SQR_FAST) && /* can we use the fast comba multiplier? */
17 473216 : (((a->used * 2) + 1) < MP_WARRAY) &&
18 236608 : (a->used < (MP_MAXFAST / 2))) {
19 236608 : err = s_mp_sqr_fast(a, b);
20 : } else if (MP_HAS(S_MP_SQR)) {
21 0 : err = s_mp_sqr(a, b);
22 : } else {
23 : err = MP_VAL;
24 : }
25 236608 : b->sign = MP_ZPOS;
26 236608 : return err;
27 : }
28 : #endif
|