Martin Willi | 31d7247 | 2015-07-16 19:14:00 +0200 | [diff] [blame] | 1 | /* |
Eric Biggers | 1141ebc | 2018-11-16 17:26:20 -0800 | [diff] [blame^] | 2 | * 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 Willi | 31d7247 | 2015-07-16 19:14:00 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef _CRYPTO_CHACHA20_H |
| 10 | #define _CRYPTO_CHACHA20_H |
| 11 | |
| 12 | #include <linux/types.h> |
| 13 | #include <linux/crypto.h> |
| 14 | |
Eric Biggers | 1141ebc | 2018-11-16 17:26:20 -0800 | [diff] [blame^] | 15 | /* 32-bit stream position, then 96-bit nonce (RFC7539 convention) */ |
Martin Willi | 31d7247 | 2015-07-16 19:14:00 +0200 | [diff] [blame] | 16 | #define CHACHA20_IV_SIZE 16 |
Eric Biggers | 1141ebc | 2018-11-16 17:26:20 -0800 | [diff] [blame^] | 17 | |
Martin Willi | 31d7247 | 2015-07-16 19:14:00 +0200 | [diff] [blame] | 18 | #define CHACHA20_KEY_SIZE 32 |
| 19 | #define CHACHA20_BLOCK_SIZE 64 |
| 20 | |
Eric Biggers | 1141ebc | 2018-11-16 17:26:20 -0800 | [diff] [blame^] | 21 | /* 192-bit nonce, then 64-bit stream position */ |
| 22 | #define XCHACHA20_IV_SIZE 32 |
| 23 | |
Martin Willi | 31d7247 | 2015-07-16 19:14:00 +0200 | [diff] [blame] | 24 | struct chacha20_ctx { |
| 25 | u32 key[8]; |
| 26 | }; |
| 27 | |
Eric Biggers | ede5c83 | 2018-09-11 20:05:10 -0700 | [diff] [blame] | 28 | void chacha20_block(u32 *state, u8 *stream); |
Eric Biggers | bc41a67 | 2018-11-16 17:26:18 -0800 | [diff] [blame] | 29 | void hchacha20_block(const u32 *in, u32 *out); |
| 30 | |
Martin Willi | 31d7247 | 2015-07-16 19:14:00 +0200 | [diff] [blame] | 31 | void crypto_chacha20_init(u32 *state, struct chacha20_ctx *ctx, u8 *iv); |
| 32 | int crypto_chacha20_setkey(struct crypto_tfm *tfm, const u8 *key, |
| 33 | unsigned int keysize); |
| 34 | int crypto_chacha20_crypt(struct blkcipher_desc *desc, struct scatterlist *dst, |
| 35 | struct scatterlist *src, unsigned int nbytes); |
Eric Biggers | 1141ebc | 2018-11-16 17:26:20 -0800 | [diff] [blame^] | 36 | int crypto_xchacha20_crypt(struct blkcipher_desc *desc, struct scatterlist *dst, |
| 37 | struct scatterlist *src, unsigned int nbytes); |
Martin Willi | 31d7247 | 2015-07-16 19:14:00 +0200 | [diff] [blame] | 38 | |
| 39 | #endif |