Crypto++
vmac.h
1 #ifndef CRYPTOPP_VMAC_H
2 #define CRYPTOPP_VMAC_H
3 
4 #include "iterhash.h"
5 #include "seckey.h"
6 
7 NAMESPACE_BEGIN(CryptoPP)
8 
9 /// .
11 {
12 public:
13  std::string AlgorithmName() const {return std::string("VMAC(") + GetCipher().AlgorithmName() + ")-" + IntToString(DigestSize()*8);}
14  unsigned int IVSize() const {return GetCipher().BlockSize();}
15  unsigned int MinIVLength() const {return 1;}
16  void Resynchronize(const byte *nonce, int length=-1);
17  void GetNextIV(RandomNumberGenerator &rng, byte *IV);
18  unsigned int DigestSize() const {return m_is128 ? 16 : 8;};
19  void UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs &params);
20  void TruncatedFinal(byte *mac, size_t size);
21  unsigned int BlockSize() const {return m_L1KeyLength;}
22  ByteOrder GetByteOrder() const {return LITTLE_ENDIAN_ORDER;}
23 
24 protected:
25  virtual BlockCipher & AccessCipher() =0;
26  virtual int DefaultDigestSize() const =0;
27  const BlockCipher & GetCipher() const {return const_cast<VMAC_Base *>(this)->AccessCipher();}
28  void HashEndianCorrectedBlock(const word64 *data);
29  size_t HashMultipleBlocks(const word64 *input, size_t length);
30  void Init() {}
31  word64* StateBuf() {return NULL;}
32  word64* DataBuf() {return (word64 *)m_data();}
33 
34  void VHASH_Update_SSE2(const word64 *data, size_t blocksRemainingInWord64, int tagPart);
35 #if !(defined(_MSC_VER) && _MSC_VER < 1300) // can't use function template here with VC6
36  template <bool T_128BitTag>
37 #endif
38  void VHASH_Update_Template(const word64 *data, size_t blockRemainingInWord128);
39  void VHASH_Update(const word64 *data, size_t blocksRemainingInWord128);
40 
41  CRYPTOPP_BLOCK_1(polyState, word64, 4*(m_is128+1))
42  CRYPTOPP_BLOCK_2(nhKey, word64, m_L1KeyLength/sizeof(word64) + 2*m_is128)
43  CRYPTOPP_BLOCK_3(data, byte, m_L1KeyLength)
44  CRYPTOPP_BLOCK_4(l3Key, word64, 2*(m_is128+1))
45  CRYPTOPP_BLOCK_5(nonce, byte, IVSize())
46  CRYPTOPP_BLOCK_6(pad, byte, IVSize())
47  CRYPTOPP_BLOCKS_END(6)
48 
49  bool m_is128, m_padCached, m_isFirstBlock;
50  int m_L1KeyLength;
51 };
52 
53 /// <a href="http://www.cryptolounge.org/wiki/VMAC">VMAC</a>
54 template <class T_BlockCipher, int T_DigestBitSize = 128>
55 class VMAC : public SimpleKeyingInterfaceImpl<VMAC_Base, SameKeyLengthAs<T_BlockCipher, SimpleKeyingInterface::UNIQUE_IV, T_BlockCipher::BLOCKSIZE> >
56 {
57 public:
58  static std::string StaticAlgorithmName() {return std::string("VMAC(") + T_BlockCipher::StaticAlgorithmName() + ")-" + IntToString(T_DigestBitSize);}
59 
60 private:
61  BlockCipher & AccessCipher() {return m_cipher;}
62  int DefaultDigestSize() const {return T_DigestBitSize/8;}
63  typename T_BlockCipher::Encryption m_cipher;
64 };
65 
66 NAMESPACE_END
67 
68 #endif
std::string AlgorithmName() const
returns name of this algorithm, not universally implemented yet
Definition: vmac.h:13
VMAC
Definition: vmac.h:55
interface for message authentication codes
Definition: cryptlib.h:617
unsigned int DigestSize() const
size of the hash/digest/MAC returned by Final()
Definition: vmac.h:18
Definition: vmac.h:10
unsigned int BlockSize() const
block size of underlying compression function, or 0 if not block based
Definition: vmac.h:21
interface for random number generators
Definition: cryptlib.h:668
interface for one direction (encryption or decryption) of a block cipher
Definition: cryptlib.h:603
keying interface for crypto algorithms that take byte strings as keys
Definition: cryptlib.h:346
support query of key length that's the same as another class
Definition: seckey.h:114
unsigned int MinIVLength() const
returns minimal length of IVs accepted by this object
Definition: vmac.h:15
interface for retrieving values given their names
Definition: cryptlib.h:224