Botan  2.1.0
Crypto and TLS for C++11
cmac.h
Go to the documentation of this file.
1 /*
2 * CMAC
3 * (C) 1999-2007,2014 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_CMAC_H__
9 #define BOTAN_CMAC_H__
10 
11 #include <botan/mac.h>
12 #include <botan/block_cipher.h>
13 
14 namespace Botan {
15 
16 /**
17 * CMAC, also known as OMAC1
18 */
19 class BOTAN_DLL CMAC final : public MessageAuthenticationCode
20  {
21  public:
22  std::string name() const override;
23  size_t output_length() const override { return m_cipher->block_size(); }
24  MessageAuthenticationCode* clone() const override;
25 
26  void clear() override;
27 
29  {
30  return m_cipher->key_spec();
31  }
32 
33  /**
34  * CMAC's polynomial doubling operation
35  * @param in the input
36  */
37  static secure_vector<uint8_t> poly_double(const secure_vector<uint8_t>& in);
38 
39  /**
40  * @param cipher the block cipher to use
41  */
42  explicit CMAC(BlockCipher* cipher);
43 
44  CMAC(const CMAC&) = delete;
45  CMAC& operator=(const CMAC&) = delete;
46  private:
47  void add_data(const uint8_t[], size_t) override;
48  void final_result(uint8_t[]) override;
49  void key_schedule(const uint8_t[], size_t) override;
50 
51  std::unique_ptr<BlockCipher> m_cipher;
52  secure_vector<uint8_t> m_buffer, m_state, m_B, m_P;
53  size_t m_position;
54  };
55 
56 }
57 
58 #endif
size_t output_length() const override
Definition: cmac.h:23
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Definition: alg_id.cpp:13
Key_Length_Specification key_spec() const override
Definition: cmac.h:28