Use SeArray as Hmac::KeyType.

This commit is contained in:
hashlag committed 2026-10-18 02:40:52 +03:00
1 parent ceccd04b35
commit 89bf5914d5
1 file changed
+11 -11
+11 -11
View File
@@ -1,10 +1,10 @@
#ifndef CHAOS_MAC_HMAC_HPP #ifndef CHAOS_MAC_HMAC_HPP
#define CHAOS_MAC_HMAC_HPP #define CHAOS_MAC_HMAC_HPP
#include <array>
#include <cstdint> #include <cstdint>
#include "Hash/Hasher.hpp" #include "Hash/Hasher.hpp"
#include "Service/SeArray.hpp"
#include "Service/ChaosException.hpp" #include "Service/ChaosException.hpp"
namespace Chaos::Mac::Hmac namespace Chaos::Mac::Hmac
@@ -46,14 +46,14 @@ public:
Hasher_.Reset(); Hasher_.Reset();
KeyType opaddedKey = PadKey<OPAD_BYTE>(Key_); KeyType opaddedKey = PadKey<OPAD_BYTE>(Key_);
Hasher_.Update(opaddedKey.begin(), opaddedKey.end()); Hasher_.Update(opaddedKey.Begin(), opaddedKey.End());
Hasher_.Update(innerDigest.begin(), innerDigest.end()); Hasher_.Update(innerDigest.begin(), innerDigest.end());
return Hasher_.Finish(); return Hasher_.Finish();
} }
private: private:
using KeyType = std::array<uint8_t, HasherImpl::BlockSize>; using KeyType = Service::SeArray<uint8_t, HasherImpl::BlockSize>;
static constexpr uint8_t OPAD_BYTE = 0x5c; static constexpr uint8_t OPAD_BYTE = 0x5c;
static constexpr uint8_t IPAD_BYTE = 0x36; static constexpr uint8_t IPAD_BYTE = 0x36;
@@ -75,12 +75,12 @@ private:
static KeyType GenerateKey(InputIt keyBegin, InputIt keyEnd) static KeyType GenerateKey(InputIt keyBegin, InputIt keyEnd)
{ {
KeyType key; KeyType key;
key.fill(0); key.Fill(0);
InputIt keyIt = keyBegin; InputIt keyIt = keyBegin;
uint64_t idx = 0; uint64_t idx = 0;
for (; keyIt != keyEnd && idx < key.size(); for (; keyIt != keyEnd && idx < key.Size();
++keyIt, ++idx) ++keyIt, ++idx)
{ {
key[idx] = *keyIt; key[idx] = *keyIt;
@@ -90,17 +90,17 @@ private:
{ {
HasherImpl keyHasher; HasherImpl keyHasher;
keyHasher.Update(key.begin(), key.end()); keyHasher.Update(key.Begin(), key.End());
keyHasher.Update(keyIt, keyEnd); keyHasher.Update(keyIt, keyEnd);
auto digest = keyHasher.Finish().GetRawDigest(); auto digest = keyHasher.Finish().GetRawDigest();
static_assert(digest.size() <= HasherImpl::BlockSize); static_assert(digest.size() <= HasherImpl::BlockSize);
key.fill(0); key.Fill(0);
idx = 0; idx = 0;
for (auto it = digest.begin(); for (auto it = digest.begin();
it != digest.end() && idx < key.size(); it != digest.end() && idx < key.Size();
++it, ++idx) ++it, ++idx)
{ {
key[idx] = *it; key[idx] = *it;
@@ -118,8 +118,8 @@ private:
KeyType paddedKey; KeyType paddedKey;
uint64_t idx = 0; uint64_t idx = 0;
for (auto it = key.cbegin(); for (auto it = key.Begin();
it != key.cend() && idx < paddedKey.size(); it != key.End() && idx < paddedKey.Size();
++it, ++idx) ++it, ++idx)
{ {
paddedKey[idx] = (*it) ^ PAD_BYTE; paddedKey[idx] = (*it) ^ PAD_BYTE;
@@ -135,7 +135,7 @@ private:
Hasher_.Reset(); Hasher_.Reset();
KeyType ipaddedKey = PadKey<IPAD_BYTE>(Key_); KeyType ipaddedKey = PadKey<IPAD_BYTE>(Key_);
Hasher_.Update(ipaddedKey.begin(), ipaddedKey.end()); Hasher_.Update(ipaddedKey.Begin(), ipaddedKey.End());
IsInitialized_ = true; IsInitialized_ = true;
} }