Security Scol plugin
cmac.h
Go to the documentation of this file.
1// cmac.h - originally written and placed in the public domain by Wei Dai
2
6
7#ifndef CRYPTOPP_CMAC_H
8#define CRYPTOPP_CMAC_H
9
10#include "seckey.h"
11#include "secblock.h"
12
16#ifndef CRYPTOPP_CMAC_WIDE_BLOCK_CIPHERS
17# define CRYPTOPP_CMAC_WIDE_BLOCK_CIPHERS 1
18#endif // CRYPTOPP_CMAC_WIDE_BLOCK_CIPHERS
19
20NAMESPACE_BEGIN(CryptoPP)
21
22
24class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CMAC_Base : public MessageAuthenticationCode
25{
26public:
27
28 virtual ~CMAC_Base() {}
29 CMAC_Base() : m_counter(0) {}
30
31 void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params);
32 void Update(const byte *input, size_t length);
33 void TruncatedFinal(byte *mac, size_t size);
34 unsigned int DigestSize() const {return GetCipher().BlockSize();}
35 unsigned int OptimalBlockSize() const {return GetCipher().BlockSize();}
36 unsigned int OptimalDataAlignment() const {return GetCipher().OptimalDataAlignment();}
37 std::string AlgorithmProvider() const {return GetCipher().AlgorithmProvider();}
38
39protected:
40 friend class EAX_Base;
41
42 const BlockCipher & GetCipher() const {return const_cast<CMAC_Base*>(this)->AccessCipher();}
43 virtual BlockCipher & AccessCipher() =0;
44
45 void ProcessBuf();
46 SecByteBlock m_reg;
47 unsigned int m_counter;
48};
49
55template <class T>
56class CMAC : public MessageAuthenticationCodeImpl<CMAC_Base, CMAC<T> >, public SameKeyLengthAs<T>
57{
58public:
60 CMAC() {}
64 CMAC(const byte *key, size_t length=SameKeyLengthAs<T>::DEFAULT_KEYLENGTH)
65 {this->SetKey(key, length);}
66
67 static std::string StaticAlgorithmName() {return std::string("CMAC(") + T::StaticAlgorithmName() + ")";}
68
69private:
70 BlockCipher & AccessCipher() {return m_cipher;}
71 typename T::Encryption m_cipher;
72};
73
74NAMESPACE_END
75
76#endif
Interface for one direction (encryption or decryption) of a block cipher.
Definition cryptlib.h:1283
CMAC base implementation.
Definition cmac.h:25
std::string AlgorithmProvider() const
Retrieve the provider of this algorithm.
Definition cmac.h:37
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition cmac.h:36
unsigned int OptimalBlockSize() const
Provides the input block size most efficient for this hash.
Definition cmac.h:35
unsigned int DigestSize() const
Definition cmac.h:34
CMAC message authentication code.
Definition cmac.h:57
CMAC()
Construct a CMAC.
Definition cmac.h:60
CMAC(const byte *key, size_t length=SameKeyLengthAs< T >::DEFAULT_KEYLENGTH)
Construct a CMAC.
Definition cmac.h:64
EAX block cipher base implementation.
Definition eax.h:19
Interface for message authentication codes.
Definition cryptlib.h:1299
Provides a base implementation of Algorithm and SimpleKeyingInterface for message authentication code...
Definition seckey.h:363
Interface for retrieving values given their names.
Definition cryptlib.h:322
Provides key lengths based on another class's key length.
Definition seckey.h:218
Classes and functions for secure memory allocations.
Classes and functions for implementing secret key algorithms.