Apply %restore_fcommon macro for Address Sanitizer
[platform/upstream/nettle.git] / 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 #define _chacha_core _nettle_chacha_core
51
52 /* Currently, only 256-bit keys are supported. */
53 #define CHACHA_KEY_SIZE 32
54 #define CHACHA_BLOCK_SIZE 64
55 #define CHACHA_NONCE_SIZE 8
56 #define CHACHA_NONCE96_SIZE 12
57
58 #define _CHACHA_STATE_LENGTH 16
59
60 struct chacha_ctx
61 {
62   /* Indices 0-3 holds a constant (SIGMA or TAU).
63      Indices 4-11 holds the key.
64      Indices 12-13 holds the block counter.
65      Indices 14-15 holds the IV:
66
67      This creates the state matrix:
68      C C C C
69      K K K K
70      K K K K
71      B B I I
72   */
73   uint32_t state[_CHACHA_STATE_LENGTH];
74 };
75
76 void
77 chacha_set_key(struct chacha_ctx *ctx, const uint8_t *key);
78
79 void
80 chacha_set_nonce(struct chacha_ctx *ctx, const uint8_t *nonce);
81
82 void
83 chacha_set_nonce96(struct chacha_ctx *ctx, const uint8_t *nonce);
84
85 void
86 chacha_crypt(struct chacha_ctx *ctx, size_t length, 
87              uint8_t *dst, const uint8_t *src);
88
89 void
90 _chacha_core(uint32_t *dst, const uint32_t *src, unsigned rounds);
91
92 #ifdef __cplusplus
93 }
94 #endif
95
96 #endif /* NETTLE_CHACHA_H_INCLUDED */