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