Botan  1.11.15
Public Types | Public Member Functions | Static Public Member Functions
Botan::HMAC Class Reference

#include <hmac.h>

Inheritance diagram for Botan::HMAC:
Botan::MessageAuthenticationCode Botan::Buffered_Computation Botan::SymmetricAlgorithm

List of all members.

Public Types

typedef SCAN_Name Spec

Public Member Functions

void clear ()
MessageAuthenticationCodeclone () const
void final (byte out[])
secure_vector< bytefinal ()
template<typename Alloc >
void final (std::vector< byte, Alloc > &out)
 HMAC (HashFunction *hash)
 HMAC (const HMAC &)
Key_Length_Specification key_spec () const
size_t maximum_keylength () const
size_t minimum_keylength () const
std::string name () const
HMACoperator= (const HMAC &)
size_t output_length () const
secure_vector< byteprocess (const byte in[], size_t length)
secure_vector< byteprocess (const secure_vector< byte > &in)
secure_vector< byteprocess (const std::vector< byte > &in)
secure_vector< byteprocess (const std::string &in)
void set_key (const SymmetricKey &key)
template<typename Alloc >
void set_key (const std::vector< byte, Alloc > &key)
void set_key (const byte key[], size_t length)
void update (const byte in[], size_t length)
void update (const secure_vector< byte > &in)
void update (const std::vector< byte > &in)
void update (const std::string &str)
void update (byte in)
template<typename T >
void update_be (const T in)
bool valid_keylength (size_t length) const
virtual bool verify_mac (const byte in[], size_t length)

Static Public Member Functions

static HMACmake (const Spec &spec)

Detailed Description

HMAC

Definition at line 19 of file hmac.h.


Member Typedef Documentation

Definition at line 44 of file mac.h.


Constructor & Destructor Documentation

Parameters:
hashthe hash to use for HMACing

Definition at line 100 of file hmac.cpp.

Referenced by clone(), and make().

                             : m_hash(hash)
   {
   if(m_hash->hash_block_size() == 0)
      throw Invalid_Argument("HMAC cannot be used with " + m_hash->name());
   }
Botan::HMAC::HMAC ( const HMAC )

Member Function Documentation

void Botan::HMAC::clear ( ) [virtual]

Implements Botan::SymmetricAlgorithm.

Definition at line 74 of file hmac.cpp.

References Botan::zap().

   {
   m_hash->clear();
   zap(m_ikey);
   zap(m_okey);
   }

Get a new object representing the same algorithm as *this

Implements Botan::MessageAuthenticationCode.

Definition at line 92 of file hmac.cpp.

References HMAC().

   {
   return new HMAC(m_hash->clone());
   }
void Botan::Buffered_Computation::final ( byte  out[]) [inline, inherited]

Complete the computation and retrieve the final result.

Parameters:
outThe byte array to be filled with the result. Must be of length output_length()

Definition at line 90 of file buf_comp.h.

Referenced by botan_hash_final(), botan_mac_final(), Botan::McEliece_KEM_Decryptor::decrypt(), Botan::TLS::Session::decrypt(), Botan::McEliece_KEM_Encryptor::encrypt(), Botan::TLS::Session::encrypt(), Botan::mgf1_mask(), Botan::pbkdf2(), and Botan::TLS::write_record().

{ final_result(out); }
secure_vector<byte> Botan::Buffered_Computation::final ( ) [inline, inherited]

Complete the computation and retrieve the final result.

Returns:
secure_vector holding the result

Definition at line 97 of file buf_comp.h.

         {
         secure_vector<byte> output(output_length());
         final_result(&output[0]);
         return output;
         }
template<typename Alloc >
void Botan::Buffered_Computation::final ( std::vector< byte, Alloc > &  out) [inline, inherited]

Definition at line 105 of file buf_comp.h.

         {
         out.resize(output_length());
         final_result(&out[0]);
         }
Key_Length_Specification Botan::HMAC::key_spec ( ) const [inline, virtual]
Returns:
object describing limits on key size

