/src/nettle/chacha-set-nonce.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* chacha-set-nonce.c |
2 | | |
3 | | Setting the nonce the ChaCha stream cipher. |
4 | | Based on the Salsa20 implementation in Nettle. |
5 | | |
6 | | Copyright (C) 2013 Joachim Strömbergon |
7 | | Copyright (C) 2012 Simon Josefsson |
8 | | Copyright (C) 2012, 2014 Niels Möller |
9 | | |
10 | | This file is part of GNU Nettle. |
11 | | |
12 | | GNU Nettle is free software: you can redistribute it and/or |
13 | | modify it under the terms of either: |
14 | | |
15 | | * the GNU Lesser General Public License as published by the Free |
16 | | Software Foundation; either version 3 of the License, or (at your |
17 | | option) any later version. |
18 | | |
19 | | or |
20 | | |
21 | | * the GNU General Public License as published by the Free |
22 | | Software Foundation; either version 2 of the License, or (at your |
23 | | option) any later version. |
24 | | |
25 | | or both in parallel, as here. |
26 | | |
27 | | GNU Nettle is distributed in the hope that it will be useful, |
28 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
29 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
30 | | General Public License for more details. |
31 | | |
32 | | You should have received copies of the GNU General Public License and |
33 | | the GNU Lesser General Public License along with this program. If |
34 | | not, see http://www.gnu.org/licenses/. |
35 | | */ |
36 | | |
37 | | /* Based on: |
38 | | ChaCha specification (doc id: 4027b5256e17b9796842e6d0f68b0b5e) and reference |
39 | | implementation dated 2008.01.20 |
40 | | D. J. Bernstein |
41 | | Public domain. |
42 | | */ |
43 | | |
44 | | #if HAVE_CONFIG_H |
45 | | # include "config.h" |
46 | | #endif |
47 | | |
48 | | #include <assert.h> |
49 | | |
50 | | #include "chacha.h" |
51 | | |
52 | | #include "macros.h" |
53 | | |
54 | | void |
55 | | chacha_set_nonce(struct chacha_ctx *ctx, const uint8_t *nonce) |
56 | 0 | { |
57 | 0 | ctx->state[12] = 0; |
58 | 0 | ctx->state[13] = 0; |
59 | 0 | ctx->state[14] = LE_READ_UINT32(nonce + 0); |
60 | 0 | ctx->state[15] = LE_READ_UINT32(nonce + 4); |
61 | 0 | } |
62 | | |
63 | | void |
64 | | chacha_set_nonce96(struct chacha_ctx *ctx, const uint8_t *nonce) |
65 | 0 | { |
66 | 0 | ctx->state[12] = 0; |
67 | 0 | ctx->state[13] = LE_READ_UINT32(nonce + 0); |
68 | 0 | ctx->state[14] = LE_READ_UINT32(nonce + 4); |
69 | 0 | ctx->state[15] = LE_READ_UINT32(nonce + 8); |
70 | 0 | } |
71 | | |
72 | | void |
73 | | chacha_set_counter(struct chacha_ctx *ctx, const uint8_t *counter) |
74 | 0 | { |
75 | 0 | ctx->state[12] = LE_READ_UINT32(counter + 0); |
76 | 0 | ctx->state[13] = LE_READ_UINT32(counter + 4); |
77 | 0 | } |
78 | | |
79 | | void |
80 | | chacha_set_counter32(struct chacha_ctx *ctx, const uint8_t *counter) |
81 | 0 | { |
82 | 0 | ctx->state[12] = LE_READ_UINT32(counter + 0); |
83 | 0 | } |