| 12 | #include "commons/openssl.hpp" |
| 13 | |
| 14 | bool 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 | |
| 34 | bool CCrypter::SetKey(const CKeyingMaterial& chNewKey, const vector<unsigned char>& chNewIV) { |
| 35 | if (chNewKey.size() != WALLET_CRYPTO_KEY_SIZE || chNewIV.size() != WALLET_CRYPTO_KEY_SIZE) |
no test coverage detected