]> asedeno.scripts.mit.edu Git - linux.git/blob - include/crypto/chacha20.h
crypto: chacha20-generic - add XChaCha20 support
[linux.git] / include / crypto / chacha20.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Common values and helper functions for the ChaCha20 and XChaCha20 algorithms.
4  *
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.
8  */
9
10 #ifndef _CRYPTO_CHACHA20_H
11 #define _CRYPTO_CHACHA20_H
12
13 #include <crypto/skcipher.h>
14 #include <linux/types.h>
15 #include <linux/crypto.h>
16
17 /* 32-bit stream position, then 96-bit nonce (RFC7539 convention) */
18 #define CHACHA20_IV_SIZE        16
19
20 #define CHACHA20_KEY_SIZE       32
21 #define CHACHA20_BLOCK_SIZE     64
22 #define CHACHAPOLY_IV_SIZE      12
23
24 /* 192-bit nonce, then 64-bit stream position */
25 #define XCHACHA20_IV_SIZE       32
26
27 struct chacha20_ctx {
28         u32 key[8];
29 };
30
31 void chacha20_block(u32 *state, u8 *stream);
32 void hchacha20_block(const u32 *in, u32 *out);
33
34 void crypto_chacha20_init(u32 *state, struct chacha20_ctx *ctx, u8 *iv);
35
36 int crypto_chacha20_setkey(struct crypto_skcipher *tfm, const u8 *key,
37                            unsigned int keysize);
38
39 int crypto_chacha20_crypt(struct skcipher_request *req);
40 int crypto_xchacha20_crypt(struct skcipher_request *req);
41
42 #endif