diff --git a/Chaos/Cipher/Des/DesCrypt.hpp b/Chaos/Cipher/Des/DesCrypt.hpp index e9ac70f..b2dda46 100644 --- a/Chaos/Cipher/Des/DesCrypt.hpp +++ b/Chaos/Cipher/Des/DesCrypt.hpp @@ -280,6 +280,11 @@ public: Inner_::Bitwise::CrunchUInt64(out, decrypted); } + uint64_t DecryptBlock(uint64_t block) + { + return DesCrypt::ProcessBlock(block, Schedule_); + } + private: Inner_::KeySchedule Schedule_; }; diff --git a/ChaosTests/Cipher/DesCryptTests.cpp b/ChaosTests/Cipher/DesCryptTests.cpp index aad6d27..b98a502 100644 --- a/ChaosTests/Cipher/DesCryptTests.cpp +++ b/ChaosTests/Cipher/DesCryptTests.cpp @@ -245,6 +245,50 @@ TEST(DesCryptTests, DecryptTest) } } +TEST(DesCryptTests, DecryptUInt64BlockTest) +{ + struct Helper + { + uint64_t operator()(uint64_t data, + const std::array & 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 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 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 key = { 0xda, 0xec, 0x68, 0xae, 0x83, 0xe0, 0x1e, 0xab }; + + uint64_t expected = 0xe51a9fd419a79344; + + ASSERT_EQ(expected, des(data, key)); + } +} + TEST(DesCryptTests, DecryptShortDataTest) { struct Helper