Botan  1.11.15
src/lib/mac/hmac/hmac.h
Go to the documentation of this file.
00001 /*
00002 * HMAC
00003 * (C) 1999-2007,2014 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_HMAC_H__
00009 #define BOTAN_HMAC_H__
00010 
00011 #include <botan/mac.h>
00012 #include <botan/hash.h>
00013 
00014 namespace Botan {
00015 
00016 /**
00017 * HMAC
00018 */
00019 class BOTAN_DLL HMAC : public MessageAuthenticationCode
00020    {
00021    public:
00022       void clear();
00023       std::string name() const;
00024       MessageAuthenticationCode* clone() const;
00025 
00026       size_t output_length() const { return m_hash->output_length(); }
00027 
00028       Key_Length_Specification key_spec() const
00029          {
00030          // Absurd max length here is to support PBKDF2
00031          return Key_Length_Specification(0, 512);
00032          }
00033 
00034       /**
00035       * @param hash the hash to use for HMACing
00036       */
00037       HMAC(HashFunction* hash);
00038 
00039       static HMAC* make(const Spec& spec);
00040 
00041       HMAC(const HMAC&) = delete;
00042       HMAC& operator=(const HMAC&) = delete;
00043    private:
00044       void add_data(const byte[], size_t);
00045       void final_result(byte[]);
00046       void key_schedule(const byte[], size_t);
00047 
00048       std::unique_ptr<HashFunction> m_hash;
00049       secure_vector<byte> m_ikey, m_okey;
00050    };
00051 
00052 }
00053 
00054 #endif