bn_mp_reduce_setup.c 498 B

1234567891011121314151617
  1. #include "tommath_private.h"
  2. #ifdef BN_MP_REDUCE_SETUP_C
  3. /* LibTomMath, multiple-precision integer library -- Tom St Denis */
  4. /* SPDX-License-Identifier: Unlicense */
  5. /* pre-calculate the value required for Barrett reduction
  6. * For a given modulus "b" it calulates the value required in "a"
  7. */
  8. mp_err mp_reduce_setup(mp_int *a, const mp_int *b)
  9. {
  10. mp_err err;
  11. if ((err = mp_2expt(a, b->used * 2 * MP_DIGIT_BIT)) != MP_OKAY) {
  12. return err;
  13. }
  14. return mp_div(a, b, a, NULL);
  15. }
  16. #endif