Botan  2.1.0
Crypto and TLS for C++11
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Botan::GMAC Class Reference

#include <gmac.h>

Inheritance diagram for Botan::GMAC:
Botan::MessageAuthenticationCode Botan::GHASH Botan::Buffered_Computation Botan::SymmetricAlgorithm Botan::SymmetricAlgorithm

Public Member Functions

void clear () override
 
MessageAuthenticationCodeclone () const override
 
void final (uint8_t out[])
 
secure_vector< uint8_t > final ()
 
template<typename Alloc >
void final (std::vector< uint8_t, Alloc > &out)
 
secure_vector< uint8_t > final ()
 
std::vector< uint8_t > final_stdvec ()
 
 GMAC (BlockCipher *cipher)
 
 GMAC (const GMAC &)=delete
 
Key_Length_Specification key_spec () const override
 
size_t maximum_keylength () const
 
size_t maximum_keylength () const
 
size_t minimum_keylength () const
 
size_t minimum_keylength () const
 
std::string name () const override
 
secure_vector< uint8_t > nonce_hash (const uint8_t nonce[], size_t len)
 
GMACoperator= (const GMAC &)=delete
 
size_t output_length () const override
 
secure_vector< uint8_t > process (const uint8_t in[], size_t length)
 
secure_vector< uint8_t > process (const secure_vector< uint8_t > &in)
 
secure_vector< uint8_t > process (const std::vector< uint8_t > &in)
 
secure_vector< uint8_t > process (const std::string &in)
 
virtual std::string provider () const
 
void reset ()
 
void set_associated_data (const uint8_t ad[], size_t ad_len)
 
void set_key (const SymmetricKey &key)
 
void set_key (const SymmetricKey &key)
 
template<typename Alloc >
void set_key (const std::vector< uint8_t, Alloc > &key)
 
template<typename Alloc >
void set_key (const std::vector< uint8_t, Alloc > &key)
 
void set_key (const uint8_t key[], size_t length)
 
void set_key (const uint8_t key[], size_t length)
 
void start (const uint8_t nonce[], size_t nonce_len)
 
void start (const secure_vector< uint8_t > &nonce)
 
void start (const std::vector< uint8_t > &nonce)
 
template<typename Alloc >
void start (const std::vector< uint8_t, Alloc > &nonce)
 
void start ()
 
void update (const uint8_t in[], size_t length)
 
void update (const secure_vector< uint8_t > &in)
 
void update (const std::vector< uint8_t > &in)
 
void update (const std::string &str)
 
void update (uint8_t in)
 
void update (const uint8_t in[], size_t len)
 
template<typename T >
void update_be (const T in)
 
bool valid_keylength (size_t length) const
 
bool valid_keylength (size_t length) const
 
virtual bool verify_mac (const uint8_t in[], size_t length)
 
virtual bool verify_mac (const std::vector< uint8_t > &in)
 
virtual bool verify_mac (const secure_vector< uint8_t > &in)
 

Static Public Member Functions

static std::unique_ptr< MessageAuthenticationCodecreate (const std::string &algo_spec, const std::string &provider="")
 
static std::unique_ptr< MessageAuthenticationCodecreate_or_throw (const std::string &algo_spec, const std::string &provider="")
 
static std::vector< std::string > providers (const std::string &algo_spec)
 

Protected Member Functions

void add_final_block (secure_vector< uint8_t > &x, size_t ad_len, size_t pt_len)
 
void ghash_update (secure_vector< uint8_t > &x, const uint8_t input[], size_t input_len)
 

Protected Attributes

size_t m_ad_len = 0
 
secure_vector< uint8_t > m_ghash
 
secure_vector< uint8_t > m_H
 
secure_vector< uint8_t > m_H_ad
 

Detailed Description

GMAC

Definition at line 21 of file gmac.h.

Constructor & Destructor Documentation

Botan::GMAC::GMAC ( BlockCipher cipher)
explicit

Creates a new GMAC instance.

Parameters
cipherthe underlying block cipher to use

