Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Protected Member Functions | List of all members
Botan::GHASH Class Referencefinal

`#include <ghash.h>`

Inheritance diagram for Botan::GHASH:

## Public Member Functions
void | add_final_block (secure_vector< uint8_t > &x, size_t ad_len, size_t pt_len)
void | clear () override
secure_vector< uint8_t > | final ()
void | final (uint8_t out[], size_t out_len)
void | ghash_update (secure_vector< uint8_t > &x, const uint8_t input[], size_t input_len)
Key_Length_Specification | key_spec () const override
size_t | maximum_keylength () const
size_t | minimum_keylength () const
std::string | name () const override
secure_vector< uint8_t > | nonce_hash (const uint8_t nonce[], size_t nonce_len)
void | nonce_hash (secure_vector< uint8_t > &y0, const uint8_t nonce[], size_t len)
std::string | provider () const
void | reset ()
void | set_associated_data (const uint8_t ad[], size_t ad_len)
void | set_key (const SymmetricKey &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 | start (const uint8_t nonce[], size_t len)
void | update (const uint8_t in[], size_t len)
void | update_associated_data (const uint8_t ad[], size_t len)
bool | valid_keylength (size_t length) const

## Protected Member Functions
void | verify_key_set (bool cond) const

## Detailed Description

GCM's GHASH This is not intended for general use, but is exposed to allow shared code between GCM and GMAC

Definition at line 22 of file ghash.h.

## Member Function Documentation

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

Definition at line 197 of file ghash.cpp.

References ghash_update().

Referenced by final(), and nonce_hash().

199 {
200 /*
201 * stack buffer is fine here since the text len is public
202 * and the length of the AD is probably not sensitive either.
203 */
204 uint8_t final_block[GCM_BS];
205 store_be<uint64_t>(final_block, 8*ad_len, 8*text_len);
206 ghash_update(hash, final_block, GCM_BS);
207 }
Botan::GHASH::ghash_update
void ghash_update(secure_vector< uint8_t > &x, const uint8_t input[], size_t input_len)
Definition: ghash.cpp:96
hash
MechanismType hash
Definition: p11_mechanism.cpp:64

void Botan::GHASH::clear | ( |  | ) |
| override virtual

Reset the state.

Implements Botan::SymmetricAlgorithm.

Definition at line 229 of file ghash.cpp.

References reset(), and Botan::zap().

230 {
231 zap(m_H);
232 zap(m_HM);
233 reset();
234 }
Botan::GHASH::reset
void reset()
Definition: ghash.cpp:236
Botan::zap
void zap(std::vector< T, Alloc > &vec)
Definition: secmem.h:170

secure_vector<uint8_t> Botan::GHASH::final | ( |  | ) |
| inline

Definition at line 49 of file ghash.h.

50 {
51 secure_vector<uint8_t> mac(GCM_BS);
52 final(mac.data(), mac.size());
53 return mac;
54 }

void Botan::GHASH::final | ( | uint8_t | out[],
|  | size_t | out_len
| ) |  |

Definition at line 209 of file ghash.cpp.

References add_final_block(), and BOTAN_ARG_CHECK.

210 {
211 BOTAN_ARG_CHECK(mac_len > 0 && mac_len <= 16, "GHASH output length");
212 add_final_block(m_ghash, m_ad_len, m_text_len);
213
214 for(size_t i = 0; i != mac_len; ++i)
215 mac[i] = m_ghash[i] ^ m_nonce[i];
216
217 m_ghash.clear();
218 m_text_len = 0;
219 }
Botan::GHASH::add_final_block
void add_final_block(secure_vector< uint8_t > &x, size_t ad_len, size_t pt_len)
Definition: ghash.cpp:197
BOTAN_ARG_CHECK
#define BOTAN_ARG_CHECK(expr, msg)
Definition: assert.h:37

void Botan::GHASH::ghash_update | ( | secure_vector< uint8_t > & | x,
|  | const uint8_t | input[],
|  | size_t | input_len
| ) |  |

Definition at line 96 of file ghash.cpp.

References Botan::copy_mem(), Botan::secure_scrub_memory(), and Botan::SymmetricAlgorithm::verify_key_set().

Referenced by add_final_block(), nonce_hash(), set_associated_data(), update(), and update_associated_data().

98 {
99 verify_key_set(!m_HM.empty());
100
101 /*
102 This assumes if less than block size input then we're just on the
103 final block and should pad with zeros
104 */
105
106 const size_t full_blocks = length / GCM_BS;
107 const size_t final_bytes = length - (full_blocks * GCM_BS);
108
109 if(full_blocks > 0)
110 {
111 gcm_multiply(ghash, input, full_blocks);
112 }
113
114 if(final_bytes)
115 {
116 uint8_t last_block[GCM_BS] = { 0 };
117 copy_mem(last_block, input + full_blocks * GCM_BS, final_bytes);
118 gcm_multiply(ghash, last_block, 1);
119 secure_scrub_memory(last_block, final_bytes);
120 }
121 }
Botan::copy_mem
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:132
Botan::SymmetricAlgorithm::verify_key_set
void verify_key_set(bool cond) const
Definition: sym_algo.h:89
Botan::secure_scrub_memory
void secure_scrub_memory(void *ptr, size_t n)
Definition: os_utils.cpp:66

Key_Length_Specification Botan::GHASH::key_spec | ( |  | ) | const
| inline override virtual

Returns
  object describing limits on key size

Implements Botan::SymmetricAlgorithm.

Definition at line 58 of file ghash.h.

59 { return Key_Length_Specification(16); }

size_t Botan::SymmetricAlgorithm::maximum_keylength | ( |  | ) | const
| inline inherited

Returns
  minimum allowed key length

Definition at line 38 of file sym_algo.h.

39 {
40 return key_spec().maximum_keylength();
41 }
Botan::Key_Length_Specification::maximum_keylength
size_t maximum_keylength() const
Definition: key_spec.h:69
Botan::SymmetricAlgorithm::key_spec
virtual Key_Length_Specification key_spec() const =0

size_t Botan::SymmetricAlgorithm::minimum_keylength | ( |  | ) | const
| inline inherited

Returns
  maximum allowed key length

Definition at line 46 of file sym_algo.h.

Referenced by botan_block_cipher_get_keyspec(), and botan_mac_get_keyspec().

47 {
48 return key_spec().minimum_keylength();
49 }
Botan::Key_Length_Specification::minimum_keylength
size_t minimum_keylength() const
Definition: key_spec.h:61
Botan::SymmetricAlgorithm::key_spec
virtual Key_Length_Specification key_spec() const =0

std::string Botan::GHASH::name | ( |  | ) | const
| inline override virtual

Returns
  the algorithm name

Implements Botan::SymmetricAlgorithm.

Definition at line 65 of file ghash.h.

65 { return "GHASH"; }

secure_vector<uint8_t> Botan::GHASH::nonce_hash | ( | const uint8_t | nonce[],
|  | size_t | nonce_len
| ) |  |
| inline

Definition at line 28 of file ghash.h.

29 {
30 secure_vector<uint8_t> y0(GCM_BS);
31 nonce_hash(y0, nonce, nonce_len);
32 return y0;
33 }
Botan::GHASH::nonce_hash
secure_vector< uint8_t > nonce_hash(const uint8_t nonce[], size_t nonce_len)
Definition: ghash.h:28

void Botan::GHASH::nonce_hash | ( | secure_vector< uint8_t > & | y0,
|  | const uint8_t | nonce[],
|  | size_t | len
| ) |  |

Definition at line 221 of file ghash.cpp.

References add_final_block(), BOTAN_ASSERT, and ghash_update().

222 {
223 BOTAN_ASSERT(m_ghash.size() == 0, "nonce_hash called during wrong time");
224
225 ghash_update(y0, nonce, nonce_len);
226 add_final_block(y0, 0, nonce_len);
227 }
Botan::GHASH::add_final_block
void add_final_block(secure_vector< uint8_t > &x, size_t ad_len, size_t pt_len)
Definition: ghash.cpp:197
Botan::GHASH::ghash_update
void ghash_update(secure_vector< uint8_t > &x, const uint8_t input[], size_t input_len)
Definition: ghash.cpp:96
BOTAN_ASSERT
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:55

std::string Botan::GHASH::provider | ( |  | ) | const

Definition at line 25 of file ghash.cpp.

References Botan::CPUID::has_carryless_multiply().

26 {
27 #if defined(BOTAN_HAS_GCM_CLMUL_CPU)
28 if(CPUID::has_carryless_multiply())
29 return "clmul";
30 #endif
31
32 #if defined(BOTAN_HAS_GCM_CLMUL_SSSE3)
33 if(CPUID::has_ssse3())
34 return "ssse3";
35 #endif
36
37 return "base";
38 }
Botan::CPUID::has_carryless_multiply
static bool has_carryless_multiply()
Definition: cpuid.h:341

void Botan::GHASH::reset | ( |  | ) |

Definition at line 236 of file ghash.cpp.

References Botan::zeroise().

Referenced by clear().

237 {
238 zeroise(m_H_ad);
239 m_ghash.clear();
240 m_nonce.clear();
241 m_text_len = m_ad_len = 0;
242 }
Botan::zeroise
void zeroise(std::vector< T, Alloc > &vec)
Definition: secmem.h:160

void Botan::GHASH::set_associated_data | ( | const uint8_t | ad[],
|  | size_t | ad_len
| ) |  |

Definition at line 172 of file ghash.cpp.

References ghash_update(), and Botan::zeroise().

173 {
174 if(m_ghash.empty() == false)
175 throw Invalid_State("Too late to set AD in GHASH");
176
177 zeroise(m_H_ad);
178
179 ghash_update(m_H_ad, input, length);
180 m_ad_len = length;
181 }
Botan::GHASH::ghash_update
void ghash_update(secure_vector< uint8_t > &x, const uint8_t input[], size_t input_len)
Definition: ghash.cpp:96
Botan::zeroise
void zeroise(std::vector< T, Alloc > &vec)
Definition: secmem.h:160

void Botan::SymmetricAlgorithm::set_key | ( | const SymmetricKey & | key | ) |
| inline inherited

Set the symmetric key of this object.

Parameters

  key | the SymmetricKey to be set.

Definition at line 65 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_cipher_set_key(), botan_mac_set_key(), Botan::Sodium::crypto_stream_salsa20(), Botan::Sodium::crypto_stream_salsa20_xor_ic(), Botan::Sodium::crypto_stream_xsalsa20(), Botan::Sodium::crypto_stream_xsalsa20_xor_ic(), Botan::FPE::fe1_decrypt(), Botan::FPE::fe1_encrypt(), and Botan::Sodium::randombytes_buf_deterministic().

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

void Botan::SymmetricAlgorithm::set_key | ( | const std::vector< uint8_t, Alloc > & | key | ) |
| inline inherited

Definition at line 71 of file sym_algo.h.

72 {
73 set_key(key.data(), key.size());
74 }
Botan::SymmetricAlgorithm::set_key
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:65

void Botan::SymmetricAlgorithm::set_key | ( | const uint8_t | key[],
|  | size_t | length
| ) |  |
| inherited

Set the symmetric key of this object.

Parameters

  key | the to be set as a byte array.
  length | in bytes of key param

Definition at line 17 of file sym_algo.cpp.

References Botan::SymmetricAlgorithm::name(), and Botan::SymmetricAlgorithm::valid_keylength().

18 {
19 if(!valid_keylength(length))
20 throw Invalid_Key_Length(name(), length);
21 key_schedule(key, length);
22 }
Botan::SymmetricAlgorithm::valid_keylength
bool valid_keylength(size_t length) const
Definition: sym_algo.h:56
Botan::SymmetricAlgorithm::name
virtual std::string name() const =0

void Botan::GHASH::start | ( | const uint8_t | nonce[],
|  | size_t | len
| ) |  |

Definition at line 165 of file ghash.cpp.

References BOTAN_ARG_CHECK.

166 {
167 BOTAN_ARG_CHECK(len == 16, "GHASH requires a 128-bit nonce");
168 m_nonce.assign(nonce, nonce + len);
169 m_ghash = m_H_ad;
170 }
BOTAN_ARG_CHECK
#define BOTAN_ARG_CHECK(expr, msg)
Definition: assert.h:37

void Botan::GHASH::update | ( | const uint8_t | in[],
|  | size_t | len
| ) |  |

Definition at line 190 of file ghash.cpp.

References ghash_update(), and Botan::SymmetricAlgorithm::verify_key_set().

191 {
192 verify_key_set(m_ghash.size() == GCM_BS);
193 m_text_len += length;
194 ghash_update(m_ghash, input, length);
195 }
Botan::GHASH::ghash_update
void ghash_update(secure_vector< uint8_t > &x, const uint8_t input[], size_t input_len)
Definition: ghash.cpp:96
Botan::SymmetricAlgorithm::verify_key_set
void verify_key_set(bool cond) const
Definition: sym_algo.h:89

void Botan::GHASH::update_associated_data | ( | const uint8_t | ad[],
|  | size_t | len
| ) |  |

Definition at line 183 of file ghash.cpp.

References ghash_update(), and Botan::SymmetricAlgorithm::verify_key_set().

184 {
185 verify_key_set(m_ghash.size() == GCM_BS);
186 m_ad_len += length;
187 ghash_update(m_ghash, ad, length);
188 }
Botan::GHASH::ghash_update
void ghash_update(secure_vector< uint8_t > &x, const uint8_t input[], size_t input_len)
Definition: ghash.cpp:96
Botan::SymmetricAlgorithm::verify_key_set
void verify_key_set(bool cond) const
Definition: sym_algo.h:89

bool Botan::SymmetricAlgorithm::valid_keylength | ( | size_t | length | ) | const
| inline inherited

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

Parameters

  length | the key length to be checked.

Returns
  true if the key length is valid.

Definition at line 56 of file sym_algo.h.

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

57 {
58 return key_spec().valid_keylength(length);
59 }
Botan::Key_Length_Specification::valid_keylength
bool valid_keylength(size_t length) const
Definition: key_spec.h:51
Botan::SymmetricAlgorithm::key_spec
virtual Key_Length_Specification key_spec() const =0

void Botan::SymmetricAlgorithm::verify_key_set | ( | bool | cond | ) | const
| inline protected inherited

Definition at line 89 of file sym_algo.h.

Referenced by Botan::Salsa20::cipher(), Botan::CTR_BE::cipher(), Botan::RC4::cipher(), Botan::SHAKE_128_Cipher::cipher(), Botan::ChaCha::cipher(), Botan::SHACAL2::decrypt_n(), Botan::Twofish::decrypt_n(), Botan::AES_128::decrypt_n(), Botan::KASUMI::decrypt_n(), Botan::Noekeon::decrypt_n(), Botan::CAST_256::decrypt_n(), Botan::SM4::decrypt_n(), Botan::DES::decrypt_n(), Botan::DESX::decrypt_n(), Botan::XTEA::decrypt_n(), Botan::Camellia_128::decrypt_n(), Botan::IDEA::decrypt_n(), Botan::CAST_128::decrypt_n(), Botan::MISTY1::decrypt_n(), Botan::SEED::decrypt_n(), Botan::Blowfish::decrypt_n(), Botan::Serpent::decrypt_n(), Botan::Threefish_512::decrypt_n(), Botan::Lion::decrypt_n(), Botan::ARIA_128::decrypt_n(), Botan::Camellia_192::decrypt_n(), Botan::TripleDES::decrypt_n(), Botan::ARIA_192::decrypt_n(), Botan::Camellia_256::decrypt_n(), Botan::GOST_28147_89::decrypt_n(), Botan::AES_192::decrypt_n(), Botan::ARIA_256::decrypt_n(), Botan::AES_256::decrypt_n(), Botan::SEED::encrypt_n(), Botan::CAST_256::encrypt_n(), Botan::SHACAL2::encrypt_n(), Botan::SM4::encrypt_n(), Botan::IDEA::encrypt_n(), Botan::KASUMI::encrypt_n(), Botan::AES_128::encrypt_n(), Botan::MISTY1::encrypt_n(), Botan::Noekeon::encrypt_n(), Botan::CAST_128::encrypt_n(), Botan::DES::encrypt_n(), Botan::Blowfish::encrypt_n(), Botan::Twofish::encrypt_n(), Botan::Camellia_128::encrypt_n(), Botan::XTEA::encrypt_n(), Botan::DESX::encrypt_n(), Botan::Threefish_512::encrypt_n(), Botan::Serpent::encrypt_n(), Botan::Lion::encrypt_n(), Botan::ARIA_128::encrypt_n(), Botan::Camellia_192::encrypt_n(), Botan::TripleDES::encrypt_n(), Botan::ARIA_192::encrypt_n(), Botan::Camellia_256::encrypt_n(), Botan::GOST_28147_89::encrypt_n(), Botan::AES_192::encrypt_n(), Botan::ARIA_256::encrypt_n(), Botan::AES_256::encrypt_n(), Botan::OCB_Encryption::finish(), Botan::OCB_Decryption::finish(), ghash_update(), Botan::CFB_Encryption::process(), Botan::CFB_Decryption::process(), Botan::Salsa20::seek(), Botan::CTR_BE::seek(), Botan::ChaCha::seek(), Botan::OCB_Mode::set_associated_data(), Botan::Salsa20::set_iv(), Botan::ChaCha::set_iv(), update(), update_associated_data(), and Botan::ChaCha::write_keystream().

90 {
91 if(cond == false)
92 throw_key_not_set_error();
93 }

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

- src/lib/modes/aead/gcm/ghash.h
- src/lib/modes/aead/gcm/ghash.cpp