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.

91 lines
2.6 KiB

  1. #ifndef CRYPTOPP_EAX_H
  2. #define CRYPTOPP_EAX_H
  3. #include "authenc.h"
  4. #include "modes.h"
  5. #include "cmac.h"
  6. NAMESPACE_BEGIN(CryptoPP)
  7. //! .
  8. class CRYPTOPP_NO_VTABLE EAX_Base : public AuthenticatedSymmetricCipherBase
  9. {
  10. public:
  11. // AuthenticatedSymmetricCipher
  12. std::string AlgorithmName() const
  13. {return GetMAC().GetCipher().AlgorithmName() + std::string("/EAX");}
  14. size_t MinKeyLength() const
  15. {return GetMAC().MinKeyLength();}
  16. size_t MaxKeyLength() const
  17. {return GetMAC().MaxKeyLength();}
  18. size_t DefaultKeyLength() const
  19. {return GetMAC().DefaultKeyLength();}
  20. size_t GetValidKeyLength(size_t n) const
  21. {return GetMAC().GetValidKeyLength(n);}
  22. bool IsValidKeyLength(size_t n) const
  23. {return GetMAC().IsValidKeyLength(n);}
  24. unsigned int OptimalDataAlignment() const
  25. {return GetMAC().OptimalDataAlignment();}
  26. IV_Requirement IVRequirement() const
  27. {return UNIQUE_IV;}
  28. unsigned int IVSize() const
  29. {return GetMAC().TagSize();}
  30. unsigned int MinIVLength() const
  31. {return 0;}
  32. unsigned int MaxIVLength() const
  33. {return UINT_MAX;}
  34. unsigned int DigestSize() const
  35. {return GetMAC().TagSize();}
  36. lword MaxHeaderLength() const
  37. {return LWORD_MAX;}
  38. lword MaxMessageLength() const
  39. {return LWORD_MAX;}
  40. protected:
  41. // AuthenticatedSymmetricCipherBase
  42. bool AuthenticationIsOnPlaintext() const
  43. {return false;}
  44. unsigned int AuthenticationBlockSize() const
  45. {return 1;}
  46. void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs &params);
  47. void Resync(const byte *iv, size_t len);
  48. size_t AuthenticateBlocks(const byte *data, size_t len);
  49. void AuthenticateLastHeaderBlock();
  50. void AuthenticateLastFooterBlock(byte *mac, size_t macSize);
  51. SymmetricCipher & AccessSymmetricCipher() {return m_ctr;}
  52. const CMAC_Base & GetMAC() const {return const_cast<EAX_Base *>(this)->AccessMAC();}
  53. virtual CMAC_Base & AccessMAC() =0;
  54. CTR_Mode_ExternalCipher::Encryption m_ctr;
  55. };
  56. //! .
  57. template <class T_BlockCipher, bool T_IsEncryption>
  58. class EAX_Final : public EAX_Base
  59. {
  60. public:
  61. static std::string StaticAlgorithmName()
  62. {return T_BlockCipher::StaticAlgorithmName() + std::string("/EAX");}
  63. bool IsForwardTransformation() const
  64. {return T_IsEncryption;}
  65. private:
  66. CMAC_Base & AccessMAC() {return m_cmac;}
  67. CMAC<T_BlockCipher> m_cmac;
  68. };
  69. #ifdef EAX // EAX is defined to 11 on GCC 3.4.3, OpenSolaris 8.11
  70. #undef EAX
  71. #endif
  72. /// <a href="http://www.cryptolounge.org/wiki/EAX">EAX</a>
  73. template <class T_BlockCipher>
  74. struct EAX : public AuthenticatedSymmetricCipherDocumentation
  75. {
  76. typedef EAX_Final<T_BlockCipher, true> Encryption;
  77. typedef EAX_Final<T_BlockCipher, false> Decryption;
  78. };
  79. NAMESPACE_END
  80. #endif