| 39 | } |
| 40 | |
| 41 | bool CCrypter::SetKeyFromPassphrase(const SecureString& key_data, const std::span<const unsigned char> salt, const unsigned int rounds, const unsigned int derivation_method) |
| 42 | { |
| 43 | if (rounds < 1 || salt.size() != WALLET_CRYPTO_SALT_SIZE) { |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | int i = 0; |
| 48 | if (derivation_method == 0) { |
| 49 | i = BytesToKeySHA512AES(salt, key_data, rounds, vchKey.data(), vchIV.data()); |
| 50 | } |
| 51 | |
| 52 | if (i != (int)WALLET_CRYPTO_KEY_SIZE) |
| 53 | { |
| 54 | memory_cleanse(vchKey.data(), vchKey.size()); |
| 55 | memory_cleanse(vchIV.data(), vchIV.size()); |
| 56 | return false; |
| 57 | } |
| 58 | |
| 59 | fKeySet = true; |
| 60 | return true; |
| 61 | } |
| 62 | |
| 63 | bool CCrypter::SetKey(const CKeyingMaterial& new_key, const std::span<const unsigned char> new_iv) |
| 64 | { |