GNU Linux-libre 4.9.337-gnu1
[releases.git] / include / crypto / chacha20.h
1 /*
2  * Common values for the ChaCha20 algorithm
3  */
4
5 #ifndef _CRYPTO_CHACHA20_H
6 #define _CRYPTO_CHACHA20_H
7
8 #include <linux/types.h>
9 #include <linux/crypto.h>
10
11 #define CHACHA20_IV_SIZE        16
12 #define CHACHA20_KEY_SIZE       32
13 #define CHACHA20_BLOCK_SIZE     64
14
15 struct chacha20_ctx {
16         u32 key[8];
17 };
18
19 void chacha20_block(u32 *state, u8 *stream);
20 void crypto_chacha20_init(u32 *state, struct chacha20_ctx *ctx, u8 *iv);
21 int crypto_chacha20_setkey(struct crypto_tfm *tfm, const u8 *key,
22                            unsigned int keysize);
23 int crypto_chacha20_crypt(struct blkcipher_desc *desc, struct scatterlist *dst,
24                           struct scatterlist *src, unsigned int nbytes);
25
26 enum chacha_constants { /* expand 32-byte k */
27         CHACHA_CONSTANT_EXPA = 0x61707865U,
28         CHACHA_CONSTANT_ND_3 = 0x3320646eU,
29         CHACHA_CONSTANT_2_BY = 0x79622d32U,
30         CHACHA_CONSTANT_TE_K = 0x6b206574U
31 };
32
33 static inline void chacha_init_consts(u32 *state)
34 {
35         state[0]  = CHACHA_CONSTANT_EXPA;
36         state[1]  = CHACHA_CONSTANT_ND_3;
37         state[2]  = CHACHA_CONSTANT_2_BY;
38         state[3]  = CHACHA_CONSTANT_TE_K;
39 }
40
41 #endif