diff --git a/hash/md4.cpp b/hash/md4.cpp index 1d257d7..54e1b85 100644 --- a/hash/md4.cpp +++ b/hash/md4.cpp @@ -8,6 +8,7 @@ #include "md4.hpp" +#include #include #include @@ -19,51 +20,29 @@ using cruft::crypto::hash::MD4; /////////////////////////////////////////////////////////////////////////////// // Auxiliary functions for each set of rounds -static inline constexpr -uint32_t -F (uint32_t X, uint32_t Y, uint32_t Z) -{ - return (X & Y) | (~X & Z); -} - +static constexpr u32 F (u32 X, u32 Y, u32 Z) { return (X & Y) | (~X & Z); } +static constexpr u32 G (u32 X, u32 Y, u32 Z) { return (X & Y) | (X & Z) | (Y & Z); } +static constexpr u32 H (u32 X, u32 Y, u32 Z) { return X ^ Y ^ Z; } //----------------------------------------------------------------------------- -static inline constexpr -uint32_t -G (uint32_t X, uint32_t Y, uint32_t Z) -{ - return (X & Y) | (X & Z) | (Y & Z); -} - - -//----------------------------------------------------------------------------- -static inline constexpr -uint32_t -H (uint32_t X, uint32_t Y, uint32_t Z) -{ - return X ^ Y ^ Z; -} - - -//----------------------------------------------------------------------------- -static constexpr uint32_t INITIAL_A = 0x67452301; -static constexpr uint32_t INITIAL_B = 0xefcdab89; -static constexpr uint32_t INITIAL_C = 0x98badcfe; -static constexpr uint32_t INITIAL_D = 0x10325476; +static constexpr u32 INITIAL_A = 0x67452301; +static constexpr u32 INITIAL_B = 0xefcdab89; +static constexpr u32 INITIAL_C = 0x98badcfe; +static constexpr u32 INITIAL_D = 0x10325476; /////////////////////////////////////////////////////////////////////////////// static void -transform (std::array &ABCD, const std::array &X) noexcept +transform (std::array &ABCD, const std::array &X) noexcept { - uint32_t A = ABCD[0], + u32 A = ABCD[0], B = ABCD[1], C = ABCD[2], D = ABCD[3]; -#define ROUND1(a,b,c,d,k,s) do { \ +#define ROUND1(a,b,c,d,k,s) do { \ (a) += F((b), (c), (d)) + X[k]; \ - (a) = cruft::rotatel ((a), (s)); \ + (a) = cruft::rotatel ((a), (s)); \ } while (0) ROUND1(A,B,C,D, 0, 3); @@ -86,9 +65,9 @@ transform (std::array &ABCD, const std::array &X) noexc ROUND1(C,D,A,B, 14, 11); ROUND1(B,C,D,A, 15, 19); -#define ROUND2(a,b,c,d,k,s) do { \ +#define ROUND2(a,b,c,d,k,s) do { \ (a) += G((b),(c),(d)) + X[k] + 0x5A827999u; \ - (a) = cruft::rotatel ((a), (s)); \ + (a) = cruft::rotatel ((a), (s)); \ } while (0) ROUND2(A,B,C,D, 0, 3); @@ -111,9 +90,9 @@ transform (std::array &ABCD, const std::array &X) noexc ROUND2(C,D,A,B, 11, 9); ROUND2(B,C,D,A, 15, 13); -#define ROUND3(a,b,c,d,k,s) do { \ +#define ROUND3(a,b,c,d,k,s) do { \ (a) += H((b),(c),(d)) + X[k] + 0x6ED9EBA1u; \ - (a) = cruft::rotatel ((a), (s)); \ + (a) = cruft::rotatel ((a), (s)); \ } while (0) ROUND3(A,B,C,D, 0, 3); @@ -145,12 +124,12 @@ transform (std::array &ABCD, const std::array &X) noexc /////////////////////////////////////////////////////////////////////////////// MD4::digest_t -MD4::operator() (cruft::view data) noexcept +MD4::operator() (cruft::view data) noexcept { /* RESET */ - uint64_t total = 0; + u64 total = 0; - std::array ABCD { + std::array ABCD { INITIAL_A, INITIAL_B, INITIAL_C, @@ -158,8 +137,8 @@ MD4::operator() (cruft::view data) noexcept }; union { - std::array X; - std::array Xb; + std::array X; + std::array Xb; }; static_assert (sizeof (X) == sizeof (Xb)); static_assert (sizeof (ABCD) == sizeof (digest_t)); @@ -180,7 +159,7 @@ MD4::operator() (cruft::view data) noexcept total += remain.size (); } - uint64_t bits = total * 8; + u64 bits = total * 8; /* FINISH */ {