Security Scol plugin
cbcmac.h
Go to the documentation of this file.
1// cbcmac.h - originally written and placed in the public domain by Wei Dai
2
6
7#ifndef CRYPTOPP_CBCMAC_H
8#define CRYPTOPP_CBCMAC_H
9
10#include "seckey.h"
11#include "secblock.h"
12
13NAMESPACE_BEGIN(CryptoPP)
14
15
17class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_MAC_Base : public MessageAuthenticationCode
18{
19public:
20 CBC_MAC_Base() : m_counter(0) {}
21
22 void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params);
23 void Update(const byte *input, size_t length);
24 void TruncatedFinal(byte *mac, size_t size);
25 unsigned int DigestSize() const {return const_cast<CBC_MAC_Base*>(this)->AccessCipher().BlockSize();}
26
27protected:
28 virtual BlockCipher & AccessCipher() =0;
29
30private:
31 void ProcessBuf();
32 SecByteBlock m_reg;
33 unsigned int m_counter;
34};
35
42template <class T>
43class CBC_MAC : public MessageAuthenticationCodeImpl<CBC_MAC_Base, CBC_MAC<T> >, public SameKeyLengthAs<T>
44{
45public:
51 CBC_MAC(const byte *key, size_t length=SameKeyLengthAs<T>::DEFAULT_KEYLENGTH)
52 {this->SetKey(key, length);}
53
54 static std::string StaticAlgorithmName() {return std::string("CBC-MAC(") + T::StaticAlgorithmName() + ")";}
55
56private:
57 BlockCipher & AccessCipher() {return m_cipher;}
58 typename T::Encryption m_cipher;
59};
60
61NAMESPACE_END
62
63#endif
Interface for one direction (encryption or decryption) of a block cipher.
Definition cryptlib.h:1283
CBC-MAC base class.
Definition cbcmac.h:18
unsigned int DigestSize() const
Definition cbcmac.h:25
CBC-MAC.
Definition cbcmac.h:44
CBC_MAC()
Construct a CBC_MAC.
Definition cbcmac.h:47
CBC_MAC(const byte *key, size_t length=SameKeyLengthAs< T >::DEFAULT_KEYLENGTH)
Construct a CBC_MAC.
Definition cbcmac.h:51
virtual unsigned int BlockSize() const
Provides the block size of the compression function.
Definition cryptlib.h:1165
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.