| 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 | { |
no test coverage detected