3 * HMAC message authentication code (RFC-2104).
6 /* nettle, low-level cryptographics library
8 * Copyright (C) 2001, 2002 Niels Möller
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,
26 #ifndef NETTLE_HMAC_H_INCLUDED
27 #define NETTLE_HMAC_H_INCLUDED
29 #include "nettle-meta.h"
38 hmac_set_key(void *outer
, void *inner
, void *state
,
39 const struct nettle_hash
*hash
,
40 unsigned length
, const uint8_t *key
);
42 /* This function is not strictly needed, it's s just the same as the
43 * hash update function. */
45 hmac_update(void *state
,
46 const struct nettle_hash
*hash
,
47 unsigned length
, const uint8_t *data
);
50 hmac_digest(const void *outer
, const void *inner
, void *state
,
51 const struct nettle_hash
*hash
,
52 unsigned length
, uint8_t *digest
);
55 #define HMAC_CTX(type) \
56 { type outer; type inner; type state; }
58 #define HMAC_SET_KEY(ctx, hash, length, key) \
59 hmac_set_key( &(ctx)->outer, &(ctx)->inner, &(ctx)->state, \
60 (hash), (length), (key) )
62 #define HMAC_DIGEST(ctx, hash, length, digest) \
63 hmac_digest( &(ctx)->outer, &(ctx)->inner, &(ctx)->state, \
64 (hash), (length), (digest) )
66 /* HMAC using specific hash functions */
69 struct hmac_md4_ctx
HMAC_CTX(struct md4_ctx
);
72 hmac_md4_set_key(struct hmac_md4_ctx
*ctx
,
73 unsigned key_length
, const uint8_t *key
);
76 hmac_md4_update(struct hmac_md4_ctx
*ctx
,
77 unsigned length
, const uint8_t *data
);
80 hmac_md4_digest(struct hmac_md4_ctx
*ctx
,
81 unsigned length
, uint8_t *digest
);
84 struct hmac_md5_ctx
HMAC_CTX(struct md5_ctx
);
87 hmac_md5_set_key(struct hmac_md5_ctx
*ctx
,
88 unsigned key_length
, const uint8_t *key
);
91 hmac_md5_update(struct hmac_md5_ctx
*ctx
,
92 unsigned length
, const uint8_t *data
);
95 hmac_md5_digest(struct hmac_md5_ctx
*ctx
,
96 unsigned length
, uint8_t *digest
);
99 struct hmac_sha1_ctx
HMAC_CTX(struct sha1_ctx
);
102 hmac_sha1_set_key(struct hmac_sha1_ctx
*ctx
,
103 unsigned key_length
, const uint8_t *key
);
106 hmac_sha1_update(struct hmac_sha1_ctx
*ctx
,
107 unsigned length
, const uint8_t *data
);
110 hmac_sha1_digest(struct hmac_sha1_ctx
*ctx
,
111 unsigned length
, uint8_t *digest
);
114 struct hmac_sha256_ctx
HMAC_CTX(struct sha256_ctx
);
117 hmac_sha256_set_key(struct hmac_sha256_ctx
*ctx
,
118 unsigned key_length
, const uint8_t *key
);
121 hmac_sha256_update(struct hmac_sha256_ctx
*ctx
,
122 unsigned length
, const uint8_t *data
);
125 hmac_sha256_digest(struct hmac_sha256_ctx
*ctx
,
126 unsigned length
, uint8_t *digest
);
128 #endif /* NETTLE_HMAC_H_INCLUDED */