3 HMAC message authentication code (RFC-2104).
5 Copyright (C) 2001, 2002 Niels Möller
7 This file is part of GNU Nettle.
9 GNU Nettle is free software: you can redistribute it and/or
10 modify it under the terms of either:
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.
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.
22 or both in parallel, as here.
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.
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/.
34 #ifndef NETTLE_HMAC_H_INCLUDED
35 #define NETTLE_HMAC_H_INCLUDED
37 #include "nettle-meta.h"
39 #include "gosthash94.h"
41 #include "ripemd160.h"
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
80 hmac_set_key(void *outer, void *inner, void *state,
81 const struct nettle_hash *hash,
82 size_t length, const uint8_t *key);
84 /* This function is not strictly needed, it's s just the same as the
85 * hash update function. */
87 hmac_update(void *state,
88 const struct nettle_hash *hash,
89 size_t length, const uint8_t *data);
92 hmac_digest(const void *outer, const void *inner, void *state,
93 const struct nettle_hash *hash,
94 size_t length, uint8_t *digest);
97 #define HMAC_CTX(type) \
98 { type outer; type inner; type state; }
100 #define HMAC_SET_KEY(ctx, hash, length, key) \
101 hmac_set_key( &(ctx)->outer, &(ctx)->inner, &(ctx)->state, \
102 (hash), (length), (key) )
104 #define HMAC_DIGEST(ctx, hash, length, digest) \
105 hmac_digest( &(ctx)->outer, &(ctx)->inner, &(ctx)->state, \
106 (hash), (length), (digest) )
108 /* HMAC using specific hash functions */
111 struct hmac_md5_ctx HMAC_CTX(struct md5_ctx);
114 hmac_md5_set_key(struct hmac_md5_ctx *ctx,
115 size_t key_length, const uint8_t *key);
118 hmac_md5_update(struct hmac_md5_ctx *ctx,
119 size_t length, const uint8_t *data);
122 hmac_md5_digest(struct hmac_md5_ctx *ctx,
123 size_t length, uint8_t *digest);
127 struct hmac_ripemd160_ctx HMAC_CTX(struct ripemd160_ctx);
130 hmac_ripemd160_set_key(struct hmac_ripemd160_ctx *ctx,
131 size_t key_length, const uint8_t *key);
134 hmac_ripemd160_update(struct hmac_ripemd160_ctx *ctx,
135 size_t length, const uint8_t *data);
138 hmac_ripemd160_digest(struct hmac_ripemd160_ctx *ctx,
139 size_t length, uint8_t *digest);
143 struct hmac_sha1_ctx HMAC_CTX(struct sha1_ctx);
146 hmac_sha1_set_key(struct hmac_sha1_ctx *ctx,
147 size_t key_length, const uint8_t *key);
150 hmac_sha1_update(struct hmac_sha1_ctx *ctx,
151 size_t length, const uint8_t *data);
154 hmac_sha1_digest(struct hmac_sha1_ctx *ctx,
155 size_t length, uint8_t *digest);
158 struct hmac_sha256_ctx HMAC_CTX(struct sha256_ctx);
161 hmac_sha256_set_key(struct hmac_sha256_ctx *ctx,
162 size_t key_length, const uint8_t *key);
165 hmac_sha256_update(struct hmac_sha256_ctx *ctx,
166 size_t length, const uint8_t *data);
169 hmac_sha256_digest(struct hmac_sha256_ctx *ctx,
170 size_t length, uint8_t *digest);
173 #define hmac_sha224_ctx hmac_sha256_ctx
176 hmac_sha224_set_key(struct hmac_sha224_ctx *ctx,
177 size_t key_length, const uint8_t *key);
179 #define hmac_sha224_update nettle_hmac_sha256_update
182 hmac_sha224_digest(struct hmac_sha224_ctx *ctx,
183 size_t length, uint8_t *digest);
186 struct hmac_sha512_ctx HMAC_CTX(struct sha512_ctx);
189 hmac_sha512_set_key(struct hmac_sha512_ctx *ctx,
190 size_t key_length, const uint8_t *key);
193 hmac_sha512_update(struct hmac_sha512_ctx *ctx,
194 size_t length, const uint8_t *data);
197 hmac_sha512_digest(struct hmac_sha512_ctx *ctx,
198 size_t length, uint8_t *digest);
201 #define hmac_sha384_ctx hmac_sha512_ctx
204 hmac_sha384_set_key(struct hmac_sha512_ctx *ctx,
205 size_t key_length, const uint8_t *key);
207 #define hmac_sha384_update nettle_hmac_sha512_update
210 hmac_sha384_digest(struct hmac_sha512_ctx *ctx,
211 size_t length, uint8_t *digest);
213 /* hmac-gosthash94 */
214 struct hmac_gosthash94_ctx HMAC_CTX(struct gosthash94_ctx);
217 hmac_gosthash94_set_key(struct hmac_gosthash94_ctx *ctx,
218 size_t key_length, const uint8_t *key);
221 hmac_gosthash94_update(struct hmac_gosthash94_ctx *ctx,
222 size_t length, const uint8_t *data);
225 hmac_gosthash94_digest(struct hmac_gosthash94_ctx *ctx,
226 size_t length, uint8_t *digest);
228 struct hmac_gosthash94cp_ctx HMAC_CTX(struct gosthash94cp_ctx);
231 hmac_gosthash94cp_set_key(struct hmac_gosthash94cp_ctx *ctx,
232 size_t key_length, const uint8_t *key);
235 hmac_gosthash94cp_update(struct hmac_gosthash94cp_ctx *ctx,
236 size_t length, const uint8_t *data);
239 hmac_gosthash94cp_digest(struct hmac_gosthash94cp_ctx *ctx,
240 size_t length, uint8_t *digest);
247 #endif /* NETTLE_HMAC_H_INCLUDED */