MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / SetKeyFromPassphrase

Method SetKeyFromPassphrase

src/wallet/crypter.cpp:14–32  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12#include "commons/openssl.hpp"
13
14bool CCrypter::SetKeyFromPassphrase(const SecureString& strKeyData, const vector<unsigned char>& chSalt,
15 const uint32_t nRounds, const uint32_t nDerivationMethod) {
16 if (nRounds < 1 || chSalt.size() != WALLET_CRYPTO_SALT_SIZE)
17 return false;
18
19 int32_t i = 0;
20 if (nDerivationMethod == 0)
21 i = EVP_BytesToKey(EVP_aes_256_cbc(), EVP_sha512(), &chSalt[0], (unsigned char*)&strKeyData[0],
22 strKeyData.size(), nRounds, chKey, chIV);
23
24 if (i != (int32_t)WALLET_CRYPTO_KEY_SIZE) {
25 OPENSSL_cleanse(chKey, sizeof(chKey));
26 OPENSSL_cleanse(chIV, sizeof(chIV));
27 return false;
28 }
29
30 fKeySet = true;
31 return true;
32}
33
34bool CCrypter::SetKey(const CKeyingMaterial& chNewKey, const vector<unsigned char>& chNewIV) {
35 if (chNewKey.size() != WALLET_CRYPTO_KEY_SIZE || chNewIV.size() != WALLET_CRYPTO_KEY_SIZE)

Callers 3

UnlockMethod · 0.80
EncryptWalletMethod · 0.80

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected