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