Fix messages.
[shishi.git] / crypto / hmac.h
blobbb231c538b1afa18177675b6668ded3607776b24
1 /* hmac.h
3 * HMAC message authentication code (RFC-2104).
4 */
6 /* nettle, low-level cryptographics library
8 * Copyright (C) 2001, 2002 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., 59 Temple Place - Suite 330, Boston,
23 * MA 02111-1307, USA.
26 #ifndef NETTLE_HMAC_H_INCLUDED
27 #define NETTLE_HMAC_H_INCLUDED
29 #include "nettle-meta.h"
31 #include "md4.h"
32 #include "md5.h"
33 #include "sha.h"
35 /* Namespace mangling */
36 #define hmac_set_key nettle_hmac_set_key
37 #define hmac_update nettle_hmac_update
38 #define hmac_digest nettle_hmac_digest
39 #define hmac_md5_set_key nettle_hmac_md5_set_key
40 #define hmac_md5_update nettle_hmac_md5_update
41 #define hmac_md5_digest nettle_hmac_md5_digest
42 #define hmac_sha1_set_key nettle_hmac_sha1_set_key
43 #define hmac_sha1_update nettle_hmac_sha1_update
44 #define hmac_sha1_digest nettle_hmac_sha1_digest
45 #define hmac_sha256_set_key nettle_hmac_sha256_set_key
46 #define hmac_sha256_update nettle_hmac_sha256_update
47 #define hmac_sha256_digest nettle_hmac_sha256_digest
49 void
50 hmac_set_key(void *outer, void *inner, void *state,
51 const struct nettle_hash *hash,
52 unsigned length, const uint8_t *key);
54 /* This function is not strictly needed, it's s just the same as the
55 * hash update function. */
56 void
57 hmac_update(void *state,
58 const struct nettle_hash *hash,
59 unsigned length, const uint8_t *data);
61 void
62 hmac_digest(const void *outer, const void *inner, void *state,
63 const struct nettle_hash *hash,
64 unsigned length, uint8_t *digest);
67 #define HMAC_CTX(type) \
68 { type outer; type inner; type state; }
70 #define HMAC_SET_KEY(ctx, hash, length, key) \
71 hmac_set_key( &(ctx)->outer, &(ctx)->inner, &(ctx)->state, \
72 (hash), (length), (key) )
74 #define HMAC_DIGEST(ctx, hash, length, digest) \
75 hmac_digest( &(ctx)->outer, &(ctx)->inner, &(ctx)->state, \
76 (hash), (length), (digest) )
78 /* HMAC using specific hash functions */
80 /* hmac-md4 */
81 struct hmac_md4_ctx HMAC_CTX(struct md4_ctx);
83 void
84 hmac_md4_set_key(struct hmac_md4_ctx *ctx,
85 unsigned key_length, const uint8_t *key);
87 void
88 hmac_md4_update(struct hmac_md4_ctx *ctx,
89 unsigned length, const uint8_t *data);
91 void
92 hmac_md4_digest(struct hmac_md4_ctx *ctx,
93 unsigned length, uint8_t *digest);
95 /* hmac-md5 */
96 struct hmac_md5_ctx HMAC_CTX(struct md5_ctx);
98 void
99 hmac_md5_set_key(struct hmac_md5_ctx *ctx,
100 unsigned key_length, const uint8_t *key);
102 void
103 hmac_md5_update(struct hmac_md5_ctx *ctx,
104 unsigned length, const uint8_t *data);
106 void
107 hmac_md5_digest(struct hmac_md5_ctx *ctx,
108 unsigned length, uint8_t *digest);
110 /* hmac-sha1 */
111 struct hmac_sha1_ctx HMAC_CTX(struct sha1_ctx);
113 void
114 hmac_sha1_set_key(struct hmac_sha1_ctx *ctx,
115 unsigned key_length, const uint8_t *key);
117 void
118 hmac_sha1_update(struct hmac_sha1_ctx *ctx,
119 unsigned length, const uint8_t *data);
121 void
122 hmac_sha1_digest(struct hmac_sha1_ctx *ctx,
123 unsigned length, uint8_t *digest);
125 /* hmac-sha256 */
126 struct hmac_sha256_ctx HMAC_CTX(struct sha256_ctx);
128 void
129 hmac_sha256_set_key(struct hmac_sha256_ctx *ctx,
130 unsigned key_length, const uint8_t *key);
132 void
133 hmac_sha256_update(struct hmac_sha256_ctx *ctx,
134 unsigned length, const uint8_t *data);
136 void
137 hmac_sha256_digest(struct hmac_sha256_ctx *ctx,
138 unsigned length, uint8_t *digest);
140 #endif /* NETTLE_HMAC_H_INCLUDED */