1 #include "tommath_private.h"
2 #ifdef BN_MP_REDUCE_2K_C
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 /* SPDX-License-Identifier: Unlicense */
6 /* reduces a modulo n where n is of the form 2**p - d */
7 mp_err mp_reduce_2k(mp_int *a, const mp_int *n, mp_digit d)
13 if ((err = mp_init(&q)) != MP_OKAY) {
19 /* q = a/2**p, a = a mod 2**p */
20 if ((err = mp_div_2d(a, p, &q, a)) != MP_OKAY) {
26 if ((err = mp_mul_d(&q, d, &q)) != MP_OKAY) {
32 if ((err = s_mp_add(a, &q, a)) != MP_OKAY) {
36 if (mp_cmp_mag(a, n) != MP_LT) {
37 if ((err = s_mp_sub(a, n, a)) != MP_OKAY) {