Botan  1.11.11
Public Member Functions | List of all members
Botan::CBC_MAC Class Reference

#include <cbc_mac.h>

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

Public Member Functions

 CBC_MAC (BlockCipher *cipher)
 
void clear ()
 
MessageAuthenticationCodeclone () const
 
void final (byte out[])
 
secure_vector< bytefinal ()
 
Key_Length_Specification key_spec () const
 
size_t maximum_keylength () const
 
size_t minimum_keylength () const
 
std::string name () const
 
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)
 

Detailed Description

CBC-MAC

Definition at line 19 of file cbc_mac.h.

Constructor & Destructor Documentation

Botan::CBC_MAC::CBC_MAC ( BlockCipher cipher)
Parameters
cipherthe underlying block cipher to use

Definition at line 91 of file cbc_mac.cpp.

Referenced by clone().

91  :
92  m_cipher(cipher), m_state(cipher->block_size())
93  {
94  }

Member Function Documentation

void Botan::CBC_MAC::clear ( )
virtual

Implements Botan::SymmetricAlgorithm.

Definition at line 65 of file cbc_mac.cpp.

References Botan::zeroise().

66  {
67  m_cipher->clear();
68  zeroise(m_state);
69  m_position = 0;
70  }
void zeroise(std::vector< T, Alloc > &vec)
Definition: secmem.h:166
MessageAuthenticationCode * Botan::CBC_MAC::clone ( ) const
virtual

Get a new object representing the same algorithm as *this

Implements Botan::MessageAuthenticationCode.

Definition at line 83 of file cbc_mac.cpp.

References CBC_MAC().

84  {
85  return new CBC_MAC(m_cipher->clone());
86  }
CBC_MAC(BlockCipher *cipher)
Definition: cbc_mac.cpp:91
void Botan::Buffered_Computation::final ( byte  out[])
inlineinherited

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::McEliece_KEM_Decryptor::decrypt(), Botan::X942_PRF::derive(), Botan::McEliece_KEM_Encryptor::encrypt(), Botan::mgf1_mask(), and Botan::TLS::write_record().

90 { final_result(out); }
secure_vector<byte> Botan::Buffered_Computation::final ( )
inlineinherited

Complete the computation and retrieve the final result.

Returns
secure_vector holding the result

Definition at line 97 of file buf_comp.h.

98  {
99  secure_vector<byte> output(output_length());
100  final_result(&output[0]);
101  return output;
102  }
virtual size_t output_length() const =0
Key_Length_Specification Botan::CBC_MAC::key_spec ( ) const
inlinevirtual
Returns
object describing limits on key size

Implements Botan::SymmetricAlgorithm.

Definition at line 27 of file cbc_mac.h.

28  {
29  return m_cipher->key_spec();
30  }
size_t Botan::SymmetricAlgorithm::maximum_keylength ( ) const
inlineinherited
Returns
minimum allowed key length

Definition at line 36 of file sym_algo.h.

37  {
38  return key_spec().maximum_keylength();
39  }
size_t maximum_keylength() const
Definition: key_spec.h:69
virtual Key_Length_Specification key_spec() const =0
size_t Botan::SymmetricAlgorithm::minimum_keylength ( ) const
inlineinherited
Returns
maxmium allowed key length

Definition at line 44 of file sym_algo.h.

45  {
46  return key_spec().minimum_keylength();
47  }
size_t minimum_keylength() const
Definition: key_spec.h:61
virtual Key_Length_Specification key_spec() const =0
std::string Botan::CBC_MAC::name ( ) const
virtual

Get the name of this algorithm.

Returns
name of this algorithm

Implements Botan::MessageAuthenticationCode.

Definition at line 75 of file cbc_mac.cpp.

76  {
77  return "CBC-MAC(" + m_cipher->name() + ")";
78  }
size_t Botan::CBC_MAC::output_length ( ) const
inlinevirtual
Returns
length of the output of this function in bytes

Implements Botan::Buffered_Computation.

Definition at line 24 of file cbc_mac.h.

24 { return m_cipher->block_size(); }
secure_vector<byte> Botan::Buffered_Computation::process ( const byte  in[],
size_t  length 
)
inlineinherited

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 111 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().

