1 #include "tommath_private.h"
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 /* SPDX-License-Identifier: Unlicense */
6 /* single digit subtraction */
7 mp_err mp_sub_d(const mp_int *a, mp_digit b, mp_int *c)
13 /* grow c as required */
14 if (c->alloc < (a->used + 1)) {
15 if ((err = mp_grow(c, a->used + 1)) != MP_OKAY) {
20 /* if a is negative just do an unsigned
21 * addition [with fudged signs]
23 if (a->sign == MP_NEG) {
26 err = mp_add_d(&a_, b, c);
40 /* if a <= b simply fix the single digit */
41 if (((a->used == 1) && (a->dp[0] <= b)) || (a->used == 0)) {
59 /* subtract digits, mu is carry */
60 for (ix = 0; ix < a->used; ix++) {
62 mu = *tmpc >> (MP_SIZEOF_BITS(mp_digit) - 1u);
67 /* zero excess digits */
68 MP_ZERO_DIGITS(tmpc, oldused - ix);