Botan
1.11.15
|
00001 /* 00002 * CMAC 00003 * (C) 1999-2007,2014 Jack Lloyd 00004 * 00005 * Botan is released under the Simplified BSD License (see license.txt) 00006 */ 00007 00008 #ifndef BOTAN_CMAC_H__ 00009 #define BOTAN_CMAC_H__ 00010 00011 #include <botan/mac.h> 00012 #include <botan/block_cipher.h> 00013 00014 namespace Botan { 00015 00016 /** 00017 * CMAC, also known as OMAC1 00018 */ 00019 class BOTAN_DLL CMAC : public MessageAuthenticationCode 00020 { 00021 public: 00022 std::string name() const; 00023 size_t output_length() const { return m_cipher->block_size(); } 00024 MessageAuthenticationCode* clone() const; 00025 00026 void clear(); 00027 00028 Key_Length_Specification key_spec() const 00029 { 00030 return m_cipher->key_spec(); 00031 } 00032 00033 /** 00034 * CMAC's polynomial doubling operation 00035 * @param in the input 00036 * @param polynomial the byte value of the polynomial 00037 */ 00038 static secure_vector<byte> poly_double(const secure_vector<byte>& in); 00039 00040 /** 00041 * @param cipher the underlying block cipher to use 00042 */ 00043 CMAC(BlockCipher* cipher); 00044 00045 static CMAC* make(const Spec& spec); 00046 00047 CMAC(const CMAC&) = delete; 00048 CMAC& operator=(const CMAC&) = delete; 00049 private: 00050 void add_data(const byte[], size_t); 00051 void final_result(byte[]); 00052 void key_schedule(const byte[], size_t); 00053 00054 std::unique_ptr<BlockCipher> m_cipher; 00055 secure_vector<byte> m_buffer, m_state, m_B, m_P; 00056 size_t m_position; 00057 }; 00058 00059 } 00060 00061 #endif