3 The ChaCha stream cipher.
5 Copyright (C) 2013 Joachim Strömbergson
6 Copyright (C) 2012 Simon Josefsson
7 Copyright (C) 2014 Niels Möller
9 This file is part of GNU Nettle.
11 GNU Nettle is free software: you can redistribute it and/or
12 modify it under the terms of either:
14 * the GNU Lesser General Public License as published by the Free
15 Software Foundation; either version 3 of the License, or (at your
16 option) any later version.
20 * the GNU General Public License as published by the Free
21 Software Foundation; either version 2 of the License, or (at your
22 option) any later version.
24 or both in parallel, as here.
26 GNU Nettle is distributed in the hope that it will be useful,
27 but WITHOUT ANY WARRANTY; without even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 General Public License for more details.
31 You should have received copies of the GNU General Public License and
32 the GNU Lesser General Public License along with this program. If
33 not, see http://www.gnu.org/licenses/.
36 #ifndef NETTLE_CHACHA_H_INCLUDED
37 #define NETTLE_CHACHA_H_INCLUDED
39 #include "nettle-types.h"
46 #define chacha_set_key nettle_chacha_set_key
47 #define chacha_set_nonce nettle_chacha_set_nonce
48 #define chacha_set_nonce96 nettle_chacha_set_nonce96
49 #define chacha_crypt nettle_chacha_crypt
51 /* Currently, only 256-bit keys are supported. */
52 #define CHACHA_KEY_SIZE 32
53 #define CHACHA_BLOCK_SIZE 64
54 #define CHACHA_NONCE_SIZE 8
55 #define CHACHA_NONCE96_SIZE 12
57 #define _CHACHA_STATE_LENGTH 16
61 /* Indices 0-3 holds a constant (SIGMA or TAU).
62 Indices 4-11 holds the key.
63 Indices 12-13 holds the block counter.
64 Indices 14-15 holds the IV:
66 This creates the state matrix:
72 uint32_t state[_CHACHA_STATE_LENGTH];
76 chacha_set_key(struct chacha_ctx *ctx, const uint8_t *key);
79 chacha_set_nonce(struct chacha_ctx *ctx, const uint8_t *nonce);
82 chacha_set_nonce96(struct chacha_ctx *ctx, const uint8_t *nonce);
85 chacha_crypt(struct chacha_ctx *ctx, size_t length,
86 uint8_t *dst, const uint8_t *src);
92 #endif /* NETTLE_CHACHA_H_INCLUDED */