increment their nonce by n. (Also make sure the counters never wrap
around.)
-### void crypto\_chacha20\_Xinit()
+### void crypto\_chacha20\_x_init()
- void crypto_chacha20_Xinit(crypto_chacha_ctx *ctx,
- const uint8_t key[32],
- const uint8_t nonce[24]);
+ void crypto_chacha20_x_init(crypto_chacha_ctx *ctx,
+ const uint8_t key[32],
+ const uint8_t nonce[24]);
Initialises a chacha context with a big nonce (192 bits). This nonce
is big enough to be selected at random (use the OS; avoid user space
ctx->input[15] = load32_le(nonce + 4); // nonce
}
-void crypto_chacha20_Xinit(crypto_chacha_ctx *ctx,
- const u8 key[32],
- const u8 nonce[24])
+void crypto_chacha20_x_init(crypto_chacha_ctx *ctx,
+ const u8 key[32],
+ const u8 nonce[24])
{
u8 derived_key[32];
crypto_chacha20_H(derived_key, key, nonce);
{ // encrypt then mac
u8 auth_key[32];
crypto_chacha_ctx e_ctx;
- crypto_chacha20_Xinit (&e_ctx, key, nonce);
+ crypto_chacha20_x_init (&e_ctx, key, nonce);
crypto_chacha20_stream (&e_ctx, auth_key, 32);
crypto_chacha20_encrypt(&e_ctx, ciphertext, plaintext, text_size);
authenticate2(mac, auth_key, ad, ad_size, ciphertext, text_size);
{
u8 auth_key[32], real_mac[16];
crypto_chacha_ctx e_ctx;
- crypto_chacha20_Xinit (&e_ctx, key, nonce);
+ crypto_chacha20_x_init(&e_ctx, key, nonce);
crypto_chacha20_stream(&e_ctx, auth_key, 32);
authenticate2(real_mac, auth_key, ad, ad_size, ciphertext, text_size);
if (crypto_memcmp(real_mac, mac, 16)) { return -1; } // reject forgeries
const uint8_t key[32],
const uint8_t nonce[8]);
-void crypto_chacha20_Xinit(crypto_chacha_ctx *ctx,
- const uint8_t key[32],
- const uint8_t nonce[24]);
+void crypto_chacha20_x_init(crypto_chacha_ctx *ctx,
+ const uint8_t key[32],
+ const uint8_t nonce[24]);
void crypto_chacha20_encrypt(crypto_chacha_ctx *ctx,
uint8_t *cipher_text,
p_random(nonce, 24);
p_random(in, size);
rename_chacha_ctx ctx;
- rename_chacha20_Xinit(&ctx, key, nonce);
+ rename_chacha20_x_init(&ctx, key, nonce);
rename_chacha20_encrypt(&ctx, mono, in, size);
crypto_stream_xchacha20_xor(sodium, in, size, nonce, key);
status |= rename_memcmp(mono, sodium, size);
const vector *key = in;
const vector *nonce = in + 1;
crypto_chacha_ctx ctx;
- crypto_chacha20_Xinit (&ctx, key->buf, nonce->buf);
+ crypto_chacha20_x_init(&ctx, key->buf, nonce->buf);
crypto_chacha20_stream(&ctx, out->buf, out->size);
}