aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeston <treeston.mmoc@gmail.com>2019-08-06 11:24:48 +0200
committerTreeston <treeston.mmoc@gmail.com>2019-08-06 11:24:48 +0200
commitb2b9880377f75a333b94a71ce6076016b8285e0b (patch)
tree2b83635cec1c69697dc43d3c13a951f9c3433d40
parent4fcb322010edb6a80fa08e633ce331f80410f301 (diff)
Core/Common: fix a bug in BigNumber::AsByteArray that was causing incorrect output in 1/256 cases with explicit minSize (iff MSB zero)
-rw-r--r--src/common/Cryptography/BigNumber.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/common/Cryptography/BigNumber.cpp b/src/common/Cryptography/BigNumber.cpp
index fd14c117e33..96f9144181e 100644
--- a/src/common/Cryptography/BigNumber.cpp
+++ b/src/common/Cryptography/BigNumber.cpp
@@ -184,11 +184,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;