Compare commits

..
1 Commits
Author SHA1 Message Date
hashlag 4d613d8015 Introduce BlockAdapter.
Chaos Ci / test (push) Successful in 3m23s
Chaos Ci / benchmark (push) Successful in 1m33s
2026-10-12 01:05:14 +03:00
16 changed files with 29 additions and 265 deletions

No files matched your search

-7
View File
@@ -1,7 +0,0 @@
returnByReference:Chaos/Hash/Md4.hpp:141
returnByReference:Chaos/Hash/Md5.hpp:165
returnByReference:Chaos/Hash/Sha1.hpp:134
useInitializationList:Chaos/Service/SeArray.hpp:25
accessMoved:ChaosTests/Service/SeArrayTests.cpp:309
accessMoved:ChaosTests/Service/SeArrayTests.cpp:331
accessMoved:ChaosTests/Service/SeArrayTests.cpp:367
-32
View File
@@ -58,38 +58,6 @@ jobs:
include-hidden-files: true include-hidden-files: true
retention-days: 10 retention-days: 10
static-analysis:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true
- name: Install
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake cppcheck
- name: Generate compile commands
run: |
mkdir build-debug
cmake -S . -B build-debug/ -D CMAKE_BUILD_TYPE=Debug -D CMAKE_EXPORT_COMPILE_COMMANDS=ON
- name: Run cppcheck
run: |
cppcheck --version
cppcheck --project=build-debug/compile_commands.json \
--file-filter='*ChaosTests/*' \
--file-filter='*ChaosBenches/*' \
--enable=warning,performance,portability \
--suppress='*:*/_deps/*' \
--suppress=missingIncludeSystem \
--suppressions-list=.cppcheck \
--inline-suppr \
--error-exitcode=1
benchmark: benchmark:
runs-on: ubuntu-latest runs-on: ubuntu-latest
-30
View File
@@ -114,12 +114,6 @@ public:
Decrypt Decrypt
}; };
KeySchedule(const KeySchedule & other) = delete;
KeySchedule(KeySchedule && other) = delete;
KeySchedule & operator=(const KeySchedule & other) = delete;
KeySchedule & operator=(KeySchedule && other) = delete;
KeySchedule(Direction direction, const RawKey & rawKey) KeySchedule(Direction direction, const RawKey & rawKey)
{ {
Key56 key56 = Pc1(Bitwise::PackUInt64(rawKey.Begin(), rawKey.End())); Key56 key56 = Pc1(Bitwise::PackUInt64(rawKey.Begin(), rawKey.End()));
@@ -216,22 +210,10 @@ public:
DesCrypt() = delete; DesCrypt() = delete;
DesCrypt(const DesCrypt & other) = delete;
DesCrypt(DesCrypt && other) = delete;
DesCrypt & operator=(const DesCrypt & other) = delete;
DesCrypt & operator=(DesCrypt && other) = delete;
class Key class Key
{ {
friend class DesCrypt; friend class DesCrypt;
public: public:
Key(const Key & other) = delete;
Key(Key && other) = delete;
Key & operator=(const Key & other) = delete;
Key & operator=(Key && other) = delete;
template<typename InputIt> template<typename InputIt>
Key(InputIt keyBegin, InputIt keyEnd) Key(InputIt keyBegin, InputIt keyEnd)
{ {
@@ -263,12 +245,6 @@ public:
static constexpr size_t BlockSize = DesCrypt::BlockSize; static constexpr size_t BlockSize = DesCrypt::BlockSize;
static constexpr size_t KeySize = DesCrypt::KeySize; static constexpr size_t KeySize = DesCrypt::KeySize;
Encryptor(const Encryptor & other) = delete;
Encryptor(Encryptor && other) = delete;
Encryptor & operator=(const Encryptor & other) = delete;
Encryptor & operator=(Encryptor && other) = delete;
Encryptor(const Key & key) Encryptor(const Key & key)
: Schedule_(Inner_::KeySchedule::Direction::Encrypt, key.Key_) : Schedule_(Inner_::KeySchedule::Direction::Encrypt, key.Key_)
{ } { }
@@ -317,12 +293,6 @@ public:
static constexpr size_t BlockSize = DesCrypt::BlockSize; static constexpr size_t BlockSize = DesCrypt::BlockSize;
static constexpr size_t KeySize = DesCrypt::KeySize; static constexpr size_t KeySize = DesCrypt::KeySize;
Decryptor(const Decryptor & other) = delete;
Decryptor(Decryptor && other) = delete;
Decryptor & operator=(const Decryptor & other) = delete;
Decryptor & operator=(Decryptor && other) = delete;
Decryptor(const Key & key) Decryptor(const Key & key)
: Schedule_(Inner_::KeySchedule::Direction::Decrypt, key.Key_) : Schedule_(Inner_::KeySchedule::Direction::Decrypt, key.Key_)
{ } { }
-20
View File
@@ -19,23 +19,9 @@ public:
using Cipher = CipherT; using Cipher = CipherT;
using Padder = PadderT; using Padder = PadderT;
EcbMode() = delete;
EcbMode(const EcbMode & other) = delete;
EcbMode(EcbMode && other) = delete;
EcbMode & operator=(const EcbMode & other) = delete;
EcbMode & operator=(EcbMode && other) = delete;
class Encryptor class Encryptor
{ {
public: public:
Encryptor(const Encryptor & other) = delete;
Encryptor(Encryptor && other) = delete;
Encryptor & operator=(const Encryptor & other) = delete;
Encryptor & operator=(Encryptor && other) = delete;
Encryptor(const typename CipherT::Key & key) Encryptor(const typename CipherT::Key & key)
: Encryptor_(key) : Encryptor_(key)
, BlockBytesPacked_(0) , BlockBytesPacked_(0)
@@ -129,12 +115,6 @@ public:
class Decryptor class Decryptor
{ {
public: public:
Decryptor(const Decryptor & other) = delete;
Decryptor(Decryptor && other) = delete;
Decryptor & operator=(const Decryptor & other) = delete;
Decryptor & operator=(Decryptor && other) = delete;
Decryptor(const typename CipherT::Key & key) Decryptor(const typename CipherT::Key & key)
: Decryptor_(key) : Decryptor_(key)
, BlockBytesPacked_(0) , BlockBytesPacked_(0)
-6
View File
@@ -17,12 +17,6 @@ public:
Arc4Crypt() Arc4Crypt()
{ } { }
Arc4Crypt(const Arc4Crypt & other) = delete;
Arc4Crypt(Arc4Crypt && other) = delete;
Arc4Crypt & operator=(const Arc4Crypt & other) = delete;
Arc4Crypt & operator=(Arc4Crypt && other) = delete;
template<typename InputIt> template<typename InputIt>
Arc4Crypt(InputIt keyBegin, InputIt keyEnd) Arc4Crypt(InputIt keyBegin, InputIt keyEnd)
{ {
-8
View File
@@ -16,16 +16,8 @@ class Arc4Gen
public: public:
Arc4Gen() Arc4Gen()
: IsInitialized_(false) : IsInitialized_(false)
, I_(0)
, J_(0)
{ } { }
Arc4Gen(const Arc4Gen & other) = delete;
Arc4Gen(Arc4Gen && other) = delete;
Arc4Gen & operator=(const Arc4Gen & other) = delete;
Arc4Gen & operator=(Arc4Gen && other) = delete;
template<typename InputIt> template<typename InputIt>
Arc4Gen(InputIt keyBegin, InputIt keyEnd) Arc4Gen(InputIt keyBegin, InputIt keyEnd)
{ {
-6
View File
@@ -175,12 +175,6 @@ public:
ResetImpl(); ResetImpl();
} }
Md4Hasher(const Md4Hasher & other) = delete;
Md4Hasher(Md4Hasher && other) = delete;
Md4Hasher & operator=(const Md4Hasher & other) = delete;
Md4Hasher & operator=(Md4Hasher && other) = delete;
void Reset() void Reset()
{ {
ResetImpl(); ResetImpl();
-6
View File
@@ -199,12 +199,6 @@ public:
ResetImpl(); ResetImpl();
} }
Md5Hasher(const Md5Hasher & other) = delete;
Md5Hasher(Md5Hasher && other) = delete;
Md5Hasher & operator=(const Md5Hasher & other) = delete;
Md5Hasher & operator=(Md5Hasher && other) = delete;
void Reset() void Reset()
{ {
ResetImpl(); ResetImpl();
-6
View File
@@ -169,12 +169,6 @@ public:
ResetImpl(); ResetImpl();
} }
Sha1Hasher(const Sha1Hasher & other) = delete;
Sha1Hasher(Sha1Hasher && other) = delete;
Sha1Hasher & operator=(const Sha1Hasher & other) = delete;
Sha1Hasher & operator=(Sha1Hasher && other) = delete;
void Reset() void Reset()
{ {
ResetImpl(); ResetImpl();
+11 -17
View File
@@ -1,10 +1,10 @@
#ifndef CHAOS_MAC_HMAC_HPP #ifndef CHAOS_MAC_HMAC_HPP
#define CHAOS_MAC_HMAC_HPP #define CHAOS_MAC_HMAC_HPP
#include <array>
#include <cstdint> #include <cstdint>
#include "Hash/Hasher.hpp" #include "Hash/Hasher.hpp"
#include "Service/SeArray.hpp"
#include "Service/ChaosException.hpp" #include "Service/ChaosException.hpp"
namespace Chaos::Mac::Hmac namespace Chaos::Mac::Hmac
@@ -18,12 +18,6 @@ public:
: IsInitialized_(false) : IsInitialized_(false)
{ } { }
Hmac(const Hmac & other) = delete;
Hmac(Hmac && other) = delete;
Hmac & operator=(const Hmac & other) = delete;
Hmac & operator=(Hmac && other) = delete;
template<typename InputIt> template<typename InputIt>
Hmac(InputIt keyBegin, InputIt keyEnd) Hmac(InputIt keyBegin, InputIt keyEnd)
{ {
@@ -52,14 +46,14 @@ public:
Hasher_.Reset(); Hasher_.Reset();
KeyType opaddedKey = PadKey<OPAD_BYTE>(Key_); KeyType opaddedKey = PadKey<OPAD_BYTE>(Key_);
Hasher_.Update(opaddedKey.Begin(), opaddedKey.End()); Hasher_.Update(opaddedKey.begin(), opaddedKey.end());
Hasher_.Update(innerDigest.begin(), innerDigest.end()); Hasher_.Update(innerDigest.begin(), innerDigest.end());
return Hasher_.Finish(); return Hasher_.Finish();
} }
private: private:
using KeyType = Service::SeArray<uint8_t, HasherImpl::BlockSize>; using KeyType = std::array<uint8_t, HasherImpl::BlockSize>;
static constexpr uint8_t OPAD_BYTE = 0x5c; static constexpr uint8_t OPAD_BYTE = 0x5c;
static constexpr uint8_t IPAD_BYTE = 0x36; static constexpr uint8_t IPAD_BYTE = 0x36;
@@ -81,12 +75,12 @@ private:
static KeyType GenerateKey(InputIt keyBegin, InputIt keyEnd) static KeyType GenerateKey(InputIt keyBegin, InputIt keyEnd)
{ {
KeyType key; KeyType key;
key.Fill(0); key.fill(0);
InputIt keyIt = keyBegin; InputIt keyIt = keyBegin;
uint64_t idx = 0; uint64_t idx = 0;
for (; keyIt != keyEnd && idx < key.Size(); for (; keyIt != keyEnd && idx < key.size();
++keyIt, ++idx) ++keyIt, ++idx)
{ {
key[idx] = *keyIt; key[idx] = *keyIt;
@@ -96,17 +90,17 @@ private:
{ {
HasherImpl keyHasher; HasherImpl keyHasher;
keyHasher.Update(key.Begin(), key.End()); keyHasher.Update(key.begin(), key.end());
keyHasher.Update(keyIt, keyEnd); keyHasher.Update(keyIt, keyEnd);
auto digest = keyHasher.Finish().GetRawDigest(); auto digest = keyHasher.Finish().GetRawDigest();
static_assert(digest.size() <= HasherImpl::BlockSize); static_assert(digest.size() <= HasherImpl::BlockSize);
key.Fill(0); key.fill(0);
idx = 0; idx = 0;
for (auto it = digest.begin(); for (auto it = digest.begin();
it != digest.end() && idx < key.Size(); it != digest.end() && idx < key.size();
++it, ++idx) ++it, ++idx)
{ {
key[idx] = *it; key[idx] = *it;
@@ -124,8 +118,8 @@ private:
KeyType paddedKey; KeyType paddedKey;
uint64_t idx = 0; uint64_t idx = 0;
for (auto it = key.Begin(); for (auto it = key.cbegin();
it != key.End() && idx < paddedKey.Size(); it != key.cend() && idx < paddedKey.size();
++it, ++idx) ++it, ++idx)
{ {
paddedKey[idx] = (*it) ^ PAD_BYTE; paddedKey[idx] = (*it) ^ PAD_BYTE;
@@ -141,7 +135,7 @@ private:
Hasher_.Reset(); Hasher_.Reset();
KeyType ipaddedKey = PadKey<IPAD_BYTE>(Key_); KeyType ipaddedKey = PadKey<IPAD_BYTE>(Key_);
Hasher_.Update(ipaddedKey.Begin(), ipaddedKey.End()); Hasher_.Update(ipaddedKey.begin(), ipaddedKey.end());
IsInitialized_ = true; IsInitialized_ = true;
} }
-8
View File
@@ -15,14 +15,6 @@ namespace Chaos::Padding
class PadderIso7816 class PadderIso7816
{ {
public: public:
PadderIso7816() = delete;
PadderIso7816(const PadderIso7816 & other) = delete;
PadderIso7816(PadderIso7816 && other) = delete;
PadderIso7816 & operator=(const PadderIso7816 & other) = delete;
PadderIso7816 & operator=(PadderIso7816 && other) = delete;
template<typename OutputIt> template<typename OutputIt>
static void Pad(OutputIt begin, OutputIt end) static void Pad(OutputIt begin, OutputIt end)
{ {
-8
View File
@@ -16,14 +16,6 @@ namespace Chaos::Padding
class PadderPkcs7 class PadderPkcs7
{ {
public: public:
PadderPkcs7() = delete;
PadderPkcs7(const PadderPkcs7 & other) = delete;
PadderPkcs7(PadderPkcs7 && other) = delete;
PadderPkcs7 & operator=(const PadderPkcs7 & other) = delete;
PadderPkcs7 & operator=(PadderPkcs7 && other) = delete;
template<typename OutputIt> template<typename OutputIt>
static void Pad(OutputIt begin, OutputIt end) static void Pad(OutputIt begin, OutputIt end)
{ {
+2 -21
View File
@@ -4,7 +4,6 @@
#include <array> #include <array>
#include <concepts> #include <concepts>
#include <cstddef> #include <cstddef>
#include <utility>
namespace Chaos::Service namespace Chaos::Service
{ {
@@ -19,28 +18,10 @@ public:
} }
SeArray(const SeArray & other) = delete; SeArray(const SeArray & other) = delete;
SeArray(SeArray && other) = delete;
SeArray(SeArray && other) noexcept
{
Storage_ = std::move(other.Storage_);
other.EraseImpl();
}
SeArray & operator=(const SeArray & other) = default; SeArray & operator=(const SeArray & other) = default;
SeArray & operator=(SeArray && other) = delete;
SeArray & operator=(SeArray && other) noexcept
{
if (this == &other)
{
return *this;
}
EraseImpl();
Storage_ = std::move(other.Storage_);
other.EraseImpl();
return *this;
}
~SeArray() ~SeArray()
{ {
+8 -6
View File
@@ -110,9 +110,9 @@ TEST(PadIso7816Tests, PadOutIteratorUsageTest)
} }
template<Padder PadderImpl, typename OutputIt> template<Padder PadderImpl, typename OutputIt>
void PadGeneric(OutputIt begin, OutputIt end) void PadGeneric(const PadderImpl & padder, OutputIt begin, OutputIt end)
{ {
PadderImpl::Pad(begin, end); padder.Pad(begin, end);
} }
TEST(PadIso7816Tests, PadThroughBaseTest) TEST(PadIso7816Tests, PadThroughBaseTest)
@@ -126,7 +126,8 @@ TEST(PadIso7816Tests, PadThroughBaseTest)
0x80, 0x00, 0x00, 0x00, 0x00 0x80, 0x00, 0x00, 0x00, 0x00
}; };
PadGeneric<PadderIso7816>(fact.begin(), fact.end()); const PadderIso7816 padder;
PadGeneric(padder, fact.begin(), fact.end());
ASSERT_EQ(expected, fact); ASSERT_EQ(expected, fact);
} }
@@ -324,9 +325,9 @@ TEST(PadIso7816Tests, UnpadErrorTest)
} }
template<Padder PadderImpl, typename OutputIt> template<Padder PadderImpl, typename OutputIt>
auto ComputeUnpadGeneric(OutputIt begin, OutputIt end) auto ComputeUnpadGeneric(const PadderImpl & padder, OutputIt begin, OutputIt end)
{ {
return PadderImpl::ComputeUnpad(begin, end); return padder.ComputeUnpad(begin, end);
} }
TEST(PadIso7816Tests, ComputeUnpadThroughBaseTest) TEST(PadIso7816Tests, ComputeUnpadThroughBaseTest)
@@ -334,7 +335,8 @@ TEST(PadIso7816Tests, ComputeUnpadThroughBaseTest)
{ {
std::array<uint8_t, 5> data = { 0x80, 0x00, 0x00, 0x00, 0x00 }; std::array<uint8_t, 5> data = { 0x80, 0x00, 0x00, 0x00, 0x00 };
auto result = ComputeUnpadGeneric<PadderIso7816>(data.begin(), data.end()); const PadderIso7816 padder;
auto result = ComputeUnpadGeneric(padder, data.begin(), data.end());
ASSERT_TRUE(result.IsOkay_); ASSERT_TRUE(result.IsOkay_);
ASSERT_EQ(5, result.PadSize_); ASSERT_EQ(5, result.PadSize_);
+8 -6
View File
@@ -138,9 +138,9 @@ TEST(PadPkcs7Tests, PadOutIteratorUsageTest)
} }
template<Padder PadderImpl, typename OutputIt> template<Padder PadderImpl, typename OutputIt>
void PadGeneric(OutputIt begin, OutputIt end) void PadGeneric(const PadderImpl & padder, OutputIt begin, OutputIt end)
{ {
PadderImpl::Pad(begin, end); padder.Pad(begin, end);
} }
TEST(PadPkcs7Tests, PadThroughBaseTest) TEST(PadPkcs7Tests, PadThroughBaseTest)
@@ -152,7 +152,8 @@ TEST(PadPkcs7Tests, PadThroughBaseTest)
0x05, 0x05, 0x05, 0x05, 0x05 0x05, 0x05, 0x05, 0x05, 0x05
}; };
PadGeneric<PadderPkcs7>(fact.begin(), fact.end()); const PadderPkcs7 padder;
PadGeneric(padder, fact.begin(), fact.end());
ASSERT_EQ(expected, fact); ASSERT_EQ(expected, fact);
} }
@@ -347,9 +348,9 @@ TEST(PadPkcs7Tests, UnpadErrorTest)
} }
template<Padder PadderImpl, typename OutputIt> template<Padder PadderImpl, typename OutputIt>
auto ComputeUnpadGeneric(OutputIt begin, OutputIt end) auto ComputeUnpadGeneric(const PadderImpl & padder, OutputIt begin, OutputIt end)
{ {
return PadderImpl::ComputeUnpad(begin, end); return padder.ComputeUnpad(begin, end);
} }
TEST(PadPkcs7Tests, ComputeUnpadThroughBaseTest) TEST(PadPkcs7Tests, ComputeUnpadThroughBaseTest)
@@ -357,7 +358,8 @@ TEST(PadPkcs7Tests, ComputeUnpadThroughBaseTest)
{ {
std::array<uint8_t, 5> data = { 0x05, 0x05, 0x05, 0x05, 0x05 }; std::array<uint8_t, 5> data = { 0x05, 0x05, 0x05, 0x05, 0x05 };
auto result = ComputeUnpadGeneric<PadderPkcs7>(data.begin(), data.end()); const PadderPkcs7 padder;
auto result = ComputeUnpadGeneric(padder, data.begin(), data.end());
ASSERT_TRUE(result.IsOkay_); ASSERT_TRUE(result.IsOkay_);
ASSERT_EQ(5, result.PadSize_); ASSERT_EQ(5, result.PadSize_);
-78
View File
@@ -3,7 +3,6 @@
#include <cstdint> #include <cstdint>
#include <iterator> #include <iterator>
#include <cstddef> #include <cstddef>
#include <utility>
#include "Service/SeArray.hpp" #include "Service/SeArray.hpp"
@@ -291,80 +290,3 @@ TEST(SeArrayTests, CopyAssignTest)
ASSERT_EQ(0, arr1[4]); ASSERT_EQ(0, arr1[4]);
} }
} }
TEST(SeArrayTests, MoveAssignTest)
{
{
SeArray<uint8_t, 2> arr1;
SeArray<uint8_t, 2> arr2;
arr2[0] = 0xaa;
arr2[1] = 0xbb;
arr1 = std::move(arr2);
ASSERT_EQ(0xaa, arr1[0]);
ASSERT_EQ(0xbb, arr1[1]);
ASSERT_EQ(0, arr2[0]);
ASSERT_EQ(0, arr2[1]);
}
{
SeArray<int32_t, 5> arr1;
arr1[0] = 0x33;
arr1[1] = 0x44;
arr1[2] = 0x55;
arr1[3] = 0x66;
arr1[4] = 0x77;
SeArray<int32_t, 5> arr2;
arr1 = std::move(arr2);
ASSERT_EQ(0, arr1[0]);
ASSERT_EQ(0, arr1[1]);
ASSERT_EQ(0, arr1[2]);
ASSERT_EQ(0, arr1[3]);
ASSERT_EQ(0, arr1[4]);
ASSERT_EQ(0, arr2[0]);
ASSERT_EQ(0, arr2[1]);
ASSERT_EQ(0, arr2[2]);
ASSERT_EQ(0, arr2[3]);
ASSERT_EQ(0, arr2[4]);
}
{
SeArray<int32_t, 5> arr1;
arr1[0] = 0x33;
arr1[1] = 0x44;
arr1[2] = 0x55;
arr1[3] = 0x66;
arr1[4] = 0x77;
arr1 = std::move(arr1);
ASSERT_EQ(0x33, arr1[0]);
ASSERT_EQ(0x44, arr1[1]);
ASSERT_EQ(0x55, arr1[2]);
ASSERT_EQ(0x66, arr1[3]);
ASSERT_EQ(0x77, arr1[4]);
}
}
TEST(SeArrayTests, MoveConstructTest)
{
{
SeArray<int32_t, 2> arr1;
arr1[0] = 0x11;
arr1[1] = 0x22;
SeArray<int32_t, 2> arr2(std::move(arr1));
ASSERT_EQ(0x11, arr2[0]);
ASSERT_EQ(0x22, arr2[1]);
ASSERT_EQ(0, arr1[0]);
ASSERT_EQ(0, arr1[1]);
}
}