diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2017-12-07 13:27:11 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2017-12-25 19:28:03 +0000 |
commit | 1e5491e942d0a372ebebe9ef3d40941fc4a4fbb6 (patch) | |
tree | d13f404893c3994db28935da90947fbea1fc7cd5 /src/crypto/chacha.h | |
parent | Merge pull request #2936 (diff) | |
download | monero-1e5491e942d0a372ebebe9ef3d40941fc4a4fbb6.tar.xz |
Add a chacha20 variant to go with chacha8
Diffstat (limited to '')
-rw-r--r-- | src/crypto/chacha.h (renamed from src/crypto/chacha8.h) | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/crypto/chacha8.h b/src/crypto/chacha.h index dcbe6a933..a9665030d 100644 --- a/src/crypto/chacha8.h +++ b/src/crypto/chacha.h @@ -33,8 +33,8 @@ #include <stdint.h> #include <stddef.h> -#define CHACHA8_KEY_SIZE 32 -#define CHACHA8_IV_SIZE 8 +#define CHACHA_KEY_SIZE 32 +#define CHACHA_IV_SIZE 8 #if defined(__cplusplus) #include <memory.h> @@ -46,33 +46,38 @@ namespace crypto { extern "C" { #endif void chacha8(const void* data, size_t length, const uint8_t* key, const uint8_t* iv, char* cipher); + void chacha20(const void* data, size_t length, const uint8_t* key, const uint8_t* iv, char* cipher); #if defined(__cplusplus) } - using chacha8_key = tools::scrubbed_arr<uint8_t, CHACHA8_KEY_SIZE>; + using chacha_key = tools::scrubbed_arr<uint8_t, CHACHA_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]; + // MS VC 2012 doesn't interpret `class chacha_iv` as POD in spite of [9.0.10], so it is a struct + struct chacha_iv { + uint8_t data[CHACHA_IV_SIZE]; }; #pragma pack(pop) - static_assert(sizeof(chacha8_key) == CHACHA8_KEY_SIZE && sizeof(chacha8_iv) == CHACHA8_IV_SIZE, "Invalid structure size"); + static_assert(sizeof(chacha_key) == CHACHA_KEY_SIZE && sizeof(chacha_iv) == CHACHA_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) { + inline void chacha8(const void* data, std::size_t length, const chacha_key& key, const chacha_iv& iv, char* 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"); + inline void chacha20(const void* data, std::size_t length, const chacha_key& key, const chacha_iv& iv, char* cipher) { + chacha20(data, length, key.data(), reinterpret_cast<const uint8_t*>(&iv), cipher); + } + + inline void generate_chacha_key(const void *data, size_t size, chacha_key& key) { + static_assert(sizeof(chacha_key) <= sizeof(hash), "Size of hash must be at least that of chacha_key"); 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) { - return generate_chacha8_key(password.data(), password.size(), key); + inline void generate_chacha_key(std::string password, chacha_key& key) { + return generate_chacha_key(password.data(), password.size(), key); } } |