| 1 |
/* |
| 2 |
* (C) 2025 Jack Lloyd |
| 3 |
* |
| 4 |
* Botan is released under the Simplified BSD License (see license.txt) |
| 5 |
*/ |
| 6 |
|
| 7 |
#ifndef BOTAN_SHA1_FN_H_ |
| 8 |
#define BOTAN_SHA1_FN_H_ |
| 9 |
|
| 10 |
#include <botan/types.h> |
| 11 |
#include <botan/internal/bit_ops.h> |
| 12 |
#include <botan/internal/rotate.h> |
| 13 |
|
| 14 |
namespace Botan::SHA1_F { |
| 15 |
|
| 16 |
constexpr uint32_t K1 = 0x5A827999; |
| 17 |
constexpr uint32_t K2 = 0x6ED9EBA1; |
| 18 |
constexpr uint32_t K3 = 0x8F1BBCDC; |
| 19 |
constexpr uint32_t K4 = 0xCA62C1D6; |
| 20 |
|
| 21 |
inline void F1(uint32_t A, uint32_t& B, uint32_t C, uint32_t D, uint32_t& E, uint32_t M) { |
| 22 |
E += choose(B, C, D) + M + rotl<5>(A); |
| 23 |
B = rotl<30>(B); |
| 24 |
} |
| 25 |
|
| 26 |
inline void F2(uint32_t A, uint32_t& B, uint32_t C, uint32_t D, uint32_t& E, uint32_t M) { |
| 27 |
E += (B ^ C ^ D) + M + rotl<5>(A); |
| 28 |
B = rotl<30>(B); |
| 29 |
} |
| 30 |
|
| 31 |
inline void F3(uint32_t A, uint32_t& B, uint32_t C, uint32_t D, uint32_t& E, uint32_t M) { |
| 32 |
E += majority(B, C, D) + M + rotl<5>(A); |
| 33 |
B = rotl<30>(B); |
| 34 |
} |
| 35 |
|
| 36 |
// NOTE: identical to F4 besides the constant addition |
| 37 |
inline void F4(uint32_t A, uint32_t& B, uint32_t C, uint32_t D, uint32_t& E, uint32_t M) { |
| 38 |
E += (B ^ C ^ D) + M + rotl<5>(A); |
| 39 |
B = rotl<30>(B); |
| 40 |
} |
| 41 |
|
| 42 |
} // namespace Botan::SHA1_F |
| 43 |
|
| 44 |
#endif |