diff --git a/src/lib/math/mp/mp_core.h b/src/lib/math/mp/mp_core.h index 27307767579..eef1e985ef0 100644 --- a/src/lib/math/mp/mp_core.h +++ b/src/lib/math/mp/mp_core.h @@ -845,15 +845,29 @@ inline constexpr W shift_left(std::array& x) { static_assert(S < WordInfo::bits, "Shift too large"); W carry = 0; - for(size_t j = 0; j != N; ++j) { - const W w = x[j]; - x[j] = (w << S) | carry; + for(size_t i = 0; i != N; ++i) { + const W w = x[i]; + x[i] = (w << S) | carry; carry = w >> (WordInfo::bits - S); } return carry; } +template +inline consteval W shift_right(std::array& x) { + static_assert(S < WordInfo::bits, "Shift too large"); + + W carry = 0; + for(size_t i = 0; i != N; ++i) { + const W w = x[N - 1 - i]; + x[N - 1 - i] = (w >> S) | carry; + carry = w << (WordInfo::bits - S); + } + + return carry; +} + template consteval auto hex_to_words(const char (&s)[N]) { // Char count includes null terminator which we ignore