MCPcopy Create free account
hub / github.com/bcndev/bytecoin / encrypt_data

Method encrypt_data

src/Core/WalletHDsqlite.cpp:232–248  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

230}
231
232BinaryArray 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
250BinaryArray WalletHDsqlite::decrypt_data(const chacha_key &wallet_key, const uint8_t *value_data, size_t value_size) {
251 Hash iv;

Callers

nothing calls this directly

Calls 6

cn_fast_hashFunction · 0.85
chachaFunction · 0.85
uint_le_to_bytesFunction · 0.50
sizeMethod · 0.45
dataMethod · 0.45
as_binary_arrayMethod · 0.45

Tested by

no test coverage detected