cfb8: Fix decrypt path
[gd/nettle] / chacha.h
1 /* chacha.h
2
3    The ChaCha stream cipher.
4
5    Copyright (C) 2013 Joachim Strömbergson
6    Copyright (C) 2012 Simon Josefsson
7    Copyright (C) 2014 Niels Möller
8
9    This file is part of GNU Nettle.
10
11    GNU Nettle is free software: you can redistribute it and/or
12    modify it under the terms of either:
13
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.
17
18    or
19
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.
23
24    or both in parallel, as here.
25
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.
30
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/.
34 */
35
36 #ifndef NETTLE_CHACHA_H_INCLUDED
37 #define NETTLE_CHACHA_H_INCLUDED
38
39 #include "nettle-types.h"
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 /* Name mangling */
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
50
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
56
57 #define _CHACHA_STATE_LENGTH 16
58
59 struct chacha_ctx
60 {
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:
65
66      This creates the state matrix:
67      C C C C
68      K K K K
69      K K K K
70      B B I I
71   */
72   uint32_t state[_CHACHA_STATE_LENGTH];
73 };
74
75 void
76 chacha_set_key(struct chacha_ctx *ctx, const uint8_t *key);
77
78 void
79 chacha_set_nonce(struct chacha_ctx *ctx, const uint8_t *nonce);
80
81 void
82 chacha_set_nonce96(struct chacha_ctx *ctx, const uint8_t *nonce);
83
84 void
85 chacha_crypt(struct chacha_ctx *ctx, size_t length, 
86              uint8_t *dst, const uint8_t *src);
87
88 #ifdef __cplusplus
89 }
90 #endif
91
92 #endif /* NETTLE_CHACHA_H_INCLUDED */