Core/Common: fix a bug in BigNumber::AsByteArray that was causing incorrect output in 1/256 cases with explicit minSize (iff MSB zero)

(cherry picked from commit b2b9880377f75a333b94a71ce6076016b8285e0b)
This commit is contained in:
Treeston authored and funjoker committed 2023-05-19 22:38:42 +02:00
1 parent e63f994af6
commit d568eb7871
1 file changed
+2 -2
+2 -2
View File
@@ -183,11 +183,11 @@ std::unique_ptr<uint8[]> BigNumber::AsByteArray(int32 minSize, bool littleEndian
if (length > numBytes)
memset((void*)array, 0, length);
BN_bn2bin(_bn, (unsigned char *)array);
BN_bn2bin(_bn, array + (length-numBytes));
// openssl's BN stores data internally in big endian format, reverse if little endian desired
if (littleEndian)
std::reverse(array, array + numBytes);
std::reverse(array, array + length);
std::unique_ptr<uint8[]> ret(array);
return ret;