aboutsummaryrefslogtreecommitdiffstats
path: root/src/mac/hmac/hmac.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mac/hmac/hmac.cpp')
-rw-r--r--src/mac/hmac/hmac.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/mac/hmac/hmac.cpp b/src/mac/hmac/hmac.cpp
index fc35e26ea..4b4ed2f70 100644
--- a/src/mac/hmac/hmac.cpp
+++ b/src/mac/hmac/hmac.cpp
@@ -37,12 +37,16 @@ void HMAC::final_result(byte mac[])
void HMAC::key_schedule(const byte key[], size_t length)
{
hash->clear();
+
+ i_key.resize(hash->hash_block_size());
+ o_key.resize(hash->hash_block_size());
+
std::fill(i_key.begin(), i_key.end(), 0x36);
std::fill(o_key.begin(), o_key.end(), 0x5C);
if(length > hash->hash_block_size())
{
- SecureVector<byte> hmac_key = hash->process(key, length);
+ secure_vector<byte> hmac_key = hash->process(key, length);
xor_buf(i_key, hmac_key, hmac_key.size());
xor_buf(o_key, hmac_key, hmac_key.size());
}
@@ -61,8 +65,8 @@ void HMAC::key_schedule(const byte key[], size_t length)
void HMAC::clear()
{
hash->clear();
- zeroise(i_key);
- zeroise(o_key);
+ i_key.clear();
+ o_key.clear();
}
/*
@@ -88,9 +92,6 @@ HMAC::HMAC(HashFunction* hash_in) : hash(hash_in)
{
if(hash->hash_block_size() == 0)
throw Invalid_Argument("HMAC cannot be used with " + hash->name());
-
- i_key.resize(hash->hash_block_size());
- o_key.resize(hash->hash_block_size());
}
}