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