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.

144 lines
4.4 KiB

  1. #ifndef CRYPTOPP_DES_H
  2. #define CRYPTOPP_DES_H
  3. /** \file
  4. */
  5. #include "seckey.h"
  6. #include "secblock.h"
  7. NAMESPACE_BEGIN(CryptoPP)
  8. class CRYPTOPP_DLL RawDES
  9. {
  10. public:
  11. void RawSetKey(CipherDir direction, const byte *userKey);
  12. void RawProcessBlock(word32 &l, word32 &r) const;
  13. protected:
  14. static const word32 Spbox[8][64];
  15. FixedSizeSecBlock<word32, 32> k;
  16. };
  17. //! _
  18. struct DES_Info : public FixedBlockSize<8>, public FixedKeyLength<8>
  19. {
  20. // disable DES in DLL version by not exporting this function
  21. static const char * StaticAlgorithmName() {return "DES";}
  22. };
  23. /// <a href="http://www.weidai.com/scan-mirror/cs.html#DES">DES</a>
  24. /*! The DES implementation in Crypto++ ignores the parity bits
  25. (the least significant bits of each byte) in the key. However
  26. you can use CheckKeyParityBits() and CorrectKeyParityBits() to
  27. check or correct the parity bits if you wish. */
  28. class DES : public DES_Info, public BlockCipherDocumentation
  29. {
  30. class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_Info>, public RawDES
  31. {
  32. public:
  33. void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
  34. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  35. };
  36. public:
  37. //! check DES key parity bits
  38. static bool CheckKeyParityBits(const byte *key);
  39. //! correct DES key parity bits
  40. static void CorrectKeyParityBits(byte *key);
  41. typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
  42. typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
  43. };
  44. //! _
  45. struct DES_EDE2_Info : public FixedBlockSize<8>, public FixedKeyLength<16>
  46. {
  47. CRYPTOPP_DLL static const char * CRYPTOPP_API StaticAlgorithmName() {return "DES-EDE2";}
  48. };
  49. /// <a href="http://www.weidai.com/scan-mirror/cs.html#DESede">DES-EDE2</a>
  50. class DES_EDE2 : public DES_EDE2_Info, public BlockCipherDocumentation
  51. {
  52. class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_EDE2_Info>
  53. {
  54. public:
  55. void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
  56. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  57. protected:
  58. RawDES m_des1, m_des2;
  59. };
  60. public:
  61. typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
  62. typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
  63. };
  64. //! _
  65. struct DES_EDE3_Info : public FixedBlockSize<8>, public FixedKeyLength<24>
  66. {
  67. CRYPTOPP_DLL static const char * CRYPTOPP_API StaticAlgorithmName() {return "DES-EDE3";}
  68. };
  69. /// <a href="http://www.weidai.com/scan-mirror/cs.html#DESede">DES-EDE3</a>
  70. class DES_EDE3 : public DES_EDE3_Info, public BlockCipherDocumentation
  71. {
  72. class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_EDE3_Info>
  73. {
  74. public:
  75. void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
  76. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  77. protected:
  78. RawDES m_des1, m_des2, m_des3;
  79. };
  80. public:
  81. typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
  82. typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
  83. };
  84. //! _
  85. struct DES_XEX3_Info : public FixedBlockSize<8>, public FixedKeyLength<24>
  86. {
  87. static const char *StaticAlgorithmName() {return "DES-XEX3";}
  88. };
  89. /// <a href="http://www.weidai.com/scan-mirror/cs.html#DESX">DES-XEX3</a>, AKA DESX
  90. class DES_XEX3 : public DES_XEX3_Info, public BlockCipherDocumentation
  91. {
  92. class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_XEX3_Info>
  93. {
  94. public:
  95. void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
  96. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  97. protected:
  98. FixedSizeSecBlock<byte, BLOCKSIZE> m_x1, m_x3;
  99. // VS2005 workaround: calling modules compiled with /clr gets unresolved external symbol DES::Base::ProcessAndXorBlock
  100. // if we use DES::Encryption here directly without value_ptr.
  101. value_ptr<DES::Encryption> m_des;
  102. };
  103. public:
  104. typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
  105. typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
  106. };
  107. typedef DES::Encryption DESEncryption;
  108. typedef DES::Decryption DESDecryption;
  109. typedef DES_EDE2::Encryption DES_EDE2_Encryption;
  110. typedef DES_EDE2::Decryption DES_EDE2_Decryption;
  111. typedef DES_EDE3::Encryption DES_EDE3_Encryption;
  112. typedef DES_EDE3::Decryption DES_EDE3_Decryption;
  113. typedef DES_XEX3::Encryption DES_XEX3_Encryption;
  114. typedef DES_XEX3::Decryption DES_XEX3_Decryption;
  115. NAMESPACE_END
  116. #endif