Fabcoin Core  0.16.2
P2P Digital Currency
default.h
Go to the documentation of this file.
1 // default.h - written and placed in the public domain by Wei Dai
2 
5 
6 #ifndef CRYPTOPP_DEFAULT_H
7 #define CRYPTOPP_DEFAULT_H
8 
9 #include "sha.h"
10 #include "hmac.h"
11 #include "aes.h"
12 #include "des.h"
13 #include "modes.h"
14 #include "filters.h"
15 #include "smartptr.h"
16 
18 
24 typedef HMAC<LegacyHashModule> LegacyMAC;
25 
31 typedef HMAC<DefaultHashModule> DefaultMAC;
32 
36 {
37 public:
38  DataDecryptorErr(const std::string &s)
39  : Exception(DATA_INTEGRITY_CHECK_FAILED, s) {}
40 };
41 
45 {
46  public: KeyBadErr()
47  : DataDecryptorErr("DataDecryptor: cannot decrypt message with this passphrase") {}
48 };
49 
53 {
54  public: MACBadErr()
55  : DataDecryptorErr("DataDecryptorWithMAC: MAC check failed") {}
56 };
57 
60 template <unsigned int BlockSize, unsigned int KeyLength, unsigned int DigestSize, unsigned int SaltSize, unsigned int Iterations>
62 {
63  CRYPTOPP_CONSTANT(BLOCKSIZE = BlockSize)
64  CRYPTOPP_CONSTANT(KEYLENGTH = KeyLength)
65  CRYPTOPP_CONSTANT(SALTLENGTH = SaltSize)
66  CRYPTOPP_CONSTANT(DIGESTSIZE = DigestSize)
67  CRYPTOPP_CONSTANT(ITERATIONS = Iterations)
68 };
69 
72 
82 template <class BC, class H, class Info>
83 class DataEncryptor : public ProxyFilter, public Info
84 {
85 public:
86  CRYPTOPP_CONSTANT(BLOCKSIZE = Info::BLOCKSIZE)
87  CRYPTOPP_CONSTANT(KEYLENGTH = Info::KEYLENGTH)
88  CRYPTOPP_CONSTANT(SALTLENGTH = Info::SALTLENGTH)
89  CRYPTOPP_CONSTANT(DIGESTSIZE = Info::DIGESTSIZE)
90  CRYPTOPP_CONSTANT(ITERATIONS = Info::ITERATIONS)
91 
92 
93  DataEncryptor(const char *passphrase, BufferedTransformation *attachment = NULL);
96 
101  DataEncryptor(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment = NULL);
102 
103 protected:
104  void FirstPut(const byte *);
105  void LastPut(const byte *inString, size_t length);
106 
107 private:
110 };
111 
121 template <class BC, class H, class Info>
122 class DataDecryptor : public ProxyFilter, public Info
123 {
124 public:
125  CRYPTOPP_CONSTANT(BLOCKSIZE = Info::BLOCKSIZE)
126  CRYPTOPP_CONSTANT(KEYLENGTH = Info::KEYLENGTH)
127  CRYPTOPP_CONSTANT(SALTLENGTH = Info::SALTLENGTH)
128  CRYPTOPP_CONSTANT(DIGESTSIZE = Info::DIGESTSIZE)
129  CRYPTOPP_CONSTANT(ITERATIONS = Info::ITERATIONS)
130 
131 
132  DataDecryptor(const char *passphrase, BufferedTransformation *attachment = NULL, bool throwException=true);
136 
142  DataDecryptor(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment = NULL, bool throwException=true);
143 
144  enum State {WAITING_FOR_KEYCHECK, KEY_GOOD, KEY_BAD};
145  State CurrentState() const {return m_state;}
146 
147 protected:
148  void FirstPut(const byte *inString);
149  void LastPut(const byte *inString, size_t length);
150 
152 
153 private:
154  void CheckKey(const byte *salt, const byte *keyCheck);
155 
160 
161 };
162 
179 template <class BC, class H, class MAC, class Info>
181 {
182 public:
186  DataEncryptorWithMAC(const char *passphrase, BufferedTransformation *attachment = NULL);
187 
192  DataEncryptorWithMAC(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment = NULL);
193 
194 protected:
195  void FirstPut(const byte *inString) {CRYPTOPP_UNUSED(inString);}
196  void LastPut(const byte *inString, size_t length);
197 
198 private:
200 
201 };
202 
219 template <class BC, class H, class MAC, class Info>
221 {
222 public:
227  DataDecryptorWithMAC(const char *passphrase, BufferedTransformation *attachment = NULL, bool throwException=true);
228 
234  DataDecryptorWithMAC(const byte *passphrase, size_t passphraseLength, BufferedTransformation *attachment = NULL, bool throwException=true);
235 
236  typename DataDecryptor<BC,H,Info>::State CurrentState() const;
237  bool CheckLastMAC() const;
238 
239 protected:
240  void FirstPut(const byte *inString) {CRYPTOPP_UNUSED(inString);}
241  void LastPut(const byte *inString, size_t length);
242 
243 private:
247 };
248 
249 #if defined(CRYPTOPP_DOXYGEN_PROCESSING)
250 struct LegacyEncryptor : public DataEncryptor<LegacyBlockCipher,LegacyHashModule,LegacyParametersInfo> {};
261 struct LegacyDecryptor : public DataDecryptor<LegacyBlockCipher,LegacyHashModule,LegacyParametersInfo> {};
267 struct DefaultEncryptor : public DataEncryptor<DefaultBlockCipher,DefaultHashModule,DefaultParametersInfo> {};
273 struct DefaultDecryptor : public DataDecryptor<DefaultBlockCipher,DefaultHashModule,DefaultParametersInfo> {};
279 struct LegacyEncryptorWithMAC : public DataEncryptorWithMAC<LegacyBlockCipher,LegacyHashModule,DefaultMAC,LegacyParametersInfo> {};
285 struct LegacyDecryptorWithMAC : public DataDecryptorWithMAC<LegacyBlockCipher,LegacyHashModule,DefaultMAC,LegacyParametersInfo> {};
291 struct DefaultEncryptorWithMAC : public DataEncryptorWithMAC<DefaultBlockCipher,DefaultHashModule,DefaultMAC,DefaultParametersInfo> {};
297 struct DefaultDecryptorWithMAC : public DataDecryptorWithMAC<DefaultBlockCipher,DefaultHashModule,DefaultMAC,DefaultParametersInfo> {};
298 #else
301 
304 
307 
310 #endif
311 
313 
314 #endif
Base class for all exceptions thrown by the library.
Definition: cryptlib.h:140
member_ptr< MAC > m_mac
Definition: default.h:199
DataParametersInfo< LegacyBlockCipher::BLOCKSIZE, LegacyBlockCipher::DEFAULT_KEYLENGTH, LegacyHashModule::DIGESTSIZE, 8, 200 > LegacyParametersInfo
Definition: default.h:70
Exception thrown when a bad key is encountered in DefaultDecryptorWithMAC and LegacyDecryptorWithMAC...
Definition: default.h:44
DataEncryptor< LegacyBlockCipher, LegacyHashModule, LegacyParametersInfo > LegacyEncryptor
Definition: default.h:299
Base class for Filter classes that are proxies for a chain of other filters.
Definition: filters.h:951
uint8_t byte
Definition: Common.h:57
DataEncryptorWithMAC< LegacyBlockCipher, LegacyHashModule, DefaultMAC, LegacyParametersInfo > LegacyEncryptorWithMAC
Definition: default.h:305
SHA-256 message digest.
Definition: sha.h:39
void FirstPut(const byte *inString)
Definition: default.h:240
HashVerificationFilter * m_hashVerifier
Definition: default.h:245
Class file for modes of operation.
CBC_Mode< BC >::Decryption m_cipher
Definition: default.h:157
MACBadErr()
Definition: default.h:54
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
Password-based Encryptor.
Definition: default.h:83
Password-based Decryptor.
Definition: default.h:122
Classes for automatic resource management.
void FirstPut(const byte *inString)
Definition: default.h:195
Interface for buffered transformations.
Definition: cryptlib.h:1352
DataEncryptorWithMAC< DefaultBlockCipher, DefaultHashModule, DefaultMAC, DefaultParametersInfo > DefaultEncryptorWithMAC
Definition: default.h:308
DataEncryptor< DefaultBlockCipher, DefaultHashModule, DefaultParametersInfo > DefaultEncryptor
Definition: default.h:302
DataDecryptorWithMAC< LegacyBlockCipher, LegacyHashModule, DefaultMAC, LegacyParametersInfo > LegacyDecryptorWithMAC
Definition: default.h:306
State CurrentState() const
Definition: default.h:145
Classes for HMAC message authentication codes.
Filter wrapper for HashTransformation.
Definition: filters.h:550
Password-based encryptor with MAC.
Definition: default.h:180
Class file for the AES cipher (Rijndael)
SecByteBlock m_passphrase
Definition: default.h:156
2-key TripleDES block cipher
Definition: des.h:75
SHA-1 message digest.
Definition: sha.h:25
DataDecryptor< LegacyBlockCipher, LegacyHashModule, LegacyParametersInfo > LegacyDecryptor
Definition: default.h:300
bool m_throwException
Definition: default.h:159
member_ptr< FilterWithBufferedInput > m_decryptor
Definition: default.h:158
Exception thrown when LegacyDecryptorWithMAC or DefaultDecryptorWithMAC decryption error is encounter...
Definition: default.h:35
#define CRYPTOPP_CONSTANT(x)
Definition: config.h:540
DataDecryptorWithMAC< DefaultBlockCipher, DefaultHashModule, DefaultMAC, DefaultParametersInfo > DefaultDecryptorWithMAC
Definition: default.h:309
AES block cipher (Rijndael)
Algorithm information for password-based encryptors and decryptors.
Definition: default.h:61
CBC_Mode< BC >::Encryption m_cipher
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.
DataParametersInfo< DefaultBlockCipher::BLOCKSIZE, DefaultBlockCipher::DEFAULT_KEYLENGTH, DefaultHashModule::DIGESTSIZE, 8, 2500 > DefaultParametersInfo
Definition: default.h:71
Implementation of BufferedTransformation&#39;s attachment interface.
State m_state
Definition: default.h:151
HMAC.
Definition: hmac.h:50
DataDecryptorErr(const std::string &s)
Definition: default.h:38
#define CRYPTOPP_UNUSED(x)
Definition: config.h:741
SecByteBlock m_passphrase
Definition: default.h:108
Password-based decryptor with MAC.
Definition: default.h:220
#define NAMESPACE_END
Definition: config.h:201
member_ptr< MAC > m_mac
Definition: default.h:244
KeyBadErr()
Definition: default.h:46
DataDecryptor< DefaultBlockCipher, DefaultHashModule, DefaultParametersInfo > DefaultDecryptor
Definition: default.h:303
Exception thrown when an incorrect MAC is encountered in DefaultDecryptorWithMAC and LegacyDecryptorW...
Definition: default.h:52
CBC mode.
Definition: modes.h:430