Dibbler - a portable DHCPv6  1.0.2RC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
hmac.h
Go to the documentation of this file.
1 /* hmac.h
2  *
3  * HMAC message authentication code (RFC-2104).
4  */
5 
6 /* nettle, low-level cryptographics library
7  *
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.
14  *
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.
19  *
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.
24  */
25 
26 #ifndef NETTLE_HMAC_H_INCLUDED
27 #define NETTLE_HMAC_H_INCLUDED
28 
29 #include "nettle-meta.h"
30 
31 #include "md5.h"
32 #include "sha.h"
33 
34 /* Namespace mangling */
35 #define hmac_set_key nettle_hmac_set_key
36 #define hmac_update nettle_hmac_update
37 #define hmac_digest nettle_hmac_digest
38 #define hmac_md5_set_key nettle_hmac_md5_set_key
39 #define hmac_md5_update nettle_hmac_md5_update
40 #define hmac_md5_digest nettle_hmac_md5_digest
41 #define hmac_sha1_set_key nettle_hmac_sha1_set_key
42 #define hmac_sha1_update nettle_hmac_sha1_update
43 #define hmac_sha1_digest nettle_hmac_sha1_digest
44 #define hmac_sha256_set_key nettle_hmac_sha256_set_key
45 #define hmac_sha256_update nettle_hmac_sha256_update
46 #define hmac_sha256_digest nettle_hmac_sha256_digest
47 
48 void
49 hmac_set_key(void *outer, void *inner, void *state,
50  const struct nettle_hash *hash,
51  unsigned length, const uint8_t *key);
52 
53 /* This function is not strictly needed, it's s just the same as the
54  * hash update function. */
55 void
56 hmac_update(void *state,
57  const struct nettle_hash *hash,
58  unsigned length, const uint8_t *data);
59 
60 void
61 hmac_digest(const void *outer, const void *inner, void *state,
62  const struct nettle_hash *hash,
63  unsigned length, uint8_t *digest);
64 
65 
66 #define HMAC_CTX(type) \
67 { type outer; type inner; type state; }
68 
69 #define HMAC_SET_KEY(ctx, hash, length, key) \
70  hmac_set_key( &(ctx)->outer, &(ctx)->inner, &(ctx)->state, \
71  (hash), (length), (key) )
72 
73 #define HMAC_DIGEST(ctx, hash, length, digest) \
74  hmac_digest( &(ctx)->outer, &(ctx)->inner, &(ctx)->state, \
75  (hash), (length), (digest) )
76 
77 /* HMAC using specific hash functions */
78 
79 /* hmac-md5 */
80 struct hmac_md5_ctx HMAC_CTX(struct md5_ctx);
81 
82 void
83 hmac_md5_set_key(struct hmac_md5_ctx *ctx,
84  unsigned key_length, const uint8_t *key);
85 
86 void
87 hmac_md5_update(struct hmac_md5_ctx *ctx,
88  unsigned length, const uint8_t *data);
89 
90 void
91 hmac_md5_digest(struct hmac_md5_ctx *ctx,
92  unsigned length, uint8_t *digest);
93 
94 
95 /* hmac-sha1 */
97 
98 void
100  unsigned key_length, const uint8_t *key);
101 
102 void
103 hmac_sha1_update(struct hmac_sha1_ctx *ctx,
104  unsigned length, const uint8_t *data);
105 
106 void
107 hmac_sha1_digest(struct hmac_sha1_ctx *ctx,
108  unsigned length, uint8_t *digest);
109 
110 /* hmac-sha256 */
112 
113 void
115  unsigned key_length, const uint8_t *key);
116 
117 void
119  unsigned length, const uint8_t *data);
120 
121 void
123  unsigned length, uint8_t *digest);
124 
125 #endif /* NETTLE_HMAC_H_INCLUDED */
126