blob: 3d8cd62861a302ff81b33a954363c13dfc525dbb [file] [log] [blame]
Martin Willi31d72472015-07-16 19:14:00 +02001/*
Eric Biggers1141ebc2018-11-16 17:26:20 -08002 * Common values and helper functions for the ChaCha20 and XChaCha20 algorithms.
3 *
4 * XChaCha20 extends ChaCha20's nonce to 192 bits, while provably retaining
5 * ChaCha20's security. Here they share the same key size, tfm context, and
6 * setkey function; only their IV size and encrypt/decrypt function differ.
Martin Willi31d72472015-07-16 19:14:00 +02007 */
8
9#ifndef _CRYPTO_CHACHA20_H
10#define _CRYPTO_CHACHA20_H
11
12#include <linux/types.h>
13#include <linux/crypto.h>
14
Eric Biggers1141ebc2018-11-16 17:26:20 -080015/* 32-bit stream position, then 96-bit nonce (RFC7539 convention) */
Martin Willi31d72472015-07-16 19:14:00 +020016#define CHACHA20_IV_SIZE 16
Eric Biggers1141ebc2018-11-16 17:26:20 -080017
Martin Willi31d72472015-07-16 19:14:00 +020018#define CHACHA20_KEY_SIZE 32
19#define CHACHA20_BLOCK_SIZE 64
20
Eric Biggers1141ebc2018-11-16 17:26:20 -080021/* 192-bit nonce, then 64-bit stream position */
22#define XCHACHA20_IV_SIZE 32
23
Martin Willi31d72472015-07-16 19:14:00 +020024struct chacha20_ctx {
25 u32 key[8];
26};
27
Eric Biggersede5c832018-09-11 20:05:10 -070028void chacha20_block(u32 *state, u8 *stream);
Eric Biggersbc41a672018-11-16 17:26:18 -080029void hchacha20_block(const u32 *in, u32 *out);
30
Martin Willi31d72472015-07-16 19:14:00 +020031void crypto_chacha20_init(u32 *state, struct chacha20_ctx *ctx, u8 *iv);
32int crypto_chacha20_setkey(struct crypto_tfm *tfm, const u8 *key,
33 unsigned int keysize);
34int crypto_chacha20_crypt(struct blkcipher_desc *desc, struct scatterlist *dst,
35 struct scatterlist *src, unsigned int nbytes);
Eric Biggers1141ebc2018-11-16 17:26:20 -080036int crypto_xchacha20_crypt(struct blkcipher_desc *desc, struct scatterlist *dst,
37 struct scatterlist *src, unsigned int nbytes);
Martin Willi31d72472015-07-16 19:14:00 +020038
39#endif