36 #define CHACHA_KEY_SIZE 32
37 #define CHACHA_IV_SIZE 8
39 #if defined(__cplusplus)
49 void chacha8(
const void* data,
size_t length,
const uint8_t* key,
const uint8_t*
iv,
char* cipher);
50 void chacha20(
const void* data,
size_t length,
const uint8_t* key,
const uint8_t*
iv,
char* cipher);
51 #if defined(__cplusplus)
54 using chacha_key = epee::mlocked<tools::scrubbed_arr<uint8_t, CHACHA_KEY_SIZE>>;
65 inline void chacha8(
const void* data, std::size_t length,
const chacha_key& key,
const chacha_iv&
iv,
char* cipher) {
66 chacha8(data, length, key.data(),
reinterpret_cast<const uint8_t*
>(&
iv), cipher);
69 inline void chacha20(
const void* data, std::size_t length,
const chacha_key& key,
const chacha_iv&
iv,
char* cipher) {
70 chacha20(data, length, key.data(),
reinterpret_cast<const uint8_t*
>(&
iv), cipher);
73 inline void generate_chacha_key(
const void *data,
size_t size, chacha_key& key, uint64_t kdf_rounds) {
74 static_assert(
sizeof(chacha_key) <=
sizeof(
hash),
"Size of hash must be at least that of chacha_key");
75 epee::mlocked<tools::scrubbed_arr<char, HASH_SIZE>> pwd_hash;
77 for (uint64_t n = 1; n < kdf_rounds; ++n)
79 memcpy(&unwrap(unwrap(key)), pwd_hash.data(),
sizeof(key));
82 inline void generate_chacha_key_prehashed(
const void *data,
size_t size, chacha_key& key, uint64_t kdf_rounds) {
83 static_assert(
sizeof(chacha_key) <=
sizeof(
hash),
"Size of hash must be at least that of chacha_key");
84 epee::mlocked<tools::scrubbed_arr<char, HASH_SIZE>> pwd_hash;
86 for (uint64_t n = 1; n < kdf_rounds; ++n)
88 memcpy(&unwrap(unwrap(key)), pwd_hash.data(),
sizeof(key));
91 inline void generate_chacha_key(std::string password, chacha_key& key, uint64_t kdf_rounds) {
92 return generate_chacha_key(password.data(), password.size(), key, kdf_rounds);
void chacha20(const void *data, size_t length, const uint8_t *key, const uint8_t *iv, char *cipher)
Definition: chacha.c:179
#define CHACHA_KEY_SIZE
Definition: chacha.h:36
void chacha8(const void *data, size_t length, const uint8_t *key, const uint8_t *iv, char *cipher)
Definition: chacha.c:174
#define CHACHA_IV_SIZE
Definition: chacha.h:37
void * memcpy(void *a, const void *b, size_t c)
Definition: glibc_compat.cpp:16
crypto namespace.
Definition: crypto.cpp:58
POD_CLASS hash
Definition: hash.h:50
void cn_slow_hash(const void *data, std::size_t length, hash &hash, int variant=0, uint64_t height=0)
Definition: hash.h:79
static const unsigned char iv[64]
Definition: sha512-hash.c:13