diff options
Diffstat (limited to 'libtommath/bn_mp_add_d.c')
-rw-r--r-- | libtommath/bn_mp_add_d.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/libtommath/bn_mp_add_d.c b/libtommath/bn_mp_add_d.c index fd1a186..c2f2e0e 100644 --- a/libtommath/bn_mp_add_d.c +++ b/libtommath/bn_mp_add_d.c @@ -17,7 +17,7 @@ /* single digit addition */ int -mp_add_d (mp_int * a, mp_digit b, mp_int * c) +mp_add_d (const mp_int * a, mp_digit b, mp_int * c) { int res, ix, oldused; mp_digit *tmpa, *tmpc, mu; @@ -31,14 +31,15 @@ mp_add_d (mp_int * a, mp_digit b, mp_int * c) /* if a is negative and |a| >= b, call c = |a| - b */ if ((a->sign == MP_NEG) && ((a->used > 1) || (a->dp[0] >= b))) { + mp_int a_ = *a; /* temporarily fix sign of a */ - a->sign = MP_ZPOS; + a_.sign = MP_ZPOS; /* c = |a| - b */ - res = mp_sub_d(a, b, c); + res = mp_sub_d(&a_, b, c); /* fix sign */ - a->sign = c->sign = MP_NEG; + c->sign = MP_NEG; /* clamp */ mp_clamp(c); |