Line | Count | Source (jump to first uncovered line) |
1 | | /* shake256.c |
2 | | |
3 | | The SHAKE256 hash function, arbitrary length output. |
4 | | |
5 | | Copyright (C) 2017 Daiki Ueno |
6 | | Copyright (C) 2017 Red Hat, Inc. |
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 | | #if HAVE_CONFIG_H |
36 | | # include "config.h" |
37 | | #endif |
38 | | |
39 | | #include <stddef.h> |
40 | | #include <string.h> |
41 | | |
42 | | #include "sha3.h" |
43 | | #include "sha3-internal.h" |
44 | | |
45 | | #include "nettle-write.h" |
46 | | |
47 | | void |
48 | | sha3_256_shake (struct sha3_256_ctx *ctx, |
49 | | size_t length, |
50 | | uint8_t *dst) |
51 | 0 | { |
52 | 0 | _sha3_pad_shake (&ctx->state, SHA3_256_BLOCK_SIZE, ctx->block, ctx->index); |
53 | 0 | while (length > SHA3_256_BLOCK_SIZE) |
54 | 0 | { |
55 | 0 | _nettle_write_le64 (SHA3_256_BLOCK_SIZE, dst, ctx->state.a); |
56 | 0 | length -= SHA3_256_BLOCK_SIZE; |
57 | 0 | dst += SHA3_256_BLOCK_SIZE; |
58 | 0 | sha3_permute (&ctx->state); |
59 | 0 | } |
60 | 0 | _nettle_write_le64 (length, dst, ctx->state.a); |
61 | |
|
62 | 0 | sha3_256_init (ctx); |
63 | 0 | } |