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.

132 lines
3.4 KiB

  1. #ifndef CRYPTOPP_TEA_H
  2. #define CRYPTOPP_TEA_H
  3. /** \file
  4. */
  5. #include "seckey.h"
  6. #include "secblock.h"
  7. NAMESPACE_BEGIN(CryptoPP)
  8. //! _
  9. struct TEA_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public VariableRounds<32>
  10. {
  11. static const char *StaticAlgorithmName() {return "TEA";}
  12. };
  13. /// <a href="http://www.weidai.com/scan-mirror/cs.html#TEA">TEA</a>
  14. class TEA : public TEA_Info, public BlockCipherDocumentation
  15. {
  16. class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<TEA_Info>
  17. {
  18. public:
  19. void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
  20. protected:
  21. FixedSizeSecBlock<word32, 4> m_k;
  22. word32 m_limit;
  23. };
  24. class CRYPTOPP_NO_VTABLE Enc : public Base
  25. {
  26. public:
  27. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  28. };
  29. class CRYPTOPP_NO_VTABLE Dec : public Base
  30. {
  31. public:
  32. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  33. };
  34. public:
  35. typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
  36. typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
  37. };
  38. typedef TEA::Encryption TEAEncryption;
  39. typedef TEA::Decryption TEADecryption;
  40. //! _
  41. struct XTEA_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public VariableRounds<32>
  42. {
  43. static const char *StaticAlgorithmName() {return "XTEA";}
  44. };
  45. /// <a href="http://www.weidai.com/scan-mirror/cs.html#TEA">XTEA</a>
  46. class XTEA : public XTEA_Info, public BlockCipherDocumentation
  47. {
  48. class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<XTEA_Info>
  49. {
  50. public:
  51. void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
  52. protected:
  53. FixedSizeSecBlock<word32, 4> m_k;
  54. word32 m_limit;
  55. };
  56. class CRYPTOPP_NO_VTABLE Enc : public Base
  57. {
  58. public:
  59. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  60. };
  61. class CRYPTOPP_NO_VTABLE Dec : public Base
  62. {
  63. public:
  64. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  65. };
  66. public:
  67. typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
  68. typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
  69. };
  70. //! _
  71. struct BTEA_Info : public FixedKeyLength<16>
  72. {
  73. static const char *StaticAlgorithmName() {return "BTEA";}
  74. };
  75. //! <a href="http://www.weidai.com/scan-mirror/cs.html#TEA">corrected Block TEA</a> (as described in "xxtea").
  76. /*! This class hasn't been tested yet. */
  77. class BTEA : public BTEA_Info, public BlockCipherDocumentation
  78. {
  79. class CRYPTOPP_NO_VTABLE Base : public AlgorithmImpl<SimpleKeyingInterfaceImpl<BlockCipher, BTEA_Info>, BTEA_Info>, public BTEA_Info
  80. {
  81. public:
  82. void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params)
  83. {
  84. m_blockSize = params.GetIntValueWithDefault("BlockSize", 60*4);
  85. GetUserKey(BIG_ENDIAN_ORDER, m_k.begin(), 4, key, KEYLENGTH);
  86. }
  87. unsigned int BlockSize() const {return m_blockSize;}
  88. protected:
  89. FixedSizeSecBlock<word32, 4> m_k;
  90. unsigned int m_blockSize;
  91. };
  92. class CRYPTOPP_NO_VTABLE Enc : public Base
  93. {
  94. public:
  95. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  96. };
  97. class CRYPTOPP_NO_VTABLE Dec : public Base
  98. {
  99. public:
  100. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  101. };
  102. public:
  103. typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
  104. typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
  105. };
  106. NAMESPACE_END
  107. #endif