vmac.h
Go to the documentation of this file.
// vmac.h - written and placed in the public domain by Wei Dai
//! \file vmac.h
//! \brief Classes for the VMAC message authentication code
#ifndef CRYPTOPP_VMAC_H
#define CRYPTOPP_VMAC_H
#include "cryptlib.h"
#include "iterhash.h"
#include "seckey.h"
#if CRYPTOPP_BOOL_X32
# define CRYPTOPP_DISABLE_VMAC_ASM
#endif
NAMESPACE_BEGIN(CryptoPP)
//! \class VMAC_Base
//! \brief VMAC message authentication code base class
class VMAC_Base : public IteratedHashBase<word64, MessageAuthenticationCode>
{
public:
std::string AlgorithmName() const {return std::string("VMAC(") + GetCipher().AlgorithmName() + ")-" + IntToString(DigestSize()*8);}
unsigned int IVSize() const {return GetCipher().BlockSize();}
unsigned int MinIVLength() const {return 1;}
void Resynchronize(const byte *nonce, int length=-1);
void GetNextIV(RandomNumberGenerator &rng, byte *IV);
unsigned int DigestSize() const {return m_is128 ? 16 : 8;};
void UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs &params);
void TruncatedFinal(byte *mac, size_t size);
unsigned int BlockSize() const {return m_L1KeyLength;}
ByteOrder GetByteOrder() const {return LITTLE_ENDIAN_ORDER;}
unsigned int OptimalDataAlignment() const;
protected:
virtual BlockCipher & AccessCipher() =0;
virtual int DefaultDigestSize() const =0;
const BlockCipher & GetCipher() const {return const_cast<VMAC_Base *>(this)->AccessCipher();}
void HashEndianCorrectedBlock(const word64 *data);
size_t HashMultipleBlocks(const word64 *input, size_t length);
void Init() {}
word64* StateBuf() {return NULL;}
word64* DataBuf() {return (word64 *)(void*)m_data();}
void VHASH_Update_SSE2(const word64 *data, size_t blocksRemainingInWord64, int tagPart);
#if !(defined(_MSC_VER) && _MSC_VER < 1300) // can't use function template here with VC6
template <bool T_128BitTag>
#endif
void VHASH_Update_Template(const word64 *data, size_t blockRemainingInWord128);
void VHASH_Update(const word64 *data, size_t blocksRemainingInWord128);
CRYPTOPP_BLOCK_1(polyState, word64, 4*(m_is128+1))
CRYPTOPP_BLOCK_2(nhKey, word64, m_L1KeyLength/sizeof(word64) + 2*m_is128)
CRYPTOPP_BLOCK_3(data, byte, m_L1KeyLength)
CRYPTOPP_BLOCK_4(l3Key, word64, 2*(m_is128+1))
CRYPTOPP_BLOCK_5(nonce, byte, IVSize())
CRYPTOPP_BLOCK_6(pad, byte, IVSize())
CRYPTOPP_BLOCKS_END(6)
bool m_is128, m_padCached, m_isFirstBlock;
int m_L1KeyLength;
};
//! \class VMAC
//! \brief VMAC message authentication code
//! \tparam T_BlockCipher block cipher
//! \tparam T_DigestBitSize digest size, in bits
//! \details VMAC is a block cipher-based message authentication code algorithm
//! using a universal hash proposed by Ted Krovetz and Wei Dai in April 2007. The
//! algorithm was designed for high performance backed by a formal analysis.
//! \details The implementation is based on Ted Krovetz's public domain vmac.c
//! and <a href="http://tools.ietf.org/html/draft-krovetz-vmac-01">draft-krovetz-vmac-01.txt</a>.
//! \sa <a href="http://www.cryptolounge.org/wiki/VMAC">VMAC</a>.
template <class T_BlockCipher, int T_DigestBitSize = 128>
class VMAC : public SimpleKeyingInterfaceImpl<VMAC_Base, SameKeyLengthAs<T_BlockCipher, SimpleKeyingInterface::UNIQUE_IV, T_BlockCipher::BLOCKSIZE> >
{
public:
static std::string StaticAlgorithmName() {return std::string("VMAC(") + T_BlockCipher::StaticAlgorithmName() + ")-" + IntToString(T_DigestBitSize);}
private:
BlockCipher & AccessCipher() {return m_cipher;}
int DefaultDigestSize() const {return T_DigestBitSize/8;}
typename T_BlockCipher::Encryption m_cipher;
};
NAMESPACE_END
#endif
VMAC_Base
VMAC message authentication code base class.
Definition: vmac.h:21
SimpleKeyingInterfaceImpl
Provides a base implementation of SimpleKeyingInterface.
Definition: seckey.h:278
SimpleKeyingInterface
Interface for algorithms that take byte strings as keys.
Definition: cryptlib.h:524
LITTLE_ENDIAN_ORDER
@ LITTLE_ENDIAN_ORDER
byte order is little-endian
Definition: cryptlib.h:125
VMAC_Base::DigestSize
unsigned int DigestSize() const
Provides the digest size of the hash.
Definition: vmac.h:29
VMAC_Base::AlgorithmName
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: vmac.h:24
VMAC_Base::BlockSize
unsigned int BlockSize() const
Provides the block size of the compression function.
Definition: vmac.h:32
RandomNumberGenerator
Interface for random number generators.
Definition: cryptlib.h:1186
VMAC_Base::IVSize
unsigned int IVSize() const
Returns length of the IV accepted by this object.
Definition: vmac.h:25
SameKeyLengthAs
Provides key lengths based on another class's key length.
Definition: seckey.h:237
IntToString
std::string IntToString(T value, unsigned int base=10)
Converts a value to a string.
Definition: misc.h:530
ByteOrder
ByteOrder
Provides the byte ordering.
Definition: cryptlib.h:123
seckey.h
Classes and functions for implementing secret key algorithms.
IteratedHashBase
_
Definition: iterhash.h:21
VMAC
VMAC message authentication code.
Definition: vmac.h:76
CryptoPP
Crypto++ library namespace.
BlockCipher
Interface for one direction (encryption or decryption) of a block cipher.
Definition: cryptlib.h:1091
MessageAuthenticationCode
Interface for message authentication codes.
Definition: cryptlib.h:1107
NameValuePairs
Interface for retrieving values given their names.
Definition: cryptlib.h:277
cryptlib.h
Abstract base classes that provide a uniform interface to this library.
VMAC_Base::MinIVLength
unsigned int MinIVLength() const
Provides the minimum size of an IV.
Definition: vmac.h:26