- Main Page
- Namespaces
- Classes
- Files

# vmac.h

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