| 230 | } |
| 231 | |
| 232 | BinaryArray WalletHDsqlite::encrypt_data(const chacha_key &wallet_key, const BinaryArray &data) { |
| 233 | const size_t MIN_SIZE = 256; |
| 234 | const size_t EXTRA_SIZE = sizeof(Hash) + 4; // iv, actual size in le |
| 235 | size_t actual_size = 1; |
| 236 | while (actual_size < data.size() + EXTRA_SIZE || actual_size < MIN_SIZE) |
| 237 | actual_size *= 2; |
| 238 | BinaryArray large_data(actual_size - sizeof(Hash)); |
| 239 | uint_le_to_bytes(large_data.data(), 4, data.size()); |
| 240 | memcpy(large_data.data() + 4, data.data(), data.size()); |
| 241 | BinaryArray enc_data(sizeof(Hash) + large_data.size()); |
| 242 | Hash iv = crypto::rand<Hash>(); |
| 243 | memcpy(enc_data.data(), iv.data, sizeof(iv)); |
| 244 | const BinaryArray key_data = wallet_key.as_binary_array() | iv.as_binary_array(); |
| 245 | chacha_key key{cn_fast_hash(key_data)}; |
| 246 | chacha(20, large_data.data(), large_data.size(), key, chacha_iv{}, enc_data.data() + sizeof(Hash)); |
| 247 | return enc_data; |
| 248 | } |
| 249 | |
| 250 | BinaryArray WalletHDsqlite::decrypt_data(const chacha_key &wallet_key, const uint8_t *value_data, size_t value_size) { |
| 251 | Hash iv; |
nothing calls this directly
no test coverage detected