]>
git.ipfire.org Git - thirdparty/nettle.git/blob - sha3-shake.c
3 Copyright (C) 2017, 2024 Daiki Ueno
4 Copyright (C) 2017 Red Hat, Inc.
5 Copyright (C) 2024 Niels Möller
7 This file is part of GNU Nettle.
9 GNU Nettle is free software: you can redistribute it and/or
10 modify it under the terms of either:
12 * the GNU Lesser General Public License as published by the Free
13 Software Foundation; either version 3 of the License, or (at your
14 option) any later version.
18 * the GNU General Public License as published by the Free
19 Software Foundation; either version 2 of the License, or (at your
20 option) any later version.
22 or both in parallel, as here.
24 GNU Nettle is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 General Public License for more details.
29 You should have received copies of the GNU General Public License and
30 the GNU Lesser General Public License along with this program. If
31 not, see http://www.gnu.org/licenses/.
42 #include "sha3-internal.h"
44 #include "nettle-write.h"
47 _nettle_sha3_shake (struct sha3_state
*state
,
48 unsigned block_size
, uint8_t *block
,
50 size_t length
, uint8_t *dst
)
52 _sha3_pad_shake (state
, block_size
, block
, index
);
54 while (length
> block_size
)
57 _nettle_write_le64 (block_size
, dst
, state
->a
);
63 _nettle_write_le64 (length
, dst
, state
->a
);
67 _nettle_sha3_shake_output (struct sha3_state
*state
,
68 unsigned block_size
, uint8_t *block
,
70 size_t length
, uint8_t *dst
)
74 /* We use one's complement of the index value to indicate SHAKE is
76 if (index
< block_size
)
78 /* This is the first call of _shake_output. */
79 _sha3_pad_shake (state
, block_size
, block
, index
);
80 /* Point at the end of block to trigger fill in of the buffer. */
86 assert (index
<= block_size
);
88 /* Write remaining data from the buffer. */
89 left
= block_size
- index
;
92 memcpy (dst
, block
+ index
, length
);
93 return ~(index
+ length
);
97 memcpy (dst
, block
+ index
, left
);
102 /* Write full blocks. */
103 while (length
> block_size
)
105 sha3_permute (state
);
106 _nettle_write_le64 (block_size
, dst
, state
->a
);
107 length
-= block_size
;
111 sha3_permute (state
);
112 /* Fill in the buffer for next call. */
113 _nettle_write_le64 (block_size
, block
, state
->a
);
114 memcpy (dst
, block
, length
);