1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-25 01:02:24 +00:00

Add some missing invariants in bigdiv and bigmod.

The underlying function 'bigdivmod' does not ensure either of its
outputs is normalised, so its callers must do so.
This commit is contained in:
Simon Tatham 2014-11-01 19:20:51 +00:00
parent df87cb9dfc
commit eac7e041f1

View File

@ -1610,6 +1610,8 @@ Bignum bigdiv(Bignum a, Bignum b)
{
Bignum q = newbn(a[0]);
bigdivmod(a, b, NULL, q);
while (q[0] > 1 && q[q[0]] == 0)
q[0]--;
return q;
}
@ -1620,6 +1622,8 @@ Bignum bigmod(Bignum a, Bignum b)
{
Bignum r = newbn(b[0]);
bigdivmod(a, b, r, NULL);
while (r[0] > 1 && r[r[0]] == 0)
r[0]--;
return r;
}
@ -1679,6 +1683,8 @@ Bignum modinv(Bignum number, Bignum modulus)
bigdivmod(a, b, t, q);
while (t[0] > 1 && t[t[0]] == 0)
t[0]--;
while (q[0] > 1 && q[q[0]] == 0)
q[0]--;
freebn(a);
a = b;
b = t;