aboutsummaryrefslogtreecommitdiff
path: root/src/server/shared/Cryptography/BigNumber.cpp
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2015-03-01 14:16:16 +0100
committerShauren <shauren.trinity@gmail.com>2015-03-04 12:22:10 +0100
commit5e860daa22e1e589db248b613fc93805b825c68c (patch)
tree4a811da041b91766b70ccde134a8b7030b42ea00 /src/server/shared/Cryptography/BigNumber.cpp
parentb60cfa9bf4863776a767ba5c43c48ca35fecea1a (diff)
Core/Crypto: Fixed output of BigNumber::AsByteArray when generated array is shorter than requested size
(cherry picked from commit e52b46abba9250c611312a891fda0adaccce0f0c)
Diffstat (limited to 'src/server/shared/Cryptography/BigNumber.cpp')
-rw-r--r--src/server/shared/Cryptography/BigNumber.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/server/shared/Cryptography/BigNumber.cpp b/src/server/shared/Cryptography/BigNumber.cpp
index 0097f4722e1..5be425a3d16 100644
--- a/src/server/shared/Cryptography/BigNumber.cpp
+++ b/src/server/shared/Cryptography/BigNumber.cpp
@@ -176,19 +176,20 @@ bool BigNumber::IsNegative() const
std::unique_ptr<uint8[]> BigNumber::AsByteArray(int32 minSize, bool littleEndian)
{
- int length = (minSize >= GetNumBytes()) ? minSize : GetNumBytes();
+ int numBytes = GetNumBytes();
+ int length = (minSize >= numBytes) ? minSize : numBytes;
uint8* array = new uint8[length];
// If we need more bytes than length of BigNumber set the rest to 0
- if (length > GetNumBytes())
+ if (length > numBytes)
memset((void*)array, 0, length);
BN_bn2bin(_bn, (unsigned char *)array);
// openssl's BN stores data internally in big endian format, reverse if little endian desired
if (littleEndian)
- std::reverse(array, array + length);
+ std::reverse(array, array + numBytes);
std::unique_ptr<uint8[]> ret(array);
return ret;