/src/nettle-with-libgmp/chacha-set-key.c
Line  | Count  | Source  | 
1  |  | /* chacha-set-key.c  | 
2  |  |  | 
3  |  |    Copyright (C) 2014 Niels Möller  | 
4  |  |  | 
5  |  |    This file is part of GNU Nettle.  | 
6  |  |  | 
7  |  |    GNU Nettle is free software: you can redistribute it and/or  | 
8  |  |    modify it under the terms of either:  | 
9  |  |  | 
10  |  |      * the GNU Lesser General Public License as published by the Free  | 
11  |  |        Software Foundation; either version 3 of the License, or (at your  | 
12  |  |        option) any later version.  | 
13  |  |  | 
14  |  |    or  | 
15  |  |  | 
16  |  |      * the GNU General Public License as published by the Free  | 
17  |  |        Software Foundation; either version 2 of the License, or (at your  | 
18  |  |        option) any later version.  | 
19  |  |  | 
20  |  |    or both in parallel, as here.  | 
21  |  |  | 
22  |  |    GNU Nettle is distributed in the hope that it will be useful,  | 
23  |  |    but WITHOUT ANY WARRANTY; without even the implied warranty of  | 
24  |  |    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  | 
25  |  |    General Public License for more details.  | 
26  |  |  | 
27  |  |    You should have received copies of the GNU General Public License and  | 
28  |  |    the GNU Lesser General Public License along with this program.  If  | 
29  |  |    not, see http://www.gnu.org/licenses/.  | 
30  |  | */  | 
31  |  |  | 
32  |  | #if HAVE_CONFIG_H  | 
33  |  | # include "config.h"  | 
34  |  | #endif  | 
35  |  |  | 
36  |  | #include <stdlib.h>  | 
37  |  | #include <string.h>  | 
38  |  |  | 
39  |  | #include "chacha.h"  | 
40  |  |  | 
41  |  | #include "macros.h"  | 
42  |  |  | 
43  |  | void  | 
44  |  | chacha_set_key(struct chacha_ctx *ctx, const uint8_t *key)  | 
45  | 278  | { | 
46  | 278  |   static const uint32_t sigma[4] = { | 
47  |  |     /* "expand 32-byte k" */  | 
48  | 278  |     0x61707865, 0x3320646e, 0x79622d32, 0x6b206574  | 
49  | 278  |   };  | 
50  | 278  |   ctx->state[4] = LE_READ_UINT32(key + 0);  | 
51  | 278  |   ctx->state[5] = LE_READ_UINT32(key + 4);  | 
52  | 278  |   ctx->state[6] = LE_READ_UINT32(key + 8);  | 
53  | 278  |   ctx->state[7] = LE_READ_UINT32(key + 12);  | 
54  |  |  | 
55  | 278  |   ctx->state[8]  = LE_READ_UINT32(key + 16);  | 
56  | 278  |   ctx->state[9]  = LE_READ_UINT32(key + 20);  | 
57  | 278  |   ctx->state[10] = LE_READ_UINT32(key + 24);  | 
58  | 278  |   ctx->state[11] = LE_READ_UINT32(key + 28);  | 
59  |  |  | 
60  | 278  |   memcpy (ctx->state, sigma, sizeof(sigma));  | 
61  | 278  | }  |