aboutsummaryrefslogtreecommitdiffstats
path: root/src/hmac.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-09-28 18:19:22 +0000
committerlloyd <[email protected]>2008-09-28 18:19:22 +0000
commit9caed38cf07ae1cb6fcb4e21c600818a48bf313e (patch)
tree388d4c2ed79f8dc5580c41f4e474ee7517121a25 /src/hmac.cpp
parent983a8ecb42e844f89466d0ae52bba591d4fc4275 (diff)
Modularize CMAC and HMAC
Diffstat (limited to 'src/hmac.cpp')
-rw-r--r--src/hmac.cpp97
1 files changed, 0 insertions, 97 deletions
diff --git a/src/hmac.cpp b/src/hmac.cpp
deleted file mode 100644
index b8c76e8f6..000000000
--- a/src/hmac.cpp
+++ /dev/null
@@ -1,97 +0,0 @@
-/*************************************************
-* HMAC Source File *
-* (C) 1999-2007 Jack Lloyd *
-* 2007 Yves Jerschow *
-*************************************************/
-
-#include <botan/hmac.h>
-#include <botan/lookup.h>
-#include <botan/xor_buf.h>
-
-namespace Botan {
-
-/*************************************************
-* Update a HMAC Calculation *
-*************************************************/
-void HMAC::add_data(const byte input[], u32bit length)
- {
- hash->update(input, length);
- }
-
-/*************************************************
-* Finalize a HMAC Calculation *
-*************************************************/
-void HMAC::final_result(byte mac[])
- {
- hash->final(mac);
- hash->update(o_key);
- hash->update(mac, OUTPUT_LENGTH);
- hash->final(mac);
- hash->update(i_key);
- }
-
-/*************************************************
-* HMAC Key Schedule *
-*************************************************/
-void HMAC::key(const byte key[], u32bit length)
- {
- hash->clear();
- 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);
- 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);
- }
-
- hash->update(i_key);
- }
-
-/*************************************************
-* Clear memory of sensitive data *
-*************************************************/
-void HMAC::clear() throw()
- {
- hash->clear();
- i_key.clear();
- o_key.clear();
- }
-
-/*************************************************
-* Return the name of this type *
-*************************************************/
-std::string HMAC::name() const
- {
- return "HMAC(" + hash->name() + ")";
- }
-
-/*************************************************
-* Return a clone of this object *
-*************************************************/
-MessageAuthenticationCode* HMAC::clone() const
- {
- return new HMAC(hash->name());
- }
-
-/*************************************************
-* HMAC Constructor *
-*************************************************/
-HMAC::HMAC(const std::string& hash_name) :
- MessageAuthenticationCode(output_length_of(hash_name),
- 1, 2*block_size_of(hash_name)),
- hash(get_hash(hash_name))
- {
- if(hash->HASH_BLOCK_SIZE == 0)
- throw Invalid_Argument("HMAC cannot be used with " + hash->name());
- i_key.create(hash->HASH_BLOCK_SIZE);
- o_key.create(hash->HASH_BLOCK_SIZE);
- }
-
-}