Definition at line 12 of file gmac.cpp.

Referenced by clone().

13  : GHASH(),
14  m_aad_buf(),
15  m_cipher(cipher),
16  m_initialized(false)
17  {}
Botan::GMAC::GMAC ( const GMAC )
delete

Member Function Documentation

void Botan::GHASH::add_final_block ( secure_vector< uint8_t > &  x,
size_t  ad_len,
size_t  pt_len 
)
protectedinherited

Definition at line 120 of file gcm.cpp.

References Botan::GHASH::ghash_update().

Referenced by Botan::GHASH::final(), and Botan::GHASH::nonce_hash().

122  {
123  secure_vector<uint8_t> final_block(GCM_BS);
124  store_be<uint64_t>(final_block.data(), 8*ad_len, 8*text_len);
125  ghash_update(hash, final_block.data(), final_block.size());
126  }
void ghash_update(secure_vector< uint8_t > &x, const uint8_t input[], size_t input_len)
Definition: gcm.cpp:69
MechanismType hash
void Botan::GMAC::clear ( )
overridevirtual

Reset the state.

Implements Botan::SymmetricAlgorithm.

Definition at line 19 of file gmac.cpp.

References Botan::GHASH::clear(), Botan::GHASH::m_ghash, Botan::GHASH::m_H, and Botan::GHASH::m_H_ad.

20  {
21  GHASH::clear();
22  m_H.resize(GCM_BS);
23  m_H_ad.resize(GCM_BS);
24  m_ghash.resize(GCM_BS);
25  m_cipher->clear();
26  m_aad_buf.clear();
27  m_initialized = false;
28  }
secure_vector< uint8_t > m_H
Definition: gcm.h:144
secure_vector< uint8_t > m_ghash
Definition: gcm.h:146
secure_vector< uint8_t > m_H_ad
Definition: gcm.h:145
void clear() override
Definition: gcm.cpp:151
MessageAuthenticationCode * Botan::GMAC::clone ( ) const
overridevirtual

Get a new object representing the same algorithm as *this

Implements Botan::MessageAuthenticationCode.

Definition at line 109 of file gmac.cpp.

References GMAC().

110  {
111  return new GMAC(m_cipher->clone());
112  }
GMAC(BlockCipher *cipher)
Definition: gmac.cpp:12
std::unique_ptr< MessageAuthenticationCode > Botan::MessageAuthenticationCode::create ( const std::string &  algo_spec,
const std::string &  provider = "" 
)
staticinherited

Create an instance based on a name If provider is empty then best available is chosen.

Parameters
algo_specalgorithm name
providerprovider implementation to use
Returns
a null pointer if the algo/provider combination cannot be found

Definition at line 43 of file mac.cpp.

References Botan::SCAN_Name::algo_name(), Botan::SCAN_Name::arg(), Botan::SCAN_Name::arg_as_integer(), Botan::SCAN_Name::arg_count(), BOTAN_UNUSED, Botan::HashFunction::create(), and Botan::BlockCipher::create().

Referenced by botan_mac_init(), Botan::PBKDF::create(), Botan::KDF::create(), Botan::MessageAuthenticationCode::create_or_throw(), Botan::TLS::Session::decrypt(), Botan::TLS::Session::encrypt(), Botan::get_mac(), Botan::TLS::Hello_Verify_Request::Hello_Verify_Request(), Botan::make_message_auth(), and Botan::RFC6979_Nonce_Generator::RFC6979_Nonce_Generator().

