From ffaa805a0b2ffa079271a225b4121ecb11f04a7f Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Fri, 9 Oct 2020 10:15:02 -0400 Subject: Correct hash to integer conversions for ECDSA When the hash and group sizes differ sometimes our conversion was different from standard. Closes #2415 --- src/lib/math/bigint/bigint.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/lib') diff --git a/src/lib/math/bigint/bigint.cpp b/src/lib/math/bigint/bigint.cpp index ad9e5a0da..8510da1d3 100644 --- a/src/lib/math/bigint/bigint.cpp +++ b/src/lib/math/bigint/bigint.cpp @@ -89,14 +89,13 @@ BigInt::BigInt(const uint8_t input[], size_t length, Base base) BigInt::BigInt(const uint8_t buf[], size_t length, size_t max_bits) { - const size_t max_bytes = std::min(length, (max_bits + 7) / 8); - binary_decode(buf, max_bytes); + if(8 * length > max_bits) + length = (max_bits + 7) / 8; - const size_t b = this->bits(); - if(b > max_bits) - { - *this >>= (b - max_bits); - } + binary_decode(buf, length); + + if(8 * length > max_bits) + *this >>= (8 - (max_bits % 8)); } /* -- cgit v1.2.3