mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-15 10:00:28 +00:00
feat(Core/Authserver): TOTP rewrite (#5620)
This commit is contained in:
@@ -1,23 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license, you may redistribute it and/or modify it under version 2 of the License, or (at your option), any later version.
|
||||
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
|
||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license, you may redistribute it and/or modify it under version 2 of the License, or (at your option), any later version.
|
||||
* Copyright (C) 2021+ WarheadCore <https://github.com/WarheadCore>
|
||||
*/
|
||||
|
||||
#include "Cryptography/BigNumber.h"
|
||||
#include "Errors.h"
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
|
||||
BigNumber::BigNumber()
|
||||
: _bn(BN_new())
|
||||
{
|
||||
}
|
||||
{ }
|
||||
|
||||
BigNumber::BigNumber(BigNumber const& bn)
|
||||
: _bn(BN_dup(bn.BN()))
|
||||
{
|
||||
}
|
||||
{ }
|
||||
|
||||
BigNumber::~BigNumber()
|
||||
{
|
||||
@@ -64,9 +63,10 @@ void BigNumber::SetBinary(uint8 const* bytes, int32 len, bool littleEndian)
|
||||
BN_bin2bn(bytes, len, _bn);
|
||||
}
|
||||
|
||||
void BigNumber::SetHexStr(char const* str)
|
||||
bool BigNumber::SetHexStr(char const* str)
|
||||
{
|
||||
BN_hex2bn(&_bn, str);
|
||||
int n = BN_hex2bn(&_bn, str);
|
||||
return (n > 0);
|
||||
}
|
||||
|
||||
void BigNumber::SetRand(int32 numbits)
|
||||
@@ -83,19 +83,19 @@ BigNumber& BigNumber::operator=(BigNumber const& bn)
|
||||
return *this;
|
||||
}
|
||||
|
||||
BigNumber BigNumber::operator+=(BigNumber const& bn)
|
||||
BigNumber& BigNumber::operator+=(BigNumber const& bn)
|
||||
{
|
||||
BN_add(_bn, _bn, bn._bn);
|
||||
return *this;
|
||||
}
|
||||
|
||||
BigNumber BigNumber::operator-=(BigNumber const& bn)
|
||||
BigNumber& BigNumber::operator-=(BigNumber const& bn)
|
||||
{
|
||||
BN_sub(_bn, _bn, bn._bn);
|
||||
return *this;
|
||||
}
|
||||
|
||||
BigNumber BigNumber::operator*=(BigNumber const& bn)
|
||||
BigNumber& BigNumber::operator*=(BigNumber const& bn)
|
||||
{
|
||||
BN_CTX* bnctx;
|
||||
|
||||
@@ -106,7 +106,7 @@ BigNumber BigNumber::operator*=(BigNumber const& bn)
|
||||
return *this;
|
||||
}
|
||||
|
||||
BigNumber BigNumber::operator/=(BigNumber const& bn)
|
||||
BigNumber& BigNumber::operator/=(BigNumber const& bn)
|
||||
{
|
||||
BN_CTX* bnctx;
|
||||
|
||||
@@ -117,7 +117,7 @@ BigNumber BigNumber::operator/=(BigNumber const& bn)
|
||||
return *this;
|
||||
}
|
||||
|
||||
BigNumber BigNumber::operator%=(BigNumber const& bn)
|
||||
BigNumber& BigNumber::operator%=(BigNumber const& bn)
|
||||
{
|
||||
BN_CTX* bnctx;
|
||||
|
||||
@@ -128,6 +128,17 @@ BigNumber BigNumber::operator%=(BigNumber const& bn)
|
||||
return *this;
|
||||
}
|
||||
|
||||
BigNumber& BigNumber::operator<<=(int n)
|
||||
{
|
||||
BN_lshift(_bn, _bn, n);
|
||||
return *this;
|
||||
}
|
||||
|
||||
int BigNumber::CompareTo(BigNumber const& bn) const
|
||||
{
|
||||
return BN_cmp(_bn, bn._bn);
|
||||
}
|
||||
|
||||
BigNumber BigNumber::Exp(BigNumber const& bn) const
|
||||
{
|
||||
BigNumber ret;
|
||||
@@ -157,16 +168,21 @@ int32 BigNumber::GetNumBytes() const
|
||||
return BN_num_bytes(_bn);
|
||||
}
|
||||
|
||||
uint32 BigNumber::AsDword()
|
||||
uint32 BigNumber::AsDword() const
|
||||
{
|
||||
return (uint32)BN_get_word(_bn);
|
||||
}
|
||||
|
||||
bool BigNumber::isZero() const
|
||||
bool BigNumber::IsZero() const
|
||||
{
|
||||
return BN_is_zero(_bn);
|
||||
}
|
||||
|
||||
bool BigNumber::IsNegative() const
|
||||
{
|
||||
return BN_is_negative(_bn);
|
||||
}
|
||||
|
||||
void BigNumber::GetBytes(uint8* buf, size_t bufsize, bool littleEndian) const
|
||||
{
|
||||
#if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
@@ -201,12 +217,18 @@ std::vector<uint8> BigNumber::ToByteVector(int32 minSize, bool littleEndian) con
|
||||
return v;
|
||||
}
|
||||
|
||||
char* BigNumber::AsHexStr() const
|
||||
std::string BigNumber::AsHexStr() const
|
||||
{
|
||||
return BN_bn2hex(_bn);
|
||||
char* ch = BN_bn2hex(_bn);
|
||||
std::string ret = ch;
|
||||
OPENSSL_free(ch);
|
||||
return ret;
|
||||
}
|
||||
|
||||
char* BigNumber::AsDecStr() const
|
||||
std::string BigNumber::AsDecStr() const
|
||||
{
|
||||
return BN_bn2dec(_bn);
|
||||
char* ch = BN_bn2dec(_bn);
|
||||
std::string ret = ch;
|
||||
OPENSSL_free(ch);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user