45  {
46  const SCAN_Name req(algo_spec);
47 
48 #if defined(BOTAN_HAS_GMAC)
49  if(req.algo_name() == "GMAC" && req.arg_count() == 1)
50  {
51  if(provider.empty() || provider == "base")
52  {
53  if(auto bc = BlockCipher::create(req.arg(0)))
54  return std::unique_ptr<MessageAuthenticationCode>(new GMAC(bc.release()));
55  }
56  }
57 #endif
58 
59 #if defined(BOTAN_HAS_HMAC)
60  if(req.algo_name() == "HMAC" && req.arg_count() == 1)
61  {
62  // TODO OpenSSL
63  if(provider.empty() || provider == "base")
64  {
65  if(auto h = HashFunction::create(req.arg(0)))
66  return std::unique_ptr<MessageAuthenticationCode>(new HMAC(h.release()));
67  }
68  }
69 #endif
70 
71 #if defined(BOTAN_HAS_POLY1305)
72  if(req.algo_name() == "Poly1305" && req.arg_count() == 0)
73  {
74  if(provider.empty() || provider == "base")
75  return std::unique_ptr<MessageAuthenticationCode>(new Poly1305);
76  }
77 #endif
78 
79 #if defined(BOTAN_HAS_SIPHASH)
80  if(req.algo_name() == "SipHash")
81  {
82  if(provider.empty() || provider == "base")
83  {
84  return std::unique_ptr<MessageAuthenticationCode>(
85  new SipHash(req.arg_as_integer(0, 2), req.arg_as_integer(1, 4)));
86  }
87  }
88 #endif
89 
90 #if defined(BOTAN_HAS_CMAC)
91  if((req.algo_name() == "CMAC" || req.algo_name() == "OMAC") && req.arg_count() == 1)
92  {
93  // TODO: OpenSSL CMAC
94  if(provider.empty() || provider == "base")
95  {
96  if(auto bc = BlockCipher::create(req.arg(0)))
97  return std::unique_ptr<MessageAuthenticationCode>(new CMAC(bc.release()));
98  }
99  }
100 #endif
101 
102 
103 #if defined(BOTAN_HAS_CBC_MAC)
104  if(req.algo_name() == "CBC-MAC" && req.arg_count() == 1)
105  {
106  if(provider.empty() || provider == "base")
107  {
108  if(auto bc = BlockCipher::create(req.arg(0)))
109  return std::unique_ptr<MessageAuthenticationCode>(new CBC_MAC(bc.release()));
110  }
111  }
112 #endif
113 
114 #if defined(BOTAN_HAS_ANSI_X919_MAC)
115  if(req.algo_name() == "X9.19-MAC")
116  {
117  if(provider.empty() || provider == "base")
118  {
119  return std::unique_ptr<MessageAuthenticationCode>(new ANSI_X919_MAC);
120  }
121  }
122 #endif
123 
124  BOTAN_UNUSED(req);
126 
127  return nullptr;
128  }
virtual std::string provider() const
Definition: mac.h:139
#define BOTAN_UNUSED(v)
Definition: assert.h:92
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:93
static std::unique_ptr< BlockCipher > create(const std::string &algo_spec, const std::string &provider="")
std::unique_ptr< MessageAuthenticationCode > Botan::MessageAuthenticationCode::create_or_throw ( const std::string &  algo_spec,
const std::string &  provider = "" 
)
staticinherited

Definition at line 138 of file mac.cpp.

References Botan::MessageAuthenticationCode::create().

Referenced by Botan::AutoSeeded_RNG::AutoSeeded_RNG(), Botan::ECIES_System_Params::create_mac(), and Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::TLS_CBC_HMAC_AEAD_Mode().

