From 6fc50d402e74dcf2de71a64785ddc4d79856127e Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 6 Jan 2019 19:15:35 +0000 Subject: [PATCH] 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. --- mpint.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mpint.c b/mpint.c index ffd8f6f6..8bb06cd0 100644 --- a/mpint.c +++ b/mpint.c @@ -793,7 +793,7 @@ unsigned mp_hs_integer(mp_int *x, uintmax_t n) BignumInt carry = 1; for (size_t i = 0; i < x->nw; i++) { 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; BignumADC(dummy_out, carry, x->w[i], ~nword, carry); (void)dummy_out; @@ -819,7 +819,7 @@ unsigned mp_eq_integer(mp_int *x, uintmax_t n) BignumInt diff = 0; for (size_t i = 0; i < x->nw; i++) { 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; } return 1 ^ normalise_to_1(diff); /* return 1 if diff _is_ zero */