From d63855a505bbb11517ea32902c2670c7c5a763bc Mon Sep 17 00:00:00 2001 From: hashlag Date: Thu, 15 Jan 2026 03:14:45 +0300 Subject: [PATCH] Add Bitwise::PackUInt64(<...>) utility function --- Chaos/Cipher/Des/DesCrypt.hpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/Chaos/Cipher/Des/DesCrypt.hpp b/Chaos/Cipher/Des/DesCrypt.hpp index 4af001c..07cac48 100644 --- a/Chaos/Cipher/Des/DesCrypt.hpp +++ b/Chaos/Cipher/Des/DesCrypt.hpp @@ -62,6 +62,20 @@ struct Bitwise { return (lhs << BitsUsedIn) | rhs; } + + template + static uint64_t PackUInt64(InputIt begin, InputIt end) + { + uint64_t result = 0; + + int_fast8_t i = 0; + for (InputIt it = begin; i < 8 && it != end; ++i, ++it) + { + result |= static_cast(*it) << (56 - (i * 8)); + } + + return result; + } }; using RawKeyArray = Service::SeArray; @@ -76,18 +90,7 @@ public: KeySchedule(const RawKeyArray & rawKeyArray) { - Key64 key64 = 0; - - key64 |= static_cast(rawKeyArray[7]) << 0; - key64 |= static_cast(rawKeyArray[6]) << 8; - key64 |= static_cast(rawKeyArray[5]) << 16; - key64 |= static_cast(rawKeyArray[4]) << 24; - key64 |= static_cast(rawKeyArray[3]) << 32; - key64 |= static_cast(rawKeyArray[2]) << 40; - key64 |= static_cast(rawKeyArray[1]) << 48; - key64 |= static_cast(rawKeyArray[0]) << 56; - - Key56 key56 = Pc1(key64); + Key56 key56 = Pc1(Bitwise::PackUInt64(rawKeyArray.Begin(), rawKeyArray.End())); auto [c28, d28] = Bitwise::Split<28>(key56);