diff options
Diffstat (limited to 'src/crypto/chacha8.h')
-rw-r--r-- | src/crypto/chacha8.h | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/src/crypto/chacha8.h b/src/crypto/chacha8.h index 1bf695731..dcbe6a933 100644 --- a/src/crypto/chacha8.h +++ b/src/crypto/chacha8.h @@ -49,16 +49,9 @@ namespace crypto { #if defined(__cplusplus) } -#pragma pack(push, 1) - struct chacha8_key { - uint8_t data[CHACHA8_KEY_SIZE]; - - ~chacha8_key() - { - memwipe(data, sizeof(data)); - } - }; + using chacha8_key = tools::scrubbed_arr<uint8_t, CHACHA8_KEY_SIZE>; +#pragma pack(push, 1) // MS VC 2012 doesn't interpret `class chacha8_iv` as POD in spite of [9.0.10], so it is a struct struct chacha8_iv { uint8_t data[CHACHA8_IV_SIZE]; @@ -68,15 +61,14 @@ namespace crypto { static_assert(sizeof(chacha8_key) == CHACHA8_KEY_SIZE && sizeof(chacha8_iv) == CHACHA8_IV_SIZE, "Invalid structure size"); inline void chacha8(const void* data, std::size_t length, const chacha8_key& key, const chacha8_iv& iv, char* cipher) { - chacha8(data, length, reinterpret_cast<const uint8_t*>(&key), reinterpret_cast<const uint8_t*>(&iv), cipher); + chacha8(data, length, key.data(), reinterpret_cast<const uint8_t*>(&iv), cipher); } inline void generate_chacha8_key(const void *data, size_t size, chacha8_key& key) { static_assert(sizeof(chacha8_key) <= sizeof(hash), "Size of hash must be at least that of chacha8_key"); - char pwd_hash[HASH_SIZE]; - crypto::cn_slow_hash(data, size, pwd_hash); - memcpy(&key, pwd_hash, sizeof(key)); - memwipe(pwd_hash, sizeof(pwd_hash)); + tools::scrubbed_arr<char, HASH_SIZE> pwd_hash; + crypto::cn_slow_hash(data, size, pwd_hash.data()); + memcpy(&key, pwd_hash.data(), sizeof(key)); } inline void generate_chacha8_key(std::string password, chacha8_key& key) { |