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 701396 : mp_err mp_sqr(const mp_int *a, mp_int *b) 8 : { 9 33132 : mp_err err; 10 701396 : if (MP_HAS(S_MP_TOOM_SQR) && /* use Toom-Cook? */ 11 701396 : (a->used >= MP_TOOM_SQR_CUTOFF)) { 12 0 : err = s_mp_toom_sqr(a, b); 13 701396 : } else if (MP_HAS(S_MP_KARATSUBA_SQR) && /* Karatsuba? */ 14 668264 : (a->used >= MP_KARATSUBA_SQR_CUTOFF)) { 15 2698 : err = s_mp_karatsuba_sqr(a, b); 16 698698 : } else if (MP_HAS(S_MP_SQR_FAST) && /* can we use the fast comba multiplier? */ 17 698698 : (((a->used * 2) + 1) < MP_WARRAY) && 18 665566 : (a->used < (MP_MAXFAST / 2))) { 19 698698 : err = s_mp_sqr_fast(a, b); 20 0 : } else if (MP_HAS(S_MP_SQR)) { 21 0 : err = s_mp_sqr(a, b); 22 : } else { 23 : err = MP_VAL; 24 : } 25 701396 : b->sign = MP_ZPOS; 26 701396 : return err; 27 : } 28 : #endif