Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

crypter.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2015 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <wallet/crypter.h>
6 
7 #include <crypto/aes.h>
8 #include <crypto/sha512.h>
9 #include <script/script.h>
10 #include <script/standard.h>
11 #include <util.h>
12 
13 #include <string>
14 #include <vector>
15 
16 int CCrypter::BytesToKeySHA512AES(const std::vector<unsigned char>& chSalt, const SecureString& strKeyData, int count, unsigned char *key,unsigned char *iv) const
17 {
18  // This mimics the behavior of openssl's EVP_BytesToKey with an aes256cbc
19  // cipher and sha512 message digest. Because sha512's output size (64b) is
20  // greater than the aes256 block size (16b) + aes256 key size (32b),
21  // there's no need to process more than once (D_0).
22 
23  if(!count || !key || !iv)
24  return 0;
25 
26  unsigned char buf[CSHA512::OUTPUT_SIZE];
27  CSHA512 di;
28 
29  di.Write((const unsigned char*)strKeyData.c_str(), strKeyData.size());
30  di.Write(chSalt.data(), chSalt.size());
31  di.Finalize(buf);
32 
33  for(int i = 0; i != count - 1; i++)
34  di.Reset().Write(buf, sizeof(buf)).Finalize(buf);
35 
36  memcpy(key, buf, WALLET_CRYPTO_KEY_SIZE);
38  memory_cleanse(buf, sizeof(buf));
40 }
41 
42 bool CCrypter::SetKeyFromPassphrase(const SecureString& strKeyData, const std::vector<unsigned char>& chSalt, const unsigned int nRounds, const unsigned int nDerivationMethod)
43 {
44  if (nRounds < 1 || chSalt.size() != WALLET_CRYPTO_SALT_SIZE)
45  return false;
46 
47  int i = 0;
48  if (nDerivationMethod == 0)
49  i = BytesToKeySHA512AES(chSalt, strKeyData, nRounds, vchKey.data(), vchIV.data());
50 
51  if (i != (int)WALLET_CRYPTO_KEY_SIZE)
52  {
53  memory_cleanse(vchKey.data(), vchKey.size());
54  memory_cleanse(vchIV.data(), vchIV.size());
55  return false;
56  }
57 
58  fKeySet = true;
59  return true;
60 }
61 
62 bool CCrypter::SetKey(const CKeyingMaterial& chNewKey, const std::vector<unsigned char>& chNewIV)
63 {
64  if (chNewKey.size() != WALLET_CRYPTO_KEY_SIZE || chNewIV.size() != WALLET_CRYPTO_IV_SIZE)
65  return false;
66 
67  memcpy(vchKey.data(), chNewKey.data(), chNewKey.size());
68  memcpy(vchIV.data(), chNewIV.data(), chNewIV.size());
69 
70  fKeySet = true;
71  return true;
72 }
73 
74 bool CCrypter::Encrypt(const CKeyingMaterial& vchPlaintext, std::vector<unsigned char> &vchCiphertext) const
75 {
76  if (!fKeySet)
77  return false;
78 
79  // max ciphertext len for a n bytes of plaintext is
80  // n + AES_BLOCKSIZE bytes
81  vchCiphertext.resize(vchPlaintext.size() + AES_BLOCKSIZE);
82 
83  AES256CBCEncrypt enc(vchKey.data(), vchIV.data(), true);
84  size_t nLen = enc.Encrypt(&vchPlaintext[0], vchPlaintext.size(), vchCiphertext.data());
85  if(nLen < vchPlaintext.size())
86  return false;
87  vchCiphertext.resize(nLen);
88 
89  return true;
90 }
91 
92 bool CCrypter::Decrypt(const std::vector<unsigned char>& vchCiphertext, CKeyingMaterial& vchPlaintext) const
93 {
94  if (!fKeySet)
95  return false;
96 
97  // plaintext will always be equal to or lesser than length of ciphertext
98  int nLen = vchCiphertext.size();
99 
100  vchPlaintext.resize(nLen);
101 
102  AES256CBCDecrypt dec(vchKey.data(), vchIV.data(), true);
103  nLen = dec.Decrypt(vchCiphertext.data(), vchCiphertext.size(), &vchPlaintext[0]);
104  if(nLen == 0)
105  return false;
106  vchPlaintext.resize(nLen);
107  return true;
108 }
109 
110 
111 static bool EncryptSecret(const CKeyingMaterial& vMasterKey, const CKeyingMaterial &vchPlaintext, const uint256& nIV, std::vector<unsigned char> &vchCiphertext)
112 {
113  CCrypter cKeyCrypter;
114  std::vector<unsigned char> chIV(WALLET_CRYPTO_IV_SIZE);
115  memcpy(chIV.data(), &nIV, WALLET_CRYPTO_IV_SIZE);
116  if(!cKeyCrypter.SetKey(vMasterKey, chIV))
117  return false;
118  return cKeyCrypter.Encrypt(*((const CKeyingMaterial*)&vchPlaintext), vchCiphertext);
119 }
120 
121 
122 // General secure AES 256 CBC encryption routine
123 bool EncryptAES256(const SecureString& sKey, const SecureString& sPlaintext, const std::string& sIV, std::string& sCiphertext)
124 {
125  // Verify key sizes
126  if(sKey.size() != 32 || sIV.size() != AES_BLOCKSIZE) {
127  LogPrintf("crypter EncryptAES256 - Invalid key or block size: Key: %d sIV:%d\n", sKey.size(), sIV.size());
128  return false;
129  }
130 
131  // max ciphertext len for a n bytes of plaintext is
132  // n + AES_BLOCKSIZE bytes
133  sCiphertext.resize(sPlaintext.size() + AES_BLOCKSIZE);
134 
135  AES256CBCEncrypt enc((const unsigned char*) &sKey[0], (const unsigned char*) &sIV[0], true);
136  size_t nLen = enc.Encrypt((const unsigned char*) &sPlaintext[0], sPlaintext.size(), (unsigned char*) &sCiphertext[0]);
137  if(nLen < sPlaintext.size())
138  return false;
139  sCiphertext.resize(nLen);
140  return true;
141 }
142 
143 
144 static bool DecryptSecret(const CKeyingMaterial& vMasterKey, const std::vector<unsigned char>& vchCiphertext, const uint256& nIV, CKeyingMaterial& vchPlaintext)
145 {
146  CCrypter cKeyCrypter;
147  std::vector<unsigned char> chIV(WALLET_CRYPTO_IV_SIZE);
148  memcpy(chIV.data(), &nIV, WALLET_CRYPTO_IV_SIZE);
149  if(!cKeyCrypter.SetKey(vMasterKey, chIV))
150  return false;
151  return cKeyCrypter.Decrypt(vchCiphertext, *((CKeyingMaterial*)&vchPlaintext));
152 }
153 
154 // General secure AES 256 CBC decryption routine
155 bool DecryptAES256(const SecureString& sKey, const std::string& sCiphertext, const std::string& sIV, SecureString& sPlaintext)
156 {
157  // Verify key sizes
158  if(sKey.size() != 32 || sIV.size() != AES_BLOCKSIZE) {
159  LogPrintf("crypter DecryptAES256 - Invalid key or block size\n");
160  return false;
161  }
162 
163  // plaintext will always be equal to or lesser than length of ciphertext
164  int nLen = sCiphertext.size();
165 
166  sPlaintext.resize(nLen);
167 
168  AES256CBCDecrypt dec((const unsigned char*) &sKey[0], (const unsigned char*) &sIV[0], true);
169  nLen = dec.Decrypt((const unsigned char*) &sCiphertext[0], sCiphertext.size(), (unsigned char*) &sPlaintext[0]);
170  if(nLen == 0)
171  return false;
172  sPlaintext.resize(nLen);
173  return true;
174 }
175 
176 
177 static bool DecryptKey(const CKeyingMaterial& vMasterKey, const std::vector<unsigned char>& vchCryptedSecret, const CPubKey& vchPubKey, CKey& key)
178 {
179  CKeyingMaterial vchSecret;
180  if(!DecryptSecret(vMasterKey, vchCryptedSecret, vchPubKey.GetHash(), vchSecret))
181  return false;
182 
183  if (vchSecret.size() != 32)
184  return false;
185 
186  key.Set(vchSecret.begin(), vchSecret.end(), vchPubKey.IsCompressed());
187  return key.VerifyPubKey(vchPubKey);
188 }
189 
191 {
192  LOCK(cs_KeyStore);
193  if (fUseCrypto)
194  return true;
195  if (!mapKeys.empty())
196  return false;
197  fUseCrypto = true;
198  return true;
199 }
200 
201 // This function should be used in a different combinations to determine
202 // if CCryptoKeyStore is fully locked so that no operations requiring access
203 // to private keys are possible:
204 // IsLocked(true)
205 // or if CCryptoKeyStore's private keys are available for mixing only:
206 // !IsLocked(true) && IsLocked()
207 // or if they are available for everything:
208 // !IsLocked()
209 bool CCryptoKeyStore::IsLocked(bool fForMixing) const
210 {
211  if (!IsCrypted())
212  return false;
213  bool result;
214  {
215  LOCK(cs_KeyStore);
216  result = vMasterKey.empty();
217  }
218  // fForMixing fOnlyMixingAllowed return
219  // ---------------------------------------
220  // true true result
221  // true false result
222  // false true true
223  // false false result
224 
225  if(!fForMixing && fOnlyMixingAllowed) return true;
226 
227  return result;
228 }
229 
230 bool CCryptoKeyStore::Lock(bool fAllowMixing)
231 {
232  if (!SetCrypted())
233  return false;
234 
235  if(!fAllowMixing) {
236  LOCK(cs_KeyStore);
237  vMasterKey.clear();
238  }
239 
240  fOnlyMixingAllowed = fAllowMixing;
241  NotifyStatusChanged(this);
242  return true;
243 }
244 
245 bool CCryptoKeyStore::Unlock(const CKeyingMaterial& vMasterKeyIn, bool fForMixingOnly)
246 {
247  {
248  LOCK(cs_KeyStore);
249  if (!SetCrypted())
250  return false;
251 
252  bool keyPass = false;
253  bool keyFail = false;
254  CryptedKeyMap::const_iterator mi = mapCryptedKeys.begin();
255  for (; mi != mapCryptedKeys.end(); ++mi)
256  {
257  const CPubKey &vchPubKey = (*mi).second.first;
258  const std::vector<unsigned char> &vchCryptedSecret = (*mi).second.second;
259  CKey key;
260  if (!DecryptKey(vMasterKeyIn, vchCryptedSecret, vchPubKey, key))
261  {
262  keyFail = true;
263  break;
264  }
265  keyPass = true;
267  break;
268  }
269  if (keyPass && keyFail)
270  {
271  LogPrintf("The wallet is probably corrupted: Some keys decrypt but not all.\n");
272  assert(false);
273  }
274  if (keyFail || (!keyPass && cryptedHDChain.IsNull()))
275  return false;
276 
277  vMasterKey = vMasterKeyIn;
278 
279  if(!cryptedHDChain.IsNull()) {
280  bool chainPass = false;
281  // try to decrypt seed and make sure it matches
282  CHDChain hdChainTmp;
283  if (DecryptHDChain(hdChainTmp)) {
284  // make sure seed matches this chain
285  chainPass = cryptedHDChain.GetID() == hdChainTmp.GetSeedHash();
286  }
287  if (!chainPass) {
288  vMasterKey.clear();
289  return false;
290  }
291  }
293  }
294  fOnlyMixingAllowed = fForMixingOnly;
295  NotifyStatusChanged(this);
296  return true;
297 }
298 
299 bool CCryptoKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey)
300 {
301  LOCK(cs_KeyStore);
302  if (!IsCrypted()) {
303  return CBasicKeyStore::AddKeyPubKey(key, pubkey);
304  }
305 
306  if (IsLocked(true)) {
307  return false;
308  }
309 
310  std::vector<unsigned char> vchCryptedSecret;
311  CKeyingMaterial vchSecret(key.begin(), key.end());
312  if (!EncryptSecret(vMasterKey, vchSecret, pubkey.GetHash(), vchCryptedSecret)) {
313  return false;
314  }
315 
316  if (!AddCryptedKey(pubkey, vchCryptedSecret)) {
317  return false;
318  }
319  return true;
320 }
321 
322 
323 bool CCryptoKeyStore::AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret)
324 {
325  LOCK(cs_KeyStore);
326  if (!SetCrypted()) {
327  return false;
328  }
329 
330  mapCryptedKeys[vchPubKey.GetID()] = make_pair(vchPubKey, vchCryptedSecret);
331  return true;
332 }
333 
334 bool CCryptoKeyStore::HaveKey(const CKeyID &address) const
335 {
336  LOCK(cs_KeyStore);
337  if (!IsCrypted()) {
338  return CBasicKeyStore::HaveKey(address);
339  }
340  return mapCryptedKeys.count(address) > 0;
341 }
342 
343 bool CCryptoKeyStore::GetKey(const CKeyID &address, CKey& keyOut) const
344 {
345  LOCK(cs_KeyStore);
346  if (!IsCrypted()) {
347  return CBasicKeyStore::GetKey(address, keyOut);
348  }
349 
350  CryptedKeyMap::const_iterator mi = mapCryptedKeys.find(address);
351  if (mi != mapCryptedKeys.end())
352  {
353  const CPubKey &vchPubKey = (*mi).second.first;
354  const std::vector<unsigned char> &vchCryptedSecret = (*mi).second.second;
355  return DecryptKey(vMasterKey, vchCryptedSecret, vchPubKey, keyOut);
356  }
357  return false;
358 }
359 
360 bool CCryptoKeyStore::GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const
361 {
362  LOCK(cs_KeyStore);
363  if (!IsCrypted())
364  return CBasicKeyStore::GetPubKey(address, vchPubKeyOut);
365 
366  CryptedKeyMap::const_iterator mi = mapCryptedKeys.find(address);
367  if (mi != mapCryptedKeys.end())
368  {
369  vchPubKeyOut = (*mi).second.first;
370  return true;
371  }
372  // Check for watch-only pubkeys
373  return CBasicKeyStore::GetPubKey(address, vchPubKeyOut);
374 }
375 
376 std::set<CKeyID> CCryptoKeyStore::GetKeys() const
377 {
378  LOCK(cs_KeyStore);
379  if (!IsCrypted()) {
380  return CBasicKeyStore::GetKeys();
381  }
382  std::set<CKeyID> set_address;
383  for (const auto& mi : mapCryptedKeys) {
384  set_address.insert(mi.first);
385  }
386  return set_address;
387 }
388 
390 {
391  LOCK(cs_KeyStore);
392  if (!mapCryptedKeys.empty() || IsCrypted())
393  return false;
394 
395  fUseCrypto = true;
396  for (KeyMap::value_type& mKey : mapKeys)
397  {
398  const CKey &key = mKey.second;
399  CPubKey vchPubKey = key.GetPubKey();
400  CKeyingMaterial vchSecret(key.begin(), key.end());
401  std::vector<unsigned char> vchCryptedSecret;
402  if (!EncryptSecret(vMasterKeyIn, vchSecret, vchPubKey.GetHash(), vchCryptedSecret))
403  return false;
404  if (!AddCryptedKey(vchPubKey, vchCryptedSecret))
405  return false;
406  }
407  mapKeys.clear();
408  return true;
409 }
410 
412 {
413  // should call EncryptKeys first
414  if (!IsCrypted())
415  return false;
416 
417  if (!cryptedHDChain.IsNull())
418  return true;
419 
421  return true;
422 
423  // make sure seed matches this chain
424  if (hdChain.GetID() != hdChain.GetSeedHash())
425  return false;
426 
427  std::vector<unsigned char> vchCryptedSeed;
428  if (!EncryptSecret(vMasterKeyIn, hdChain.GetSeed(), hdChain.GetID(), vchCryptedSeed))
429  return false;
430 
431  hdChain.Debug(__func__);
434 
435  SecureVector vchSecureCryptedSeed(vchCryptedSeed.begin(), vchCryptedSeed.end());
436  if (!cryptedHDChain.SetSeed(vchSecureCryptedSeed, false))
437  return false;
438 
439  SecureVector vchMnemonic;
440  SecureVector vchMnemonicPassphrase;
441 
442  // it's ok to have no mnemonic if wallet was initialized via hdseed
443  if (hdChain.GetMnemonic(vchMnemonic, vchMnemonicPassphrase)) {
444  std::vector<unsigned char> vchCryptedMnemonic;
445  std::vector<unsigned char> vchCryptedMnemonicPassphrase;
446 
447  if (!vchMnemonic.empty() && !EncryptSecret(vMasterKeyIn, vchMnemonic, hdChain.GetID(), vchCryptedMnemonic))
448  return false;
449  if (!vchMnemonicPassphrase.empty() && !EncryptSecret(vMasterKeyIn, vchMnemonicPassphrase, hdChain.GetID(), vchCryptedMnemonicPassphrase))
450  return false;
451 
452  SecureVector vchSecureCryptedMnemonic(vchCryptedMnemonic.begin(), vchCryptedMnemonic.end());
453  SecureVector vchSecureCryptedMnemonicPassphrase(vchCryptedMnemonicPassphrase.begin(), vchCryptedMnemonicPassphrase.end());
454  if (!cryptedHDChain.SetMnemonic(vchSecureCryptedMnemonic, vchSecureCryptedMnemonicPassphrase, false))
455  return false;
456  }
457 
458  if (!hdChain.SetNull())
459  return false;
460 
461  return true;
462 }
463 
465 {
466  if (!IsCrypted())
467  return true;
468 
469  if (cryptedHDChain.IsNull())
470  return false;
471 
472  if (!cryptedHDChain.IsCrypted())
473  return false;
474 
475  SecureVector vchSecureSeed;
476  SecureVector vchSecureCryptedSeed = cryptedHDChain.GetSeed();
477  std::vector<unsigned char> vchCryptedSeed(vchSecureCryptedSeed.begin(), vchSecureCryptedSeed.end());
478  if (!DecryptSecret(vMasterKey, vchCryptedSeed, cryptedHDChain.GetID(), vchSecureSeed))
479  return false;
480 
481  hdChainRet = cryptedHDChain;
482  if (!hdChainRet.SetSeed(vchSecureSeed, false))
483  return false;
484 
485  // hash of decrypted seed must match chain id
486  if (hdChainRet.GetSeedHash() != cryptedHDChain.GetID())
487  return false;
488 
489  SecureVector vchSecureCryptedMnemonic;
490  SecureVector vchSecureCryptedMnemonicPassphrase;
491 
492  // it's ok to have no mnemonic if wallet was initialized via hdseed
493  if (cryptedHDChain.GetMnemonic(vchSecureCryptedMnemonic, vchSecureCryptedMnemonicPassphrase)) {
494  SecureVector vchSecureMnemonic;
495  SecureVector vchSecureMnemonicPassphrase;
496 
497  std::vector<unsigned char> vchCryptedMnemonic(vchSecureCryptedMnemonic.begin(), vchSecureCryptedMnemonic.end());
498  std::vector<unsigned char> vchCryptedMnemonicPassphrase(vchSecureCryptedMnemonicPassphrase.begin(), vchSecureCryptedMnemonicPassphrase.end());
499 
500  if (!vchCryptedMnemonic.empty() && !DecryptSecret(vMasterKey, vchCryptedMnemonic, cryptedHDChain.GetID(), vchSecureMnemonic))
501  return false;
502  if (!vchCryptedMnemonicPassphrase.empty() && !DecryptSecret(vMasterKey, vchCryptedMnemonicPassphrase, cryptedHDChain.GetID(), vchSecureMnemonicPassphrase))
503  return false;
504 
505  if (!hdChainRet.SetMnemonic(vchSecureMnemonic, vchSecureMnemonicPassphrase, false))
506  return false;
507  }
508 
509  hdChainRet.SetCrypted(false);
510  hdChainRet.Debug(__func__);
511 
512  return true;
513 }
514 
516 {
517  if (IsCrypted())
518  return false;
519 
520  if (chain.IsCrypted())
521  return false;
522 
523  hdChain = chain;
524  return true;
525 }
526 
528 {
529  if (!SetCrypted())
530  return false;
531 
532  if (!chain.IsCrypted())
533  return false;
534 
535  cryptedHDChain = chain;
536  return true;
537 }
538 
539 bool CCryptoKeyStore::GetHDChain(CHDChain& hdChainRet) const
540 {
541  if(IsCrypted()) {
542  hdChainRet = cryptedHDChain;
543  return !cryptedHDChain.IsNull();
544  }
545 
546  hdChainRet = hdChain;
547  return !hdChain.IsNull();
548 }
bool SetKeyFromPassphrase(const SecureString &strKeyData, const std::vector< unsigned char > &chSalt, const unsigned int nRounds, const unsigned int nDerivationMethod)
Definition: crypter.cpp:42
bool SetHDChain(const CHDChain &chain)
Definition: crypter.cpp:515
bool Lock(bool fForMixing=false)
Definition: crypter.cpp:230
CCriticalSection cs_KeyStore
Definition: keystore.h:22
bool HaveKey(const CKeyID &address) const override
Check whether a key corresponding to a given address is present in the store.
Definition: crypter.cpp:334
const unsigned int WALLET_CRYPTO_KEY_SIZE
Definition: crypter.h:14
bool Encrypt(const CKeyingMaterial &vchPlaintext, std::vector< unsigned char > &vchCiphertext) const
Definition: crypter.cpp:74
bool EncryptAES256(const SecureString &sKey, const SecureString &sPlaintext, const std::string &sIV, std::string &sCiphertext)
Definition: crypter.cpp:123
bool SetKey(const CKeyingMaterial &chNewKey, const std::vector< unsigned char > &chNewIV)
Definition: crypter.cpp:62
Encryption/decryption context with key information.
Definition: crypter.h:76
bool VerifyPubKey(const CPubKey &vchPubKey) const
Verify thoroughly whether a private key and a public key match.
Definition: key.cpp:207
CPubKey GetPubKey() const
Compute the public key from a private key.
Definition: key.cpp:179
bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const override
Definition: keystore.cpp:14
bool IsCrypted() const
Definition: crypter.h:155
bool SetCrypted()
Definition: crypter.cpp:190
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:57
std::set< CKeyID > GetKeys() const override
Definition: keystore.cpp:43
uint256 GetHash() const
Get the 256-bit hash of this public key.
Definition: pubkey.h:155
std::vector< unsigned char, secure_allocator< unsigned char > > CKeyingMaterial
Definition: keystore.h:85
uint256 GetID() const
Definition: hdchain.h:110
bool EncryptKeys(CKeyingMaterial &vMasterKeyIn)
will encrypt previously unencrypted keys
Definition: crypter.cpp:389
int BytesToKeySHA512AES(const std::vector< unsigned char > &chSalt, const SecureString &strKeyData, int count, unsigned char *key, unsigned char *iv) const
Definition: crypter.cpp:16
static bool DecryptKey(const CKeyingMaterial &vMasterKey, const std::vector< unsigned char > &vchCryptedSecret, const CPubKey &vchPubKey, CKey &key)
Definition: crypter.cpp:177
int Decrypt(const unsigned char *data, int size, unsigned char *out) const
Definition: aes.cpp:176
std::atomic< bool > fUseCrypto
if fUseCrypto is true, mapKeys must be empty if fUseCrypto is false, vMasterKey must be empty ...
Definition: crypter.h:128
CKeyingMaterial vMasterKey
Definition: crypter.h:124
bool Decrypt(const std::vector< unsigned char > &vchCiphertext, CKeyingMaterial &vchPlaintext) const
Definition: crypter.cpp:92
const unsigned int WALLET_CRYPTO_IV_SIZE
Definition: crypter.h:16
bool Unlock(const CKeyingMaterial &vMasterKeyIn, bool fForMixingOnly=false)
Definition: crypter.cpp:245
virtual bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret)
Definition: crypter.cpp:323
const unsigned char * begin() const
Definition: key.h:89
void Debug(const std::string &strName) const
Definition: hdchain.cpp:42
uint256 GetSeedHash()
Definition: hdchain.cpp:146
bool DecryptAES256(const SecureString &sKey, const std::string &sCiphertext, const std::string &sIV, SecureString &sPlaintext)
Definition: crypter.cpp:155
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Definition: pubkey.h:149
bool fOnlyMixingAllowed
if fOnlyMixingAllowed is true, only mixing should be allowed in unlocked wallet
Definition: crypter.h:134
CHDChain hdChain
Definition: keystore.h:64
bool SetCryptedHDChain(const CHDChain &chain)
Definition: crypter.cpp:527
bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const override
Definition: crypter.cpp:360
void Finalize(unsigned char hash[OUTPUT_SIZE])
Definition: sha512.cpp:185
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) override
Add a key to the store.
Definition: crypter.cpp:299
boost::signals2::signal< void(CCryptoKeyStore *wallet)> NotifyStatusChanged
Wallet status (encrypted, locked) changed.
Definition: crypter.h:172
void memory_cleanse(void *ptr, size_t len)
Definition: cleanse.cpp:31
static const size_t OUTPUT_SIZE
Definition: sha512.h:20
#define LogPrintf(...)
Definition: util.h:203
void SetCrypted(bool fCryptedIn)
Definition: hdchain.cpp:32
std::vector< unsigned char, secure_allocator< unsigned char > > vchKey
Definition: crypter.h:80
std::vector< unsigned char, secure_allocator< unsigned char > > vchIV
Definition: crypter.h:81
#define LOCK(cs)
Definition: sync.h:178
bool fKeySet
Definition: crypter.h:82
CSHA512 & Reset()
Definition: sha512.cpp:202
std::vector< unsigned char, secure_allocator< unsigned char > > SecureVector
Definition: secure.h:59
An encapsulated public key.
Definition: pubkey.h:30
virtual bool GetHDChain(CHDChain &hdChainRet) const override
Definition: crypter.cpp:539
int Encrypt(const unsigned char *data, int size, unsigned char *out) const
Definition: aes.cpp:159
bool IsNull() const
Definition: hdchain.cpp:27
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) override
Add a key to the store.
Definition: keystore.cpp:30
bool EncryptHDChain(const CKeyingMaterial &vMasterKeyIn)
Definition: crypter.cpp:411
bool GetKey(const CKeyID &address, CKey &keyOut) const override
Definition: crypter.cpp:343
bool GetKey(const CKeyID &address, CKey &keyOut) const override
Definition: keystore.cpp:53
void Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
Definition: key.h:74
static bool DecryptSecret(const CKeyingMaterial &vMasterKey, const std::vector< unsigned char > &vchCiphertext, const uint256 &nIV, CKeyingMaterial &vchPlaintext)
Definition: crypter.cpp:144
KeyMap mapKeys
Definition: keystore.h:59
256-bit opaque blob.
Definition: uint256.h:123
const unsigned int WALLET_CRYPTO_SALT_SIZE
Definition: crypter.h:15
bool GetMnemonic(SecureVector &vchMnemonicRet, SecureVector &vchMnemonicPassphraseRet) const
Definition: hdchain.cpp:107
CryptedKeyMap mapCryptedKeys
Definition: crypter.h:148
SecureVector GetSeed() const
Definition: hdchain.cpp:141
bool IsLocked(bool fForMixing=false) const
Definition: crypter.cpp:209
void * memcpy(void *a, const void *b, size_t c)
const unsigned char * end() const
Definition: key.h:90
CSHA512 & Write(const unsigned char *data, size_t len)
Definition: sha512.cpp:159
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:20
static int count
Definition: tests.c:45
bool SetMnemonic(const SecureVector &vchMnemonic, const SecureVector &vchMnemonicPassphrase, bool fUpdateID)
Definition: hdchain.cpp:72
bool IsCrypted() const
Definition: hdchain.cpp:37
bool SetSeed(const SecureVector &vchSeedIn, bool fUpdateID)
Definition: hdchain.cpp:130
An encapsulated private key.
Definition: key.h:27
A hasher class for SHA-512.
Definition: sha512.h:12
bool SetNull()
Definition: hdchain.cpp:12
std::set< CKeyID > GetKeys() const override
Definition: crypter.cpp:376
bool HaveKey(const CKeyID &address) const override
Check whether a key corresponding to a given address is present in the store.
Definition: keystore.cpp:37
bool fDecryptionThoroughlyChecked
keeps track of whether Unlock has run a thorough check before
Definition: crypter.h:131
CHDChain cryptedHDChain
Definition: crypter.h:122
static const int AES_BLOCKSIZE
Definition: aes.h:14
bool DecryptHDChain(CHDChain &hdChainRet) const
Definition: crypter.cpp:464
static bool EncryptSecret(const CKeyingMaterial &vMasterKey, const CKeyingMaterial &vchPlaintext, const uint256 &nIV, std::vector< unsigned char > &vchCiphertext)
Definition: crypter.cpp:111
bool IsCompressed() const
Check whether this is a compressed public key.
Definition: pubkey.h:174
Released under the MIT license