Samba Patch - Denial of service - CPU loop and memory allocation.
[tomato.git] / release / src / router / nettle / sha3.h
blobc6830b2738aaed3f3152e85e1efdd35a93a46adc
1 /* sha3.h
3 * The sha3 hash function (aka Keccak).
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 #ifndef NETTLE_SHA3_H_INCLUDED
27 #define NETTLE_SHA3_H_INCLUDED
29 #include "nettle-types.h"
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
35 #define sha3_permute nettle_sha3_permute
36 #define _sha3_update _nettle_sha3_update
37 #define _sha3_pad _nettle_sha3_pad
38 #define sha3_224_init nettle_sha3_224_init
39 #define sha3_224_update nettle_sha3_224_update
40 #define sha3_224_digest nettle_sha3_224_digest
41 #define sha3_256_init nettle_sha3_256_init
42 #define sha3_256_update nettle_sha3_256_update
43 #define sha3_256_digest nettle_sha3_256_digest
44 #define sha3_384_init nettle_sha3_384_init
45 #define sha3_384_update nettle_sha3_384_update
46 #define sha3_384_digest nettle_sha3_384_digest
47 #define sha3_512_init nettle_sha3_512_init
48 #define sha3_512_update nettle_sha3_512_update
49 #define sha3_512_digest nettle_sha3_512_digest
51 /* The sha3 state is a 5x5 matrix of 64-bit words. In the notation of
52 Keccak description, S[x,y] is element x + 5*y, so if x is
53 interpreted as the row index and y the column index, it is stored
54 in column-major order. */
55 #define SHA3_STATE_LENGTH 25
57 /* The "width" is 1600 bits or 200 octets */
58 struct sha3_state
60 uint64_t a[SHA3_STATE_LENGTH];
63 void
64 sha3_permute (struct sha3_state *state);
66 unsigned
67 _sha3_update (struct sha3_state *state,
68 unsigned block_size, uint8_t *block,
69 unsigned pos,
70 unsigned length, const uint8_t *data);
71 void
72 _sha3_pad (struct sha3_state *state,
73 unsigned block_size, uint8_t *block, unsigned pos);
75 /* The "capacity" is set to 2*(digest size), 512 bits or 64 octets.
76 The "rate" is the width - capacity, or width - 2 * (digest
77 size). */
79 #define SHA3_224_DIGEST_SIZE 28
80 #define SHA3_224_DATA_SIZE 144
82 #define SHA3_256_DIGEST_SIZE 32
83 #define SHA3_256_DATA_SIZE 136
85 #define SHA3_384_DIGEST_SIZE 48
86 #define SHA3_384_DATA_SIZE 104
88 #define SHA3_512_DIGEST_SIZE 64
89 #define SHA3_512_DATA_SIZE 72
92 struct sha3_224_ctx
94 struct sha3_state state;
95 unsigned index;
96 uint8_t block[SHA3_224_DATA_SIZE];
99 void
100 sha3_224_init (struct sha3_224_ctx *ctx);
102 void
103 sha3_224_update (struct sha3_224_ctx *ctx,
104 unsigned length,
105 const uint8_t *data);
107 void
108 sha3_224_digest(struct sha3_224_ctx *ctx,
109 unsigned length,
110 uint8_t *digest);
112 struct sha3_256_ctx
114 struct sha3_state state;
115 unsigned index;
116 uint8_t block[SHA3_256_DATA_SIZE];
119 void
120 sha3_256_init (struct sha3_256_ctx *ctx);
122 void
123 sha3_256_update (struct sha3_256_ctx *ctx,
124 unsigned length,
125 const uint8_t *data);
127 void
128 sha3_256_digest(struct sha3_256_ctx *ctx,
129 unsigned length,
130 uint8_t *digest);
132 struct sha3_384_ctx
134 struct sha3_state state;
135 unsigned index;
136 uint8_t block[SHA3_384_DATA_SIZE];
139 void
140 sha3_384_init (struct sha3_384_ctx *ctx);
142 void
143 sha3_384_update (struct sha3_384_ctx *ctx,
144 unsigned length,
145 const uint8_t *data);
147 void
148 sha3_384_digest(struct sha3_384_ctx *ctx,
149 unsigned length,
150 uint8_t *digest);
152 struct sha3_512_ctx
154 struct sha3_state state;
155 unsigned index;
156 uint8_t block[SHA3_512_DATA_SIZE];
159 void
160 sha3_512_init (struct sha3_512_ctx *ctx);
162 void
163 sha3_512_update (struct sha3_512_ctx *ctx,
164 unsigned length,
165 const uint8_t *data);
167 void
168 sha3_512_digest(struct sha3_512_ctx *ctx,
169 unsigned length,
170 uint8_t *digest);
172 #ifdef __cplusplus
174 #endif
176 #endif /* NETTLE_SHA3_H_INCLUDED */