Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / nettle / sha3.c
blob21e7beb72e3886743cb1216a5f220e14ef1fc23f
1 /* sha3.c
3 * The sha3 hash function.
4 */
6 /* nettle, low-level cryptographics library
8 * Copyright (C) 2012 Niels Möller
9 *
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,
23 * MA 02111-1301, USA.
26 #if HAVE_CONFIG_H
27 # include "config.h"
28 #endif
30 #include <assert.h>
31 #include <string.h>
33 #include "sha3.h"
35 #include "macros.h"
36 #include "memxor.h"
38 static void
39 sha3_absorb (struct sha3_state *state, unsigned length, const uint8_t *data)
41 assert ( (length & 7) == 0);
42 #if WORDS_BIGENDIAN
44 uint64_t *p;
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);
50 #endif
52 sha3_permute (state);
55 unsigned
56 _sha3_update (struct sha3_state *state,
57 unsigned block_size, uint8_t *block,
58 unsigned pos,
59 unsigned length, const uint8_t *data)
61 if (pos > 0)
63 unsigned left = block_size - pos;
64 if (length < left)
66 memcpy (block + pos, data, length);
67 return pos + length;
69 else
71 memcpy (block + pos, data, left);
72 data += left;
73 length -= 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);
81 return length;
84 void
85 _sha3_pad (struct sha3_state *state,
86 unsigned block_size, uint8_t *block, unsigned pos)
88 assert (pos < block_size);
89 block[pos++] = 1;
91 memset (block + pos, 0, block_size - pos);
92 block[block_size - 1] |= 0x80;
94 sha3_absorb (state, block_size, block);