Botan  2.8.0
Crypto and TLS for C++11
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 
13 namespace Botan {
14 
15 /**
16 * GCM's GHASH
17 * This is not intended for general use, but is exposed to allow
18 * shared code between GCM and GMAC
19 */
21  {
22  public:
23  void set_associated_data(const uint8_t ad[], size_t ad_len);
24 
25  secure_vector<uint8_t> nonce_hash(const uint8_t nonce[], size_t len);
26 
27  void start(const uint8_t nonce[], size_t len);
28 
29  /*
30  * Assumes input len is multiple of 16
31  */
32  void update(const uint8_t in[], size_t len);
33 
34  /*
35  * Incremental update of associated data
36  */
37  void update_associated_data(const uint8_t ad[], size_t len);
38 
39  secure_vector<uint8_t> final();
40 
42  { return Key_Length_Specification(16); }
43 
44  void clear() override;
45 
46  void reset();
47 
48  std::string name() const override { return "GHASH"; }
49 
50  std::string provider() const;
51 
52  void ghash_update(secure_vector<uint8_t>& x,
53  const uint8_t input[], size_t input_len);
54 
55  void add_final_block(secure_vector<uint8_t>& x,
56  size_t ad_len, size_t pt_len);
57  private:
58  void key_schedule(const uint8_t key[], size_t key_len) override;
59 
60  void gcm_multiply(secure_vector<uint8_t>& x,
61  const uint8_t input[],
62  size_t blocks);
63 
64  static const size_t GCM_BS = 16;
65 
68  secure_vector<uint8_t> m_ghash;
69  secure_vector<uint8_t> m_nonce;
72  size_t m_ad_len = 0;
73  size_t m_text_len = 0;
74  };
75 
76 }
77 
78 #endif
Key_Length_Specification key_spec() const override
Definition: ghash.h:41
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
Definition: alg_id.cpp:13
int(* update)(CTX *, const void *, CC_LONG len)
std::string name() const override
Definition: ghash.h:48
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88