1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Common values and helper functions for the ChaCha20 and XChaCha20 algorithms.
5 * XChaCha20 extends ChaCha20's nonce to 192 bits, while provably retaining
6 * ChaCha20's security. Here they share the same key size, tfm context, and
7 * setkey function; only their IV size and encrypt/decrypt function differ.
10 #ifndef _CRYPTO_CHACHA20_H
11 #define _CRYPTO_CHACHA20_H
13 #include <crypto/skcipher.h>
14 #include <linux/types.h>
15 #include <linux/crypto.h>
17 /* 32-bit stream position, then 96-bit nonce (RFC7539 convention) */
18 #define CHACHA20_IV_SIZE 16
20 #define CHACHA20_KEY_SIZE 32
21 #define CHACHA20_BLOCK_SIZE 64
22 #define CHACHAPOLY_IV_SIZE 12
24 /* 192-bit nonce, then 64-bit stream position */
25 #define XCHACHA20_IV_SIZE 32
31 void chacha20_block(u32 *state, u8 *stream);
32 void hchacha20_block(const u32 *in, u32 *out);
34 void crypto_chacha20_init(u32 *state, struct chacha20_ctx *ctx, u8 *iv);
36 int crypto_chacha20_setkey(struct crypto_skcipher *tfm, const u8 *key,
37 unsigned int keysize);
39 int crypto_chacha20_crypt(struct skcipher_request *req);
40 int crypto_xchacha20_crypt(struct skcipher_request *req);