mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-25 01:02:24 +00:00
Fix 32-bit-only bug in mp_{eq,hs}_integer.
I got the maximum shift count _completely_ wrong when trying to work out whether each word should be compared against part of the input uintmax_t: I measured it in bytes rather than bits _and_ applied it to the wrong type. Ahem.
This commit is contained in:
parent
8024b55ea6
commit
6fc50d402e
4
mpint.c
4
mpint.c
@ -793,7 +793,7 @@ unsigned mp_hs_integer(mp_int *x, uintmax_t n)
|
|||||||
BignumInt carry = 1;
|
BignumInt carry = 1;
|
||||||
for (size_t i = 0; i < x->nw; i++) {
|
for (size_t i = 0; i < x->nw; i++) {
|
||||||
size_t shift = i * BIGNUM_INT_BITS;
|
size_t shift = i * BIGNUM_INT_BITS;
|
||||||
BignumInt nword = shift < BIGNUM_INT_BYTES ? n >> shift : 0;
|
BignumInt nword = shift < CHAR_BIT*sizeof(n) ? n >> shift : 0;
|
||||||
BignumInt dummy_out;
|
BignumInt dummy_out;
|
||||||
BignumADC(dummy_out, carry, x->w[i], ~nword, carry);
|
BignumADC(dummy_out, carry, x->w[i], ~nword, carry);
|
||||||
(void)dummy_out;
|
(void)dummy_out;
|
||||||
@ -819,7 +819,7 @@ unsigned mp_eq_integer(mp_int *x, uintmax_t n)
|
|||||||
BignumInt diff = 0;
|
BignumInt diff = 0;
|
||||||
for (size_t i = 0; i < x->nw; i++) {
|
for (size_t i = 0; i < x->nw; i++) {
|
||||||
size_t shift = i * BIGNUM_INT_BITS;
|
size_t shift = i * BIGNUM_INT_BITS;
|
||||||
BignumInt nword = shift < BIGNUM_INT_BYTES ? n >> shift : 0;
|
BignumInt nword = shift < CHAR_BIT*sizeof(n) ? n >> shift : 0;
|
||||||
diff |= x->w[i] ^ nword;
|
diff |= x->w[i] ^ nword;
|
||||||
}
|
}
|
||||||
return 1 ^ normalise_to_1(diff); /* return 1 if diff _is_ zero */
|
return 1 ^ normalise_to_1(diff); /* return 1 if diff _is_ zero */
|
||||||
|
Loading…
Reference in New Issue
Block a user