mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-03-16 03:53:01 -05:00
A fix in modmul: don't segfault or fill the result with rubbish if
the unreduced product is shorter than the modulus. [originally from svn r965]
This commit is contained in:
parent
5f0d3bd19d
commit
47fc223782
9
sshbn.c
9
sshbn.c
@ -289,7 +289,7 @@ Bignum modmul(Bignum p, Bignum q, Bignum mod)
|
|||||||
{
|
{
|
||||||
unsigned short *a, *n, *m, *o;
|
unsigned short *a, *n, *m, *o;
|
||||||
int mshift;
|
int mshift;
|
||||||
int pqlen, mlen, i, j;
|
int pqlen, mlen, rlen, i, j;
|
||||||
Bignum result;
|
Bignum result;
|
||||||
|
|
||||||
/* Allocate m of size mlen, copy mod to m */
|
/* Allocate m of size mlen, copy mod to m */
|
||||||
@ -339,9 +339,10 @@ Bignum modmul(Bignum p, Bignum q, Bignum mod)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Copy result to buffer */
|
/* Copy result to buffer */
|
||||||
result = newbn(mod[0]);
|
rlen = (mlen < pqlen*2 ? mlen : pqlen*2);
|
||||||
for (i = 0; i < mlen; i++)
|
result = newbn(rlen);
|
||||||
result[result[0] - i] = a[i+2*pqlen-mlen];
|
for (i = 0; i < rlen; i++)
|
||||||
|
result[result[0] - i] = a[i+2*pqlen-rlen];
|
||||||
while (result[0] > 1 && result[result[0]] == 0) result[0]--;
|
while (result[0] > 1 && result[result[0]] == 0) result[0]--;
|
||||||
|
|
||||||
/* Free temporary arrays */
|
/* Free temporary arrays */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user