cfb8: Fix decrypt path
[gd/nettle] / sha3.h
1 /* sha3.h
2
3    The sha3 hash function (aka Keccak).
4
5    Copyright (C) 2012 Niels Möller
6
7    This file is part of GNU Nettle.
8
9    GNU Nettle is free software: you can redistribute it and/or
10    modify it under the terms of either:
11
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.
15
16    or
17
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.
21
22    or both in parallel, as here.
23
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.
28
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/.
32 */
33  
34 #ifndef NETTLE_SHA3_H_INCLUDED
35 #define NETTLE_SHA3_H_INCLUDED
36
37 #include "nettle-types.h"
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 /* Name mangling */
44 #define sha3_permute nettle_sha3_permute
45 #define sha3_224_init nettle_sha3_224_init
46 #define sha3_224_update nettle_sha3_224_update
47 #define sha3_224_digest nettle_sha3_224_digest
48 #define sha3_256_init nettle_sha3_256_init
49 #define sha3_256_update nettle_sha3_256_update
50 #define sha3_256_digest nettle_sha3_256_digest
51 #define sha3_384_init nettle_sha3_384_init
52 #define sha3_384_update nettle_sha3_384_update
53 #define sha3_384_digest nettle_sha3_384_digest
54 #define sha3_512_init nettle_sha3_512_init
55 #define sha3_512_update nettle_sha3_512_update
56 #define sha3_512_digest nettle_sha3_512_digest
57
58 /* Indicates that SHA3 is the NIST FIPS 202 version. */
59 #define NETTLE_SHA3_FIPS202 1
60
61 /* The sha3 state is a 5x5 matrix of 64-bit words. In the notation of
62    Keccak description, S[x,y] is element x + 5*y, so if x is
63    interpreted as the row index and y the column index, it is stored
64    in column-major order. */
65 #define SHA3_STATE_LENGTH 25
66
67 /* The "width" is 1600 bits or 200 octets */
68 struct sha3_state
69 {
70   uint64_t a[SHA3_STATE_LENGTH];
71 };
72
73 void
74 sha3_permute (struct sha3_state *state);
75
76 /* The "capacity" is set to 2*(digest size), 512 bits or 64 octets.
77    The "rate" is the width - capacity, or width - 2 * (digest
78    size). */
79
80 #define SHA3_224_DIGEST_SIZE 28
81 #define SHA3_224_BLOCK_SIZE 144
82
83 #define SHA3_256_DIGEST_SIZE 32
84 #define SHA3_256_BLOCK_SIZE 136
85
86 #define SHA3_384_DIGEST_SIZE 48
87 #define SHA3_384_BLOCK_SIZE 104
88
89 #define SHA3_512_DIGEST_SIZE 64
90 #define SHA3_512_BLOCK_SIZE 72
91
92 /* For backwards compatibility */
93 #define SHA3_224_DATA_SIZE SHA3_224_BLOCK_SIZE
94 #define SHA3_256_DATA_SIZE SHA3_256_BLOCK_SIZE
95 #define SHA3_384_DATA_SIZE SHA3_384_BLOCK_SIZE
96 #define SHA3_512_DATA_SIZE SHA3_512_BLOCK_SIZE
97
98 struct sha3_224_ctx
99 {
100   struct sha3_state state;
101   unsigned index;
102   uint8_t block[SHA3_224_BLOCK_SIZE];
103 };
104
105 void
106 sha3_224_init (struct sha3_224_ctx *ctx);
107
108 void
109 sha3_224_update (struct sha3_224_ctx *ctx,
110                  size_t length,
111                  const uint8_t *data);
112
113 void
114 sha3_224_digest(struct sha3_224_ctx *ctx,
115                 size_t length,
116                 uint8_t *digest);
117
118 struct sha3_256_ctx
119 {
120   struct sha3_state state;
121   unsigned index;
122   uint8_t block[SHA3_256_BLOCK_SIZE];
123 };
124
125 void
126 sha3_256_init (struct sha3_256_ctx *ctx);
127
128 void
129 sha3_256_update (struct sha3_256_ctx *ctx,
130                  size_t length,
131                  const uint8_t *data);
132
133 void
134 sha3_256_digest(struct sha3_256_ctx *ctx,
135                 size_t length,
136                 uint8_t *digest);
137
138 struct sha3_384_ctx
139 {
140   struct sha3_state state;
141   unsigned index;
142   uint8_t block[SHA3_384_BLOCK_SIZE];
143 };
144
145 void
146 sha3_384_init (struct sha3_384_ctx *ctx);
147
148 void
149 sha3_384_update (struct sha3_384_ctx *ctx,
150                  size_t length,
151                  const uint8_t *data);
152
153 void
154 sha3_384_digest(struct sha3_384_ctx *ctx,
155                 size_t length,
156                 uint8_t *digest);
157
158 struct sha3_512_ctx
159 {
160   struct sha3_state state;
161   unsigned index;
162   uint8_t block[SHA3_512_BLOCK_SIZE];
163 };
164
165 void
166 sha3_512_init (struct sha3_512_ctx *ctx);
167
168 void
169 sha3_512_update (struct sha3_512_ctx *ctx,
170                  size_t length,
171                  const uint8_t *data);
172
173 void
174 sha3_512_digest(struct sha3_512_ctx *ctx,
175                 size_t length,
176                 uint8_t *digest);
177
178 #ifdef __cplusplus
179 }
180 #endif
181
182 #endif /* NETTLE_SHA3_H_INCLUDED */