Implements Botan::SymmetricAlgorithm.

Definition at line 28 of file hmac.h.

         {
         // Absurd max length here is to support PBKDF2
         return Key_Length_Specification(0, 512);
         }
HMAC * Botan::HMAC::make ( const Spec spec) [static]

Definition at line 14 of file hmac.cpp.

References Botan::SCAN_Name::arg(), Botan::SCAN_Name::arg_count(), HMAC(), and Botan::Algo_Registry< T >::make().

   {
   if(spec.arg_count() == 1)
      return new HMAC(Algo_Registry<HashFunction>::global_registry().make(spec.arg(0)));
   return nullptr;
   }
size_t Botan::SymmetricAlgorithm::maximum_keylength ( ) const [inline, inherited]
Returns:
minimum allowed key length

Definition at line 36 of file sym_algo.h.

References Botan::Key_Length_Specification::maximum_keylength().

         {
         return key_spec().maximum_keylength();
         }
size_t Botan::SymmetricAlgorithm::minimum_keylength ( ) const [inline, inherited]
Returns:
maxmium allowed key length

Definition at line 44 of file sym_algo.h.

         {
         return key_spec().minimum_keylength();
         }
std::string Botan::HMAC::name ( ) const [virtual]

Get the name of this algorithm.

Returns:
name of this algorithm

Implements Botan::MessageAuthenticationCode.

Definition at line 84 of file hmac.cpp.

   {
   return "HMAC(" + m_hash->name() + ")";
   }
HMAC& Botan::HMAC::operator= ( const HMAC )
size_t Botan::HMAC::output_length ( ) const [inline, virtual]
Returns:
length of the output of this function in bytes

Implements Botan::Buffered_Computation.

Definition at line 26 of file hmac.h.

References m_hash.

{ return m_hash->output_length(); }
secure_vector<byte> Botan::Buffered_Computation::process ( const byte  in[],
size_t  length 
) [inline, inherited]

Update and finalize computation. Does the same as calling update() and final() consecutively.

Parameters:
inthe input to process as a byte array
lengththe length of the byte array
Returns:
the result of the call to final()

Definition at line 118 of file buf_comp.h.

Referenced by Botan::HMAC_RNG::HMAC_RNG(), Botan::RTSS_Share::split(), and Botan::Cert_Extension::Subject_Key_ID::Subject_Key_ID().

         {
         add_data(in, length);
         return final();
         }
secure_vector<byte> Botan::Buffered_Computation::process ( const secure_vector< byte > &  in) [inline, inherited]

Update and finalize computation. Does the same as calling update() and final() consecutively.

Parameters:
inthe input to process
Returns:
the result of the call to final()

Definition at line 130 of file buf_comp.h.

         {
         add_data(&in[0], in.size());
         return final();
         }
secure_vector<byte> Botan::Buffered_Computation::process ( const std::vector< byte > &  in) [inline, inherited]

Update and finalize computation. Does the same as calling update() and final() consecutively.

Parameters:
inthe input to process
Returns:
the result of the call to final()

Definition at line 142 of file buf_comp.h.

         {
         add_data(&in[0], in.size());
         return final();
         }
secure_vector<byte> Botan::Buffered_Computation::process ( const std::string &  in) [inline, inherited]

Update and finalize computation. Does the same as calling update() and final() consecutively.

Parameters:
inthe input to process as a string
Returns:
the result of the call to final()

Definition at line 154 of file buf_comp.h.

         {
         update(in);
         return final();
         }
void Botan::SymmetricAlgorithm::set_key ( const SymmetricKey key) [inline, inherited]

Set the symmetric key of this object.

Parameters:
keythe SymmetricKey to be set.

Definition at line 63 of file sym_algo.h.

References Botan::OctetString::begin(), and Botan::OctetString::length().

Referenced by Botan::aont_package(), Botan::aont_unpackage(), botan_mac_set_key(), Botan::TLS::Session::decrypt(), Botan::TLS::Session::encrypt(), and Botan::pbkdf2().

         {
         set_key(key.begin(), key.length());
         }