140  {
141  if(auto mac = MessageAuthenticationCode::create(algo, provider))
142  {
143  return mac;
144  }
145  throw Lookup_Error("MAC", algo, provider);
146  }
static std::unique_ptr< MessageAuthenticationCode > create(const std::string &algo_spec, const std::string &provider="")
Definition: mac.cpp:43
virtual std::string provider() const
Definition: mac.h:139
void Botan::Buffered_Computation::final ( uint8_t  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 89 of file buf_comp.h.

Referenced by botan_hash_final(), botan_mac_final(), Botan::TLS::TLS_CBC_HMAC_AEAD_Encryption::finish(), Botan::TLS::TLS_CBC_HMAC_AEAD_Decryption::finish(), Botan::mgf1_mask(), and Botan::pbkdf2().

89 { final_result(out); }
secure_vector<uint8_t> Botan::Buffered_Computation::final ( )
inlineinherited

Complete the computation and retrieve the final result.

Returns
secure_vector holding the result

Definition at line 96 of file buf_comp.h.

97  {
98  secure_vector<uint8_t> output(output_length());
99  final_result(output.data());
100  return output;
101  }
virtual size_t output_length() const =0
template<typename Alloc >
void Botan::Buffered_Computation::final ( std::vector< uint8_t, Alloc > &  out)
inlineinherited

Definition at line 111 of file buf_comp.h.

112  {
113  out.resize(output_length());
114  final_result(out.data());
115  }
virtual size_t output_length() const =0
secure_vector< uint8_t > Botan::GHASH::final ( )
inherited

Definition at line 128 of file gcm.cpp.

References Botan::GHASH::add_final_block(), Botan::GHASH::m_ad_len, and Botan::GHASH::m_ghash.

129  {
130  add_final_block(m_ghash, m_ad_len, m_text_len);
131 
132  secure_vector<uint8_t> mac;
133  mac.swap(m_ghash);
134 
135  mac ^= m_nonce;
136  m_text_len = 0;
137  return mac;
138  }
secure_vector< uint8_t > m_ghash
Definition: gcm.h:146
void add_final_block(secure_vector< uint8_t > &x, size_t ad_len, size_t pt_len)
Definition: gcm.cpp:120
size_t m_ad_len
Definition: gcm.h:147
std::vector<uint8_t> Botan::Buffered_Computation::final_stdvec ( )
inlineinherited

Definition at line 103 of file buf_comp.h.

104  {
105  std::vector<uint8_t> output(output_length());
106  final_result(output.data());
107  return output;
108  }
virtual size_t output_length() const =0
void Botan::GHASH::ghash_update ( secure_vector< uint8_t > &  x,
const uint8_t  input[],
size_t  input_len 
)
protectedinherited

Definition at line 69 of file gcm.cpp.

References Botan::CT::min(), and Botan::xor_buf().

Referenced by Botan::GHASH::add_final_block(), Botan::GHASH::nonce_hash(), Botan::GHASH::set_associated_data(), and Botan::GHASH::update().

71  {
72  /*
73  This assumes if less than block size input then we're just on the
74  final block and should pad with zeros
75  */
76  while(length)
77  {
78  const size_t to_proc = std::min(length, GCM_BS);
79 
80  xor_buf(ghash.data(), input, to_proc);
81 
82  gcm_multiply(ghash);
83 
84  input += to_proc;
85  length -= to_proc;
86  }
87  }
void xor_buf(T out[], const T in[], size_t length)
Definition: mem_ops.h:115
T min(T a, T b)
Definition: ct_utils.h:180
Key_Length_Specification Botan::GMAC::key_spec ( ) const
inlineoverridevirtual
Returns
object describing limits on key size

Implements Botan::SymmetricAlgorithm.

Definition at line 56 of file gmac.h.

57  {
58  return m_cipher->key_spec();
59  }
size_t Botan::SymmetricAlgorithm::maximum_keylength ( ) const
inlineinherited
Returns
minimum allowed key length

Definition at line 39 of file sym_algo.h.

40  {
41  return key_spec().maximum_keylength();
42  }
size_t maximum_keylength() const
Definition: key_spec.h:69
virtual Key_Length_Specification key_spec() const =0
size_t Botan::SymmetricAlgorithm::maximum_keylength ( ) const
inlineinherited
Returns
minimum allowed key length

Definition at line 39 of file sym_algo.h.

40  {
41  return key_spec().maximum_keylength();
42  }
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
maximum allowed key length

Definition at line 47 of file sym_algo.h.

48  {
49  return key_spec().minimum_keylength();
50  }
size_t minimum_keylength() const
Definition: key_spec.h:61
virtual Key_Length_Specification key_spec() const =0
size_t Botan::SymmetricAlgorithm::minimum_keylength ( ) const
inlineinherited
Returns
maximum allowed key length

Definition at line 47 of file sym_algo.h.

48  {
49  return key_spec().minimum_keylength();
50  }
size_t minimum_keylength() const
Definition: key_spec.h:61
virtual Key_Length_Specification key_spec() const =0
std::string Botan::GMAC::name ( ) const
overridevirtual
Returns
the algorithm name

Implements Botan::SymmetricAlgorithm.

Definition at line 30 of file gmac.cpp.

31  {
32  return "GMAC(" + m_cipher->name() + ")";
33  }
secure_vector< uint8_t > Botan::GHASH::nonce_hash ( const uint8_t  nonce[],
size_t  len 
)
inherited

Definition at line 140 of file gcm.cpp.

References Botan::GHASH::add_final_block(), BOTAN_ASSERT, Botan::GHASH::ghash_update(), and Botan::GHASH::m_ghash.

141  {
142  BOTAN_ASSERT(m_ghash.size() == 0, "nonce_hash called during wrong time");
143  secure_vector<uint8_t> y0(GCM_BS);
144 
145  ghash_update(y0, nonce, nonce_len);
146  add_final_block(y0, 0, nonce_len);
147 
148  return y0;
149  }
secure_vector< uint8_t > m_ghash
Definition: gcm.h:146
void add_final_block(secure_vector< uint8_t > &x, size_t ad_len, size_t pt_len)
Definition: gcm.cpp:120
void ghash_update(secure_vector< uint8_t > &x, const uint8_t input[], size_t input_len)
Definition: gcm.cpp:69
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:27
GMAC& Botan::GMAC::operator= ( const GMAC )
delete
size_t Botan::GMAC::output_length ( ) const
overridevirtual
Returns
length of the output of this function in bytes

Implements Botan::Buffered_Computation.

Definition at line 35 of file gmac.cpp.

36  {
37  return GCM_BS;
38  }
secure_vector<uint8_t> Botan::Buffered_Computation::process ( const uint8_t  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 124 of file buf_comp.h.

Referenced by Botan::RTSS_Share::split().

125  {
126  add_data(in, length);
127  return final();
128  }
secure_vector<uint8_t> Botan::Buffered_Computation::process ( const secure_vector< uint8_t > &  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 136 of file buf_comp.h.

137  {
138  add_data(in.data(), in.size());
139  return final();
140  }
secure_vector<uint8_t> Botan::Buffered_Computation::process ( const std::vector< uint8_t > &  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 148 of file buf_comp.h.

149  {
150  add_data(in.data(), in.size());
151  return final();
152  }
secure_vector<uint8_t> 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 160 of file buf_comp.h.

161  {
162  update(in);
163  return final();
164  }
void update(const uint8_t in[], size_t length)
Definition: buf_comp.h:34
virtual std::string Botan::MessageAuthenticationCode::provider ( ) const
inlinevirtualinherited
Returns
provider information about this implementation. Default is "base", might also return "sse2", "avx2", "openssl", or some other arbitrary string.

Definition at line 139 of file mac.h.

139 { return "base"; }
std::vector< std::string > Botan::MessageAuthenticationCode::providers ( const std::string &  algo_spec)
staticinherited
Returns
list of available providers for this algorithm, empty if not available

Definition at line 131 of file mac.cpp.

Referenced by Botan::get_mac_providers().

132  {
133  return probe_providers_of<MessageAuthenticationCode>(algo_spec, {"base", "openssl"});
134  }
void Botan::GHASH::reset ( )
inherited

Definition at line 157 of file gcm.cpp.

References Botan::GHASH::m_ad_len, Botan::GHASH::m_ghash, Botan::GHASH::m_H_ad, and Botan::zeroise().

Referenced by Botan::GHASH::clear().

158  {
159  zeroise(m_H_ad);
160  m_ghash.clear();
161  m_nonce.clear();
162  m_text_len = m_ad_len = 0;
163  }
secure_vector< uint8_t > m_ghash
Definition: gcm.h:146
secure_vector< uint8_t > m_H_ad
Definition: gcm.h:145
size_t m_ad_len
Definition: gcm.h:147
void zeroise(std::vector< T, Alloc > &vec)
Definition: secmem.h:211
void Botan::GHASH::set_associated_data ( const uint8_t  ad[],
size_t  ad_len 
)
inherited

Definition at line 103 of file gcm.cpp.

References Botan::GHASH::ghash_update(), Botan::GHASH::m_ad_len, Botan::GHASH::m_H_ad, and Botan::zeroise().

104  {
105  zeroise(m_H_ad);
106 
107  ghash_update(m_H_ad, input, length);
108  m_ad_len = length;
109  }
void ghash_update(secure_vector< uint8_t > &x, const uint8_t input[], size_t input_len)
Definition: gcm.cpp:69
secure_vector< uint8_t > m_H_ad
Definition: gcm.h:145
size_t m_ad_len
Definition: gcm.h:147
void zeroise(std::vector< T, Alloc > &vec)
Definition: secmem.h:211
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 66 of file sym_algo.h.

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

Referenced by Botan::aont_package(), Botan::aont_unpackage(), botan_block_cipher_set_key(), botan_mac_set_key(), and Botan::pbkdf2().

67  {
68  set_key(key.begin(), key.length());
69  }
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:66
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 66 of file sym_algo.h.

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

Referenced by Botan::aont_package(), Botan::aont_unpackage(), botan_block_cipher_set_key(), botan_mac_set_key(), and Botan::pbkdf2().

67  {
68  set_key(key.begin(), key.length());
69  }
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:66
template<typename Alloc >
void Botan::SymmetricAlgorithm::set_key ( const std::vector< uint8_t, Alloc > &  key)
inlineinherited

Definition at line 72 of file sym_algo.h.

73  {
74  set_key(key.data(), key.size());
75  }
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:66
template<typename Alloc >
void Botan::SymmetricAlgorithm::set_key ( const std::vector< uint8_t, Alloc > &  key)
inlineinherited

Definition at line 72 of file sym_algo.h.

73  {
74  set_key(key.data(), key.size());
75  }
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:66
void Botan::SymmetricAlgorithm::set_key ( const uint8_t  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 82 of file sym_algo.h.

83  {
84  if(!valid_keylength(length))
85  throw Invalid_Key_Length(name(), length);
86  key_schedule(key, length);
87  }
bool valid_keylength(size_t length) const
Definition: sym_algo.h:57
virtual std::string name() const =0
void Botan::SymmetricAlgorithm::set_key ( const uint8_t  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 82 of file sym_algo.h.

83  {
84  if(!valid_keylength(length))
85  throw Invalid_Key_Length(name(), length);
86  key_schedule(key, length);
87  }
bool valid_keylength(size_t length) const
Definition: sym_algo.h:57
virtual std::string name() const =0
void Botan::GMAC::start ( const uint8_t  nonce[],
size_t  nonce_len 
)

Must be called to set the initialization vector prior to GMAC calculation.

Parameters
nonceInitialization vector.
nonce_lensize of initialization vector.
void Botan::GMAC::start ( const secure_vector< uint8_t > &  nonce)

Must be called to set the initialization vector prior to GMAC calculation.

Parameters
nonceInitialization vector.
void Botan::GMAC::start ( const std::vector< uint8_t > &  nonce)

Must be called to set the initialization vector prior to GMAC calculation.

Parameters
nonceInitialization vector.
template<typename Alloc >
void Botan::MessageAuthenticationCode::start ( const std::vector< uint8_t, Alloc > &  nonce)
inlineinherited

Begin processing a message with a nonce

Parameters
noncethe per message nonce

Definition at line 79 of file mac.h.

80  {
81  start_msg(nonce.data(), nonce.size());
82  }
virtual void start_msg(const uint8_t nonce[], size_t nonce_len)
Definition: mac.h:66
void Botan::MessageAuthenticationCode::start ( )
inlineinherited

Begin processing a message.

Definition at line 97 of file mac.h.

98  {
99  return start_msg(nullptr, 0);
100  }
virtual void start_msg(const uint8_t nonce[], size_t nonce_len)
Definition: mac.h:66
void Botan::Buffered_Computation::update ( const uint8_t  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_hash_update(), botan_mac_update(), Botan::TLS::TLS_CBC_HMAC_AEAD_Encryption::finish(), Botan::TLS::TLS_CBC_HMAC_AEAD_Decryption::finish(), Botan::mgf1_mask(), and Botan::pbkdf2().

34 { add_data(in, length); }
void Botan::Buffered_Computation::update ( const secure_vector< uint8_t > &  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.data(), in.size());
43  }
void Botan::Buffered_Computation::update ( const std::vector< uint8_t > &  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.data(), 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 72 of file buf_comp.h.

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

Process a single byte.

Parameters
inthe byte to process

Definition at line 81 of file buf_comp.h.

81 { add_data(&in, 1); }
void Botan::GHASH::update ( const uint8_t  in[],
size_t  len 
)
inherited

Definition at line 111 of file gcm.cpp.

References BOTAN_ASSERT, Botan::GHASH::ghash_update(), and Botan::GHASH::m_ghash.

112  {
113  BOTAN_ASSERT(m_ghash.size() == GCM_BS, "Key was set");
114 
115  m_text_len += length;
116 
117  ghash_update(m_ghash, input, length);
118  }
secure_vector< uint8_t > m_ghash
Definition: gcm.h:146
void ghash_update(secure_vector< uint8_t > &x, const uint8_t input[], size_t input_len)
Definition: gcm.cpp:69
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:27
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(), and Botan::pbkdf2().

59  {
60  for(size_t i = 0; i != sizeof(T); ++i)
61  {
62  uint8_t b = get_byte(i, in);
63  add_data(&b, 1);
64  }
65  }
uint8_t get_byte(size_t byte_num, T input)
Definition: loadstor.h:47
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 57 of file sym_algo.h.

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

58  {
59  return key_spec().valid_keylength(length);
60  }
bool valid_keylength(size_t length) const
Definition: key_spec.h:51
virtual Key_Length_Specification key_spec() const =0
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 57 of file sym_algo.h.

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

58  {
59  return key_spec().valid_keylength(length);
60  }
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 uint8_t  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 151 of file mac.cpp.

References Botan::same_mem().

152  {
153  secure_vector<uint8_t> our_mac = final();
154 
155  if(our_mac.size() != length)
156  return false;
157 
158  return same_mem(our_mac.data(), mac, length);
159  }
bool same_mem(const T *p1, const T *p2, size_t n)
Definition: mem_ops.h:98
virtual bool Botan::MessageAuthenticationCode::verify_mac ( const std::vector< uint8_t > &  in)
inlinevirtualinherited

Verify a MAC.

Parameters
inthe MAC to verify as a byte array
Returns
true if the MAC is valid, false otherwise

Definition at line 115 of file mac.h.

116  {
117  return verify_mac(in.data(), in.size());
118  }
virtual bool verify_mac(const uint8_t in[], size_t length)
Definition: mac.cpp:151
virtual bool Botan::MessageAuthenticationCode::verify_mac ( const secure_vector< uint8_t > &  in)
inlinevirtualinherited

Verify a MAC.

Parameters
inthe MAC to verify as a byte array
Returns
true if the MAC is valid, false otherwise

Definition at line 125 of file mac.h.

126  {
127  return verify_mac(in.data(), in.size());
128  }
virtual bool verify_mac(const uint8_t in[], size_t length)
Definition: mac.cpp:151

Member Data Documentation

size_t Botan::GHASH::m_ad_len = 0
protectedinherited
secure_vector<uint8_t> Botan::GHASH::m_ghash
protectedinherited
secure_vector<uint8_t> Botan::GHASH::m_H
protectedinherited

Definition at line 144 of file gcm.h.

Referenced by clear(), and Botan::GHASH::clear().

secure_vector<uint8_t> Botan::GHASH::m_H_ad
protectedinherited

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