3 * The sha3 hash function.
6 /* nettle, low-level cryptographics library
8 * Copyright (C) 2012 Niels Möller
10 * The nettle library is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or (at your
13 * option) any later version.
15 * The nettle library is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with the nettle library; see the file COPYING.LIB. If not, write to
22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
39 sha3_absorb (struct sha3_state *state, unsigned length, const uint8_t *data)
41 assert ( (length & 7) == 0);
45 for (p = state->a; length > 0; p++, length -= 8, data += 8)
46 *p ^= LE_READ_UINT64 (data);
48 #else /* !WORDS_BIGENDIAN */
49 memxor ((uint8_t *) state->a, data, length);
56 _sha3_update (struct sha3_state *state,
57 unsigned block_size, uint8_t *block,
59 unsigned length, const uint8_t *data)
63 unsigned left = block_size - pos;
66 memcpy (block + pos, data, length);
71 memcpy (block + pos, data, left);
74 sha3_absorb (state, block_size, block);
77 for (; length >= block_size; length -= block_size, data += block_size)
78 sha3_absorb (state, block_size, data);
80 memcpy (block, data, length);
85 _sha3_pad (struct sha3_state *state,
86 unsigned block_size, uint8_t *block, unsigned pos)
88 assert (pos < block_size);
91 memset (block + pos, 0, block_size - pos);
92 block[block_size - 1] |= 0x80;
94 sha3_absorb (state, block_size, block);