1 #include "tommath_private.h"
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 /* SPDX-License-Identifier: Unlicense */
6 /* calc a value mod 2**b */
7 mp_err mp_mod_2d(const mp_int *a, int b, mp_int *c)
12 /* if b is <= 0 then zero the int */
18 /* if the modulus is larger than the value than return */
19 if (b >= (a->used * MP_DIGIT_BIT)) {
24 if ((err = mp_copy(a, c)) != MP_OKAY) {
28 /* zero digits above the last digit of the modulus */
29 x = (b / MP_DIGIT_BIT) + (((b % MP_DIGIT_BIT) == 0) ? 0 : 1);
30 MP_ZERO_DIGITS(c->dp + x, c->used - x);
32 /* clear the digit that is not completely outside/inside the modulus */
33 c->dp[b / MP_DIGIT_BIT] &=
34 ((mp_digit)1 << (mp_digit)(b % MP_DIGIT_BIT)) - (mp_digit)1;