diff options
author | lloyd <[email protected]> | 2007-05-15 23:42:06 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2007-05-15 23:42:06 +0000 |
commit | 925a58bba71b94782fa08025ac1eac8af0e95bb5 (patch) | |
tree | 8387efe64ef47aef39aebcf0f98fb3453236da0d /src/hmac.cpp | |
parent | 6b8961ef7f6d3366c3cc96f184bd849fd83576f2 (diff) |
Check in a change from Yves Jerschow optimizing the HMAC key schedule.
Seems to be about 2-3 times faster in the case where the key is smaller
than the hash's block size, which is almost always the case.
Diffstat (limited to 'src/hmac.cpp')
-rw-r--r-- | src/hmac.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/hmac.cpp b/src/hmac.cpp index 86f68be57..2a67a91e1 100644 --- a/src/hmac.cpp +++ b/src/hmac.cpp @@ -38,12 +38,18 @@ void HMAC::key(const byte key[], u32bit length) std::fill(i_key.begin(), i_key.end(), 0x36); std::fill(o_key.begin(), o_key.end(), 0x5C); - SecureVector<byte> hmac_key(key, length); - if(hmac_key.size() > hash->HASH_BLOCK_SIZE) - hmac_key = hash->process(hmac_key); + if(length > hash->HASH_BLOCK_SIZE) + { + SecureVector<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()); + } + else + { + xor_buf(i_key, key, length); + xor_buf(o_key, key, length); + } - xor_buf(i_key, hmac_key, hmac_key.size()); - xor_buf(o_key, hmac_key, hmac_key.size()); hash->update(i_key); } |