112  {
113  add_data(in, length);
114  return final();
115  }
secure_vector<byte> Botan::Buffered_Computation::process ( const secure_vector< byte > &  in)
inlineinherited

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 123 of file buf_comp.h.

124  {
125  add_data(&in[0], in.size());
126  return final();
127  }
secure_vector<byte> Botan::Buffered_Computation::process ( const std::vector< byte > &  in)
inlineinherited

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 135 of file buf_comp.h.

136  {
137  add_data(&in[0], in.size());
138  return final();
139  }
secure_vector<byte> Botan::Buffered_Computation::process ( const std::string &  in)
inlineinherited

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 147 of file buf_comp.h.

148  {
149  update(in);
150  return final();
151  }
void update(const byte in[], size_t length)
Definition: buf_comp.h:34
void Botan::SymmetricAlgorithm::set_key ( const SymmetricKey key)
inlineinherited

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(), and Botan::aont_unpackage().

64  {
65  set_key(key.begin(), key.length());
66  }
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:63
template<typename Alloc >
void Botan::SymmetricAlgorithm::set_key ( const std::vector< byte, Alloc > &  key)
inlineinherited

Definition at line 69 of file sym_algo.h.

70  {
71  set_key(&key[0], key.size());
72  }
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:63
void Botan::SymmetricAlgorithm::set_key ( const byte  key[],
size_t  length 
)
inlineinherited

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.

80  {
81  if(!valid_keylength(length))
82  throw Invalid_Key_Length(name(), length);
83  key_schedule(key, length);
84  }
bool valid_keylength(size_t length) const
Definition: sym_algo.h:54
virtual std::string name() const =0
void Botan::Buffered_Computation::update ( const byte  in[],
size_t  length 
)
inlineinherited

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::McEliece_KEM_Decryptor::decrypt(), Botan::X942_PRF::derive(), Botan::McEliece_KEM_Encryptor::encrypt(), Botan::mgf1_mask(), and Botan::TLS::write_record().

34 { add_data(in, length); }
void Botan::Buffered_Computation::update ( const secure_vector< byte > &  in)
inlineinherited

Add new input to process.

Parameters
inthe input to process as a secure_vector

Definition at line 40 of file buf_comp.h.

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

Add new input to process.

Parameters
inthe input to process as a std::vector

Definition at line 49 of file buf_comp.h.

50  {
51  add_data(&in[0], in.size());
52  }
void Botan::Buffered_Computation::update ( const std::string &  str)
inlineinherited

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.

74  {
75  add_data(reinterpret_cast<const byte*>(str.data()), str.size());
76  }
void Botan::Buffered_Computation::update ( byte  in)
inlineinherited

Process a single byte.

Parameters
inthe byte to process

Definition at line 82 of file buf_comp.h.

82 { add_data(&in, 1); }
template<typename T >
void Botan::Buffered_Computation::update_be ( const T  in)
inlineinherited

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().

59  {
60  for(size_t i = 0; i != sizeof(T); ++i)
61  {
62  byte b = get_byte(i, in);
63  add_data(&b, 1);
64  }
65  }
byte get_byte(size_t byte_num, T input)
Definition: get_byte.h:21
uint8_t byte
Definition: types.h:30
bool Botan::SymmetricAlgorithm::valid_keylength ( size_t  length) const
inlineinherited

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().

55  {
56  return key_spec().valid_keylength(length);
57  }
bool valid_keylength(size_t length) const
Definition: key_spec.h:51
virtual Key_Length_Specification key_spec() const =0
bool Botan::MessageAuthenticationCode::verify_mac ( const byte  in[],
size_t  length 
)
virtualinherited

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().

17  {
18  secure_vector<byte> our_mac = final();
19 
20  if(our_mac.size() != length)
21  return false;
22 
23  return same_mem(&our_mac[0], &mac[0], length);
24  }
std::unique_ptr< MessageAuthenticationCode > mac
Definition: fpe_fe1.cpp:89
bool same_mem(const T *p1, const T *p2, size_t n)
Definition: mem_ops.h:63

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