MCPcopy Create free account
hub / github.com/ElementsProject/elements / BytesToKeySHA512AES

Method BytesToKeySHA512AES

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

Source from the content-addressed store, hash-verified

12
13namespace wallet {
14int CCrypter::BytesToKeySHA512AES(const std::vector<unsigned char>& chSalt, const SecureString& strKeyData, int count, unsigned char *key,unsigned char *iv) const
15{
16 // This mimics the behavior of openssl's EVP_BytesToKey with an aes256cbc
17 // cipher and sha512 message digest. Because sha512's output size (64b) is
18 // greater than the aes256 block size (16b) + aes256 key size (32b),
19 // there's no need to process more than once (D_0).
20
21 if(!count || !key || !iv)
22 return 0;
23
24 unsigned char buf[CSHA512::OUTPUT_SIZE];
25 CSHA512 di;
26
27 di.Write((const unsigned char*)strKeyData.data(), strKeyData.size());
28 di.Write(chSalt.data(), chSalt.size());
29 di.Finalize(buf);
30
31 for(int i = 0; i != count - 1; i++)
32 di.Reset().Write(buf, sizeof(buf)).Finalize(buf);
33
34 memcpy(key, buf, WALLET_CRYPTO_KEY_SIZE);
35 memcpy(iv, buf + WALLET_CRYPTO_KEY_SIZE, WALLET_CRYPTO_IV_SIZE);
36 memory_cleanse(buf, sizeof(buf));
37 return WALLET_CRYPTO_KEY_SIZE;
38}
39
40bool CCrypter::SetKeyFromPassphrase(const SecureString& strKeyData, const std::vector<unsigned char>& chSalt, const unsigned int nRounds, const unsigned int nDerivationMethod)
41{

Callers

nothing calls this directly

Calls 6

memory_cleanseFunction · 0.85
WriteMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
FinalizeMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected