diff options
author | Jack Lloyd <[email protected]> | 2021-01-09 09:12:04 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2021-01-09 10:11:11 -0500 |
commit | 2aca7afa7224ab83acc4c6dd4455e420a21450ed (patch) | |
tree | b90ffac9e06b36ed92da51cc5162f06cf3dfdc14 /src/lib/hash/sm3 | |
parent | 55c40989d4bbad795f928eaf71a111eb45c2c636 (diff) |
Add choose and majority functions
Diffstat (limited to 'src/lib/hash/sm3')
-rw-r--r-- | src/lib/hash/sm3/sm3.cpp | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/src/lib/hash/sm3/sm3.cpp b/src/lib/hash/sm3/sm3.cpp index 608752363..d29f2b505 100644 --- a/src/lib/hash/sm3/sm3.cpp +++ b/src/lib/hash/sm3/sm3.cpp @@ -1,6 +1,7 @@ /* * SM3 * (C) 2017 Ribose Inc. +* (C) 2021 Jack Lloyd * * Botan is released under the Simplified BSD License (see license.txt) */ @@ -8,6 +9,7 @@ #include <botan/internal/sm3.h> #include <botan/internal/loadstor.h> #include <botan/internal/rotate.h> +#include <botan/internal/bit_ops.h> namespace Botan { @@ -28,18 +30,6 @@ inline uint32_t P0(uint32_t X) return X ^ rotl<9>(X) ^ rotl<17>(X); } -inline uint32_t FF1(uint32_t X, uint32_t Y, uint32_t Z) - { - return (X & Y) | ((X | Y) & Z); - //return (X & Y) | (X & Z) | (Y & Z); - } - -inline uint32_t GG1(uint32_t X, uint32_t Y, uint32_t Z) - { - //return (X & Y) | (~X & Z); - return ((Z ^ (X & (Y ^ Z)))); - } - inline void R1(uint32_t A, uint32_t& B, uint32_t C, uint32_t& D, uint32_t E, uint32_t& F, uint32_t G, uint32_t& H, uint32_t TJ, uint32_t Wi, uint32_t Wj) @@ -61,8 +51,8 @@ inline void R2(uint32_t A, uint32_t& B, uint32_t C, uint32_t& D, { const uint32_t A12 = rotl<12>(A); const uint32_t SS1 = rotl<7>(A12 + E + TJ); - const uint32_t TT1 = FF1(A, B, C) + D + (SS1 ^ A12) + Wj; - const uint32_t TT2 = GG1(E, F, G) + H + SS1 + Wi; + const uint32_t TT1 = majority(A, B, C) + D + (SS1 ^ A12) + Wj; + const uint32_t TT2 = choose(E, F, G) + H + SS1 + Wi; B = rotl<9>(B); D = TT1; |