Compare commits

..
63 Commits
Author SHA1 Message Date
hashlag 8a82d33f39 Merge branch 'cppcheck-ci'
Chaos Ci / static-analysis (push) Successful in 1m19s
Chaos Ci / benchmark (push) Successful in 2m18s
Chaos Ci / test (push) Successful in 5m11s
2026-10-18 02:49:52 +03:00
hashlag a360e1b95a CI: update cppcheck's ignore rules for SeArray. 2026-10-18 02:40:52 +03:00
hashlag c4311991a9 CI: update cppcheck's ignore rules for SeArrayTests. 2026-10-18 02:40:52 +03:00
hashlag 0b12c1303f Arc4Gen: init I_, J_ in ctor.
No functional changes. Tidiness.
2026-10-18 02:40:52 +03:00
hashlag 7d312f9ba5 SeArrayTests: add move self-assignment testcase. 2026-10-18 02:40:52 +03:00
hashlag 0ee4962f70 SeArray: make move assignment operator noexcept. 2026-10-18 02:40:52 +03:00
hashlag 6b632b8be1 SeArray: make move ctor noexcept. 2026-10-18 02:40:52 +03:00
hashlag b129507559 DesCrypt::Key: delete move,copy * constructor,operator. 2026-10-18 02:40:52 +03:00
hashlag 3582890bb1 PadderPkcs7: delete move,copy * constructor,operator. 2026-10-18 02:40:52 +03:00
hashlag 706e20821a PadderPkcs7: delete default ctor. 2026-10-18 02:40:52 +03:00
hashlag e7f346cda2 PadderIso7816: delete move,copy * constructor,operator. 2026-10-18 02:40:52 +03:00
hashlag 0c041a5e9a PadderIso7816: delete default ctor. 2026-10-18 02:40:52 +03:00
hashlag a720c7b812 Hmac: delete move,copy * constructor,operator. 2026-10-18 02:40:52 +03:00
hashlag 6638e46dd9 Sha1: delete move,copy * constructor,operator. 2026-10-18 02:40:52 +03:00
hashlag ac89f55feb Md5: delete move,copy * constructor,operator. 2026-10-18 02:40:52 +03:00
hashlag f776caa528 Md4: delete move,copy * constructor,operator. 2026-10-18 02:40:52 +03:00
hashlag 8dcdaa6b85 Arc4Gen: delete move,copy * constructor,operator. 2026-10-18 02:40:52 +03:00
hashlag f636a60dab Arc4Crypt: delete move,copy * constructor,operator. 2026-10-18 02:40:52 +03:00
hashlag 22ad1fbb2b EcbMode:Decryptor: delete move,copy * constructor,operator. 2026-10-18 02:40:52 +03:00
hashlag 643c1364c7 EcbMode:Encryptor: delete move,copy * constructor,operator. 2026-10-18 02:40:52 +03:00
hashlag 62903ff9be EcbMode: delete move,copy * constructor,operator. 2026-10-18 02:40:52 +03:00
hashlag 56d6aa3601 EcbMode: delete default ctor. 2026-10-18 02:40:52 +03:00
hashlag 9ec4e6f7e6 DesCrypt::Decryptor: delete move,copy * constructor,operator. 2026-10-18 02:40:52 +03:00
hashlag e9c7b16d34 DesCrypt::Encryptor: delete move,copy * constructor,operator. 2026-10-18 02:40:52 +03:00
hashlag 90dafee249 DesCrypt: delete move,copy * constructor,operator. 2026-10-18 02:40:52 +03:00
hashlag da47dfa954 DesCrypt KeySchedule: delete move,copy * constructor,operator. 2026-10-18 02:40:52 +03:00
hashlag 0be43c9cf6 Erase the source SeArray immediately in move assignment operator. 2026-10-18 02:40:52 +03:00
hashlag fc67ba6b46 Erase the source SeArray immediately in move ctor. 2026-10-18 02:40:52 +03:00
hashlag 89bf5914d5 Use SeArray as Hmac::KeyType. 2026-10-18 02:40:52 +03:00
hashlag ceccd04b35 Add move ctor for SeArray. 2026-10-18 02:40:52 +03:00
hashlag f8a110964b Add move assignment operator for SeArray. 2026-10-18 02:40:52 +03:00
hashlag 6ee9873538 Arc4Gen: init I_, J_ in ctor.
No functional changes. Tidiness.
2026-10-18 02:39:05 +03:00
hashlag d5ddaa078e SeArrayTests: add move self-assignment testcase. 2026-10-18 02:18:11 +03:00
hashlag 8d8e452e87 SeArray: make move assignment operator noexcept. 2026-10-18 02:13:11 +03:00
hashlag 112143a9b3 SeArray: make move ctor noexcept. 2026-10-18 02:12:31 +03:00
hashlag 000e6994a4 DesCrypt::Key: delete move,copy * constructor,operator. 2026-10-18 02:09:45 +03:00
hashlag e3d729a301 PadderPkcs7: delete move,copy * constructor,operator. 2026-10-18 02:04:19 +03:00
hashlag 3f257dd483 PadderPkcs7: delete default ctor. 2026-10-18 02:04:04 +03:00
hashlag 82aa01b6f4 PadderIso7816: delete move,copy * constructor,operator. 2026-10-18 02:01:27 +03:00
hashlag 46c01bc85e PadderIso7816: delete default ctor. 2026-10-18 02:00:44 +03:00
hashlag 840b1f8149 Hmac: delete move,copy * constructor,operator. 2026-10-18 01:47:11 +03:00
hashlag 77c0f785ff Sha1: delete move,copy * constructor,operator. 2026-10-18 01:46:16 +03:00
hashlag 11dadf8c77 Md5: delete move,copy * constructor,operator. 2026-10-18 01:45:16 +03:00
hashlag dea896bd5f Md4: delete move,copy * constructor,operator. 2026-10-18 01:44:20 +03:00
hashlag 2b4972fe95 Arc4Gen: delete move,copy * constructor,operator. 2026-10-18 01:41:54 +03:00
hashlag f9e71d2c9f Arc4Crypt: delete move,copy * constructor,operator. 2026-10-18 01:39:56 +03:00
hashlag 8b7e485179 EcbMode:Decryptor: delete move,copy * constructor,operator. 2026-10-18 01:37:03 +03:00
hashlag ba47480cb2 EcbMode:Encryptor: delete move,copy * constructor,operator. 2026-10-18 01:36:02 +03:00
hashlag 8e08aad6ba EcbMode: delete move,copy * constructor,operator. 2026-10-18 01:34:44 +03:00
hashlag eeb57733e7 EcbMode: delete default ctor. 2026-10-18 01:33:08 +03:00
hashlag d78922e235 DesCrypt::Decryptor: delete move,copy * constructor,operator. 2026-10-18 01:31:49 +03:00
hashlag 4214497426 DesCrypt::Encryptor: delete move,copy * constructor,operator. 2026-10-18 01:30:43 +03:00
hashlag b464d6a6a2 DesCrypt: delete move,copy * constructor,operator. 2026-10-18 01:27:51 +03:00
hashlag 78836e4b75 DesCrypt KeySchedule: delete move,copy * constructor,operator. 2026-10-18 01:25:57 +03:00
hashlag 5ba326aa5a Erase the source SeArray immediately in move assignment operator. 2026-10-18 01:10:34 +03:00
hashlag dcaeab7b43 Erase the source SeArray immediately in move ctor. 2026-10-18 01:00:52 +03:00
hashlag 49a4b18163 Use SeArray as Hmac::KeyType. 2026-10-18 00:39:40 +03:00
hashlag ef848d6876 Add move ctor for SeArray. 2026-10-18 00:35:41 +03:00
hashlag 5c7cf222bd Add move assignment operator for SeArray. 2026-10-17 21:47:25 +03:00
hashlag d892b83e0a Configure cppcheck's suppressions list.
Chaos Ci / test (push) Canceled after 12s
Chaos Ci / benchmark (push) Canceled after 0s
Chaos Ci / static-analysis (push) Failing after 35s
2026-10-13 01:17:28 +03:00
hashlag 8d0780e016 CI: fix cppcheck’s file-filter globs. Once again.
Chaos Ci / test (push) Canceled after 3s
Chaos Ci / benchmark (push) Canceled after 0s
Chaos Ci / static-analysis (push) Failing after 35s
2026-10-12 03:16:54 +03:00
hashlag baaa98de03 CI: fix cppcheck's file-filter globs.
Chaos Ci / test (push) Canceled after 25s
Chaos Ci / benchmark (push) Canceled after 0s
Chaos Ci / static-analysis (push) Failing after 32s
2026-10-12 02:56:30 +03:00
hashlag 6cad16991e CI: introduce static-analysis job.
Chaos Ci / test (push) Successful in 3m14s
Chaos Ci / static-analysis (push) Failing after 34s
Chaos Ci / benchmark (push) Successful in 1m32s
2026-10-12 02:39:27 +03:00
19 changed files with 265 additions and 197 deletions

