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.

104 lines
3.1 KiB

  1. #ifndef CRYPTOPP_DEFAULT_H
  2. #define CRYPTOPP_DEFAULT_H
  3. #include "sha.h"
  4. #include "hmac.h"
  5. #include "des.h"
  6. #include "filters.h"
  7. #include "modes.h"
  8. NAMESPACE_BEGIN(CryptoPP)
  9. typedef DES_EDE2 Default_BlockCipher;
  10. typedef SHA DefaultHashModule;
  11. typedef HMAC<DefaultHashModule> DefaultMAC;
  12. //! Password-Based Encryptor using DES-EDE2
  13. class DefaultEncryptor : public ProxyFilter
  14. {
  15. public:
  16. DefaultEncryptor(const char *passphrase, BufferedTransformation *attachment = NULL);
  17. DefaultEncryptor(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment = NULL);
  18. protected:
  19. void FirstPut(const byte *);
  20. void LastPut(const byte *inString, size_t length);
  21. private:
  22. SecByteBlock m_passphrase;
  23. CBC_Mode<Default_BlockCipher>::Encryption m_cipher;
  24. };
  25. //! Password-Based Decryptor using DES-EDE2
  26. class DefaultDecryptor : public ProxyFilter
  27. {
  28. public:
  29. DefaultDecryptor(const char *passphrase, BufferedTransformation *attachment = NULL, bool throwException=true);
  30. DefaultDecryptor(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment = NULL, bool throwException=true);
  31. class Err : public Exception
  32. {
  33. public:
  34. Err(const std::string &s)
  35. : Exception(DATA_INTEGRITY_CHECK_FAILED, s) {}
  36. };
  37. class KeyBadErr : public Err {public: KeyBadErr() : Err("DefaultDecryptor: cannot decrypt message with this passphrase") {}};
  38. enum State {WAITING_FOR_KEYCHECK, KEY_GOOD, KEY_BAD};
  39. State CurrentState() const {return m_state;}
  40. protected:
  41. void FirstPut(const byte *inString);
  42. void LastPut(const byte *inString, size_t length);
  43. State m_state;
  44. private:
  45. void CheckKey(const byte *salt, const byte *keyCheck);
  46. SecByteBlock m_passphrase;
  47. CBC_Mode<Default_BlockCipher>::Decryption m_cipher;
  48. member_ptr<FilterWithBufferedInput> m_decryptor;
  49. bool m_throwException;
  50. };
  51. //! Password-Based Encryptor using DES-EDE2 and HMAC/SHA-1
  52. class DefaultEncryptorWithMAC : public ProxyFilter
  53. {
  54. public:
  55. DefaultEncryptorWithMAC(const char *passphrase, BufferedTransformation *attachment = NULL);
  56. DefaultEncryptorWithMAC(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment = NULL);
  57. protected:
  58. void FirstPut(const byte *inString) {}
  59. void LastPut(const byte *inString, size_t length);
  60. private:
  61. member_ptr<DefaultMAC> m_mac;
  62. };
  63. //! Password-Based Decryptor using DES-EDE2 and HMAC/SHA-1
  64. class DefaultDecryptorWithMAC : public ProxyFilter
  65. {
  66. public:
  67. class MACBadErr : public DefaultDecryptor::Err {public: MACBadErr() : DefaultDecryptor::Err("DefaultDecryptorWithMAC: MAC check failed") {}};
  68. DefaultDecryptorWithMAC(const char *passphrase, BufferedTransformation *attachment = NULL, bool throwException=true);
  69. DefaultDecryptorWithMAC(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment = NULL, bool throwException=true);
  70. DefaultDecryptor::State CurrentState() const;
  71. bool CheckLastMAC() const;
  72. protected:
  73. void FirstPut(const byte *inString) {}
  74. void LastPut(const byte *inString, size_t length);
  75. private:
  76. member_ptr<DefaultMAC> m_mac;
  77. HashVerifier *m_hashVerifier;
  78. bool m_throwException;
  79. };
  80. NAMESPACE_END
  81. #endif