Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
779bd6c568 | ||
|
|
8a82d33f39 | ||
|
|
a360e1b95a | ||
|
|
c4311991a9 | ||
|
|
0b12c1303f | ||
|
|
7d312f9ba5 | ||
|
|
0ee4962f70 | ||
|
|
6b632b8be1 | ||
|
|
b129507559 | ||
|
|
3582890bb1 | ||
|
|
706e20821a | ||
|
|
e7f346cda2 | ||
|
|
0c041a5e9a | ||
|
|
a720c7b812 | ||
|
|
6638e46dd9 | ||
|
|
ac89f55feb | ||
|
|
f776caa528 | ||
|
|
8dcdaa6b85 | ||
|
|
f636a60dab | ||
|
|
22ad1fbb2b | ||
|
|
643c1364c7 | ||
|
|
62903ff9be | ||
|
|
56d6aa3601 | ||
|
|
9ec4e6f7e6 | ||
|
|
e9c7b16d34 | ||
|
|
90dafee249 | ||
|
|
da47dfa954 | ||
|
|
0be43c9cf6 | ||
|
|
fc67ba6b46 | ||
|
|
89bf5914d5 | ||
|
|
ceccd04b35 | ||
|
|
f8a110964b | ||
|
|
6ee9873538 | ||
|
|
d5ddaa078e | ||
|
|
8d8e452e87 | ||
|
|
112143a9b3 | ||
|
|
000e6994a4 | ||
|
|
e3d729a301 | ||
|
|
3f257dd483 | ||
|
|
82aa01b6f4 | ||
|
|
46c01bc85e | ||
|
|
840b1f8149 | ||
|
|
77c0f785ff | ||
|
|
11dadf8c77 | ||
|
|
dea896bd5f | ||
|
|
2b4972fe95 | ||
|
|
f9e71d2c9f | ||
|
|
8b7e485179 | ||
|
|
ba47480cb2 | ||
|
|
8e08aad6ba | ||
|
|
eeb57733e7 | ||
|
|
d78922e235 | ||
|
|
4214497426 | ||
|
|
b464d6a6a2 | ||
|
|
78836e4b75 | ||
|
|
5ba326aa5a | ||
|
|
dcaeab7b43 | ||
|
|
49a4b18163 | ||
|
|
ef848d6876 | ||
|
|
5c7cf222bd | ||
|
|
d892b83e0a | ||
|
|
8d0780e016 | ||
|
|
baaa98de03 | ||
|
|
6cad16991e |
No files matched your search
@@ -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
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#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
|
||||
@@ -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_)
|
||||
{ }
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -20,6 +20,7 @@ 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
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
#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());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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_);
|
||||
|
||||
@@ -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_);
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user