diff options
author | Treeston <treeston.mmoc@gmail.com> | 2019-08-10 21:34:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-10 21:34:51 +0200 |
commit | 4211645834c467a03c60248e80818d3607be9ea7 (patch) | |
tree | 673a1695581503b6ea3e49da5c3e0d06bf5d892e /src/common/Cryptography/BigNumber.h | |
parent | 3d356b97d4cc4c7ec4c641487241eae6dcc0558e (diff) |
[3.3.5] Core/Authserver: TOTP rewrite: (PR #23633)
- Proper management commands (.account 2fa)
- Secrets can now be encrypted (set TOTPTokenSecret in .conf)
- Secret now stored in binary
- Argon2 and AES primitives
- Base32/64 support
Diffstat (limited to 'src/common/Cryptography/BigNumber.h')
-rw-r--r-- | src/common/Cryptography/BigNumber.h | 54 |
1 files changed, 38 insertions, 16 deletions
diff --git a/src/common/Cryptography/BigNumber.h b/src/common/Cryptography/BigNumber.h index 0f53d1b7160..e2c70fe0dd8 100644 --- a/src/common/Cryptography/BigNumber.h +++ b/src/common/Cryptography/BigNumber.h @@ -20,6 +20,7 @@ #define _AUTH_BIGNUMBER_H #include "Define.h" +#include <array> #include <memory> #include <string> @@ -36,60 +37,81 @@ class TC_COMMON_API BigNumber void SetDword(uint32); void SetQword(uint64); void SetBinary(uint8 const* bytes, int32 len); - void SetHexStr(char const* str); + bool SetHexStr(char const* str); void SetRand(int32 numbits); BigNumber& operator=(BigNumber const& bn); - BigNumber operator+=(BigNumber const& bn); - BigNumber operator+(BigNumber const& bn) + BigNumber& operator+=(BigNumber const& bn); + BigNumber operator+(BigNumber const& bn) const { BigNumber t(*this); return t += bn; } - BigNumber operator-=(BigNumber const& bn); - BigNumber operator-(BigNumber const& bn) + BigNumber& operator-=(BigNumber const& bn); + BigNumber operator-(BigNumber const& bn) const { BigNumber t(*this); return t -= bn; } - BigNumber operator*=(BigNumber const& bn); - BigNumber operator*(BigNumber const& bn) + BigNumber& operator*=(BigNumber const& bn); + BigNumber operator*(BigNumber const& bn) const { BigNumber t(*this); return t *= bn; } - BigNumber operator/=(BigNumber const& bn); - BigNumber operator/(BigNumber const& bn) + BigNumber& operator/=(BigNumber const& bn); + BigNumber operator/(BigNumber const& bn) const { BigNumber t(*this); return t /= bn; } - BigNumber operator%=(BigNumber const& bn); - BigNumber operator%(BigNumber const& bn) + BigNumber& operator%=(BigNumber const& bn); + BigNumber operator%(BigNumber const& bn) const { BigNumber t(*this); return t %= bn; } + BigNumber& operator<<=(int n); + BigNumber operator<<(int n) const + { + BigNumber t(*this); + return t <<= n; + } + + int CompareTo(BigNumber const& bn) const; + bool operator<=(BigNumber const& bn) const { return (CompareTo(bn) <= 0); } + bool operator==(BigNumber const& bn) const { return (CompareTo(bn) == 0); } + bool operator>=(BigNumber const& bn) const { return (CompareTo(bn) >= 0); } + bool operator<(BigNumber const& bn) const { return (CompareTo(bn) < 0); } + bool operator>(BigNumber const& bn) const { return (CompareTo(bn) > 0); } + bool IsZero() const; bool IsNegative() const; - BigNumber ModExp(BigNumber const& bn1, BigNumber const& bn2); - BigNumber Exp(BigNumber const&); + BigNumber ModExp(BigNumber const& bn1, BigNumber const& bn2) const; + BigNumber Exp(BigNumber const&) const; - int32 GetNumBytes(void); + int32 GetNumBytes() const; struct bignum_st *BN() { return _bn; } - uint32 AsDword(); + uint32 AsDword() const; - std::unique_ptr<uint8[]> AsByteArray(int32 minSize = 0, bool littleEndian = true); + bool AsByteArray(uint8* buf, std::size_t bufsize, bool littleEndian = true) const; + std::unique_ptr<uint8[]> AsByteArray(int32 minSize = 0, bool littleEndian = true) const; + template <std::size_t N> std::array<uint8, N> AsByteArray(bool littleEndian = true) const + { + std::array<uint8, N> buf; + AsByteArray(buf.data(), N, littleEndian); + return buf; + } std::string AsHexStr() const; std::string AsDecStr() const; |