1 /*	$NetBSD: hmacsha.h,v 1.5 2014/12/10 04:38:00 christos Exp $	*/
2 
3 /*
4  * Copyright (C) 2005-2007, 2009, 2014  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 
44 typedef HMAC_CTX isc_hmacsha1_t;
45 typedef HMAC_CTX isc_hmacsha224_t;
46 typedef HMAC_CTX isc_hmacsha256_t;
47 typedef HMAC_CTX isc_hmacsha384_t;
48 typedef HMAC_CTX isc_hmacsha512_t;
49 
50 #elif PKCS11CRYPTO
51 #include <pk11/pk11.h>
52 
53 typedef pk11_context_t isc_hmacsha1_t;
54 typedef pk11_context_t isc_hmacsha224_t;
55 typedef pk11_context_t isc_hmacsha256_t;
56 typedef pk11_context_t isc_hmacsha384_t;
57 typedef pk11_context_t isc_hmacsha512_t;
58 
59 #else
60 
61 typedef struct {
62 	isc_sha1_t sha1ctx;
63 	unsigned char key[ISC_HMACSHA1_KEYLENGTH];
64 } isc_hmacsha1_t;
65 
66 typedef struct {
67 	isc_sha224_t sha224ctx;
68 	unsigned char key[ISC_HMACSHA224_KEYLENGTH];
69 } isc_hmacsha224_t;
70 
71 typedef struct {
72 	isc_sha256_t sha256ctx;
73 	unsigned char key[ISC_HMACSHA256_KEYLENGTH];
74 } isc_hmacsha256_t;
75 
76 typedef struct {
77 	isc_sha384_t sha384ctx;
78 	unsigned char key[ISC_HMACSHA384_KEYLENGTH];
79 } isc_hmacsha384_t;
80 
81 typedef struct {
82 	isc_sha512_t sha512ctx;
83 	unsigned char key[ISC_HMACSHA512_KEYLENGTH];
84 } isc_hmacsha512_t;
85 #endif
86 
87 ISC_LANG_BEGINDECLS
88 
89 void
90 isc_hmacsha1_init(isc_hmacsha1_t *ctx, const unsigned char *key,
91 		  unsigned int len);
92 
93 void
94 isc_hmacsha1_invalidate(isc_hmacsha1_t *ctx);
95 
96 void
97 isc_hmacsha1_update(isc_hmacsha1_t *ctx, const unsigned char *buf,
98 		    unsigned int len);
99 
100 void
101 isc_hmacsha1_sign(isc_hmacsha1_t *ctx, unsigned char *digest, size_t len);
102 
103 isc_boolean_t
104 isc_hmacsha1_verify(isc_hmacsha1_t *ctx, unsigned char *digest, size_t len);
105 
106 
107 void
108 isc_hmacsha224_init(isc_hmacsha224_t *ctx, const unsigned char *key,
109 		    unsigned int len);
110 
111 void
112 isc_hmacsha224_invalidate(isc_hmacsha224_t *ctx);
113 
114 void
115 isc_hmacsha224_update(isc_hmacsha224_t *ctx, const unsigned char *buf,
116 		      unsigned int len);
117 
118 void
119 isc_hmacsha224_sign(isc_hmacsha224_t *ctx, unsigned char *digest, size_t len);
120 
121 isc_boolean_t
122 isc_hmacsha224_verify(isc_hmacsha224_t *ctx, unsigned char *digest, size_t len);
123 
124 
125 void
126 isc_hmacsha256_init(isc_hmacsha256_t *ctx, const unsigned char *key,
127 		    unsigned int len);
128 
129 void
130 isc_hmacsha256_invalidate(isc_hmacsha256_t *ctx);
131 
132 void
133 isc_hmacsha256_update(isc_hmacsha256_t *ctx, const unsigned char *buf,
134 		      unsigned int len);
135 
136 void
137 isc_hmacsha256_sign(isc_hmacsha256_t *ctx, unsigned char *digest, size_t len);
138 
139 isc_boolean_t
140 isc_hmacsha256_verify(isc_hmacsha256_t *ctx, unsigned char *digest, size_t len);
141 
142 
143 void
144 isc_hmacsha384_init(isc_hmacsha384_t *ctx, const unsigned char *key,
145 		    unsigned int len);
146 
147 void
148 isc_hmacsha384_invalidate(isc_hmacsha384_t *ctx);
149 
150 void
151 isc_hmacsha384_update(isc_hmacsha384_t *ctx, const unsigned char *buf,
152 		      unsigned int len);
153 
154 void
155 isc_hmacsha384_sign(isc_hmacsha384_t *ctx, unsigned char *digest, size_t len);
156 
157 isc_boolean_t
158 isc_hmacsha384_verify(isc_hmacsha384_t *ctx, unsigned char *digest, size_t len);
159 
160 
161 void
162 isc_hmacsha512_init(isc_hmacsha512_t *ctx, const unsigned char *key,
163 		    unsigned int len);
164 
165 void
166 isc_hmacsha512_invalidate(isc_hmacsha512_t *ctx);
167 
168 void
169 isc_hmacsha512_update(isc_hmacsha512_t *ctx, const unsigned char *buf,
170 		      unsigned int len);
171 
172 void
173 isc_hmacsha512_sign(isc_hmacsha512_t *ctx, unsigned char *digest, size_t len);
174 
175 isc_boolean_t
176 isc_hmacsha512_verify(isc_hmacsha512_t *ctx, unsigned char *digest, size_t len);
177 
178 ISC_LANG_ENDDECLS
179 
180 #endif /* ISC_HMACSHA_H */
181