Crypto++  5.6.4
Free C++ class library of cryptographic schemes
default.h
Go to the documentation of this file.
1 // default.h - written and placed in the public domain by Wei Dai
2 
3 //! \file default.h
4 //! \brief Classes for DefaultEncryptor, DefaultDecryptor, DefaultEncryptorWithMAC and DefaultDecryptorWithMAC
5 
6 #ifndef CRYPTOPP_DEFAULT_H
7 #define CRYPTOPP_DEFAULT_H
8 
9 #include "sha.h"
10 #include "hmac.h"
11 #include "des.h"
12 #include "modes.h"
13 #include "filters.h"
14 #include "smartptr.h"
15 
16 NAMESPACE_BEGIN(CryptoPP)
17 
18 //! \brief Default block cipher for DefaultEncryptor, DefaultDecryptor, DefaultEncryptorWithMAC and DefaultDecryptorWithMAC
20 //! \brief Default hash for use with DefaultEncryptorWithMAC and DefaultDecryptorWithMAC
22 //! \brief Default HMAC for use withDefaultEncryptorWithMAC and DefaultDecryptorWithMAC
23 typedef HMAC<DefaultHashModule> DefaultMAC;
24 
25 //! \class DefaultEncryptor
26 //! \brief Password-Based Encryptor using TripleDES
27 //! \details The class uses 2-key TripleDES (DES_EDE2) for encryption, which only
28 //! provides about 80-bits of security.
30 {
31 public:
32  //! \brief Construct a DefaultEncryptor
33  //! \param passphrase a C-String password
34  //! \param attachment a BufferedTransformation to attach to this object
35  DefaultEncryptor(const char *passphrase, BufferedTransformation *attachment = NULL);
36 
37  //! \brief Construct a DefaultEncryptor
38  //! \param passphrase a byte string password
39  //! \param passphraseLength the length of the byte string password
40  //! \param attachment a BufferedTransformation to attach to this object
41  DefaultEncryptor(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment = NULL);
42 
43 protected:
44  void FirstPut(const byte *);
45  void LastPut(const byte *inString, size_t length);
46 
47 private:
48  SecByteBlock m_passphrase;
50 
51 } CRYPTOPP_DEPRECATED ("DefaultEncryptor will be changing in the near future because the algorithms are no longer secure");
52 
53 //! \class DefaultDecryptor
54 //! \brief Password-Based Decryptor using TripleDES
55 //! \details The class uses 2-key TripleDES (DES_EDE2) for encryption, which only
56 //! provides about 80-bits of security.
58 {
59 public:
60  //! \brief Constructs a DefaultDecryptor
61  //! \param passphrase a C-String password
62  //! \param attachment a BufferedTransformation to attach to this object
63  //! \param throwException a flag specifiying whether an Exception should be thrown on error
64  DefaultDecryptor(const char *passphrase, BufferedTransformation *attachment = NULL, bool throwException=true);
65 
66  //! \brief Constructs a DefaultDecryptor
67  //! \param passphrase a byte string password
68  //! \param passphraseLength the length of the byte string password
69  //! \param attachment a BufferedTransformation to attach to this object
70  //! \param throwException a flag specifiying whether an Exception should be thrown on error
71  DefaultDecryptor(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment = NULL, bool throwException=true);
72 
73  class Err : public Exception
74  {
75  public:
76  Err(const std::string &s)
78  };
79  class KeyBadErr : public Err {public: KeyBadErr() : Err("DefaultDecryptor: cannot decrypt message with this passphrase") {}};
80 
81  enum State {WAITING_FOR_KEYCHECK, KEY_GOOD, KEY_BAD};
82  State CurrentState() const {return m_state;}
83 
84 protected:
85  void FirstPut(const byte *inString);
86  void LastPut(const byte *inString, size_t length);
87 
88  State m_state;
89 
90 private:
91  void CheckKey(const byte *salt, const byte *keyCheck);
92 
93  SecByteBlock m_passphrase;
96  bool m_throwException;
97 
98 } CRYPTOPP_DEPRECATED ("DefaultDecryptor will be changing in the near future because the algorithms are no longer secure");
99 
100 //! \class DefaultEncryptorWithMAC
101 //! \brief Password-Based encryptor using TripleDES and HMAC/SHA-1
102 //! \details DefaultEncryptorWithMAC uses a non-standard mashup function called Mash() to derive key
103 //! bits from the password. The class also uses 2-key TripleDES (DES_EDE2) for encryption, which only
104 //! provides about 80-bits of security.
105 //! \details The purpose of the function Mash() is to take an arbitrary length input string and
106 //! *deterministically* produce an arbitrary length output string such that (1) it looks random,
107 //! (2) no information about the input is deducible from it, and (3) it contains as much entropy
108 //! as it can hold, or the amount of entropy in the input string, whichever is smaller.
110 {
111 public:
112  //! \brief Constructs a DefaultEncryptorWithMAC
113  //! \param passphrase a C-String password
114  //! \param attachment a BufferedTransformation to attach to this object
115  DefaultEncryptorWithMAC(const char *passphrase, BufferedTransformation *attachment = NULL);
116 
117  //! \brief Constructs a DefaultEncryptorWithMAC
118  //! \param passphrase a byte string password
119  //! \param passphraseLength the length of the byte string password
120  //! \param attachment a BufferedTransformation to attach to this object
121  DefaultEncryptorWithMAC(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment = NULL);
122 
123 protected:
124  void FirstPut(const byte *inString) {CRYPTOPP_UNUSED(inString);}
125  void LastPut(const byte *inString, size_t length);
126 
127 private:
129 
130 } CRYPTOPP_DEPRECATED ("DefaultEncryptorWithMAC will be changing in the near future because the algorithms are no longer secure");
131 
132 //! \class DefaultDecryptorWithMAC
133 //! \brief Password-Based decryptor using TripleDES and HMAC/SHA-1
134 //! \details DefaultDecryptorWithMAC uses a non-standard mashup function called Mash() to derive key
135 //! bits from the password. The class also uses 2-key TripleDES (DES_EDE2) for encryption, which only
136 //! provides about 80-bits of security.
137 //! \details The purpose of the function Mash() is to take an arbitrary length input string and
138 //! *deterministically* produce an arbitrary length output string such that (1) it looks random,
139 //! (2) no information about the input is deducible from it, and (3) it contains as much entropy
140 //! as it can hold, or the amount of entropy in the input string, whichever is smaller.
142 {
143 public:
144  //! \class MACBadErr
145  //! \brief Excpetion thrown when an incorrect MAC is encountered
146  class MACBadErr : public DefaultDecryptor::Err {public: MACBadErr() : DefaultDecryptor::Err("DefaultDecryptorWithMAC: MAC check failed") {}};
147 
148  //! \brief Constructs a DefaultDecryptor
149  //! \param passphrase a C-String password
150  //! \param attachment a BufferedTransformation to attach to this object
151  //! \param throwException a flag specifiying whether an Exception should be thrown on error
152  DefaultDecryptorWithMAC(const char *passphrase, BufferedTransformation *attachment = NULL, bool throwException=true);
153 
154  //! \brief Constructs a DefaultDecryptor
155  //! \param passphrase a byte string password
156  //! \param passphraseLength the length of the byte string password
157  //! \param attachment a BufferedTransformation to attach to this object
158  //! \param throwException a flag specifiying whether an Exception should be thrown on error
159  DefaultDecryptorWithMAC(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment = NULL, bool throwException=true);
160 
161  DefaultDecryptor::State CurrentState() const;
162  bool CheckLastMAC() const;
163 
164 protected:
165  void FirstPut(const byte *inString) {CRYPTOPP_UNUSED(inString);}
166  void LastPut(const byte *inString, size_t length);
167 
168 private:
170  HashVerifier *m_hashVerifier;
171  bool m_throwException;
172 
173 } CRYPTOPP_DEPRECATED ("DefaultDecryptorWithMAC will be changing in the near future because the algorithms are no longer secure");
174 
175 NAMESPACE_END
176 
177 #endif
Base class for all exceptions thrown by the library.
Definition: cryptlib.h:144
Base class for Filter classes that are proxies for a chain of other filters.
Definition: filters.h:885
Password-Based Encryptor using TripleDES.
Definition: default.h:29
Class file for modes of operation.
Exception(ErrorType errorType, const std::string &s)
Construct a new Exception.
Definition: cryptlib.h:167
Classes for automatic resource management.
SecBlock typedef.
Definition: secblock.h:731
Interface for buffered transformations.
Definition: cryptlib.h:1359
Excpetion thrown when an incorrect MAC is encountered.
Definition: default.h:146
Data integerity check, such as CRC or MAC, failed.
Definition: cryptlib.h:157
Password-Based Decryptor using TripleDES.
Definition: default.h:57
DefaultDecryptor(const char *passphrase, BufferedTransformation *attachment=NULL, bool throwException=true)
Constructs a DefaultDecryptor.
Definition: default.cpp:136
Classes for HMAC message authentication codes.
Filter wrapper for HashTransformation.
Definition: filters.h:535
Block cipher mode of operation aggregate.
Definition: modes.h:296
2-key TripleDES block cipher
Definition: des.h:73
SHA-1
Definition: sha.h:22
Password-Based encryptor using TripleDES and HMAC/SHA-1.
Definition: default.h:109
Classes for DES, 2-key Triple-DES, 3-key Triple-DES and DESX.
Classes for SHA-1 and SHA-2 family of message digests.
Implementation of BufferedTransformation's attachment interface.
HMAC.
Definition: hmac.h:50
Password-Based decryptor using TripleDES and HMAC/SHA-1.
Definition: default.h:141
Crypto++ library namespace.
DefaultDecryptorWithMAC(const char *passphrase, BufferedTransformation *attachment=NULL, bool throwException=true)
Constructs a DefaultDecryptor.
Definition: default.cpp:238
DefaultEncryptorWithMAC(const char *passphrase, BufferedTransformation *attachment=NULL)
Constructs a DefaultEncryptorWithMAC.
Definition: default.cpp:216