cfb8: Fix decrypt path
[gd/nettle] / hmac.h
1 /* hmac.h
2
3    HMAC message authentication code (RFC-2104).
4
5    Copyright (C) 2001, 2002 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_HMAC_H_INCLUDED
35 #define NETTLE_HMAC_H_INCLUDED
36
37 #include "nettle-meta.h"
38
39 #include "gosthash94.h"
40 #include "md5.h"
41 #include "ripemd160.h"
42 #include "sha1.h"
43 #include "sha2.h"
44
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48
49 /* Namespace mangling */
50 #define hmac_set_key nettle_hmac_set_key
51 #define hmac_update nettle_hmac_update
52 #define hmac_digest nettle_hmac_digest
53 #define hmac_md5_set_key nettle_hmac_md5_set_key
54 #define hmac_md5_update nettle_hmac_md5_update
55 #define hmac_md5_digest nettle_hmac_md5_digest
56 #define hmac_ripemd160_set_key nettle_hmac_ripemd160_set_key
57 #define hmac_ripemd160_update nettle_hmac_ripemd160_update
58 #define hmac_ripemd160_digest nettle_hmac_ripemd160_digest
59 #define hmac_sha1_set_key nettle_hmac_sha1_set_key
60 #define hmac_sha1_update nettle_hmac_sha1_update
61 #define hmac_sha1_digest nettle_hmac_sha1_digest
62 #define hmac_sha224_set_key nettle_hmac_sha224_set_key
63 #define hmac_sha224_digest nettle_hmac_sha224_digest
64 #define hmac_sha256_set_key nettle_hmac_sha256_set_key
65 #define hmac_sha256_update nettle_hmac_sha256_update
66 #define hmac_sha256_digest nettle_hmac_sha256_digest
67 #define hmac_sha384_set_key nettle_hmac_sha384_set_key
68 #define hmac_sha384_digest nettle_hmac_sha384_digest
69 #define hmac_sha512_set_key nettle_hmac_sha512_set_key
70 #define hmac_sha512_update nettle_hmac_sha512_update
71 #define hmac_sha512_digest nettle_hmac_sha512_digest
72 #define hmac_gosthash94_set_key nettle_hmac_gosthash94_set_key
73 #define hmac_gosthash94_update nettle_hmac_gosthash94_update
74 #define hmac_gosthash94_digest nettle_hmac_gosthash94_digest
75 #define hmac_gosthash94cp_set_key nettle_hmac_gosthash94cp_set_key
76 #define hmac_gosthash94cp_update nettle_hmac_gosthash94cp_update
77 #define hmac_gosthash94cp_digest nettle_hmac_gosthash94cp_digest
78
79 void
80 hmac_set_key(void *outer, void *inner, void *state,
81              const struct nettle_hash *hash,
82              size_t length, const uint8_t *key);
83
84 /* This function is not strictly needed, it's s just the same as the
85  * hash update function. */
86 void
87 hmac_update(void *state,
88             const struct nettle_hash *hash,
89             size_t length, const uint8_t *data);
90
91 void
92 hmac_digest(const void *outer, const void *inner, void *state,
93             const struct nettle_hash *hash,
94             size_t length, uint8_t *digest);
95
96
97 #define HMAC_CTX(type) \
98 { type outer; type inner; type state; }
99
100 #define HMAC_SET_KEY(ctx, hash, length, key)                    \
101   hmac_set_key( &(ctx)->outer, &(ctx)->inner, &(ctx)->state,    \
102                 (hash), (length), (key) )
103
104 #define HMAC_DIGEST(ctx, hash, length, digest)                  \
105   hmac_digest( &(ctx)->outer, &(ctx)->inner, &(ctx)->state,     \
106                (hash), (length), (digest) )
107
108 /* HMAC using specific hash functions */
109
110 /* hmac-md5 */
111 struct hmac_md5_ctx HMAC_CTX(struct md5_ctx);
112
113 void
114 hmac_md5_set_key(struct hmac_md5_ctx *ctx,
115                  size_t key_length, const uint8_t *key);
116
117 void
118 hmac_md5_update(struct hmac_md5_ctx *ctx,
119                 size_t length, const uint8_t *data);
120
121 void
122 hmac_md5_digest(struct hmac_md5_ctx *ctx,
123                 size_t length, uint8_t *digest);
124
125
126 /* hmac-ripemd160 */
127 struct hmac_ripemd160_ctx HMAC_CTX(struct ripemd160_ctx);
128
129 void
130 hmac_ripemd160_set_key(struct hmac_ripemd160_ctx *ctx,
131                        size_t key_length, const uint8_t *key);
132
133 void
134 hmac_ripemd160_update(struct hmac_ripemd160_ctx *ctx,
135                       size_t length, const uint8_t *data);
136
137 void
138 hmac_ripemd160_digest(struct hmac_ripemd160_ctx *ctx,
139                       size_t length, uint8_t *digest);
140
141
142 /* hmac-sha1 */
143 struct hmac_sha1_ctx HMAC_CTX(struct sha1_ctx);
144
145 void
146 hmac_sha1_set_key(struct hmac_sha1_ctx *ctx,
147                   size_t key_length, const uint8_t *key);
148
149 void
150 hmac_sha1_update(struct hmac_sha1_ctx *ctx,
151                  size_t length, const uint8_t *data);
152
153 void
154 hmac_sha1_digest(struct hmac_sha1_ctx *ctx,
155                  size_t length, uint8_t *digest);
156
157 /* hmac-sha256 */
158 struct hmac_sha256_ctx HMAC_CTX(struct sha256_ctx);
159
160 void
161 hmac_sha256_set_key(struct hmac_sha256_ctx *ctx,
162                     size_t key_length, const uint8_t *key);
163
164 void
165 hmac_sha256_update(struct hmac_sha256_ctx *ctx,
166                    size_t length, const uint8_t *data);
167
168 void
169 hmac_sha256_digest(struct hmac_sha256_ctx *ctx,
170                    size_t length, uint8_t *digest);
171
172 /* hmac-sha224 */
173 #define hmac_sha224_ctx hmac_sha256_ctx
174
175 void
176 hmac_sha224_set_key(struct hmac_sha224_ctx *ctx,
177                     size_t key_length, const uint8_t *key);
178
179 #define hmac_sha224_update nettle_hmac_sha256_update
180
181 void
182 hmac_sha224_digest(struct hmac_sha224_ctx *ctx,
183                    size_t length, uint8_t *digest);
184
185 /* hmac-sha512 */
186 struct hmac_sha512_ctx HMAC_CTX(struct sha512_ctx);
187
188 void
189 hmac_sha512_set_key(struct hmac_sha512_ctx *ctx,
190                     size_t key_length, const uint8_t *key);
191
192 void
193 hmac_sha512_update(struct hmac_sha512_ctx *ctx,
194                    size_t length, const uint8_t *data);
195
196 void
197 hmac_sha512_digest(struct hmac_sha512_ctx *ctx,
198                    size_t length, uint8_t *digest);
199
200 /* hmac-sha384 */
201 #define hmac_sha384_ctx hmac_sha512_ctx
202
203 void
204 hmac_sha384_set_key(struct hmac_sha512_ctx *ctx,
205                     size_t key_length, const uint8_t *key);
206
207 #define hmac_sha384_update nettle_hmac_sha512_update
208
209 void
210 hmac_sha384_digest(struct hmac_sha512_ctx *ctx,
211                    size_t length, uint8_t *digest);
212
213 /* hmac-gosthash94 */
214 struct hmac_gosthash94_ctx HMAC_CTX(struct gosthash94_ctx);
215
216 void
217 hmac_gosthash94_set_key(struct hmac_gosthash94_ctx *ctx,
218                         size_t key_length, const uint8_t *key);
219
220 void
221 hmac_gosthash94_update(struct hmac_gosthash94_ctx *ctx,
222                        size_t length, const uint8_t *data);
223
224   void
225 hmac_gosthash94_digest(struct hmac_gosthash94_ctx *ctx,
226                        size_t length, uint8_t *digest);
227
228 struct hmac_gosthash94cp_ctx HMAC_CTX(struct gosthash94cp_ctx);
229
230 void
231 hmac_gosthash94cp_set_key(struct hmac_gosthash94cp_ctx *ctx,
232                           size_t key_length, const uint8_t *key);
233
234 void
235 hmac_gosthash94cp_update(struct hmac_gosthash94cp_ctx *ctx,
236                          size_t length, const uint8_t *data);
237
238 void
239 hmac_gosthash94cp_digest(struct hmac_gosthash94cp_ctx *ctx,
240                          size_t length, uint8_t *digest);
241
242
243 #ifdef __cplusplus
244 }
245 #endif
246
247 #endif /* NETTLE_HMAC_H_INCLUDED */