source: git/src-cryptopp/cbcmac.h

Last change on this file was e230cb0, checked in by David Stainton <dstainton415@…>, at 2016-10-12T13:27:29Z

Add cryptopp from tag CRYPTOPP_5_6_5

  • Property mode set to 100644
File size: 1.6 KB
Line 
1// cbcmac.h - written and placed in the public domain by Wei Dai
2
3//! \file
4//! \headerfile cbcmac.h
5//! \brief Classes for CBC MAC
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//! _
16class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_MAC_Base : public MessageAuthenticationCode
17{
18public:
19        CBC_MAC_Base() : m_counter(0) {}
20
21        void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params);
22        void Update(const byte *input, size_t length);
23        void TruncatedFinal(byte *mac, size_t size);
24        unsigned int DigestSize() const {return const_cast<CBC_MAC_Base*>(this)->AccessCipher().BlockSize();}
25
26protected:
27        virtual BlockCipher & AccessCipher() =0;
28
29private:
30        void ProcessBuf();
31        SecByteBlock m_reg;
32        unsigned int m_counter;
33};
34
35//! <a href="http://www.weidai.com/scan-mirror/mac.html#CBC-MAC">CBC-MAC</a>
36/*! Compatible with FIPS 113. T should be a class derived from BlockCipherDocumentation.
37        Secure only for fixed length messages. For variable length messages use CMAC or DMAC.
38*/
39template <class T>
40class CBC_MAC : public MessageAuthenticationCodeImpl<CBC_MAC_Base, CBC_MAC<T> >, public SameKeyLengthAs<T>
41{
42public:
43        CBC_MAC() {}
44        CBC_MAC(const byte *key, size_t length=SameKeyLengthAs<T>::DEFAULT_KEYLENGTH)
45                {this->SetKey(key, length);}
46
47        static std::string StaticAlgorithmName() {return std::string("CBC-MAC(") + T::StaticAlgorithmName() + ")";}
48
49private:
50        BlockCipher & AccessCipher() {return m_cipher;}
51        typename T::Encryption m_cipher;
52};
53
54NAMESPACE_END
55
56#endif
Note: See TracBrowser for help on using the repository browser.