From 9ea9ebe5cb72656717eea35836b0fb827a5cee86 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Fri, 7 Dec 2018 12:09:50 -0500 Subject: Avoid early exit --- src/lib/math/mp/mp_core.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/lib/math/mp/mp_core.h b/src/lib/math/mp/mp_core.h index 9caacf9fb..1ac6f7173 100644 --- a/src/lib/math/mp/mp_core.h +++ b/src/lib/math/mp/mp_core.h @@ -467,16 +467,15 @@ inline void bigint_shl2(word y[], const word x[], size_t x_size, inline void bigint_shr2(word y[], const word x[], size_t x_size, size_t word_shift, size_t bit_shift) { - if(x_size < word_shift) // XXX - return; + const size_t new_size = x_size < word_shift ? 0 : (x_size - word_shift); - copy_mem(y, x + word_shift, x_size - word_shift); + copy_mem(y, x + word_shift, new_size); const auto carry_mask = CT::Mask::expand(bit_shift); const size_t carry_shift = carry_mask.if_set_return(BOTAN_MP_WORD_BITS - bit_shift); word carry = 0; - for(size_t i = x_size - word_shift; i > 0; --i) + for(size_t i = new_size; i > 0; --i) { word w = y[i-1]; y[i-1] = (w >> bit_shift) | carry; -- cgit v1.2.3