MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / BytesToKeySHA512AES

Method BytesToKeySHA512AES

src/wallet/crypter.cpp:16–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14#include <vector>
15
16int 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);
37 memcpy(iv, buf + WALLET_CRYPTO_KEY_SIZE, WALLET_CRYPTO_IV_SIZE);
38 memory_cleanse(buf, sizeof(buf));
39 return WALLET_CRYPTO_KEY_SIZE;
40}
41
42bool CCrypter::SetKeyFromPassphrase(const SecureString& strKeyData, const std::vector<unsigned char>& chSalt, const unsigned int nRounds, const unsigned int nDerivationMethod)
43{

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected