Add options to build position-independent executables
[platform/upstream/nettle.git] / salsa20.h
1 /* salsa20.h
2  *
3  * The Salsa20 stream cipher.
4  */
5
6 /* nettle, low-level cryptographics library
7  *
8  * Copyright (C) 2012 Simon Josefsson
9  * Copyright (C) 2001 Niels Möller
10  *
11  * The nettle library is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation; either version 2.1 of the License, or (at your
14  * option) any later version.
15  *
16  * The nettle library is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
19  * License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * along with the nettle library; see the file COPYING.LIB.  If not, write to
23  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24  * MA 02111-1301, USA.
25  */
26
27 #ifndef NETTLE_SALSA20_H_INCLUDED
28 #define NETTLE_SALSA20_H_INCLUDED
29
30 #include "nettle-types.h"
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 /* Name mangling */
37 #define salsa20_set_key nettle_salsa20_set_key
38 #define salsa20_set_iv nettle_salsa20_set_iv
39 #define salsa20_crypt nettle_salsa20_crypt
40 #define _salsa20_core _nettle_salsa20_core
41
42 #define salsa20r12_crypt nettle_salsa20r12_crypt
43
44 /* Minimum and maximum keysizes, and a reasonable default. In
45  * octets.*/
46 #define SALSA20_MIN_KEY_SIZE 16
47 #define SALSA20_MAX_KEY_SIZE 32
48 #define SALSA20_KEY_SIZE 32
49 #define SALSA20_BLOCK_SIZE 64
50
51 #define SALSA20_IV_SIZE 8
52
53 #define _SALSA20_INPUT_LENGTH 16
54
55 struct salsa20_ctx
56 {
57   /* Indices 1-4 and 11-14 holds the key (two identical copies for the
58      shorter key size), indices 0, 5, 10, 15 are constant, indices 6, 7
59      are the IV, and indices 8, 9 are the block counter:
60
61      C K K K
62      K C I I
63      B B C K
64      K K K C
65   */
66   uint32_t input[_SALSA20_INPUT_LENGTH];
67 };
68
69 void
70 salsa20_set_key(struct salsa20_ctx *ctx,
71                 unsigned length, const uint8_t *key);
72
73 void
74 salsa20_set_iv(struct salsa20_ctx *ctx, const uint8_t *iv);
75
76 void
77 salsa20_crypt(struct salsa20_ctx *ctx,
78               unsigned length, uint8_t *dst,
79               const uint8_t *src);
80
81 void
82 salsa20r12_crypt(struct salsa20_ctx *ctx,
83                  unsigned length, uint8_t *dst,
84                  const uint8_t *src);
85
86 void
87 _salsa20_core(uint32_t *dst, const uint32_t *src, unsigned rounds);
88
89 #ifdef __cplusplus
90 }
91 #endif
92
93 #endif /* NETTLE_SALSA20_H_INCLUDED */