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"
40 #include "ripemd160.h"
48 /* Namespace mangling */
49 #define hmac_set_key nettle_hmac_set_key
50 #define hmac_update nettle_hmac_update
51 #define hmac_digest nettle_hmac_digest
52 #define hmac_md5_set_key nettle_hmac_md5_set_key
53 #define hmac_md5_update nettle_hmac_md5_update
54 #define hmac_md5_digest nettle_hmac_md5_digest
55 #define hmac_ripemd160_set_key nettle_hmac_ripemd160_set_key
56 #define hmac_ripemd160_update nettle_hmac_ripemd160_update
57 #define hmac_ripemd160_digest nettle_hmac_ripemd160_digest
58 #define hmac_sha1_set_key nettle_hmac_sha1_set_key
59 #define hmac_sha1_update nettle_hmac_sha1_update
60 #define hmac_sha1_digest nettle_hmac_sha1_digest
61 #define hmac_sha224_set_key nettle_hmac_sha224_set_key
62 #define hmac_sha224_digest nettle_hmac_sha224_digest
63 #define hmac_sha256_set_key nettle_hmac_sha256_set_key
64 #define hmac_sha256_update nettle_hmac_sha256_update
65 #define hmac_sha256_digest nettle_hmac_sha256_digest
66 #define hmac_sha384_set_key nettle_hmac_sha384_set_key
67 #define hmac_sha384_digest nettle_hmac_sha384_digest
68 #define hmac_sha512_set_key nettle_hmac_sha512_set_key
69 #define hmac_sha512_update nettle_hmac_sha512_update
70 #define hmac_sha512_digest nettle_hmac_sha512_digest
73 hmac_set_key(void *outer, void *inner, void *state,
74 const struct nettle_hash *hash,
75 size_t length, const uint8_t *key);
77 /* This function is not strictly needed, it's s just the same as the
78 * hash update function. */
80 hmac_update(void *state,
81 const struct nettle_hash *hash,
82 size_t length, const uint8_t *data);
85 hmac_digest(const void *outer, const void *inner, void *state,
86 const struct nettle_hash *hash,
87 size_t length, uint8_t *digest);
90 #define HMAC_CTX(type) \
91 { type outer; type inner; type state; }
93 #define HMAC_SET_KEY(ctx, hash, length, key) \
94 hmac_set_key( &(ctx)->outer, &(ctx)->inner, &(ctx)->state, \
95 (hash), (length), (key) )
97 #define HMAC_DIGEST(ctx, hash, length, digest) \
98 hmac_digest( &(ctx)->outer, &(ctx)->inner, &(ctx)->state, \
99 (hash), (length), (digest) )
101 /* HMAC using specific hash functions */
104 struct hmac_md5_ctx HMAC_CTX(struct md5_ctx);
107 hmac_md5_set_key(struct hmac_md5_ctx *ctx,
108 size_t key_length, const uint8_t *key);
111 hmac_md5_update(struct hmac_md5_ctx *ctx,
112 size_t length, const uint8_t *data);
115 hmac_md5_digest(struct hmac_md5_ctx *ctx,
116 size_t length, uint8_t *digest);
120 struct hmac_ripemd160_ctx HMAC_CTX(struct ripemd160_ctx);
123 hmac_ripemd160_set_key(struct hmac_ripemd160_ctx *ctx,
124 size_t key_length, const uint8_t *key);
127 hmac_ripemd160_update(struct hmac_ripemd160_ctx *ctx,
128 size_t length, const uint8_t *data);
131 hmac_ripemd160_digest(struct hmac_ripemd160_ctx *ctx,
132 size_t length, uint8_t *digest);
136 struct hmac_sha1_ctx HMAC_CTX(struct sha1_ctx);
139 hmac_sha1_set_key(struct hmac_sha1_ctx *ctx,
140 size_t key_length, const uint8_t *key);
143 hmac_sha1_update(struct hmac_sha1_ctx *ctx,
144 size_t length, const uint8_t *data);
147 hmac_sha1_digest(struct hmac_sha1_ctx *ctx,
148 size_t length, uint8_t *digest);
151 struct hmac_sha256_ctx HMAC_CTX(struct sha256_ctx);
154 hmac_sha256_set_key(struct hmac_sha256_ctx *ctx,
155 size_t key_length, const uint8_t *key);
158 hmac_sha256_update(struct hmac_sha256_ctx *ctx,
159 size_t length, const uint8_t *data);
162 hmac_sha256_digest(struct hmac_sha256_ctx *ctx,
163 size_t length, uint8_t *digest);
166 #define hmac_sha224_ctx hmac_sha256_ctx
169 hmac_sha224_set_key(struct hmac_sha224_ctx *ctx,
170 size_t key_length, const uint8_t *key);
172 #define hmac_sha224_update nettle_hmac_sha256_update
175 hmac_sha224_digest(struct hmac_sha224_ctx *ctx,
176 size_t length, uint8_t *digest);
179 struct hmac_sha512_ctx HMAC_CTX(struct sha512_ctx);
182 hmac_sha512_set_key(struct hmac_sha512_ctx *ctx,
183 size_t key_length, const uint8_t *key);
186 hmac_sha512_update(struct hmac_sha512_ctx *ctx,
187 size_t length, const uint8_t *data);
190 hmac_sha512_digest(struct hmac_sha512_ctx *ctx,
191 size_t length, uint8_t *digest);
194 #define hmac_sha384_ctx hmac_sha512_ctx
197 hmac_sha384_set_key(struct hmac_sha512_ctx *ctx,
198 size_t key_length, const uint8_t *key);
200 #define hmac_sha384_update nettle_hmac_sha512_update
203 hmac_sha384_digest(struct hmac_sha512_ctx *ctx,
204 size_t length, uint8_t *digest);
210 #endif /* NETTLE_HMAC_H_INCLUDED */