No files matched your search

+7
View File
@@ -0,0 +1,7 @@
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,6 +58,38 @@ jobs:
include-hidden-files: true
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:
runs-on: ubuntu-latest
-53
View File
@@ -1,53 +0,0 @@
#ifndef CHAOS_CIPHER_BLOCK_BLOCKADAPTER_HPP
#define CHAOS_CIPHER_BLOCK_BLOCKADAPTER_HPP
#include <cstdint>
#include <vector>
namespace Chaos::Cipher::Block
{
template<typename ModeT>
class BlockAdapter
{
public:
class Key
{
friend class BlockAdapter;
public:
template<typename InputIt>
Key(InputIt keyBegin, InputIt keyEnd)
: Key_(keyBegin, keyEnd)
{ }
template<typename Byte>
Key(const std::vector<Byte> & key)
: Key_(key.cbegin(), key.cend())
{ }
private:
ModeT::Cipher::Key Key_;
};
template<typename Byte>
static std::vector<Byte> Encrypt(const Key & key, const std::vector<Byte> & plaintext)
{
typename ModeT::Encryptor encryptor(key.Key_);
std::vector<Byte> result;
const uint64_t maxResultSize = encryptor.PredictMaxUpdateOutput(plaintext.size()) +
encryptor.PredictMaxFinishOutput();
result.resize(maxResultSize);
uint64_t written = encryptor.Update(result.begin(), result.end(),
plaintext.begin(), plaintext.end());
written += encryptor.Finish(result.begin() + written, result.end());
result.resize(written);
return result;
}
};
} // namespace Chaos::Cipher::Block
#endif // CHAOS_CIPHER_BLOCK_BLOCKADAPTER_HPP
+30
View File
@@ -114,6 +114,12 @@ public:
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)
{
Key56 key56 = Pc1(Bitwise::PackUInt64(rawKey.Begin(), rawKey.End()));
@@ -210,10 +216,22 @@ public:
DesCrypt() = delete;
DesCrypt(const DesCrypt & other) = delete;
DesCrypt(DesCrypt && other) = delete;
DesCrypt & operator=(const DesCrypt & other) = delete;
DesCrypt & operator=(DesCrypt && other) = delete;
class Key
{
friend class DesCrypt;
public:
Key(const Key & other) = delete;
Key(Key && other) = delete;
Key & operator=(const Key & other) = delete;
Key & operator=(Key && other) = delete;
template<typename InputIt>
Key(InputIt keyBegin, InputIt keyEnd)
{
@@ -245,6 +263,12 @@ public:
static constexpr size_t BlockSize = DesCrypt::BlockSize;
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)
: Schedule_(Inner_::KeySchedule::Direction::Encrypt, key.Key_)
{ }
@@ -293,6 +317,12 @@ public:
static constexpr size_t BlockSize = DesCrypt::BlockSize;
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)
: Schedule_(Inner_::KeySchedule::Direction::Decrypt, key.Key_)
{ }
+20
View File
@@ -19,9 +19,23 @@ public:
using Cipher = CipherT;
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
{
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_(key)
, BlockBytesPacked_(0)
@@ -115,6 +129,12 @@ public:
class Decryptor
{
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_(key)
, BlockBytesPacked_(0)
+6
View File
@@ -17,6 +17,12 @@ public:
Arc4Crypt()
{ }
Arc4Crypt(const Arc4Crypt & other) = delete;
Arc4Crypt(Arc4Crypt && other) = delete;
Arc4Crypt & operator=(const Arc4Crypt & other) = delete;
Arc4Crypt & operator=(Arc4Crypt && other) = delete;
template<typename InputIt>
Arc4Crypt(InputIt keyBegin, InputIt keyEnd)
{
+8
View File
@@ -16,8 +16,16 @@ class Arc4Gen
public:
Arc4Gen()
: 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>
Arc4Gen(InputIt keyBegin, InputIt keyEnd)
{
+6
View File
@@ -175,6 +175,12 @@ public:
ResetImpl();
}
Md4Hasher(const Md4Hasher & other) = delete;
Md4Hasher(Md4Hasher && other) = delete;
Md4Hasher & operator=(const Md4Hasher & other) = delete;
Md4Hasher & operator=(Md4Hasher && other) = delete;
void Reset()
{
ResetImpl();
+6
View File
@@ -199,6 +199,12 @@ public:
ResetImpl();
}
Md5Hasher(const Md5Hasher & other) = delete;
Md5Hasher(Md5Hasher && other) = delete;
Md5Hasher & operator=(const Md5Hasher & other) = delete;
Md5Hasher & operator=(Md5Hasher && other) = delete;
void Reset()
{
ResetImpl();
+6
View File
@@ -169,6 +169,12 @@ public:
ResetImpl();
}
Sha1Hasher(const Sha1Hasher & other) = delete;
Sha1Hasher(Sha1Hasher && other) = delete;
Sha1Hasher & operator=(const Sha1Hasher & other) = delete;
Sha1Hasher & operator=(Sha1Hasher && other) = delete;
void Reset()
{
ResetImpl();
+17 -11
View File
@@ -1,10 +1,10 @@
#ifndef CHAOS_MAC_HMAC_HPP
#define CHAOS_MAC_HMAC_HPP
#include <array>
#include <cstdint>
#include "Hash/Hasher.hpp"
#include "Service/SeArray.hpp"
#include "Service/ChaosException.hpp"
namespace Chaos::Mac::Hmac
@@ -18,6 +18,12 @@ public:
: 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>
Hmac(InputIt keyBegin, InputIt keyEnd)
{
@@ -46,14 +52,14 @@ public:
Hasher_.Reset();
KeyType opaddedKey = PadKey<OPAD_BYTE>(Key_);
Hasher_.Update(opaddedKey.begin(), opaddedKey.end());
Hasher_.Update(opaddedKey.Begin(), opaddedKey.End());
Hasher_.Update(innerDigest.begin(), innerDigest.end());
return Hasher_.Finish();
}
private:
using KeyType = std::array<uint8_t, HasherImpl::BlockSize>;
using KeyType = Service::SeArray<uint8_t, HasherImpl::BlockSize>;
static constexpr uint8_t OPAD_BYTE = 0x5c;
static constexpr uint8_t IPAD_BYTE = 0x36;
@@ -75,12 +81,12 @@ private:
static KeyType GenerateKey(InputIt keyBegin, InputIt keyEnd)
{
KeyType key;
key.fill(0);
key.Fill(0);
InputIt keyIt = keyBegin;
uint64_t idx = 0;
for (; keyIt != keyEnd && idx < key.size();
for (; keyIt != keyEnd && idx < key.Size();
++keyIt, ++idx)
{
key[idx] = *keyIt;
@@ -90,17 +96,17 @@ private:
{
HasherImpl keyHasher;
keyHasher.Update(key.begin(), key.end());
keyHasher.Update(key.Begin(), key.End());
keyHasher.Update(keyIt, keyEnd);
auto digest = keyHasher.Finish().GetRawDigest();
static_assert(digest.size() <= HasherImpl::BlockSize);
key.fill(0);
key.Fill(0);
idx = 0;
for (auto it = digest.begin();
it != digest.end() && idx < key.size();
it != digest.end() && idx < key.Size();
++it, ++idx)
{
key[idx] = *it;
@@ -118,8 +124,8 @@ private:
KeyType paddedKey;
uint64_t idx = 0;
for (auto it = key.cbegin();
it != key.cend() && idx < paddedKey.size();
for (auto it = key.Begin();
it != key.End() && idx < paddedKey.Size();
++it, ++idx)
{
paddedKey[idx] = (*it) ^ PAD_BYTE;
@@ -135,7 +141,7 @@ private:
Hasher_.Reset();
KeyType ipaddedKey = PadKey<IPAD_BYTE>(Key_);
Hasher_.Update(ipaddedKey.begin(), ipaddedKey.end());
Hasher_.Update(ipaddedKey.Begin(), ipaddedKey.End());
IsInitialized_ = true;
}
+8
View File
@@ -15,6 +15,14 @@ namespace Chaos::Padding
class PadderIso7816
{
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>
static void Pad(OutputIt begin, OutputIt end)
{
+8
View File
@@ -16,6 +16,14 @@ namespace Chaos::Padding
class PadderPkcs7
{
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>
static void Pad(OutputIt begin, OutputIt end)
{
+21 -2
View File
@@ -4,6 +4,7 @@
#include <array>
#include <concepts>
#include <cstddef>
#include <utility>
namespace Chaos::Service
{
@@ -18,10 +19,28 @@ public:
}
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=(SeArray && other) = delete;
SeArray & operator=(SeArray && other) noexcept
{
if (this == &other)
{
return *this;
}
EraseImpl();
Storage_ = std::move(other.Storage_);
other.EraseImpl();
return *this;
}
~SeArray()
{
-1
View File
@@ -20,7 +20,6 @@ set(ChaosTests_SOURCE SanCallbacks.cpp
Cipher/Stream/Arc4/Arc4CryptTests.cpp
Cipher/Block/Des/DesCryptTests.cpp
Cipher/Block/Mode/EcbModeTests.cpp
Cipher/Block/BlockAdapterTests.cpp
Padding/PadderPkcs7Tests.cpp
Padding/PadderIso7816Tests.cpp
Service/SeArrayTests.cpp
@@ -1,114 +0,0 @@
#include <gtest/gtest.h>
#include "TestHelpers/AssertThrowEx.hpp"
#include <cstring>
#include <cstdint>
#include <vector>
#include "Cipher/Block/Des/DesCrypt.hpp"
#include "Cipher/Block/Mode/Ecb.hpp"
#include "Cipher/Block/BlockAdapter.hpp"
#include "Padding/PadderPkcs7.hpp"
#include "Service/ChaosException.hpp"
using namespace Chaos::Cipher::Block;
using namespace Chaos::Cipher::Block::Mode;
using namespace Chaos::Padding;
TEST(BlockAdapterTests, EncryptTest)
{
using Adapter = BlockAdapter<EcbMode<Des::DesCrypt, PadderPkcs7>>;
{
const char * str = "smoke and mirrors";
std::vector<uint8_t> data(str, str + strlen(str));
std::vector<uint8_t> key = { 0x0c, 0xfd, 0x01, 0xa3, 0x60, 0xd0, 0x15, 0xa6 };
std::vector<uint8_t> expected = { 0x84, 0x39, 0xcd, 0xe5, 0x1f, 0x3d,
0x2a, 0x11, 0x63, 0xc3, 0x56, 0x28,
0xf5, 0x89, 0xdb, 0xc4, 0xa6, 0xca,
0x52, 0xb3, 0xa8, 0xce, 0x64, 0x2d };
ASSERT_EQ(expected, Adapter::Encrypt(key, data));
}
{
std::vector<uint8_t> data = {};
std::vector<uint8_t> key = { 0xaa, 0xbb, 0xaa, 0xbb, 0xaa, 0xbb, 0xaa, 0xbb };
std::vector<uint8_t> expected = { 0xef, 0xe2, 0x4d, 0xe9, 0x9d, 0xe7, 0x9b, 0xbf };
ASSERT_EQ(expected, Adapter::Encrypt(key, data));
}
{
std::vector<uint8_t> data = { 0x96, 0x9f, 0x42, 0xd3, 0x47, 0x10, 0x4d, 0xb4, 0x89, 0x54,
0x5c, 0xad, 0x0a, 0xb9, 0xac, 0x4e, 0xbf, 0x00, 0x1a, 0x47,
0x3d, 0xd1, 0xe7, 0xb3, 0x70, 0xb7, 0x4e, 0xd9, 0x73, 0x7d,
0xb3, 0x24 };
std::vector<uint8_t> key = { 0xe9, 0xeb, 0x1f, 0xfa, 0x39, 0x95, 0xf0, 0xb9 };
std::vector<uint8_t> expected = { 0x53, 0x06, 0x73, 0x79, 0xb8, 0xd7, 0xbe, 0x5d, 0x6e, 0xa0,
0x1f, 0x03, 0x46, 0x07, 0xd6, 0x48, 0x65, 0x4f, 0x9a, 0x8f,
0x1a, 0xe4, 0xa7, 0x7f, 0x13, 0xc9, 0x06, 0x8c, 0x57, 0xbd,
0x79, 0x5e, 0x3d, 0x21, 0x02, 0x13, 0x5f, 0xae, 0xc9, 0x45 };
ASSERT_EQ(expected, Adapter::Encrypt(key, data));
}
{
std::vector<uint8_t> data = { 0x51, 0x89, 0x9f, 0x0c, 0x32, 0x9b, 0x1d };
uint8_t key[] = { 0x28, 0x1c, 0xf3, 0x11, 0xce, 0xc6, 0xc2, 0x38 };
std::vector<uint8_t> expected = { 0x64, 0x32, 0x13, 0xe7, 0x31, 0x06, 0xc6, 0x6f };
ASSERT_EQ(expected, Adapter::Encrypt({ key, key + std::size(key) }, data));
}
}
TEST(BlockAdapterTests, InvalidKeyTest)
{
using Adapter = BlockAdapter<EcbMode<Des::DesCrypt, PadderPkcs7>>;
{
std::vector<uint8_t> key = { 0x01 };
ASSERT_THROW_EX(Adapter::Key{ key },
Chaos::Service::ChaosException,
{
ASSERT_EQ("DesCrypt::Key: invalid key length (8 bytes required)",
ex.GetMessage());
});
ASSERT_THROW_EX((Adapter::Key{ key.begin(), key.end() }),
Chaos::Service::ChaosException,
{
ASSERT_EQ("DesCrypt::Key: invalid key length (8 bytes required)",
ex.GetMessage());
});
}
{
std::vector<uint8_t> data = { 0x51, 0x89, 0x9f, 0x0c, 0x32, 0x9b, 0x1d };
std::vector<uint8_t> key = { 0xe9, 0xeb, 0x11, 0x1f, 0xfa, 0xb3, 0x39, 0x95, 0xf0, 0xb9 };
ASSERT_THROW_EX(Adapter::Encrypt(key, data),
Chaos::Service::ChaosException,
{
ASSERT_EQ("DesCrypt::Key: invalid key length (8 bytes required)",
ex.GetMessage());
});
}
{
std::vector<uint8_t> data = { 0x51, 0x89, 0x9f, 0x0c, 0x32, 0x9b, 0x1d };
uint8_t key[] = { 0x28, 0x1c, 0xf3, 0x11, 0xce, 0xc6, 0xc2 };
ASSERT_THROW_EX(Adapter::Encrypt({ key, key + std::size(key) }, data),
Chaos::Service::ChaosException,
{
ASSERT_EQ("DesCrypt::Key: invalid key length (8 bytes required)",
ex.GetMessage());
});
}
}
+6 -8
View File
@@ -110,9 +110,9 @@ TEST(PadIso7816Tests, PadOutIteratorUsageTest)
}
template<Padder PadderImpl, typename OutputIt>
void PadGeneric(const PadderImpl & padder, OutputIt begin, OutputIt end)
void PadGeneric(OutputIt begin, OutputIt end)
{
padder.Pad(begin, end);
PadderImpl::Pad(begin, end);
}
TEST(PadIso7816Tests, PadThroughBaseTest)
@@ -126,8 +126,7 @@ TEST(PadIso7816Tests, PadThroughBaseTest)
0x80, 0x00, 0x00, 0x00, 0x00
};
const PadderIso7816 padder;
PadGeneric(padder, fact.begin(), fact.end());
PadGeneric<PadderIso7816>(fact.begin(), fact.end());
ASSERT_EQ(expected, fact);
}
@@ -325,9 +324,9 @@ TEST(PadIso7816Tests, UnpadErrorTest)
}
template<Padder PadderImpl, typename OutputIt>
auto ComputeUnpadGeneric(const PadderImpl & padder, OutputIt begin, OutputIt end)
auto ComputeUnpadGeneric(OutputIt begin, OutputIt end)
{
return padder.ComputeUnpad(begin, end);
return PadderImpl::ComputeUnpad(begin, end);
}
TEST(PadIso7816Tests, ComputeUnpadThroughBaseTest)
@@ -335,8 +334,7 @@ TEST(PadIso7816Tests, ComputeUnpadThroughBaseTest)
{
std::array<uint8_t, 5> data = { 0x80, 0x00, 0x00, 0x00, 0x00 };
const PadderIso7816 padder;
auto result = ComputeUnpadGeneric(padder, data.begin(), data.end());
auto result = ComputeUnpadGeneric<PadderIso7816>(data.begin(), data.end());
ASSERT_TRUE(result.IsOkay_);
ASSERT_EQ(5, result.PadSize_);
+6 -8
View File
@@ -138,9 +138,9 @@ TEST(PadPkcs7Tests, PadOutIteratorUsageTest)
}
template<Padder PadderImpl, typename OutputIt>
void PadGeneric(const PadderImpl & padder, OutputIt begin, OutputIt end)
void PadGeneric(OutputIt begin, OutputIt end)
{
padder.Pad(begin, end);
PadderImpl::Pad(begin, end);
}
TEST(PadPkcs7Tests, PadThroughBaseTest)
@@ -152,8 +152,7 @@ TEST(PadPkcs7Tests, PadThroughBaseTest)
0x05, 0x05, 0x05, 0x05, 0x05
};
const PadderPkcs7 padder;
PadGeneric(padder, fact.begin(), fact.end());
PadGeneric<PadderPkcs7>(fact.begin(), fact.end());
ASSERT_EQ(expected, fact);
}
@@ -348,9 +347,9 @@ TEST(PadPkcs7Tests, UnpadErrorTest)
}
template<Padder PadderImpl, typename OutputIt>
auto ComputeUnpadGeneric(const PadderImpl & padder, OutputIt begin, OutputIt end)
auto ComputeUnpadGeneric(OutputIt begin, OutputIt end)
{
return padder.ComputeUnpad(begin, end);
return PadderImpl::ComputeUnpad(begin, end);
}
TEST(PadPkcs7Tests, ComputeUnpadThroughBaseTest)
@@ -358,8 +357,7 @@ TEST(PadPkcs7Tests, ComputeUnpadThroughBaseTest)
{
std::array<uint8_t, 5> data = { 0x05, 0x05, 0x05, 0x05, 0x05 };
const PadderPkcs7 padder;
auto result = ComputeUnpadGeneric(padder, data.begin(), data.end());
auto result = ComputeUnpadGeneric<PadderPkcs7>(data.begin(), data.end());
ASSERT_TRUE(result.IsOkay_);
ASSERT_EQ(5, result.PadSize_);
+78
View File
@@ -3,6 +3,7 @@
#include <cstdint>
#include <iterator>
#include <cstddef>
#include <utility>
#include "Service/SeArray.hpp"
@@ -290,3 +291,80 @@ TEST(SeArrayTests, CopyAssignTest)
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]);
}
}