aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2020-10-09 10:15:02 -0400
committerJack Lloyd <[email protected]>2020-10-28 06:03:08 -0400
commitffaa805a0b2ffa079271a225b4121ecb11f04a7f (patch)
treeb082c1d0966ee8bd71747f75a250d8e54abe82ff /src/lib
parent69e54a77bd7860ff2541fcba17e837d17ef95db9 (diff)
Correct hash to integer conversions for ECDSA
When the hash and group sizes differ sometimes our conversion was different from standard. Closes #2415
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/math/bigint/bigint.cpp13
1 files changed, 6 insertions, 7 deletions
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));
}
/*