31 constexpr size_t B = Hash::BLOCK_SIZE;
33 static_assert(Hash::OUTPUT_SIZE <= B);
34 constexpr uint8_t IPAD_CONST = 0x36;
35 constexpr uint8_t OPAD_CONST = 0x5c;
38 ipad.fill(IPAD_CONST);
39 opad.fill(OPAD_CONST);
46 const auto truncated_key = Hash::hash(
key);
47 std::copy(truncated_key.begin(), truncated_key.end(), k_prime.begin());
54 for (
size_t i = 0; i < B; ++i) {
55 h1[i] = k_prime[i] ^ opad[i];
60 for (
size_t i = 0; i < B; ++i) {
61 h2[i] = k_prime[i] ^ ipad[i];
66 std::vector<uint8_t> message_buffer;
70 const auto h3 = Hash::hash(message_buffer);
74 std::vector<uint8_t> hmac_buffer;
78 const auto hmac_key = Hash::hash(hmac_buffer);
81 std::copy(hmac_key.begin(), hmac_key.end(), result.begin());
103 requires(Hash::OUTPUT_SIZE == 32)
106 static_assert(Hash::BLOCK_SIZE > Hash::OUTPUT_SIZE);
107 constexpr size_t DOMAIN_SEPARATOR_SIZE = Hash::BLOCK_SIZE - Hash::OUTPUT_SIZE;
114 auto input = hmac<Hash, MessageContainer, KeyContainer>(message,
key);
117 std::vector<uint8_t> lo_buffer(KLO_DOMAIN_SEPARATOR.begin(), KLO_DOMAIN_SEPARATOR.end());
119 auto klo = Hash::hash(lo_buffer);
122 std::vector<uint8_t> hi_buffer(KHI_DOMAIN_SEPARATOR.begin(), KHI_DOMAIN_SEPARATOR.end());
124 auto khi = Hash::hash(hi_buffer);
127 std::vector<uint8_t> full_buffer(khi.begin(), khi.end());
130 auto field_as_u512 = from_buffer<numeric::uint512_t>(full_buffer);
std::array< uint8_t, Hash::OUTPUT_SIZE > hmac(const MessageContainer &message, const KeyContainer &key)
Compute an HMAC given a secret key and a message.