Botan 3.4.0
Crypto and TLS for C&
ghash.h
Go to the documentation of this file.
1/*
2* (C) 2013 Jack Lloyd
3* (C) 2016 Daniel Neus, Rohde & Schwarz Cybersecurity
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_GCM_GHASH_H_
9#define BOTAN_GCM_GHASH_H_
10
11#include <botan/sym_algo.h>
12
13namespace Botan {
14
15/**
16* GCM's GHASH
17*/
19 public:
20 void set_associated_data(std::span<const uint8_t> ad);
21
22 void nonce_hash(secure_vector<uint8_t>& y0, std::span<const uint8_t> nonce);
23
24 void start(std::span<const uint8_t> nonce);
25
26 /*
27 * Assumes input len is multiple of 16
28 */
29 void update(std::span<const uint8_t> in);
30
31 /*
32 * Incremental update of associated data
33 */
34 void update_associated_data(std::span<const uint8_t> ad);
35
36 void final(std::span<uint8_t> out);
37
39
40 bool has_keying_material() const override;
41
42 void clear() override;
43
44 void reset();
45
46 std::string name() const override { return "GHASH"; }
47
48 std::string provider() const;
49
50 void ghash_update(secure_vector<uint8_t>& x, std::span<const uint8_t> input);
51
52 void add_final_block(secure_vector<uint8_t>& x, size_t ad_len, size_t pt_len);
53
54 private:
55#if defined(BOTAN_HAS_GHASH_CLMUL_CPU)
56 static void ghash_precompute_cpu(const uint8_t H[16], uint64_t H_pow[4 * 2]);
57
58 static void ghash_multiply_cpu(uint8_t x[16], const uint64_t H_pow[4 * 2], const uint8_t input[], size_t blocks);
59#endif
60
61#if defined(BOTAN_HAS_GHASH_CLMUL_VPERM)
62 static void ghash_multiply_vperm(uint8_t x[16], const uint64_t HM[256], const uint8_t input[], size_t blocks);
63#endif
64
65 void key_schedule(std::span<const uint8_t> key) override;
66
67 void ghash_multiply(secure_vector<uint8_t>& x, std::span<const uint8_t> input, size_t blocks);
68
69 static const size_t GCM_BS = 16;
70
77 size_t m_ad_len = 0;
78 size_t m_text_len = 0;
79};
80
81} // namespace Botan
82
83#endif
void update_associated_data(std::span< const uint8_t > ad)
Definition ghash.cpp:165
std::string provider() const
Definition ghash.cpp:20
void nonce_hash(secure_vector< uint8_t > &y0, std::span< const uint8_t > nonce)
Definition ghash.cpp:204
void ghash_update(secure_vector< uint8_t > &x, std::span< const uint8_t > input)
Definition ghash.cpp:83
std::string name() const override
Definition ghash.h:46
void add_final_block(secure_vector< uint8_t > &x, size_t ad_len, size_t pt_len)
Definition ghash.cpp:177
void clear() override
Definition ghash.cpp:211
void reset()
Definition ghash.cpp:217
void start(std::span< const uint8_t > nonce)
Definition ghash.cpp:148
Key_Length_Specification key_spec() const override
Definition ghash.h:38
bool has_keying_material() const override
Definition ghash.cpp:106
void set_associated_data(std::span< const uint8_t > ad)
Definition ghash.cpp:154
int(* update)(CTX *, const void *, CC_LONG len)
int(* final)(unsigned char *, CTX *)
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61