1/*	$NetBSD$	*/
2
3/*
4 * Copyright (C) 2005-2007, 2009  Internet Systems Consortium, Inc. ("ISC")
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
19/* Id: hmacsha.h,v 1.9 2009/02/06 23:47:42 tbox Exp  */
20
21/*! \file isc/hmacsha.h
22 * This is the header file for the HMAC-SHA1, HMAC-SHA224, HMAC-SHA256,
23 * HMAC-SHA334 and HMAC-SHA512 hash algorithm described in RFC 2104.
24 */
25
26#ifndef ISC_HMACSHA_H
27#define ISC_HMACSHA_H 1
28
29#include <isc/lang.h>
30#include <isc/platform.h>
31#include <isc/sha1.h>
32#include <isc/sha2.h>
33#include <isc/types.h>
34
35#define ISC_HMACSHA1_KEYLENGTH ISC_SHA1_BLOCK_LENGTH
36#define ISC_HMACSHA224_KEYLENGTH ISC_SHA224_BLOCK_LENGTH
37#define ISC_HMACSHA256_KEYLENGTH ISC_SHA256_BLOCK_LENGTH
38#define ISC_HMACSHA384_KEYLENGTH ISC_SHA384_BLOCK_LENGTH
39#define ISC_HMACSHA512_KEYLENGTH ISC_SHA512_BLOCK_LENGTH
40
41#ifdef ISC_PLATFORM_OPENSSLHASH
42#include <openssl/hmac.h>
43
44typedef HMAC_CTX isc_hmacsha1_t;
45typedef HMAC_CTX isc_hmacsha224_t;
46typedef HMAC_CTX isc_hmacsha256_t;
47typedef HMAC_CTX isc_hmacsha384_t;
48typedef HMAC_CTX isc_hmacsha512_t;
49
50#else
51
52typedef struct {
53	isc_sha1_t sha1ctx;
54	unsigned char key[ISC_HMACSHA1_KEYLENGTH];
55} isc_hmacsha1_t;
56
57typedef struct {
58	isc_sha224_t sha224ctx;
59	unsigned char key[ISC_HMACSHA224_KEYLENGTH];
60} isc_hmacsha224_t;
61
62typedef struct {
63	isc_sha256_t sha256ctx;
64	unsigned char key[ISC_HMACSHA256_KEYLENGTH];
65} isc_hmacsha256_t;
66
67typedef struct {
68	isc_sha384_t sha384ctx;
69	unsigned char key[ISC_HMACSHA384_KEYLENGTH];
70} isc_hmacsha384_t;
71
72typedef struct {
73	isc_sha512_t sha512ctx;
74	unsigned char key[ISC_HMACSHA512_KEYLENGTH];
75} isc_hmacsha512_t;
76#endif
77
78ISC_LANG_BEGINDECLS
79
80void
81isc_hmacsha1_init(isc_hmacsha1_t *ctx, const unsigned char *key,
82		  unsigned int len);
83
84void
85isc_hmacsha1_invalidate(isc_hmacsha1_t *ctx);
86
87void
88isc_hmacsha1_update(isc_hmacsha1_t *ctx, const unsigned char *buf,
89		    unsigned int len);
90
91void
92isc_hmacsha1_sign(isc_hmacsha1_t *ctx, unsigned char *digest, size_t len);
93
94isc_boolean_t
95isc_hmacsha1_verify(isc_hmacsha1_t *ctx, unsigned char *digest, size_t len);
96
97
98void
99isc_hmacsha224_init(isc_hmacsha224_t *ctx, const unsigned char *key,
100		    unsigned int len);
101
102void
103isc_hmacsha224_invalidate(isc_hmacsha224_t *ctx);
104
105void
106isc_hmacsha224_update(isc_hmacsha224_t *ctx, const unsigned char *buf,
107		      unsigned int len);
108
109void
110isc_hmacsha224_sign(isc_hmacsha224_t *ctx, unsigned char *digest, size_t len);
111
112isc_boolean_t
113isc_hmacsha224_verify(isc_hmacsha224_t *ctx, unsigned char *digest, size_t len);
114
115
116void
117isc_hmacsha256_init(isc_hmacsha256_t *ctx, const unsigned char *key,
118		    unsigned int len);
119
120void
121isc_hmacsha256_invalidate(isc_hmacsha256_t *ctx);
122
123void
124isc_hmacsha256_update(isc_hmacsha256_t *ctx, const unsigned char *buf,
125		      unsigned int len);
126
127void
128isc_hmacsha256_sign(isc_hmacsha256_t *ctx, unsigned char *digest, size_t len);
129
130isc_boolean_t
131isc_hmacsha256_verify(isc_hmacsha256_t *ctx, unsigned char *digest, size_t len);
132
133
134void
135isc_hmacsha384_init(isc_hmacsha384_t *ctx, const unsigned char *key,
136		    unsigned int len);
137
138void
139isc_hmacsha384_invalidate(isc_hmacsha384_t *ctx);
140
141void
142isc_hmacsha384_update(isc_hmacsha384_t *ctx, const unsigned char *buf,
143		      unsigned int len);
144
145void
146isc_hmacsha384_sign(isc_hmacsha384_t *ctx, unsigned char *digest, size_t len);
147
148isc_boolean_t
149isc_hmacsha384_verify(isc_hmacsha384_t *ctx, unsigned char *digest, size_t len);
150
151
152void
153isc_hmacsha512_init(isc_hmacsha512_t *ctx, const unsigned char *key,
154		    unsigned int len);
155
156void
157isc_hmacsha512_invalidate(isc_hmacsha512_t *ctx);
158
159void
160isc_hmacsha512_update(isc_hmacsha512_t *ctx, const unsigned char *buf,
161		      unsigned int len);
162
163void
164isc_hmacsha512_sign(isc_hmacsha512_t *ctx, unsigned char *digest, size_t len);
165
166isc_boolean_t
167isc_hmacsha512_verify(isc_hmacsha512_t *ctx, unsigned char *digest, size_t len);
168
169ISC_LANG_ENDDECLS
170
171#endif /* ISC_HMACSHA_H */
172