Compare commits

..

2 Commits

Author SHA1 Message Date
hashlag
e8d0b93c5e Overload DecryptBlock() for the whole block as UInt64
All checks were successful
ChaosTest CI / build-and-test (push) Successful in 34s
2026-01-24 23:24:44 +03:00
hashlag
5a2d802a25 Overload EncryptBlock() for the whole block as UInt64 2026-01-24 23:14:03 +03:00
2 changed files with 98 additions and 0 deletions

View File

@@ -245,6 +245,11 @@ public:
Inner_::Bitwise::CrunchUInt64(out, encrypted);
}
uint64_t EncryptBlock(uint64_t block)
{
return DesCrypt::ProcessBlock(block, Schedule_);
}
private:
Inner_::KeySchedule Schedule_;
};
@@ -275,6 +280,11 @@ public:
Inner_::Bitwise::CrunchUInt64(out, decrypted);
}
uint64_t DecryptBlock(uint64_t block)
{
return DesCrypt::ProcessBlock(block, Schedule_);
}
private:
Inner_::KeySchedule Schedule_;
};

View File

@@ -85,6 +85,50 @@ TEST(DesCryptTests, EncryptTest)
}
}
TEST(DesCryptTests, EncryptUInt64BlockTest)
{
struct Helper
{
uint64_t operator()(uint64_t data,
const std::array<uint8_t, 8> & key) const
{
DesCrypt::Key desKey(key.begin(), key.end());
DesCrypt::Encryptor enc(desKey);
return enc.EncryptBlock(data);
}
};
Helper des;
{
uint64_t data = 0x0123456789abcdef;
std::array<uint8_t, 8> key = { 0x13, 0x34, 0x57, 0x79, 0x9b, 0xbc, 0xdf, 0xf1 };
uint64_t expected = 0x85e813540f0ab405;
ASSERT_EQ(expected, des(data, key));
}
{
uint64_t data = 0xaaf383162d2e6bcb;
std::array<uint8_t, 8> key = { 0x44, 0xbf, 0x32, 0x19, 0x99, 0x25, 0x81, 0x51 };
uint64_t expected = 0x07e87faab3171318;
ASSERT_EQ(expected, des(data, key));
}
{
uint64_t data = 0xe51a9fd419a79344;
std::array<uint8_t, 8> key = { 0xda, 0xec, 0x68, 0xae, 0x83, 0xe0, 0x1e, 0xab };
uint64_t expected = 0x422788a67b6c18ed;
ASSERT_EQ(expected, des(data, key));
}
}
TEST(DesCryptTests, EncryptShortDataTest)
{
struct Helper
@@ -201,6 +245,50 @@ TEST(DesCryptTests, DecryptTest)
}
}
TEST(DesCryptTests, DecryptUInt64BlockTest)
{
struct Helper
{
uint64_t operator()(uint64_t data,
const std::array<uint8_t, 8> & key) const
{
DesCrypt::Key desKey(key.begin(), key.end());
DesCrypt::Decryptor dec(desKey);
return dec.DecryptBlock(data);
}
};
Helper des;
{
uint64_t data = 0x85e813540f0ab405;
std::array<uint8_t, 8> key = { 0x13, 0x34, 0x57, 0x79, 0x9b, 0xbc, 0xdf, 0xf1 };
uint64_t expected = 0x0123456789abcdef;
ASSERT_EQ(expected, des(data, key));
}
{
uint64_t data = 0x07e87faab3171318;
std::array<uint8_t, 8> key = { 0x44, 0xbf, 0x32, 0x19, 0x99, 0x25, 0x81, 0x51 };
uint64_t expected = 0xaaf383162d2e6bcb;
ASSERT_EQ(expected, des(data, key));
}
{
uint64_t data = 0x422788a67b6c18ed;
std::array<uint8_t, 8> key = { 0xda, 0xec, 0x68, 0xae, 0x83, 0xe0, 0x1e, 0xab };
uint64_t expected = 0xe51a9fd419a79344;
ASSERT_EQ(expected, des(data, key));
}
}
TEST(DesCryptTests, DecryptShortDataTest)
{
struct Helper