00001
00002
00003
00004
00005
00006 #ifndef CRYPTOPP_DEFAULT_H
00007 #define CRYPTOPP_DEFAULT_H
00008
00009 #include "sha.h"
00010 #include "hmac.h"
00011 #include "des.h"
00012 #include "modes.h"
00013 #include "filters.h"
00014 #include "smartptr.h"
00015
00016 NAMESPACE_BEGIN(CryptoPP)
00017
00018
00019 typedef DES_EDE2 DefaultBlockCipher;
00020
00021 typedef SHA DefaultHashModule;
00022
00023 typedef HMAC<DefaultHashModule> DefaultMAC;
00024
00025
00026
00027
00028
00029 class DefaultEncryptor : public ProxyFilter
00030 {
00031 public:
00032
00033
00034
00035 DefaultEncryptor(const char *passphrase, BufferedTransformation *attachment = NULL);
00036
00037
00038
00039
00040
00041 DefaultEncryptor(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment = NULL);
00042
00043 protected:
00044 void FirstPut(const byte *);
00045 void LastPut(const byte *inString, size_t length);
00046
00047 private:
00048 SecByteBlock m_passphrase;
00049 CBC_Mode<DefaultBlockCipher>::Encryption m_cipher;
00050
00051 #if (CRYPTOPP_GCC_VERSION >= 40500) || (CRYPTOPP_CLANG_VERSION >= 20800)
00052 } __attribute__((deprecated ("DefaultEncryptor will be changing in the near future because the algorithms are no longer secure")));
00053 #elif (CRYPTOPP_GCC_VERSION)
00054 } __attribute__((deprecated));
00055 #else
00056 };
00057 #endif
00058
00059
00060
00061
00062
00063 class DefaultDecryptor : public ProxyFilter
00064 {
00065 public:
00066
00067
00068
00069
00070 DefaultDecryptor(const char *passphrase, BufferedTransformation *attachment = NULL, bool throwException=true);
00071
00072
00073
00074
00075
00076
00077 DefaultDecryptor(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment = NULL, bool throwException=true);
00078
00079 class Err : public Exception
00080 {
00081 public:
00082 Err(const std::string &s)
00083 : Exception(DATA_INTEGRITY_CHECK_FAILED, s) {}
00084 };
00085 class KeyBadErr : public Err {public: KeyBadErr() : Err("DefaultDecryptor: cannot decrypt message with this passphrase") {}};
00086
00087 enum State {WAITING_FOR_KEYCHECK, KEY_GOOD, KEY_BAD};
00088 State CurrentState() const {return m_state;}
00089
00090 protected:
00091 void FirstPut(const byte *inString);
00092 void LastPut(const byte *inString, size_t length);
00093
00094 State m_state;
00095
00096 private:
00097 void CheckKey(const byte *salt, const byte *keyCheck);
00098
00099 SecByteBlock m_passphrase;
00100 CBC_Mode<DefaultBlockCipher>::Decryption m_cipher;
00101 member_ptr<FilterWithBufferedInput> m_decryptor;
00102 bool m_throwException;
00103
00104 #if (CRYPTOPP_GCC_VERSION >= 40500) || (CRYPTOPP_CLANG_VERSION >= 20800)
00105 } __attribute__((deprecated ("DefaultDecryptor will be changing in the near future because the algorithms are no longer secure")));
00106 #elif (CRYPTOPP_GCC_VERSION)
00107 } __attribute__((deprecated));
00108 #else
00109 };
00110 #endif
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 class DefaultEncryptorWithMAC : public ProxyFilter
00122 {
00123 public:
00124
00125
00126
00127 DefaultEncryptorWithMAC(const char *passphrase, BufferedTransformation *attachment = NULL);
00128
00129
00130
00131
00132
00133 DefaultEncryptorWithMAC(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment = NULL);
00134
00135 protected:
00136 void FirstPut(const byte *inString) {CRYPTOPP_UNUSED(inString);}
00137 void LastPut(const byte *inString, size_t length);
00138
00139 private:
00140 member_ptr<DefaultMAC> m_mac;
00141
00142 #if (CRYPTOPP_GCC_VERSION >= 40500) || (CRYPTOPP_CLANG_VERSION >= 20800)
00143 } __attribute__((deprecated ("DefaultEncryptorWithMAC will be changing in the near future because the algorithms are no longer secure")));
00144 #elif (CRYPTOPP_GCC_VERSION)
00145 } __attribute__((deprecated));
00146 #else
00147 };
00148 #endif
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 class DefaultDecryptorWithMAC : public ProxyFilter
00160 {
00161 public:
00162
00163
00164 class MACBadErr : public DefaultDecryptor::Err {public: MACBadErr() : DefaultDecryptor::Err("DefaultDecryptorWithMAC: MAC check failed") {}};
00165
00166
00167
00168
00169
00170 DefaultDecryptorWithMAC(const char *passphrase, BufferedTransformation *attachment = NULL, bool throwException=true);
00171
00172
00173
00174
00175
00176
00177 DefaultDecryptorWithMAC(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment = NULL, bool throwException=true);
00178
00179 DefaultDecryptor::State CurrentState() const;
00180 bool CheckLastMAC() const;
00181
00182 protected:
00183 void FirstPut(const byte *inString) {CRYPTOPP_UNUSED(inString);}
00184 void LastPut(const byte *inString, size_t length);
00185
00186 private:
00187 member_ptr<DefaultMAC> m_mac;
00188 HashVerifier *m_hashVerifier;
00189 bool m_throwException;
00190
00191 #if (CRYPTOPP_GCC_VERSION >= 40500) || (CRYPTOPP_CLANG_VERSION >= 20800)
00192 } __attribute__((deprecated ("DefaultDecryptorWithMAC will be changing in the near future because the algorithms are no longer secure")));
00193 #elif (CRYPTOPP_GCC_VERSION)
00194 } __attribute__((deprecated));
00195 #else
00196 };
00197 #endif
00198
00199 NAMESPACE_END
00200
00201 #endif