bn_mp_reduce_2k_setup_l.c 1021 Bytes
Newer Older
1
#include "tommath_private.h"
2 3 4 5 6 7 8 9 10 11
#ifdef BN_MP_REDUCE_2K_SETUP_L_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
 *
 * LibTomMath is a library that provides multiple-precision
 * integer arithmetic as well as number theoretic functionality.
 *
 * The library was designed directly after the MPI library by
 * Michael Fromberger but has been written from scratch with
 * additional optimizations in place.
 *
12
 * SPDX-License-Identifier: Unlicense
13 14 15
 */

/* determines the setup value */
16
int mp_reduce_2k_setup_l(const mp_int *a, mp_int *d)
17 18 19
{
   int    res;
   mp_int tmp;
20

21 22 23
   if ((res = mp_init(&tmp)) != MP_OKAY) {
      return res;
   }
24

25
   if ((res = mp_2expt(&tmp, mp_count_bits(a))) != MP_OKAY) {
26
      goto LBL_ERR;
27
   }
28

29
   if ((res = s_mp_sub(&tmp, a, d)) != MP_OKAY) {
30
      goto LBL_ERR;
31
   }
32 33

LBL_ERR:
34 35 36 37 38
   mp_clear(&tmp);
   return res;
}
#endif

39 40 41
/* ref:         HEAD -> master, tag: v1.1.0 */
/* git commit:  08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */
/* commit time: 2019-01-28 20:32:32 +0100 */