00001 #ifndef CRYPTOPP_VMAC_H
00002 #define CRYPTOPP_VMAC_H
00003
00004 #include "cryptlib.h"
00005 #include "iterhash.h"
00006 #include "seckey.h"
00007
00008 #if CRYPTOPP_BOOL_X32
00009 # define CRYPTOPP_DISABLE_VMAC_ASM
00010 #endif
00011
00012 NAMESPACE_BEGIN(CryptoPP)
00013
00014
00015
00016 class VMAC_Base : public IteratedHashBase<word64, MessageAuthenticationCode>
00017 {
00018 public:
00019 std::string AlgorithmName() const {return std::string("VMAC(") + GetCipher().AlgorithmName() + ")-" + IntToString(DigestSize()*8);}
00020 unsigned int IVSize() const {return GetCipher().BlockSize();}
00021 unsigned int MinIVLength() const {return 1;}
00022 void Resynchronize(const byte *nonce, int length=-1);
00023 void GetNextIV(RandomNumberGenerator &rng, byte *IV);
00024 unsigned int DigestSize() const {return m_is128 ? 16 : 8;};
00025 void UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs ¶ms);
00026 void TruncatedFinal(byte *mac, size_t size);
00027 unsigned int BlockSize() const {return m_L1KeyLength;}
00028 ByteOrder GetByteOrder() const {return LITTLE_ENDIAN_ORDER;}
00029 unsigned int OptimalDataAlignment() const;
00030
00031 protected:
00032 virtual BlockCipher & AccessCipher() =0;
00033 virtual int DefaultDigestSize() const =0;
00034 const BlockCipher & GetCipher() const {return const_cast<VMAC_Base *>(this)->AccessCipher();}
00035 void HashEndianCorrectedBlock(const word64 *data);
00036 size_t HashMultipleBlocks(const word64 *input, size_t length);
00037 void Init() {}
00038 word64* StateBuf() {return NULL;}
00039 word64* DataBuf() {return (word64 *)m_data();}
00040
00041 void VHASH_Update_SSE2(const word64 *data, size_t blocksRemainingInWord64, int tagPart);
00042 #if !(defined(_MSC_VER) && _MSC_VER < 1300) // can't use function template here with VC6
00043 template <bool T_128BitTag>
00044 #endif
00045 void VHASH_Update_Template(const word64 *data, size_t blockRemainingInWord128);
00046 void VHASH_Update(const word64 *data, size_t blocksRemainingInWord128);
00047
00048 #if CRYPTOPP_DOXYGEN_PROCESSING
00049 private:
00050 #endif
00051
00052 CRYPTOPP_BLOCK_1(polyState, word64, 4*(m_is128+1))
00053 CRYPTOPP_BLOCK_2(nhKey, word64, m_L1KeyLength/sizeof(word64) + 2*m_is128)
00054 CRYPTOPP_BLOCK_3(data, byte, m_L1KeyLength)
00055 CRYPTOPP_BLOCK_4(l3Key, word64, 2*(m_is128+1))
00056 CRYPTOPP_BLOCK_5(nonce, byte, IVSize())
00057 CRYPTOPP_BLOCK_6(pad, byte, IVSize())
00058 CRYPTOPP_BLOCKS_END(6)
00059
00060 bool m_is128, m_padCached, m_isFirstBlock;
00061 int m_L1KeyLength;
00062 };
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 template <class T_BlockCipher, int T_DigestBitSize = 128>
00073 class VMAC : public SimpleKeyingInterfaceImpl<VMAC_Base, SameKeyLengthAs<T_BlockCipher, SimpleKeyingInterface::UNIQUE_IV, T_BlockCipher::BLOCKSIZE> >
00074 {
00075 public:
00076 static std::string StaticAlgorithmName() {return std::string("VMAC(") + T_BlockCipher::StaticAlgorithmName() + ")-" + IntToString(T_DigestBitSize);}
00077
00078 private:
00079 BlockCipher & AccessCipher() {return m_cipher;}
00080 int DefaultDigestSize() const {return T_DigestBitSize/8;}
00081 typename T_BlockCipher::Encryption m_cipher;
00082 };
00083
00084 NAMESPACE_END
00085
00086 #endif