testutils.c: Fix high bits of the mpz_urandomb used with mini-gmp.
[gd/nettle] / salsa20-256-set-key.c
1 /* salsa20-256-set-key.c
2
3    The Salsa20 stream cipher. Key setup for 128-bit keys.
4
5    Copyright (C) 2012 Simon Josefsson
6    Copyright (C) 2012-2014 Niels Möller
7
8    This file is part of GNU Nettle.
9
10    GNU Nettle is free software: you can redistribute it and/or
11    modify it under the terms of either:
12
13      * the GNU Lesser General Public License as published by the Free
14        Software Foundation; either version 3 of the License, or (at your
15        option) any later version.
16
17    or
18
19      * the GNU General Public License as published by the Free
20        Software Foundation; either version 2 of the License, or (at your
21        option) any later version.
22
23    or both in parallel, as here.
24
25    GNU Nettle is distributed in the hope that it will be useful,
26    but WITHOUT ANY WARRANTY; without even the implied warranty of
27    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
28    General Public License for more details.
29
30    You should have received copies of the GNU General Public License and
31    the GNU Lesser General Public License along with this program.  If
32    not, see http://www.gnu.org/licenses/.
33 */
34
35 /* Based on:
36    salsa20-ref.c version 20051118
37    D. J. Bernstein
38    Public domain.
39 */
40
41 #if HAVE_CONFIG_H
42 # include "config.h"
43 #endif
44
45 #include "salsa20.h"
46
47 #include "macros.h"
48
49 void
50 salsa20_256_set_key(struct salsa20_ctx *ctx, const uint8_t *key)
51 {
52   ctx->input[1] = LE_READ_UINT32(key + 0);
53   ctx->input[2] = LE_READ_UINT32(key + 4);
54   ctx->input[3] = LE_READ_UINT32(key + 8);
55   ctx->input[4] = LE_READ_UINT32(key + 12);
56
57   ctx->input[11] = LE_READ_UINT32(key + 16);
58   ctx->input[12] = LE_READ_UINT32(key + 20);
59   ctx->input[13] = LE_READ_UINT32(key + 24);
60   ctx->input[14] = LE_READ_UINT32(key + 28);
61
62   /* "expand 32-byte k" */
63   ctx->input[0]  = 0x61707865;
64   ctx->input[5]  = 0x3320646e;
65   ctx->input[10] = 0x79622d32;
66   ctx->input[15] = 0x6b206574;
67 }