diff options
Diffstat (limited to 'src/common/Cryptography')
20 files changed, 43 insertions, 49 deletions
diff --git a/src/common/Cryptography/AES.cpp b/src/common/Cryptography/AES.cpp index 31e0847005..f4061cdcbc 100644 --- a/src/common/Cryptography/AES.cpp +++ b/src/common/Cryptography/AES.cpp @@ -37,7 +37,7 @@ void Acore::Crypto::AES::Init(Key const& key) ASSERT(status); } -bool Acore::Crypto::AES::Process(IV const& iv, uint8* data, size_t length, Tag& tag) +bool Acore::Crypto::AES::Process(IV const& iv, uint8* data, std::size_t length, Tag& tag) { ASSERT(length <= static_cast<size_t>(std::numeric_limits<int>::max())); int len = static_cast<int>(length); diff --git a/src/common/Cryptography/AES.h b/src/common/Cryptography/AES.h index c73aeebea2..c49f181831 100644 --- a/src/common/Cryptography/AES.h +++ b/src/common/Cryptography/AES.h @@ -27,9 +27,9 @@ namespace Acore::Crypto class AC_COMMON_API AES { public: - static constexpr size_t IV_SIZE_BYTES = 12; - static constexpr size_t KEY_SIZE_BYTES = 16; - static constexpr size_t TAG_SIZE_BYTES = 12; + static constexpr std::size_t IV_SIZE_BYTES = 12; + static constexpr std::size_t KEY_SIZE_BYTES = 16; + static constexpr std::size_t TAG_SIZE_BYTES = 12; using IV = std::array<uint8, IV_SIZE_BYTES>; using Key = std::array<uint8, KEY_SIZE_BYTES>; @@ -40,7 +40,7 @@ namespace Acore::Crypto void Init(Key const& key); - bool Process(IV const& iv, uint8* data, size_t length, Tag& tag); + bool Process(IV const& iv, uint8* data, std::size_t length, Tag& tag); private: EVP_CIPHER_CTX* _ctx; diff --git a/src/common/Cryptography/ARC4.cpp b/src/common/Cryptography/ARC4.cpp index 90535f7477..10a7ad490c 100644 --- a/src/common/Cryptography/ARC4.cpp +++ b/src/common/Cryptography/ARC4.cpp @@ -40,7 +40,7 @@ Acore::Crypto::ARC4::~ARC4() #endif } -void Acore::Crypto::ARC4::Init(uint8 const* seed, size_t len) +void Acore::Crypto::ARC4::Init(uint8 const* seed, std::size_t len) { int result1 = EVP_CIPHER_CTX_set_key_length(_ctx, len); ASSERT(result1 == 1); @@ -48,7 +48,7 @@ void Acore::Crypto::ARC4::Init(uint8 const* seed, size_t len) ASSERT(result2 == 1); } -void Acore::Crypto::ARC4::UpdateData(uint8* data, size_t len) +void Acore::Crypto::ARC4::UpdateData(uint8* data, std::size_t len) { int outlen = 0; int result1 = EVP_EncryptUpdate(_ctx, data, &outlen, data, len); diff --git a/src/common/Cryptography/ARC4.h b/src/common/Cryptography/ARC4.h index f598589a29..7f4f0dc532 100644 --- a/src/common/Cryptography/ARC4.h +++ b/src/common/Cryptography/ARC4.h @@ -30,12 +30,12 @@ namespace Acore::Crypto ARC4(); ~ARC4(); - void Init(uint8 const* seed, size_t len); + void Init(uint8 const* seed, std::size_t len); template <typename Container> void Init(Container const& c) { Init(std::data(c), std::size(c)); } - void UpdateData(uint8* data, size_t len); + void UpdateData(uint8* data, std::size_t len); template <typename Container> void UpdateData(Container& c) { UpdateData(std::data(c), std::size(c)); } diff --git a/src/common/Cryptography/Authentication/AuthCrypt.cpp b/src/common/Cryptography/Authentication/AuthCrypt.cpp index 21115ed155..26084f76ab 100644 --- a/src/common/Cryptography/Authentication/AuthCrypt.cpp +++ b/src/common/Cryptography/Authentication/AuthCrypt.cpp @@ -35,13 +35,13 @@ void AuthCrypt::Init(SessionKey const& K) _initialized = true; } -void AuthCrypt::DecryptRecv(uint8* data, size_t len) +void AuthCrypt::DecryptRecv(uint8* data, std::size_t len) { ASSERT(_initialized); _clientDecrypt.UpdateData(data, len); } -void AuthCrypt::EncryptSend(uint8* data, size_t len) +void AuthCrypt::EncryptSend(uint8* data, std::size_t len) { ASSERT(_initialized); _serverEncrypt.UpdateData(data, len); diff --git a/src/common/Cryptography/Authentication/AuthCrypt.h b/src/common/Cryptography/Authentication/AuthCrypt.h index 88239a9e36..3a7ff89df9 100644 --- a/src/common/Cryptography/Authentication/AuthCrypt.h +++ b/src/common/Cryptography/Authentication/AuthCrypt.h @@ -27,8 +27,8 @@ public: AuthCrypt() = default; void Init(SessionKey const& K); - void DecryptRecv(uint8* data, size_t len); - void EncryptSend(uint8* data, size_t len); + void DecryptRecv(uint8* data, std::size_t len); + void EncryptSend(uint8* data, std::size_t len); bool IsInitialized() const { return _initialized; } diff --git a/src/common/Cryptography/Authentication/AuthDefines.h b/src/common/Cryptography/Authentication/AuthDefines.h index 85d0dbf494..3de2a02fbe 100644 --- a/src/common/Cryptography/Authentication/AuthDefines.h +++ b/src/common/Cryptography/Authentication/AuthDefines.h @@ -21,7 +21,7 @@ #include "Define.h" #include <array> -constexpr size_t SESSION_KEY_LENGTH = 40; +constexpr std::size_t SESSION_KEY_LENGTH = 40; using SessionKey = std::array<uint8, SESSION_KEY_LENGTH>; #endif diff --git a/src/common/Cryptography/Authentication/SRP6.cpp b/src/common/Cryptography/Authentication/SRP6.cpp index 20e05f5b2b..e89ac99a74 100644 --- a/src/common/Cryptography/Authentication/SRP6.cpp +++ b/src/common/Cryptography/Authentication/SRP6.cpp @@ -51,14 +51,14 @@ using SRP6 = Acore::Crypto::SRP6; { // split S into two buffers std::array<uint8, EPHEMERAL_KEY_LENGTH / 2> buf0{}, buf1{}; - for (size_t i = 0; i < EPHEMERAL_KEY_LENGTH / 2; ++i) + for (std::size_t i = 0; i < EPHEMERAL_KEY_LENGTH / 2; ++i) { buf0[i] = S[2 * i + 0]; buf1[i] = S[2 * i + 1]; } // find position of first nonzero byte - size_t p = 0; + std::size_t p = 0; while (p < EPHEMERAL_KEY_LENGTH && !S[p]) ++p; @@ -73,7 +73,7 @@ using SRP6 = Acore::Crypto::SRP6; // stick the two hashes back together SessionKey K; - for (size_t i = 0; i < SHA1::DIGEST_LENGTH; ++i) + for (std::size_t i = 0; i < SHA1::DIGEST_LENGTH; ++i) { K[2 * i + 0] = hash0[i]; K[2 * i + 1] = hash1[i]; diff --git a/src/common/Cryptography/Authentication/SRP6.h b/src/common/Cryptography/Authentication/SRP6.h index 734ef12980..d7f288dc39 100644 --- a/src/common/Cryptography/Authentication/SRP6.h +++ b/src/common/Cryptography/Authentication/SRP6.h @@ -28,13 +28,13 @@ namespace Acore::Crypto class AC_COMMON_API SRP6 { public: - static constexpr size_t SALT_LENGTH = 32; + static constexpr std::size_t SALT_LENGTH = 32; using Salt = std::array<uint8, SALT_LENGTH>; - static constexpr size_t VERIFIER_LENGTH = 32; + static constexpr std::size_t VERIFIER_LENGTH = 32; using Verifier = std::array<uint8, VERIFIER_LENGTH>; - static constexpr size_t EPHEMERAL_KEY_LENGTH = 32; + static constexpr std::size_t EPHEMERAL_KEY_LENGTH = 32; using EphemeralKey = std::array<uint8, EPHEMERAL_KEY_LENGTH>; static std::array<uint8, 1> const g; diff --git a/src/common/Cryptography/BigNumber.cpp b/src/common/Cryptography/BigNumber.cpp index 1cd8d6a199..decfeecbe5 100644 --- a/src/common/Cryptography/BigNumber.cpp +++ b/src/common/Cryptography/BigNumber.cpp @@ -195,7 +195,7 @@ bool BigNumber::IsNegative() const return BN_is_negative(_bn); } -void BigNumber::GetBytes(uint8* buf, size_t bufsize, bool littleEndian) const +void BigNumber::GetBytes(uint8* buf, std::size_t bufsize, bool littleEndian) const { #if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x10100000L int nBytes = GetNumBytes(); diff --git a/src/common/Cryptography/BigNumber.h b/src/common/Cryptography/BigNumber.h index 259fa92ed2..591da4e67a 100644 --- a/src/common/Cryptography/BigNumber.h +++ b/src/common/Cryptography/BigNumber.h @@ -34,7 +34,7 @@ public: BigNumber(int32 v) : BigNumber() { SetDword(v); } BigNumber(std::string const& v) : BigNumber() { SetHexStr(v); } - template <size_t Size> + template <std::size_t Size> BigNumber(std::array<uint8, Size> const& v, bool littleEndian = true) : BigNumber() { SetBinary(v.data(), Size, littleEndian); } ~BigNumber(); @@ -116,7 +116,7 @@ public: [[nodiscard]] uint32 AsDword() const; - void GetBytes(uint8* buf, size_t bufsize, bool littleEndian = true) const; + void GetBytes(uint8* buf, std::size_t bufsize, bool littleEndian = true) const; [[nodiscard]] std::vector<uint8> ToByteVector(int32 minSize = 0, bool littleEndian = true) const; template <std::size_t Size> diff --git a/src/common/Cryptography/CryptoConstants.h b/src/common/Cryptography/CryptoConstants.h index 3ba8b55d6a..7fadc4f366 100644 --- a/src/common/Cryptography/CryptoConstants.h +++ b/src/common/Cryptography/CryptoConstants.h @@ -18,15 +18,13 @@ #ifndef AZEROTHCORE_CRYPTO_CONSTANTS_H #define AZEROTHCORE_CRYPTO_CONSTANTS_H -#include "Define.h" - namespace Acore::Crypto { struct Constants { - static constexpr size_t MD5_DIGEST_LENGTH_BYTES = 16; - static constexpr size_t SHA1_DIGEST_LENGTH_BYTES = 20; - static constexpr size_t SHA256_DIGEST_LENGTH_BYTES = 32; + static constexpr std::size_t MD5_DIGEST_LENGTH_BYTES = 16; + static constexpr std::size_t SHA1_DIGEST_LENGTH_BYTES = 20; + static constexpr std::size_t SHA256_DIGEST_LENGTH_BYTES = 32; }; } diff --git a/src/common/Cryptography/CryptoGenerics.h b/src/common/Cryptography/CryptoGenerics.h index d4b799747c..3e84c6b3ec 100644 --- a/src/common/Cryptography/CryptoGenerics.h +++ b/src/common/Cryptography/CryptoGenerics.h @@ -47,7 +47,7 @@ namespace Acore::Impl static void SplitFromBack(std::vector<uint8>& data, Container& tail) { ASSERT(data.size() >= std::size(tail)); - for (size_t i = 1, N = std::size(tail); i <= N; ++i) + for (std::size_t i = 1, N = std::size(tail); i <= N; ++i) { tail[N - i] = data.back(); data.pop_back(); diff --git a/src/common/Cryptography/CryptoHash.h b/src/common/Cryptography/CryptoHash.h index 1763351bc7..6b98c5cd5b 100644 --- a/src/common/Cryptography/CryptoHash.h +++ b/src/common/Cryptography/CryptoHash.h @@ -43,14 +43,14 @@ namespace Acore::Impl #endif }; - template <GenericHashImpl::HashCreator HashCreator, size_t DigestLength> + template <GenericHashImpl::HashCreator HashCreator, std::size_t DigestLength> class GenericHash { public: - static constexpr size_t DIGEST_LENGTH = DigestLength; + static constexpr std::size_t DIGEST_LENGTH = DigestLength; using Digest = std::array<uint8, DIGEST_LENGTH>; - static Digest GetDigestOf(uint8 const* data, size_t len) + static Digest GetDigestOf(uint8 const* data, std::size_t len) { GenericHash hash; hash.UpdateData(data, len); @@ -112,7 +112,7 @@ namespace Acore::Impl return *this; } - void UpdateData(uint8 const* data, size_t len) + void UpdateData(uint8 const* data, std::size_t len) { int result = EVP_DigestUpdate(_ctx, data, len); ASSERT(result == 1); diff --git a/src/common/Cryptography/CryptoRandom.cpp b/src/common/Cryptography/CryptoRandom.cpp index 35d78f7444..c44f73eab5 100644 --- a/src/common/Cryptography/CryptoRandom.cpp +++ b/src/common/Cryptography/CryptoRandom.cpp @@ -19,7 +19,7 @@ #include "Errors.h" #include <openssl/rand.h> -void Acore::Crypto::GetRandomBytes(uint8* buf, size_t len) +void Acore::Crypto::GetRandomBytes(uint8* buf, std::size_t len) { int result = RAND_bytes(buf, len); ASSERT(result == 1, "Not enough randomness in OpenSSL's entropy pool. What in the world are you running on?"); diff --git a/src/common/Cryptography/CryptoRandom.h b/src/common/Cryptography/CryptoRandom.h index 07f87df00d..7554735ad5 100644 --- a/src/common/Cryptography/CryptoRandom.h +++ b/src/common/Cryptography/CryptoRandom.h @@ -23,7 +23,7 @@ namespace Acore::Crypto { - AC_COMMON_API void GetRandomBytes(uint8* buf, size_t len); + AC_COMMON_API void GetRandomBytes(uint8* buf, std::size_t len); template <typename Container> void GetRandomBytes(Container& c) @@ -31,7 +31,7 @@ namespace Acore::Crypto GetRandomBytes(std::data(c), std::size(c)); } - template <size_t S> + template <std::size_t S> std::array<uint8, S> GetRandomBytes() { std::array<uint8, S> arr; diff --git a/src/common/Cryptography/HMAC.h b/src/common/Cryptography/HMAC.h index ebfc1e14ba..6830c6131f 100644 --- a/src/common/Cryptography/HMAC.h +++ b/src/common/Cryptography/HMAC.h @@ -29,15 +29,15 @@ class BigNumber; namespace Acore::Impl { - template <GenericHashImpl::HashCreator HashCreator, size_t DigestLength> + template <GenericHashImpl::HashCreator HashCreator, std::size_t DigestLength> class GenericHMAC { public: - static constexpr size_t DIGEST_LENGTH = DigestLength; + static constexpr std::size_t DIGEST_LENGTH = DigestLength; using Digest = std::array<uint8, DIGEST_LENGTH>; template <typename Container> - static Digest GetDigestOf(Container const& seed, uint8 const* data, size_t len) + static Digest GetDigestOf(Container const& seed, uint8 const* data, std::size_t len) { GenericHMAC hash(seed); hash.UpdateData(data, len); @@ -54,7 +54,7 @@ namespace Acore::Impl return hash.GetDigest(); } - GenericHMAC(uint8 const* seed, size_t len) : _ctx(GenericHashImpl::MakeCTX()), _key(EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, nullptr, seed, len)) + GenericHMAC(uint8 const* seed, std::size_t len) : _ctx(GenericHashImpl::MakeCTX()), _key(EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, nullptr, seed, len)) { int result = EVP_DigestSignInit(_ctx, nullptr, HashCreator(), nullptr, _key); ASSERT(result == 1); @@ -105,7 +105,7 @@ namespace Acore::Impl return *this; } - void UpdateData(uint8 const* data, size_t len) + void UpdateData(uint8 const* data, std::size_t len) { int result = EVP_DigestSignUpdate(_ctx, data, len); ASSERT(result == 1); @@ -120,7 +120,7 @@ namespace Acore::Impl void Finalize() { - size_t length = DIGEST_LENGTH; + std::size_t length = DIGEST_LENGTH; int result = EVP_DigestSignFinal(_ctx, _digest.data(), &length); ASSERT(result == 1); ASSERT(length == DIGEST_LENGTH); diff --git a/src/common/Cryptography/OpenSSLCrypto.cpp b/src/common/Cryptography/OpenSSLCrypto.cpp index 036a94c0e7..1a69a0c0f8 100644 --- a/src/common/Cryptography/OpenSSLCrypto.cpp +++ b/src/common/Cryptography/OpenSSLCrypto.cpp @@ -16,7 +16,6 @@ */ #include "OpenSSLCrypto.h" -#include "Errors.h" #include <openssl/crypto.h> // NOTE: this import is NEEDED (even though some IDEs report it as unused) #if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x1010000fL diff --git a/src/common/Cryptography/SessionKeyGenerator.h b/src/common/Cryptography/SessionKeyGenerator.h index 43dca3f235..bafd9ce014 100644 --- a/src/common/Cryptography/SessionKeyGenerator.h +++ b/src/common/Cryptography/SessionKeyGenerator.h @@ -18,9 +18,6 @@ #ifndef AZEROTHCORE_SESSIONKEYGENERATOR_HPP #define AZEROTHCORE_SESSIONKEYGENERATOR_HPP -#include "CryptoHash.h" -#include <cstring> - template <typename Hash> class SessionKeyGenerator { @@ -30,8 +27,8 @@ public: o0it(o0.begin()) { uint8 const* data = std::data(buf); - size_t const len = std::size(buf); - size_t const halflen = (len / 2); + std::size_t const len = std::size(buf); + std::size_t const halflen = (len / 2); o1 = Hash::GetDigestOf(data, halflen); o2 = Hash::GetDigestOf(data + halflen, len - halflen); diff --git a/src/common/Cryptography/TOTP.h b/src/common/Cryptography/TOTP.h index ddcaf75734..56ddccb6be 100644 --- a/src/common/Cryptography/TOTP.h +++ b/src/common/Cryptography/TOTP.h @@ -26,7 +26,7 @@ namespace Acore::Crypto { struct AC_COMMON_API TOTP { - static constexpr size_t RECOMMENDED_SECRET_LENGTH = 20; + static constexpr std::size_t RECOMMENDED_SECRET_LENGTH = 20; using Secret = std::vector<uint8>; static uint32 GenerateToken(Secret const& key, time_t timestamp); |