Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

default.h

00001 #ifndef CRYPTOPP_DEFAULT_H 00002 #define CRYPTOPP_DEFAULT_H 00003 00004 #include "sha.h" 00005 #include "hmac.h" 00006 #include "des.h" 00007 #include "filters.h" 00008 #include "modes.h" 00009 00010 NAMESPACE_BEGIN(CryptoPP) 00011 00012 typedef DES_EDE2 Default_BlockCipher; 00013 typedef SHA DefaultHashModule; 00014 typedef HMAC<DefaultHashModule> DefaultMAC; 00015 00016 //! Password-Based Encryptor using DES-EDE2 00017 class DefaultEncryptor : public ProxyFilter 00018 { 00019 public: 00020 DefaultEncryptor(const char *passphrase, BufferedTransformation *attachment = NULL); 00021 DefaultEncryptor(const byte *passphrase, unsigned int passphraseLength, BufferedTransformation *attachment = NULL); 00022 00023 protected: 00024 void FirstPut(const byte *); 00025 void LastPut(const byte *inString, unsigned int length); 00026 00027 private: 00028 SecByteBlock m_passphrase; 00029 CBC_Mode<Default_BlockCipher>::Encryption m_cipher; 00030 }; 00031 00032 //! Password-Based Decryptor using DES-EDE2 00033 class DefaultDecryptor : public ProxyFilter 00034 { 00035 public: 00036 DefaultDecryptor(const char *passphrase, BufferedTransformation *attachment = NULL, bool throwException=true); 00037 DefaultDecryptor(const byte *passphrase, unsigned int passphraseLength, BufferedTransformation *attachment = NULL, bool throwException=true); 00038 00039 class Err : public Exception 00040 { 00041 public: 00042 Err(const std::string &s) 00043 : Exception(DATA_INTEGRITY_CHECK_FAILED, s) {} 00044 }; 00045 class KeyBadErr : public Err {public: KeyBadErr() : Err("DefaultDecryptor: cannot decrypt message with this passphrase") {}}; 00046 00047 enum State {WAITING_FOR_KEYCHECK, KEY_GOOD, KEY_BAD}; 00048 State CurrentState() const {return m_state;} 00049 00050 protected: 00051 void FirstPut(const byte *inString); 00052 void LastPut(const byte *inString, unsigned int length); 00053 00054 State m_state; 00055 00056 private: 00057 void CheckKey(const byte *salt, const byte *keyCheck); 00058 00059 SecByteBlock m_passphrase; 00060 CBC_Mode<Default_BlockCipher>::Decryption m_cipher; 00061 member_ptr<FilterWithBufferedInput> m_decryptor; 00062 bool m_throwException; 00063 }; 00064 00065 //! Password-Based Encryptor using DES-EDE2 and HMAC/SHA-1 00066 class DefaultEncryptorWithMAC : public ProxyFilter 00067 { 00068 public: 00069 DefaultEncryptorWithMAC(const char *passphrase, BufferedTransformation *attachment = NULL); 00070 DefaultEncryptorWithMAC(const byte *passphrase, unsigned int passphraseLength, BufferedTransformation *attachment = NULL); 00071 00072 protected: 00073 void FirstPut(const byte *inString) {} 00074 void LastPut(const byte *inString, unsigned int length); 00075 00076 private: 00077 member_ptr<DefaultMAC> m_mac; 00078 }; 00079 00080 //! Password-Based Decryptor using DES-EDE2 and HMAC/SHA-1 00081 class DefaultDecryptorWithMAC : public ProxyFilter 00082 { 00083 public: 00084 class MACBadErr : public DefaultDecryptor::Err {public: MACBadErr() : DefaultDecryptor::Err("DefaultDecryptorWithMAC: MAC check failed") {}}; 00085 00086 DefaultDecryptorWithMAC(const char *passphrase, BufferedTransformation *attachment = NULL, bool throwException=true); 00087 DefaultDecryptorWithMAC(const byte *passphrase, unsigned int passphraseLength, BufferedTransformation *attachment = NULL, bool throwException=true); 00088 00089 DefaultDecryptor::State CurrentState() const; 00090 bool CheckLastMAC() const; 00091 00092 protected: 00093 void FirstPut(const byte *inString) {} 00094 void LastPut(const byte *inString, unsigned int length); 00095 00096 private: 00097 member_ptr<DefaultMAC> m_mac; 00098 HashVerifier *m_hashVerifier; 00099 bool m_throwException; 00100 }; 00101 00102 NAMESPACE_END 00103 00104 #endif

Generated on Fri Aug 13 09:56:53 2004 for Crypto++ by doxygen 1.3.7