File indexing completed on 2025-01-18 09:55:10
0001
0002
0003
0004
0005
0006
0007 #ifndef CRYPTOPP_VMAC_H
0008 #define CRYPTOPP_VMAC_H
0009
0010 #include "cryptlib.h"
0011 #include "iterhash.h"
0012 #include "seckey.h"
0013
0014
0015
0016 #if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_MIXED_ASM)
0017 # define CRYPTOPP_DISABLE_VMAC_ASM 1
0018 #endif
0019
0020 NAMESPACE_BEGIN(CryptoPP)
0021
0022
0023
0024 class VMAC_Base : public IteratedHashBase<word64, MessageAuthenticationCode>
0025 {
0026 public:
0027 std::string AlgorithmName() const {return std::string("VMAC(") + GetCipher().AlgorithmName() + ")-" + IntToString(DigestSize()*8);}
0028 std::string AlgorithmProvider() const {return GetCipher().AlgorithmProvider();}
0029 unsigned int IVSize() const {return GetCipher().BlockSize();}
0030 unsigned int MinIVLength() const {return 1;}
0031 void Resynchronize(const byte *nonce, int length=-1);
0032 void GetNextIV(RandomNumberGenerator &rng, byte *IV);
0033 unsigned int DigestSize() const {return m_is128 ? 16 : 8;};
0034 void UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs ¶ms);
0035 void TruncatedFinal(byte *mac, size_t size);
0036 unsigned int BlockSize() const {return m_L1KeyLength;}
0037 ByteOrder GetByteOrder() const {return LITTLE_ENDIAN_ORDER;}
0038 unsigned int OptimalDataAlignment() const;
0039
0040 protected:
0041 virtual BlockCipher & AccessCipher() =0;
0042 virtual int DefaultDigestSize() const =0;
0043 const BlockCipher & GetCipher() const {return const_cast<VMAC_Base *>(this)->AccessCipher();}
0044 void HashEndianCorrectedBlock(const word64 *data);
0045 size_t HashMultipleBlocks(const word64 *input, size_t length);
0046 void Init() {}
0047 word64* StateBuf() {return NULLPTR;}
0048 word64* DataBuf() {return (word64 *)(void*)m_data();}
0049
0050 void VHASH_Update_SSE2(const word64 *data, size_t blocksRemainingInWord64, int tagPart);
0051 template <bool T_128BitTag>
0052 void VHASH_Update_Template(const word64 *data, size_t blockRemainingInWord128);
0053 void VHASH_Update(const word64 *data, size_t blocksRemainingInWord128);
0054
0055 CRYPTOPP_BLOCK_1(polyState, word64, (m_is128 ? 8 : 4))
0056 CRYPTOPP_BLOCK_2(nhKey, word64, m_L1KeyLength/sizeof(word64) + 2*m_is128)
0057 CRYPTOPP_BLOCK_3(data, byte, m_L1KeyLength)
0058 CRYPTOPP_BLOCK_4(l3Key, word64, (m_is128 ? 4 : 2))
0059 CRYPTOPP_BLOCK_5(nonce, byte, IVSize())
0060 CRYPTOPP_BLOCK_6(pad, byte, IVSize())
0061 CRYPTOPP_BLOCKS_END(6)
0062
0063 bool m_is128, m_padCached, m_isFirstBlock;
0064 unsigned int m_L1KeyLength;
0065 };
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077 template <class T_BlockCipher, int T_DigestBitSize = 128>
0078 class VMAC : public SimpleKeyingInterfaceImpl<VMAC_Base, SameKeyLengthAs<T_BlockCipher, SimpleKeyingInterface::UNIQUE_IV, T_BlockCipher::BLOCKSIZE> >
0079 {
0080 public:
0081 static std::string StaticAlgorithmName() {return std::string("VMAC(") + T_BlockCipher::StaticAlgorithmName() + ")-" + IntToString(T_DigestBitSize);}
0082
0083 private:
0084 BlockCipher & AccessCipher() {return m_cipher;}
0085 int DefaultDigestSize() const {return T_DigestBitSize/8;}
0086 typename T_BlockCipher::Encryption m_cipher;
0087 };
0088
0089 NAMESPACE_END
0090
0091 #endif