Crypto++
default.h
1 #ifndef CRYPTOPP_DEFAULT_H
2 #define CRYPTOPP_DEFAULT_H
3 
4 #include "sha.h"
5 #include "hmac.h"
6 #include "des.h"
7 #include "filters.h"
8 #include "modes.h"
9 
10 NAMESPACE_BEGIN(CryptoPP)
11 
13 typedef SHA DefaultHashModule;
14 typedef HMAC<DefaultHashModule> DefaultMAC;
15 
16 //! Password-Based Encryptor using DES-EDE2
18 {
19 public:
20  DefaultEncryptor(const char *passphrase, BufferedTransformation *attachment = NULL);
21  DefaultEncryptor(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment = NULL);
22 
23 protected:
24  void FirstPut(const byte *);
25  void LastPut(const byte *inString, size_t length);
26 
27 private:
28  SecByteBlock m_passphrase;
30 };
31 
32 //! Password-Based Decryptor using DES-EDE2
34 {
35 public:
36  DefaultDecryptor(const char *passphrase, BufferedTransformation *attachment = NULL, bool throwException=true);
37  DefaultDecryptor(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment = NULL, bool throwException=true);
38 
39  class Err : public Exception
40  {
41  public:
42  Err(const std::string &s)
44  };
45  class KeyBadErr : public Err {public: KeyBadErr() : Err("DefaultDecryptor: cannot decrypt message with this passphrase") {}};
46 
47  enum State {WAITING_FOR_KEYCHECK, KEY_GOOD, KEY_BAD};
48  State CurrentState() const {return m_state;}
49 
50 protected:
51  void FirstPut(const byte *inString);
52  void LastPut(const byte *inString, size_t length);
53 
54  State m_state;
55 
56 private:
57  void CheckKey(const byte *salt, const byte *keyCheck);
58 
59  SecByteBlock m_passphrase;
62  bool m_throwException;
63 };
64 
65 //! Password-Based Encryptor using DES-EDE2 and HMAC/SHA-1
67 {
68 public:
69  DefaultEncryptorWithMAC(const char *passphrase, BufferedTransformation *attachment = NULL);
70  DefaultEncryptorWithMAC(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment = NULL);
71 
72 protected:
73  void FirstPut(const byte *inString) {}
74  void LastPut(const byte *inString, size_t length);
75 
76 private:
78 };
79 
80 //! Password-Based Decryptor using DES-EDE2 and HMAC/SHA-1
82 {
83 public:
84  class MACBadErr : public DefaultDecryptor::Err {public: MACBadErr() : DefaultDecryptor::Err("DefaultDecryptorWithMAC: MAC check failed") {}};
85 
86  DefaultDecryptorWithMAC(const char *passphrase, BufferedTransformation *attachment = NULL, bool throwException=true);
87  DefaultDecryptorWithMAC(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment = NULL, bool throwException=true);
88 
89  DefaultDecryptor::State CurrentState() const;
90  bool CheckLastMAC() const;
91 
92 protected:
93  void FirstPut(const byte *inString) {}
94  void LastPut(const byte *inString, size_t length);
95 
96 private:
98  HashVerifier *m_hashVerifier;
99  bool m_throwException;
100 };
101 
102 NAMESPACE_END
103 
104 #endif
base class for all exceptions thrown by Crypto++
Definition: cryptlib.h:109
Base class for Filter classes that are proxies for a chain of other filters.
Definition: filters.h:539
Password-Based Encryptor using DES-EDE2.
Definition: default.h:17
interface for buffered transformations
Definition: cryptlib.h:770
data integerity check (such as CRC or MAC) failed
Definition: cryptlib.h:121
Password-Based Decryptor using DES-EDE2.
Definition: default.h:33
Filter Wrapper for HashTransformation.
Definition: filters.h:310
DES-EDE2
Definition: des.h:62
SHA-1
Definition: sha.h:9
Password-Based Encryptor using DES-EDE2 and HMAC/SHA-1.
Definition: default.h:66
HMAC
Definition: hmac.h:40
Password-Based Decryptor using DES-EDE2 and HMAC/SHA-1.
Definition: default.h:81