From 2f1b5091cda0da74813a9b826aada277aa5deb03 Mon Sep 17 00:00:00 2001 From: hashlag Date: Mon, 31 Aug 2026 00:05:18 +0300 Subject: [PATCH 01/16] Replace Hash CRTP base with a concept. --- Chaos/Hash/Hash.hpp | 29 ++++------------------------- Chaos/Hash/Md4.hpp | 4 +++- Chaos/Hash/Md5.hpp | 4 +++- Chaos/Hash/Sha1.hpp | 4 +++- 4 files changed, 13 insertions(+), 28 deletions(-) diff --git a/Chaos/Hash/Hash.hpp b/Chaos/Hash/Hash.hpp index fe252e1..af87c44 100644 --- a/Chaos/Hash/Hash.hpp +++ b/Chaos/Hash/Hash.hpp @@ -1,38 +1,17 @@ #ifndef CHAOS_HASH_HASH_HPP #define CHAOS_HASH_HASH_HPP +#include #include namespace Chaos::Hash { template -class Hash +concept Hash = requires(T hash) { -public: - auto GetRawDigest() const - { - return Impl().GetRawDigest(); - } - - std::string ToHexString() const - { - return Impl().ToHexString(); - } - -protected: - Hash() = default; - -private: - const T & Impl() const - { - return static_cast(*this); - } - - T & Impl() - { - return static_cast(*this); - } + hash.GetRawDigest(); + { hash.ToHexString() } -> std::same_as; }; } // namespace Chaos::Hash diff --git a/Chaos/Hash/Md4.hpp b/Chaos/Hash/Md4.hpp index 103bd3e..d6528d5 100644 --- a/Chaos/Hash/Md4.hpp +++ b/Chaos/Hash/Md4.hpp @@ -136,7 +136,7 @@ private: namespace Chaos::Hash::Md4 { -struct Md4Hash : public Hash +struct Md4Hash { std::array GetRawDigest() const { @@ -161,6 +161,8 @@ struct Md4Hash : public Hash std::array RawDigest_; }; +static_assert(Hash); + class Md4Hasher : public Hasher { public: diff --git a/Chaos/Hash/Md5.hpp b/Chaos/Hash/Md5.hpp index 7e6c97a..ecdb288 100644 --- a/Chaos/Hash/Md5.hpp +++ b/Chaos/Hash/Md5.hpp @@ -160,7 +160,7 @@ private: namespace Chaos::Hash::Md5 { -struct Md5Hash : public Hash +struct Md5Hash { std::array GetRawDigest() const { @@ -185,6 +185,8 @@ struct Md5Hash : public Hash std::array RawDigest_; }; +static_assert(Hash); + class Md5Hasher : public Hasher { public: diff --git a/Chaos/Hash/Sha1.hpp b/Chaos/Hash/Sha1.hpp index 877a0d8..ee99e83 100644 --- a/Chaos/Hash/Sha1.hpp +++ b/Chaos/Hash/Sha1.hpp @@ -129,7 +129,7 @@ private: namespace Chaos::Hash::Sha1 { -struct Sha1Hash : public Hash +struct Sha1Hash { std::array GetRawDigest() const { @@ -155,6 +155,8 @@ struct Sha1Hash : public Hash std::array RawDigest_; }; +static_assert(Hash); + class Sha1Hasher : public Hasher { public: From b03fddd40b63d1e3c4f376cc019ab059f3fc3e95 Mon Sep 17 00:00:00 2001 From: hashlag Date: Mon, 31 Aug 2026 01:22:07 +0300 Subject: [PATCH 02/16] Replace Hasher CRTP base with a concept. --- Chaos/Hash/Hasher.hpp | 39 ++++++++------------------------------- Chaos/Hash/Md4.hpp | 4 +++- Chaos/Hash/Md5.hpp | 4 +++- Chaos/Hash/Sha1.hpp | 4 +++- Chaos/Mac/Hmac.hpp | 4 +--- 5 files changed, 18 insertions(+), 37 deletions(-) diff --git a/Chaos/Hash/Hasher.hpp b/Chaos/Hash/Hasher.hpp index 796c02f..778bea5 100644 --- a/Chaos/Hash/Hasher.hpp +++ b/Chaos/Hash/Hasher.hpp @@ -1,42 +1,19 @@ #ifndef CHAOS_HASH_HASHER_HPP #define CHAOS_HASH_HASHER_HPP +#include + +#include "Hash.hpp" + namespace Chaos::Hash { template -class Hasher +concept Hasher = requires(T hasher, uint8_t * begin, uint8_t * end) { -public: - void Reset() - { - Impl().Reset(); - } - - template - void Update(InputIt begin, InputIt end) - { - Impl().Update(begin, end); - } - - auto Finish() - { - return Impl().Finish(); - } - -protected: - Hasher() = default; - -private: - const T & Impl() const - { - return static_cast(*this); - } - - T & Impl() - { - return static_cast(*this); - } + hasher.Reset(); + hasher.Update(begin, end); + { hasher.Finish() } -> Hash; }; } // namespace Chaos::Hash diff --git a/Chaos/Hash/Md4.hpp b/Chaos/Hash/Md4.hpp index d6528d5..e78dec3 100644 --- a/Chaos/Hash/Md4.hpp +++ b/Chaos/Hash/Md4.hpp @@ -163,7 +163,7 @@ struct Md4Hash static_assert(Hash); -class Md4Hasher : public Hasher +class Md4Hasher { public: using HashType = Md4Hash; @@ -304,6 +304,8 @@ private: } }; +static_assert(Hasher); + } // namespace Chaos::Hash::Md4 #endif // CHAOS_HASH_MD4_HPP diff --git a/Chaos/Hash/Md5.hpp b/Chaos/Hash/Md5.hpp index ecdb288..cb1be91 100644 --- a/Chaos/Hash/Md5.hpp +++ b/Chaos/Hash/Md5.hpp @@ -187,7 +187,7 @@ struct Md5Hash static_assert(Hash); -class Md5Hasher : public Hasher +class Md5Hasher { public: using HashType = Md5Hash; @@ -328,6 +328,8 @@ private: } }; +static_assert(Hasher); + } // namespace Chaos::Hash::Md5 #endif // CHAOS_HASH_MD5_HPP diff --git a/Chaos/Hash/Sha1.hpp b/Chaos/Hash/Sha1.hpp index ee99e83..ad743d8 100644 --- a/Chaos/Hash/Sha1.hpp +++ b/Chaos/Hash/Sha1.hpp @@ -157,7 +157,7 @@ struct Sha1Hash static_assert(Hash); -class Sha1Hasher : public Hasher +class Sha1Hasher { public: using HashType = Sha1Hash; @@ -298,6 +298,8 @@ private: } }; +static_assert(Hasher); + } // namespace Chaos::Hash::Sha1 #endif // CHAOS_HASH_SHA1_HPP diff --git a/Chaos/Mac/Hmac.hpp b/Chaos/Mac/Hmac.hpp index 125bb3a..82ecc7e 100644 --- a/Chaos/Mac/Hmac.hpp +++ b/Chaos/Mac/Hmac.hpp @@ -3,7 +3,6 @@ #include #include -#include #include "Hash/Hasher.hpp" #include "Service/ChaosException.hpp" @@ -11,8 +10,7 @@ namespace Chaos::Mac::Hmac { -template, HasherImpl>>> +template class Hmac { public: From 7d028cce660bd147424ead3c511395e6e42b0986 Mon Sep 17 00:00:00 2001 From: hashlag Date: Mon, 31 Aug 2026 01:32:52 +0300 Subject: [PATCH 03/16] SeArray: Replace enable_if with a concept. --- Chaos/Service/SeArray.hpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Chaos/Service/SeArray.hpp b/Chaos/Service/SeArray.hpp index 24c7875..604cc01 100644 --- a/Chaos/Service/SeArray.hpp +++ b/Chaos/Service/SeArray.hpp @@ -2,14 +2,13 @@ #define CHAOS_SERVICE_SEARRAY_HPP #include -#include +#include #include namespace Chaos::Service { -template>> +template class SeArray { public: From 1c341c6888c4a3771318fcff239dd096074bec02 Mon Sep 17 00:00:00 2001 From: hashlag Date: Tue, 1 Sep 2026 00:43:27 +0300 Subject: [PATCH 04/16] Replace Padder CRTP base with a concept. --- Chaos/Padding/Padder.hpp | 32 ++++------------------- Chaos/Padding/PadderIso7816.hpp | 4 ++- Chaos/Padding/PadderPkcs7.hpp | 4 ++- ChaosTests/Padding/PadderIso7816Tests.cpp | 12 ++++----- ChaosTests/Padding/PadderPkcs7Tests.cpp | 12 ++++----- 5 files changed, 23 insertions(+), 41 deletions(-) diff --git a/Chaos/Padding/Padder.hpp b/Chaos/Padding/Padder.hpp index 5ae50e0..1807d5e 100644 --- a/Chaos/Padding/Padder.hpp +++ b/Chaos/Padding/Padder.hpp @@ -1,38 +1,16 @@ #ifndef CHAOS_PADDING_PADDER_HPP #define CHAOS_PADDING_PADDER_HPP +#include + namespace Chaos::Padding { template -class Padder +concept Padder = requires(uint8_t * begin, uint8_t * end) { -public: - template - void Pad(OutputIt begin, OutputIt end) const - { - Impl().Pad(begin, end); - } - - template - auto ComputeUnpad(InputIt begin, InputIt end) const noexcept - { - return Impl().ComputeUnpad(begin, end); - } - -protected: - Padder() = default; - -private: - const T & Impl() const - { - return static_cast(*this); - } - - T & Impl() - { - return static_cast(*this); - } + T::Pad(begin, end); + { T::ComputeUnpad(begin, end) } noexcept; }; } // namespace Chaos::Padding diff --git a/Chaos/Padding/PadderIso7816.hpp b/Chaos/Padding/PadderIso7816.hpp index c5af640..ee21f27 100644 --- a/Chaos/Padding/PadderIso7816.hpp +++ b/Chaos/Padding/PadderIso7816.hpp @@ -12,7 +12,7 @@ namespace Chaos::Padding { -class PadderIso7816 : public Padder +class PadderIso7816 { public: template @@ -82,6 +82,8 @@ private: using Branchless = Service::Branchless; }; +static_assert(Padder); + } // namespace Chaos::Padding #endif // CHAOS_PADDING_PADDERISO7816_HPP diff --git a/Chaos/Padding/PadderPkcs7.hpp b/Chaos/Padding/PadderPkcs7.hpp index 325a01f..61c4a60 100644 --- a/Chaos/Padding/PadderPkcs7.hpp +++ b/Chaos/Padding/PadderPkcs7.hpp @@ -13,7 +13,7 @@ namespace Chaos::Padding { -class PadderPkcs7 : public Padder +class PadderPkcs7 { public: template @@ -75,6 +75,8 @@ private: using Branchless = Service::Branchless; }; +static_assert(Padder); + } // namespace Chaos::Padding #endif // CHAOS_PADDING_PADDERPKCS7_HPP diff --git a/ChaosTests/Padding/PadderIso7816Tests.cpp b/ChaosTests/Padding/PadderIso7816Tests.cpp index 0118032..e917063 100644 --- a/ChaosTests/Padding/PadderIso7816Tests.cpp +++ b/ChaosTests/Padding/PadderIso7816Tests.cpp @@ -109,8 +109,8 @@ TEST(PadIso7816Tests, PadOutIteratorUsageTest) } } -template -void PadThroughBase(const Padder & padder, OutputIt begin, OutputIt end) +template +void PadGeneric(const PadderImpl & padder, OutputIt begin, OutputIt end) { padder.Pad(begin, end); } @@ -127,7 +127,7 @@ TEST(PadIso7816Tests, PadThroughBaseTest) }; const PadderIso7816 padder; - PadThroughBase(padder, fact.begin(), fact.end()); + PadGeneric(padder, fact.begin(), fact.end()); ASSERT_EQ(expected, fact); } @@ -324,8 +324,8 @@ TEST(PadIso7816Tests, UnpadErrorTest) } } -template -auto ComputeUnpadThroughBase(const Padder & padder, OutputIt begin, OutputIt end) +template +auto ComputeUnpadGeneric(const PadderImpl & padder, OutputIt begin, OutputIt end) { return padder.ComputeUnpad(begin, end); } @@ -336,7 +336,7 @@ TEST(PadIso7816Tests, ComputeUnpadThroughBaseTest) std::array data = { 0x80, 0x00, 0x00, 0x00, 0x00 }; const PadderIso7816 padder; - auto result = ComputeUnpadThroughBase(padder, data.begin(), data.end()); + auto result = ComputeUnpadGeneric(padder, data.begin(), data.end()); ASSERT_TRUE(result.IsOkay_); ASSERT_EQ(5, result.PadSize_); diff --git a/ChaosTests/Padding/PadderPkcs7Tests.cpp b/ChaosTests/Padding/PadderPkcs7Tests.cpp index 112918b..57240ac 100644 --- a/ChaosTests/Padding/PadderPkcs7Tests.cpp +++ b/ChaosTests/Padding/PadderPkcs7Tests.cpp @@ -137,8 +137,8 @@ TEST(PadPkcs7Tests, PadOutIteratorUsageTest) } } -template -void PadThroughBase(const Padder & padder, OutputIt begin, OutputIt end) +template +void PadGeneric(const PadderImpl & padder, OutputIt begin, OutputIt end) { padder.Pad(begin, end); } @@ -153,7 +153,7 @@ TEST(PadPkcs7Tests, PadThroughBaseTest) }; const PadderPkcs7 padder; - PadThroughBase(padder, fact.begin(), fact.end()); + PadGeneric(padder, fact.begin(), fact.end()); ASSERT_EQ(expected, fact); } @@ -347,8 +347,8 @@ TEST(PadPkcs7Tests, UnpadErrorTest) } } -template -auto ComputeUnpadThroughBase(const Padder & padder, OutputIt begin, OutputIt end) +template +auto ComputeUnpadGeneric(const PadderImpl & padder, OutputIt begin, OutputIt end) { return padder.ComputeUnpad(begin, end); } @@ -359,7 +359,7 @@ TEST(PadPkcs7Tests, ComputeUnpadThroughBaseTest) std::array data = { 0x05, 0x05, 0x05, 0x05, 0x05 }; const PadderPkcs7 padder; - auto result = ComputeUnpadThroughBase(padder, data.begin(), data.end()); + auto result = ComputeUnpadGeneric(padder, data.begin(), data.end()); ASSERT_TRUE(result.IsOkay_); ASSERT_EQ(5, result.PadSize_); From f0228877b4c3237bb309d292855c7bd7597dd542 Mon Sep 17 00:00:00 2001 From: hashlag Date: Sun, 6 Sep 2026 01:05:15 +0300 Subject: [PATCH 05/16] DesCrypt: Expose Block type in Encryptor and Decryptor. --- Chaos/Cipher/Block/Des/DesCrypt.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Chaos/Cipher/Block/Des/DesCrypt.hpp b/Chaos/Cipher/Block/Des/DesCrypt.hpp index f303c50..66cdb21 100644 --- a/Chaos/Cipher/Block/Des/DesCrypt.hpp +++ b/Chaos/Cipher/Block/Des/DesCrypt.hpp @@ -236,6 +236,7 @@ public: class Encryptor : public Chaos::Cipher::Block::Encryptor { public: + using Block = DesCrypt::Block; using Key = DesCrypt::Key; static constexpr size_t BlockSize = DesCrypt::BlockSize; static constexpr size_t KeySize = DesCrypt::KeySize; @@ -281,6 +282,7 @@ public: class Decryptor : public Chaos::Cipher::Block::Decryptor { public: + using Block = DesCrypt::Block; using Key = DesCrypt::Key; static constexpr size_t BlockSize = DesCrypt::BlockSize; static constexpr size_t KeySize = DesCrypt::KeySize; From 2c6a24197ae169bf7030b1a00155bacb90c28e3f Mon Sep 17 00:00:00 2001 From: hashlag Date: Sun, 6 Sep 2026 02:27:35 +0300 Subject: [PATCH 06/16] Replace Encryptor CRTP base with a concept. --- Chaos/Cipher/Block/Des/DesCrypt.hpp | 4 +- Chaos/Cipher/Block/Encryptor.hpp | 49 ++++++------------- ChaosTests/Cipher/Block/Des/DesCryptTests.cpp | 18 +++---- 3 files changed, 28 insertions(+), 43 deletions(-) diff --git a/Chaos/Cipher/Block/Des/DesCrypt.hpp b/Chaos/Cipher/Block/Des/DesCrypt.hpp index 66cdb21..b6d72db 100644 --- a/Chaos/Cipher/Block/Des/DesCrypt.hpp +++ b/Chaos/Cipher/Block/Des/DesCrypt.hpp @@ -233,7 +233,7 @@ public: Inner_::RawKey Key_; }; - class Encryptor : public Chaos::Cipher::Block::Encryptor + class Encryptor { public: using Block = DesCrypt::Block; @@ -279,6 +279,8 @@ public: Inner_::KeySchedule Schedule_; }; + static_assert(Chaos::Cipher::Block::Encryptor); + class Decryptor : public Chaos::Cipher::Block::Decryptor { public: diff --git a/Chaos/Cipher/Block/Encryptor.hpp b/Chaos/Cipher/Block/Encryptor.hpp index ba3f9f5..3c8ada7 100644 --- a/Chaos/Cipher/Block/Encryptor.hpp +++ b/Chaos/Cipher/Block/Encryptor.hpp @@ -1,44 +1,27 @@ #ifndef CHAOS_CIPHER_BLOCK_ENCRYPTOR_HPP #define CHAOS_CIPHER_BLOCK_ENCRYPTOR_HPP +#include +#include +#include + namespace Chaos::Cipher::Block { template -class Encryptor +concept Encryptor = requires(T encryptor, + typename T::Block block, + uint8_t * outBegin, uint8_t * outEnd, + uint8_t * inBegin, uint8_t * inEnd) { -public: - template - void EncryptBlock(OutputIt outBegin, OutputIt outEnd, - InputIt inBegin, InputIt inEnd) const - { - Impl().EncryptBlock(outBegin, outEnd, inBegin, inEnd); - } - - template - auto EncryptBlock(Block block) const - { - return Impl().EncryptBlock(block); - } - - auto GetBlockSize() const - { - return Impl().GetBlockSize(); - } - -protected: - Encryptor() = default; - -private: - const T & Impl() const - { - return static_cast(*this); - } - - T & Impl() - { - return static_cast(*this); - } + typename T::Block; + typename T::Key; + requires std::constructible_from; + requires std::unsigned_integral>; + requires std::unsigned_integral>; + encryptor.EncryptBlock(outBegin, outEnd, inBegin, inEnd); + { encryptor.EncryptBlock(block) } -> std::same_as; + { encryptor.GetBlockSize() } -> std::unsigned_integral; }; } // namespace Chaos::Cipher::Block diff --git a/ChaosTests/Cipher/Block/Des/DesCryptTests.cpp b/ChaosTests/Cipher/Block/Des/DesCryptTests.cpp index 417f765..d525671 100644 --- a/ChaosTests/Cipher/Block/Des/DesCryptTests.cpp +++ b/ChaosTests/Cipher/Block/Des/DesCryptTests.cpp @@ -486,9 +486,9 @@ TEST(DesCryptTests, OutIteratorUsageDecryptTest) } } -template -static std::vector EncryptThroughBase(const Encryptor & enc, - InputIt begin, InputIt end) +template +static std::vector EncryptGeneric(const EncryptorImpl & enc, + InputIt begin, InputIt end) { std::vector result; result.resize(enc.GetBlockSize(), 0); @@ -497,7 +497,7 @@ static std::vector EncryptThroughBase(const Encryptor & enc, return result; } -TEST(DesCryptTests, EncryptThroughBaseTest) +TEST(DesCryptTests, EncryptGenericTest) { std::array key = { 0x13, 0x34, 0x57, 0x79, 0x9b, 0xbc, 0xdf, 0xf1 }; @@ -507,16 +507,16 @@ TEST(DesCryptTests, EncryptThroughBaseTest) DesCrypt::Key desKey(key.begin(), key.end()); DesCrypt::Encryptor enc(desKey); - ASSERT_EQ(expected, EncryptThroughBase(enc, data.begin(), data.end())); + ASSERT_EQ(expected, EncryptGeneric(enc, data.begin(), data.end())); } -template -static uint64_t EncryptUInt64BlockThroughBase(const Encryptor & enc, uint64_t block) +template +static uint64_t EncryptUInt64BlockGeneric(const EncryptorImpl & enc, uint64_t block) { return enc.EncryptBlock(block); } -TEST(DesCryptTests, EncryptUInt64BlockThroughBaseTest) +TEST(DesCryptTests, EncryptUInt64BlockGenericTest) { std::array key = { 0x13, 0x34, 0x57, 0x79, 0x9b, 0xbc, 0xdf, 0xf1 }; @@ -526,7 +526,7 @@ TEST(DesCryptTests, EncryptUInt64BlockThroughBaseTest) DesCrypt::Key desKey(key.begin(), key.end()); DesCrypt::Encryptor enc(desKey); - ASSERT_EQ(expected, EncryptUInt64BlockThroughBase(enc, data)); + ASSERT_EQ(expected, EncryptUInt64BlockGeneric(enc, data)); } template From 3dacd57fef88563c8e61e2645fe38bbfe4e9d071 Mon Sep 17 00:00:00 2001 From: hashlag Date: Sun, 6 Sep 2026 02:45:45 +0300 Subject: [PATCH 07/16] Replace Decryptor CRTP base with a concept. --- Chaos/Cipher/Block/Decryptor.hpp | 49 ++++++------------- Chaos/Cipher/Block/Des/DesCrypt.hpp | 4 +- ChaosTests/Cipher/Block/Des/DesCryptTests.cpp | 18 +++---- 3 files changed, 28 insertions(+), 43 deletions(-) diff --git a/Chaos/Cipher/Block/Decryptor.hpp b/Chaos/Cipher/Block/Decryptor.hpp index e27c130..d3eeb23 100644 --- a/Chaos/Cipher/Block/Decryptor.hpp +++ b/Chaos/Cipher/Block/Decryptor.hpp @@ -1,44 +1,27 @@ #ifndef CHAOS_CIPHER_BLOCK_DECRYPTOR_HPP #define CHAOS_CIPHER_BLOCK_DECRYPTOR_HPP +#include +#include +#include + namespace Chaos::Cipher::Block { template -class Decryptor +concept Decryptor = requires(T decryptor, + typename T::Block block, + uint8_t * outBegin, uint8_t * outEnd, + uint8_t * inBegin, uint8_t * inEnd) { -public: - template - void DecryptBlock(OutputIt outBegin, OutputIt outEnd, - InputIt inBegin, InputIt inEnd) const - { - Impl().DecryptBlock(outBegin, outEnd, inBegin, inEnd); - } - - template - auto DecryptBlock(Block block) const - { - return Impl().DecryptBlock(block); - } - - auto GetBlockSize() const - { - return Impl().GetBlockSize(); - } - -protected: - Decryptor() = default; - -private: - const T & Impl() const - { - return static_cast(*this); - } - - T & Impl() - { - return static_cast(*this); - } + typename T::Block; + typename T::Key; + requires std::constructible_from; + requires std::unsigned_integral>; + requires std::unsigned_integral>; + decryptor.DecryptBlock(outBegin, outEnd, inBegin, inEnd); + { decryptor.DecryptBlock(block) } -> std::same_as; + { decryptor.GetBlockSize() } -> std::unsigned_integral; }; } // namespace Chaos::Cipher::Block diff --git a/Chaos/Cipher/Block/Des/DesCrypt.hpp b/Chaos/Cipher/Block/Des/DesCrypt.hpp index b6d72db..de6119f 100644 --- a/Chaos/Cipher/Block/Des/DesCrypt.hpp +++ b/Chaos/Cipher/Block/Des/DesCrypt.hpp @@ -281,7 +281,7 @@ public: static_assert(Chaos::Cipher::Block::Encryptor); - class Decryptor : public Chaos::Cipher::Block::Decryptor + class Decryptor { public: using Block = DesCrypt::Block; @@ -327,6 +327,8 @@ public: Inner_::KeySchedule Schedule_; }; + static_assert(Chaos::Cipher::Block::Decryptor); + private: using BlockHalf = uint32_t; using RawBlockArray = Service::SeArray; diff --git a/ChaosTests/Cipher/Block/Des/DesCryptTests.cpp b/ChaosTests/Cipher/Block/Des/DesCryptTests.cpp index d525671..7d9b86b 100644 --- a/ChaosTests/Cipher/Block/Des/DesCryptTests.cpp +++ b/ChaosTests/Cipher/Block/Des/DesCryptTests.cpp @@ -529,9 +529,9 @@ TEST(DesCryptTests, EncryptUInt64BlockGenericTest) ASSERT_EQ(expected, EncryptUInt64BlockGeneric(enc, data)); } -template -static std::vector DecryptThroughBase(const Decryptor & dec, - InputIt begin, InputIt end) +template +static std::vector DecryptGeneric(const DecryptorImpl & dec, + InputIt begin, InputIt end) { std::vector result; result.resize(dec.GetBlockSize(), 0); @@ -540,7 +540,7 @@ static std::vector DecryptThroughBase(const Decryptor & dec, return result; } -TEST(DesCryptTests, DecryptThroughBaseTest) +TEST(DesCryptTests, DecryptGenericTest) { std::array key = { 0x13, 0x34, 0x57, 0x79, 0x9b, 0xbc, 0xdf, 0xf1 }; @@ -550,16 +550,16 @@ TEST(DesCryptTests, DecryptThroughBaseTest) DesCrypt::Key desKey(key.begin(), key.end()); DesCrypt::Decryptor dec(desKey); - ASSERT_EQ(expected, DecryptThroughBase(dec, data.begin(), data.end())); + ASSERT_EQ(expected, DecryptGeneric(dec, data.begin(), data.end())); } -template -static uint64_t DecryptUInt64BlockThroughBase(const Decryptor & dec, uint64_t block) +template +static uint64_t DecryptUInt64BlockGeneric(const DecryptorImpl & dec, uint64_t block) { return dec.DecryptBlock(block); } -TEST(DesCryptTests, DecryptUInt64BlockThroughBaseTest) +TEST(DesCryptTests, DecryptUInt64BlockGenericTest) { std::array key = { 0x13, 0x34, 0x57, 0x79, 0x9b, 0xbc, 0xdf, 0xf1 }; @@ -569,5 +569,5 @@ TEST(DesCryptTests, DecryptUInt64BlockThroughBaseTest) DesCrypt::Key desKey(key.begin(), key.end()); DesCrypt::Decryptor dec(desKey); - ASSERT_EQ(expected, DecryptUInt64BlockThroughBase(dec, data)); + ASSERT_EQ(expected, DecryptUInt64BlockGeneric(dec, data)); } From 134ef3dd4efe49ebeb749f511ff93341d1d57a18 Mon Sep 17 00:00:00 2001 From: hashlag Date: Sat, 12 Sep 2026 02:33:20 +0300 Subject: [PATCH 08/16] Update concept Hash: require const methods. --- Chaos/Hash/Hash.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Chaos/Hash/Hash.hpp b/Chaos/Hash/Hash.hpp index af87c44..ea73799 100644 --- a/Chaos/Hash/Hash.hpp +++ b/Chaos/Hash/Hash.hpp @@ -8,10 +8,10 @@ namespace Chaos::Hash { template -concept Hash = requires(T hash) +concept Hash = requires(const T constHash) { - hash.GetRawDigest(); - { hash.ToHexString() } -> std::same_as; + constHash.GetRawDigest(); + { constHash.ToHexString() } -> std::same_as; }; } // namespace Chaos::Hash From a015fbe6735694824b4dae5cc22555a6fde70050 Mon Sep 17 00:00:00 2001 From: hashlag Date: Sat, 12 Sep 2026 02:34:00 +0300 Subject: [PATCH 09/16] Update concept Encryptor: require const methods. --- Chaos/Cipher/Block/Encryptor.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Chaos/Cipher/Block/Encryptor.hpp b/Chaos/Cipher/Block/Encryptor.hpp index 3c8ada7..13626dc 100644 --- a/Chaos/Cipher/Block/Encryptor.hpp +++ b/Chaos/Cipher/Block/Encryptor.hpp @@ -9,7 +9,7 @@ namespace Chaos::Cipher::Block { template -concept Encryptor = requires(T encryptor, +concept Encryptor = requires(const T constEncryptor, typename T::Block block, uint8_t * outBegin, uint8_t * outEnd, uint8_t * inBegin, uint8_t * inEnd) @@ -19,9 +19,9 @@ concept Encryptor = requires(T encryptor, requires std::constructible_from; requires std::unsigned_integral>; requires std::unsigned_integral>; - encryptor.EncryptBlock(outBegin, outEnd, inBegin, inEnd); - { encryptor.EncryptBlock(block) } -> std::same_as; - { encryptor.GetBlockSize() } -> std::unsigned_integral; + constEncryptor.EncryptBlock(outBegin, outEnd, inBegin, inEnd); + { constEncryptor.EncryptBlock(block) } -> std::same_as; + { constEncryptor.GetBlockSize() } -> std::unsigned_integral; }; } // namespace Chaos::Cipher::Block From 0f41687ea6fb39fde911d8e3412a73f6646b01b1 Mon Sep 17 00:00:00 2001 From: hashlag Date: Sat, 12 Sep 2026 02:34:41 +0300 Subject: [PATCH 10/16] Update concept Decryptor: require const methods. --- Chaos/Cipher/Block/Decryptor.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Chaos/Cipher/Block/Decryptor.hpp b/Chaos/Cipher/Block/Decryptor.hpp index d3eeb23..ae2c99c 100644 --- a/Chaos/Cipher/Block/Decryptor.hpp +++ b/Chaos/Cipher/Block/Decryptor.hpp @@ -9,7 +9,7 @@ namespace Chaos::Cipher::Block { template -concept Decryptor = requires(T decryptor, +concept Decryptor = requires(const T constDecryptor, typename T::Block block, uint8_t * outBegin, uint8_t * outEnd, uint8_t * inBegin, uint8_t * inEnd) @@ -19,9 +19,9 @@ concept Decryptor = requires(T decryptor, requires std::constructible_from; requires std::unsigned_integral>; requires std::unsigned_integral>; - decryptor.DecryptBlock(outBegin, outEnd, inBegin, inEnd); - { decryptor.DecryptBlock(block) } -> std::same_as; - { decryptor.GetBlockSize() } -> std::unsigned_integral; + constDecryptor.DecryptBlock(outBegin, outEnd, inBegin, inEnd); + { constDecryptor.DecryptBlock(block) } -> std::same_as; + { constDecryptor.GetBlockSize() } -> std::unsigned_integral; }; } // namespace Chaos::Cipher::Block From cb8b6ceeb8ef3f90353a1af4a3e425eadbf8329e Mon Sep 17 00:00:00 2001 From: hashlag Date: Sat, 12 Sep 2026 02:39:44 +0300 Subject: [PATCH 11/16] Update concept Hasher: require T::HashType inner type. --- Chaos/Hash/Hasher.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Chaos/Hash/Hasher.hpp b/Chaos/Hash/Hasher.hpp index 778bea5..57f9944 100644 --- a/Chaos/Hash/Hasher.hpp +++ b/Chaos/Hash/Hasher.hpp @@ -11,6 +11,7 @@ namespace Chaos::Hash template concept Hasher = requires(T hasher, uint8_t * begin, uint8_t * end) { + typename T::HashType; hasher.Reset(); hasher.Update(begin, end); { hasher.Finish() } -> Hash; From 97aeb229ad92a430c77caeb295242bf4b2d5ff33 Mon Sep 17 00:00:00 2001 From: hashlag Date: Sat, 12 Sep 2026 02:49:12 +0300 Subject: [PATCH 12/16] Update concept Hasher: require T::BLOCK_SIZE_BYTES. --- Chaos/Hash/Hasher.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Chaos/Hash/Hasher.hpp b/Chaos/Hash/Hasher.hpp index 57f9944..4b30dd6 100644 --- a/Chaos/Hash/Hasher.hpp +++ b/Chaos/Hash/Hasher.hpp @@ -1,7 +1,9 @@ #ifndef CHAOS_HASH_HASHER_HPP #define CHAOS_HASH_HASHER_HPP +#include #include +#include #include "Hash.hpp" @@ -12,6 +14,7 @@ template concept Hasher = requires(T hasher, uint8_t * begin, uint8_t * end) { typename T::HashType; + requires std::unsigned_integral>; hasher.Reset(); hasher.Update(begin, end); { hasher.Finish() } -> Hash; From 4e28752614a2c1dcd7a62b5e77f42e582b670e2a Mon Sep 17 00:00:00 2001 From: hashlag Date: Sat, 12 Sep 2026 02:58:05 +0300 Subject: [PATCH 13/16] Update concept Encryptor: require T::BlockSize and T::KeySize to be constant expressions. --- Chaos/Cipher/Block/Encryptor.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Chaos/Cipher/Block/Encryptor.hpp b/Chaos/Cipher/Block/Encryptor.hpp index 13626dc..8150c91 100644 --- a/Chaos/Cipher/Block/Encryptor.hpp +++ b/Chaos/Cipher/Block/Encryptor.hpp @@ -18,7 +18,9 @@ concept Encryptor = requires(const T constEncryptor, typename T::Key; requires std::constructible_from; requires std::unsigned_integral>; + typename std::integral_constant; requires std::unsigned_integral>; + typename std::integral_constant; constEncryptor.EncryptBlock(outBegin, outEnd, inBegin, inEnd); { constEncryptor.EncryptBlock(block) } -> std::same_as; { constEncryptor.GetBlockSize() } -> std::unsigned_integral; From 84e906865551b49222af5a06144d131a01fc6a09 Mon Sep 17 00:00:00 2001 From: hashlag Date: Sat, 12 Sep 2026 02:59:45 +0300 Subject: [PATCH 14/16] Adjust concept Encryptor formatting. --- Chaos/Cipher/Block/Encryptor.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Chaos/Cipher/Block/Encryptor.hpp b/Chaos/Cipher/Block/Encryptor.hpp index 8150c91..ddd3cf3 100644 --- a/Chaos/Cipher/Block/Encryptor.hpp +++ b/Chaos/Cipher/Block/Encryptor.hpp @@ -17,10 +17,13 @@ concept Encryptor = requires(const T constEncryptor, typename T::Block; typename T::Key; requires std::constructible_from; + requires std::unsigned_integral>; typename std::integral_constant; + requires std::unsigned_integral>; typename std::integral_constant; + constEncryptor.EncryptBlock(outBegin, outEnd, inBegin, inEnd); { constEncryptor.EncryptBlock(block) } -> std::same_as; { constEncryptor.GetBlockSize() } -> std::unsigned_integral; From ba87a7d14956037a0eed3b0e5070a02ba8e09fd5 Mon Sep 17 00:00:00 2001 From: hashlag Date: Sat, 12 Sep 2026 03:02:03 +0300 Subject: [PATCH 15/16] Update concept Decryptor: require T::BlockSize and T::KeySize to be constant expressions. --- Chaos/Cipher/Block/Decryptor.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Chaos/Cipher/Block/Decryptor.hpp b/Chaos/Cipher/Block/Decryptor.hpp index ae2c99c..bd38cf2 100644 --- a/Chaos/Cipher/Block/Decryptor.hpp +++ b/Chaos/Cipher/Block/Decryptor.hpp @@ -17,8 +17,13 @@ concept Decryptor = requires(const T constDecryptor, typename T::Block; typename T::Key; requires std::constructible_from; + requires std::unsigned_integral>; + typename std::integral_constant; + requires std::unsigned_integral>; + typename std::integral_constant; + constDecryptor.DecryptBlock(outBegin, outEnd, inBegin, inEnd); { constDecryptor.DecryptBlock(block) } -> std::same_as; { constDecryptor.GetBlockSize() } -> std::unsigned_integral; From a070a0c343ca0661120278a26f96400bf092ff9a Mon Sep 17 00:00:00 2001 From: hashlag Date: Sat, 12 Sep 2026 03:11:05 +0300 Subject: [PATCH 16/16] Update concept Hasher: require T::BLOCK_SIZE_BYTES to be a constant expression. --- Chaos/Hash/Hasher.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Chaos/Hash/Hasher.hpp b/Chaos/Hash/Hasher.hpp index 4b30dd6..7055828 100644 --- a/Chaos/Hash/Hasher.hpp +++ b/Chaos/Hash/Hasher.hpp @@ -14,7 +14,10 @@ template concept Hasher = requires(T hasher, uint8_t * begin, uint8_t * end) { typename T::HashType; + requires std::unsigned_integral>; + typename std::integral_constant; + hasher.Reset(); hasher.Update(begin, end); { hasher.Finish() } -> Hash;