feat(Core/DB/Authserver): remove sha_pass_hash (#4827)

This commit is contained in:
UltraNix
2021-03-21 15:17:57 +01:00
committed by GitHub
parent e9ed6380a6
commit 485f7e7639
54 changed files with 1095 additions and 744 deletions

View File

@@ -11,16 +11,12 @@
BigNumber::BigNumber()
: _bn(BN_new())
{ }
{
}
BigNumber::BigNumber(BigNumber const& bn)
: _bn(BN_dup(bn._bn))
{ }
BigNumber::BigNumber(uint32 val)
: _bn(BN_new())
: _bn(BN_dup(bn.BN()))
{
BN_set_word(_bn, val);
}
BigNumber::~BigNumber()
@@ -28,6 +24,13 @@ BigNumber::~BigNumber()
BN_free(_bn);
}
void BigNumber::SetDword(int32 val)
{
SetDword(uint32(abs(val)));
if (val < 0)
BN_set_negative(_bn, 1);
}
void BigNumber::SetDword(uint32 val)
{
BN_set_word(_bn, val);
@@ -40,16 +43,25 @@ void BigNumber::SetQword(uint64 val)
BN_add_word(_bn, (uint32)(val & 0xFFFFFFFF));
}
void BigNumber::SetBinary(uint8 const* bytes, int32 len)
void BigNumber::SetBinary(uint8 const* bytes, int32 len, bool littleEndian)
{
uint8* array = new uint8[len];
if (littleEndian)
{
#if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x10100000L
uint8* array = new uint8[len];
for (int i = 0; i < len; i++)
array[i] = bytes[len - 1 - i];
for (int i = 0; i < len; i++)
array[i] = bytes[len - 1 - i];
BN_bin2bn(array, len, _bn);
BN_bin2bn(array, len, _bn);
delete[] array;
delete[] array;
#else
BN_lebin2bn(bytes, len, _bn);
#endif
}
else
BN_bin2bn(bytes, len, _bn);
}
void BigNumber::SetHexStr(char const* str)
@@ -116,7 +128,7 @@ BigNumber BigNumber::operator%=(BigNumber const& bn)
return *this;
}
BigNumber BigNumber::Exp(BigNumber const& bn)
BigNumber BigNumber::Exp(BigNumber const& bn) const
{
BigNumber ret;
BN_CTX* bnctx;
@@ -128,7 +140,7 @@ BigNumber BigNumber::Exp(BigNumber const& bn)
return ret;
}
BigNumber BigNumber::ModExp(BigNumber const& bn1, BigNumber const& bn2)
BigNumber BigNumber::ModExp(BigNumber const& bn1, BigNumber const& bn2) const
{
BigNumber ret;
BN_CTX* bnctx;
@@ -140,7 +152,7 @@ BigNumber BigNumber::ModExp(BigNumber const& bn1, BigNumber const& bn2)
return ret;
}
int32 BigNumber::GetNumBytes(void)
int32 BigNumber::GetNumBytes() const
{
return BN_num_bytes(_bn);
}
@@ -155,25 +167,38 @@ bool BigNumber::isZero() const
return BN_is_zero(_bn);
}
std::unique_ptr<uint8[]> BigNumber::AsByteArray(int32 minSize, bool littleEndian)
void BigNumber::GetBytes(uint8* buf, size_t bufsize, bool littleEndian) const
{
int numBytes = GetNumBytes();
int length = (minSize >= numBytes) ? minSize : numBytes;
#if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x10100000L
int nBytes = GetNumBytes();
ASSERT(nBytes >= 0, "Bignum has negative number of bytes (%d).", nBytes);
std::size_t numBytes = static_cast<std::size_t>(nBytes);
uint8* array = new uint8[length];
// too large to store
ASSERT(numBytes <= bufsize, "Buffer of size %zu is too small to hold bignum with %zu bytes.\n", bufsize, numBytes);
// If we need more bytes than length of BigNumber set the rest to 0
if (length > numBytes)
memset((void*)array, 0, length);
if (numBytes < bufsize)
memset((void*)buf, 0, bufsize);
BN_bn2bin(_bn, (unsigned char*)array);
BN_bn2bin(_bn, buf + (bufsize - numBytes));
// openssl's BN stores data internally in big endian format, reverse if little endian desired
if (littleEndian)
std::reverse(array, array + length);
std::reverse(buf, buf + bufsize);
#else
int res = littleEndian ? BN_bn2lebinpad(_bn, buf, bufsize) : BN_bn2binpad(_bn, buf, bufsize);
ASSERT(res > 0, "Buffer of size %zu is too small to hold bignum with %d bytes.\n", bufsize, BN_num_bytes(_bn));
#endif
}
std::unique_ptr<uint8[]> ret(array);
return ret;
std::vector<uint8> BigNumber::ToByteVector(int32 minSize, bool littleEndian) const
{
std::size_t length = std::max(GetNumBytes(), minSize);
std::vector<uint8> v;
v.resize(length);
GetBytes(v.data(), length, littleEndian);
return v;
}
char* BigNumber::AsHexStr() const