Tizen 2.0 Release
[external/nettle.git] / hmac.h
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 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 /* Namespace mangling */
39 #define hmac_set_key nettle_hmac_set_key
40 #define hmac_update nettle_hmac_update
41 #define hmac_digest nettle_hmac_digest
42 #define hmac_md5_set_key nettle_hmac_md5_set_key
43 #define hmac_md5_update nettle_hmac_md5_update
44 #define hmac_md5_digest nettle_hmac_md5_digest
45 #define hmac_sha1_set_key nettle_hmac_sha1_set_key
46 #define hmac_sha1_update nettle_hmac_sha1_update
47 #define hmac_sha1_digest nettle_hmac_sha1_digest
48 #define hmac_sha224_set_key nettle_hmac_sha224_set_key
49 #define hmac_sha224_digest nettle_hmac_sha224_digest
50 #define hmac_sha256_set_key nettle_hmac_sha256_set_key
51 #define hmac_sha256_update nettle_hmac_sha256_update
52 #define hmac_sha256_digest nettle_hmac_sha256_digest
53 #define hmac_sha384_set_key nettle_hmac_sha384_set_key
54 #define hmac_sha384_digest nettle_hmac_sha384_digest
55 #define hmac_sha512_set_key nettle_hmac_sha512_set_key
56 #define hmac_sha512_update nettle_hmac_sha512_update
57 #define hmac_sha512_digest nettle_hmac_sha512_digest
58
59 void
60 hmac_set_key(void *outer, void *inner, void *state,
61              const struct nettle_hash *hash,
62              unsigned length, const uint8_t *key);
63
64 /* This function is not strictly needed, it's s just the same as the
65  * hash update function. */
66 void
67 hmac_update(void *state,
68             const struct nettle_hash *hash,
69             unsigned length, const uint8_t *data);
70
71 void
72 hmac_digest(const void *outer, const void *inner, void *state,
73             const struct nettle_hash *hash,
74             unsigned length, uint8_t *digest);
75
76
77 #define HMAC_CTX(type) \
78 { type outer; type inner; type state; }
79
80 #define HMAC_SET_KEY(ctx, hash, length, key)                    \
81   hmac_set_key( &(ctx)->outer, &(ctx)->inner, &(ctx)->state,    \
82                 (hash), (length), (key) )
83
84 #define HMAC_DIGEST(ctx, hash, length, digest)                  \
85   hmac_digest( &(ctx)->outer, &(ctx)->inner, &(ctx)->state,     \
86                (hash), (length), (digest) )
87
88 /* HMAC using specific hash functions */
89
90 /* hmac-md5 */
91 struct hmac_md5_ctx HMAC_CTX(struct md5_ctx);
92
93 void
94 hmac_md5_set_key(struct hmac_md5_ctx *ctx,
95                  unsigned key_length, const uint8_t *key);
96
97 void
98 hmac_md5_update(struct hmac_md5_ctx *ctx,
99                 unsigned length, const uint8_t *data);
100
101 void
102 hmac_md5_digest(struct hmac_md5_ctx *ctx,
103                 unsigned length, uint8_t *digest);
104
105
106 /* hmac-sha1 */
107 struct hmac_sha1_ctx HMAC_CTX(struct sha1_ctx);
108
109 void
110 hmac_sha1_set_key(struct hmac_sha1_ctx *ctx,
111                   unsigned key_length, const uint8_t *key);
112
113 void
114 hmac_sha1_update(struct hmac_sha1_ctx *ctx,
115                  unsigned length, const uint8_t *data);
116
117 void
118 hmac_sha1_digest(struct hmac_sha1_ctx *ctx,
119                  unsigned length, uint8_t *digest);
120
121 /* hmac-sha256 */
122 struct hmac_sha256_ctx HMAC_CTX(struct sha256_ctx);
123
124 void
125 hmac_sha256_set_key(struct hmac_sha256_ctx *ctx,
126                     unsigned key_length, const uint8_t *key);
127
128 void
129 hmac_sha256_update(struct hmac_sha256_ctx *ctx,
130                    unsigned length, const uint8_t *data);
131
132 void
133 hmac_sha256_digest(struct hmac_sha256_ctx *ctx,
134                    unsigned length, uint8_t *digest);
135
136 /* hmac-sha224 */
137 #define hmac_sha224_ctx hmac_sha256_ctx
138
139 void
140 hmac_sha224_set_key(struct hmac_sha224_ctx *ctx,
141                     unsigned key_length, const uint8_t *key);
142
143 #define hmac_sha224_update nettle_hmac_sha256_update
144
145 void
146 hmac_sha224_digest(struct hmac_sha224_ctx *ctx,
147                    unsigned length, uint8_t *digest);
148
149 /* hmac-sha512 */
150 struct hmac_sha512_ctx HMAC_CTX(struct sha512_ctx);
151
152 void
153 hmac_sha512_set_key(struct hmac_sha512_ctx *ctx,
154                     unsigned key_length, const uint8_t *key);
155
156 void
157 hmac_sha512_update(struct hmac_sha512_ctx *ctx,
158                    unsigned length, const uint8_t *data);
159
160 void
161 hmac_sha512_digest(struct hmac_sha512_ctx *ctx,
162                    unsigned length, uint8_t *digest);
163
164 /* hmac-sha384 */
165 #define hmac_sha384_ctx hmac_sha512_ctx
166
167 void
168 hmac_sha384_set_key(struct hmac_sha512_ctx *ctx,
169                     unsigned key_length, const uint8_t *key);
170
171 #define hmac_sha384_update nettle_hmac_sha512_update
172
173 void
174 hmac_sha384_digest(struct hmac_sha512_ctx *ctx,
175                    unsigned length, uint8_t *digest);
176
177 #ifdef __cplusplus
178 }
179 #endif
180
181 #endif /* NETTLE_HMAC_H_INCLUDED */