template<typename Alloc >
void Botan::SymmetricAlgorithm::set_key ( const std::vector< byte, Alloc > &  key) [inline, inherited]

Definition at line 69 of file sym_algo.h.

         {
         set_key(&key[0], key.size());
         }
void Botan::SymmetricAlgorithm::set_key ( const byte  key[],
size_t  length 
) [inline, inherited]

Set the symmetric key of this object.

Parameters:
keythe to be set as a byte array.
lengthin bytes of key param

Definition at line 79 of file sym_algo.h.

         {
         if(!valid_keylength(length))
            throw Invalid_Key_Length(name(), length);
         key_schedule(key, length);
         }
void Botan::Buffered_Computation::update ( const byte  in[],
size_t  length 
) [inline, inherited]

Add new input to process.

Parameters:
inthe input to process as a byte array
lengthof param in in bytes

Definition at line 34 of file buf_comp.h.

Referenced by botan_hash_update(), botan_mac_update(), Botan::McEliece_KEM_Decryptor::decrypt(), Botan::TLS::Session::decrypt(), Botan::McEliece_KEM_Encryptor::encrypt(), Botan::TLS::Session::encrypt(), Botan::mgf1_mask(), Botan::pbkdf2(), and Botan::TLS::write_record().

{ add_data(in, length); }
void Botan::Buffered_Computation::update ( const secure_vector< byte > &  in) [inline, inherited]

Add new input to process.

Parameters:
inthe input to process as a secure_vector

Definition at line 40 of file buf_comp.h.

         {
         add_data(&in[0], in.size());
         }
void Botan::Buffered_Computation::update ( const std::vector< byte > &  in) [inline, inherited]

Add new input to process.

Parameters:
inthe input to process as a std::vector

Definition at line 49 of file buf_comp.h.

         {
         add_data(&in[0], in.size());
         }
void Botan::Buffered_Computation::update ( const std::string &  str) [inline, inherited]

Add new input to process.

Parameters:
strthe input to process as a std::string. Will be interpreted as a byte array based on the strings encoding.

Definition at line 73 of file buf_comp.h.

         {
         add_data(reinterpret_cast<const byte*>(str.data()), str.size());
         }
void Botan::Buffered_Computation::update ( byte  in) [inline, inherited]

Process a single byte.

Parameters:
inthe byte to process

Definition at line 82 of file buf_comp.h.

{ add_data(&in, 1); }
template<typename T >
void Botan::Buffered_Computation::update_be ( const T  in) [inline, inherited]

Add an integer in big-endian order

Parameters:
inthe value

Definition at line 58 of file buf_comp.h.

References Botan::get_byte().

Referenced by Botan::mgf1_mask(), and Botan::pbkdf2().

         {
         for(size_t i = 0; i != sizeof(T); ++i)
            {
            byte b = get_byte(i, in);
            add_data(&b, 1);
            }
         }
bool Botan::SymmetricAlgorithm::valid_keylength ( size_t  length) const [inline, inherited]

Check whether a given key length is valid for this algorithm.

Parameters:
lengththe key length to be checked.
Returns:
true if the key length is valid.

Definition at line 54 of file sym_algo.h.

Referenced by Botan::aont_package(), and Botan::aont_unpackage().

         {
         return key_spec().valid_keylength(length);
         }
bool Botan::MessageAuthenticationCode::verify_mac ( const byte  in[],
size_t  length 
) [virtual, inherited]

Verify a MAC.

Parameters:
inthe MAC to verify as a byte array
lengththe length of param in
Returns:
true if the MAC is valid, false otherwise

Definition at line 16 of file mac.cpp.

References Botan::same_mem().

   {
   secure_vector<byte> our_mac = final();

   if(our_mac.size() != length)
      return false;

   return same_mem(&our_mac[0], &mac[0], length);
   }

The documentation for this class was generated from the following files: