Botan  2.1.0
Crypto and TLS for C++11
gmac.h
Go to the documentation of this file.
1 /*
2  * GMAC
3  * (C) 2016 Matthias Gierlings, RenĂ© Korthaus
4  *
5  * Botan is released under the Simplified BSD License (see license.txt)
6  */
7 
8 #ifndef BOTAN_GMAC_H__
9 #define BOTAN_GMAC_H__
10 
11 #include <botan/gcm.h>
12 #include <botan/mac.h>
13 #include <botan/types.h>
14 #include <algorithm>
15 
16 namespace Botan {
17 
18 /**
19 * GMAC
20 */
21 class BOTAN_DLL GMAC : public MessageAuthenticationCode,
22  public GHASH
23 
24  {
25  public:
26  void clear() override;
27  std::string name() const override;
28  size_t output_length() const override;
29  MessageAuthenticationCode* clone() const override;
30 
31  /**
32  * Must be called to set the initialization vector prior to GMAC
33  * calculation.
34  *
35  * @param nonce Initialization vector.
36  * @param nonce_len size of initialization vector.
37  */
38  void start(const uint8_t nonce[], size_t nonce_len);
39 
40  /**
41  * Must be called to set the initialization vector prior to GMAC
42  * calculation.
43  *
44  * @param nonce Initialization vector.
45  */
46  void start(const secure_vector<uint8_t>& nonce);
47 
48  /**
49  * Must be called to set the initialization vector prior to GMAC
50  * calculation.
51  *
52  * @param nonce Initialization vector.
53  */
54  void start(const std::vector<uint8_t>& nonce);
55 
57  {
58  return m_cipher->key_spec();
59  }
60 
61  /**
62  * Creates a new GMAC instance.
63  *
64  * @param cipher the underlying block cipher to use
65  */
66  explicit GMAC(BlockCipher* cipher);
67 
68  GMAC(const GMAC&) = delete;
69  GMAC& operator=(const GMAC&) = delete;
70 
71  private:
72  void add_data(const uint8_t[], size_t) override;
73  void final_result(uint8_t[]) override;
74  void start_msg(const uint8_t nonce[], size_t nonce_len) override;
75  void key_schedule(const uint8_t key[], size_t size) override;
76 
77  static const size_t GCM_BS = 16;
78  secure_vector<uint8_t> m_aad_buf;
79  std::unique_ptr<BlockCipher> m_cipher;
80  bool m_initialized;
81  };
82 
83 }
84 #endif
Key_Length_Specification key_spec() const override
Definition: gmac.h:56
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Definition: alg_id.cpp:13