HEIMDAL: move code from source4/heimdal* to third_party/heimdal*
[samba.git] / third_party / heimdal / lib / hcrypto / libtommath / bn_mp_reduce_setup.c
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
6 /* pre-calculate the value required for Barrett reduction
7  * For a given modulus "b" it calulates the value required in "a"
8  */
9 mp_err mp_reduce_setup(mp_int *a, const mp_int *b)
10 {
11    mp_err err;
12    if ((err = mp_2expt(a, b->used * 2 * MP_DIGIT_BIT)) != MP_OKAY) {
13       return err;
14    }
15    return mp_div(a, b, a, NULL);
16 }
17 #endif