Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.6 KiB

  1. #ifndef CRYPTOPP_VMAC_H
  2. #define CRYPTOPP_VMAC_H
  3. #include "iterhash.h"
  4. #include "seckey.h"
  5. NAMESPACE_BEGIN(CryptoPP)
  6. /// .
  7. class VMAC_Base : public IteratedHashBase<word64, MessageAuthenticationCode>
  8. {
  9. public:
  10. std::string AlgorithmName() const {return std::string("VMAC(") + GetCipher().AlgorithmName() + ")-" + IntToString(DigestSize()*8);}
  11. unsigned int IVSize() const {return GetCipher().BlockSize();}
  12. unsigned int MinIVLength() const {return 1;}
  13. void Resynchronize(const byte *nonce, int length=-1);
  14. void GetNextIV(RandomNumberGenerator &rng, byte *IV);
  15. unsigned int DigestSize() const {return m_is128 ? 16 : 8;};
  16. void UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs &params);
  17. void TruncatedFinal(byte *mac, size_t size);
  18. unsigned int BlockSize() const {return m_L1KeyLength;}
  19. ByteOrder GetByteOrder() const {return LITTLE_ENDIAN_ORDER;}
  20. protected:
  21. virtual BlockCipher & AccessCipher() =0;
  22. virtual int DefaultDigestSize() const =0;
  23. const BlockCipher & GetCipher() const {return const_cast<VMAC_Base *>(this)->AccessCipher();}
  24. void HashEndianCorrectedBlock(const word64 *data);
  25. size_t HashMultipleBlocks(const word64 *input, size_t length);
  26. void Init() {}
  27. word64* StateBuf() {return NULL;}
  28. word64* DataBuf() {return (word64 *)m_data();}
  29. void VHASH_Update_SSE2(const word64 *data, size_t blocksRemainingInWord64, int tagPart);
  30. #if !(defined(_MSC_VER) && _MSC_VER < 1300) // can't use function template here with VC6
  31. template <bool T_128BitTag>
  32. #endif
  33. void VHASH_Update_Template(const word64 *data, size_t blockRemainingInWord128);
  34. void VHASH_Update(const word64 *data, size_t blocksRemainingInWord128);
  35. CRYPTOPP_BLOCK_1(polyState, word64, 4*(m_is128+1))
  36. CRYPTOPP_BLOCK_2(nhKey, word64, m_L1KeyLength/sizeof(word64) + 2*m_is128)
  37. CRYPTOPP_BLOCK_3(data, byte, m_L1KeyLength)
  38. CRYPTOPP_BLOCK_4(l3Key, word64, 2*(m_is128+1))
  39. CRYPTOPP_BLOCK_5(nonce, byte, IVSize())
  40. CRYPTOPP_BLOCK_6(pad, byte, IVSize())
  41. CRYPTOPP_BLOCKS_END(6)
  42. bool m_is128, m_padCached, m_isFirstBlock;
  43. int m_L1KeyLength;
  44. };
  45. /// <a href="http://www.cryptolounge.org/wiki/VMAC">VMAC</a>
  46. template <class T_BlockCipher, int T_DigestBitSize = 128>
  47. class VMAC : public SimpleKeyingInterfaceImpl<VMAC_Base, SameKeyLengthAs<T_BlockCipher, SimpleKeyingInterface::UNIQUE_IV, T_BlockCipher::BLOCKSIZE> >
  48. {
  49. public:
  50. static std::string StaticAlgorithmName() {return std::string("VMAC(") + T_BlockCipher::StaticAlgorithmName() + ")-" + IntToString(T_DigestBitSize);}
  51. private:
  52. BlockCipher & AccessCipher() {return m_cipher;}
  53. int DefaultDigestSize() const {return T_DigestBitSize/8;}
  54. typename T_BlockCipher::Encryption m_cipher;
  55. };
  56. NAMESPACE_END
  57. #endif