2 * Portions Copyright (C) 2004-2008, 2010 Internet Systems Consortium, Inc. ("ISC")
3 * Portions Copyright (C) 2000-2002 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NETWORK ASSOCIATES DISCLAIMS
10 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE
12 * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
15 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 * Portions Copyright (C) 1995-2000 by Network Associates, Inc.
19 * Permission to use, copy, modify, and/or distribute this software for any
20 * purpose with or without fee is hereby granted, provided that the above
21 * copyright notice and this permission notice appear in all copies.
23 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NETWORK ASSOCIATES DISCLAIMS
24 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE
26 * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
27 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
28 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
29 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
32 /* $Id: dst_internal.h,v 1.11.120.2 2010/01/15 23:47:33 tbox Exp $ */
34 #ifndef DST_DST_INTERNAL_H
35 #define DST_DST_INTERNAL_H 1
38 #include <isc/buffer.h>
40 #include <isc/magic.h>
41 #include <isc/region.h>
42 #include <isc/types.h>
46 #include <isc/hmacmd5.h>
47 #include <isc/hmacsha.h>
52 #include <openssl/dh.h>
53 #include <openssl/dsa.h>
54 #include <openssl/err.h>
55 #include <openssl/evp.h>
56 #include <openssl/objects.h>
57 #include <openssl/rsa.h>
62 #define KEY_MAGIC ISC_MAGIC('D','S','T','K')
63 #define CTX_MAGIC ISC_MAGIC('D','S','T','C')
65 #define VALID_KEY(x) ISC_MAGIC_VALID(x, KEY_MAGIC)
66 #define VALID_CTX(x) ISC_MAGIC_VALID(x, CTX_MAGIC)
68 extern isc_mem_t *dst__memory_pool;
74 typedef struct dst_func dst_func_t;
76 typedef struct dst_hmacmd5_key dst_hmacmd5_key_t;
77 typedef struct dst_hmacsha1_key dst_hmacsha1_key_t;
78 typedef struct dst_hmacsha224_key dst_hmacsha224_key_t;
79 typedef struct dst_hmacsha256_key dst_hmacsha256_key_t;
80 typedef struct dst_hmacsha384_key dst_hmacsha384_key_t;
81 typedef struct dst_hmacsha512_key dst_hmacsha512_key_t;
83 /*% DST Key Structure */
86 dns_name_t * key_name; /*%< name of the key */
87 unsigned int key_size; /*%< size of the key in bits */
88 unsigned int key_proto; /*%< protocols this key is used for */
89 unsigned int key_alg; /*%< algorithm of the key */
90 isc_uint32_t key_flags; /*%< flags of the public key */
91 isc_uint16_t key_id; /*%< identifier of the key */
92 isc_uint16_t key_bits; /*%< hmac digest bits */
93 dns_rdataclass_t key_class; /*%< class of the key record */
94 isc_mem_t *mctx; /*%< memory context */
95 char *engine; /*%< engine name (HSM) */
96 char *label; /*%< engine label (HSM) */
101 #if !defined(USE_EVP) || !USE_EVP
108 dst_hmacmd5_key_t *hmacmd5;
109 dst_hmacsha1_key_t *hmacsha1;
110 dst_hmacsha224_key_t *hmacsha224;
111 dst_hmacsha256_key_t *hmacsha256;
112 dst_hmacsha384_key_t *hmacsha384;
113 dst_hmacsha512_key_t *hmacsha512;
115 } keydata; /*%< pointer to key in crypto pkg fmt */
116 dst_func_t * func; /*%< crypto package specific functions */
125 dst_gssapi_signverifyctx_t *gssctx;
128 isc_sha256_t *sha256ctx;
129 isc_sha512_t *sha512ctx;
130 isc_hmacmd5_t *hmacmd5ctx;
131 isc_hmacsha1_t *hmacsha1ctx;
132 isc_hmacsha224_t *hmacsha224ctx;
133 isc_hmacsha256_t *hmacsha256ctx;
134 isc_hmacsha384_t *hmacsha384ctx;
135 isc_hmacsha512_t *hmacsha512ctx;
137 EVP_MD_CTX *evp_md_ctx;
146 isc_result_t (*createctx)(dst_key_t *key, dst_context_t *dctx);
147 void (*destroyctx)(dst_context_t *dctx);
148 isc_result_t (*adddata)(dst_context_t *dctx, const isc_region_t *data);
153 isc_result_t (*sign)(dst_context_t *dctx, isc_buffer_t *sig);
154 isc_result_t (*verify)(dst_context_t *dctx, const isc_region_t *sig);
155 isc_result_t (*computesecret)(const dst_key_t *pub,
156 const dst_key_t *priv,
157 isc_buffer_t *secret);
158 isc_boolean_t (*compare)(const dst_key_t *key1, const dst_key_t *key2);
159 isc_boolean_t (*paramcompare)(const dst_key_t *key1,
160 const dst_key_t *key2);
161 isc_result_t (*generate)(dst_key_t *key, int parms);
162 isc_boolean_t (*isprivate)(const dst_key_t *key);
163 void (*destroy)(dst_key_t *key);
165 /* conversion functions */
166 isc_result_t (*todns)(const dst_key_t *key, isc_buffer_t *data);
167 isc_result_t (*fromdns)(dst_key_t *key, isc_buffer_t *data);
168 isc_result_t (*tofile)(const dst_key_t *key, const char *directory);
169 isc_result_t (*parse)(dst_key_t *key, isc_lex_t *lexer);
172 void (*cleanup)(void);
174 isc_result_t (*fromlabel)(dst_key_t *key, const char *engine,
175 const char *label, const char *pin);
181 isc_result_t dst__openssl_init(void);
183 isc_result_t dst__hmacmd5_init(struct dst_func **funcp);
184 isc_result_t dst__hmacsha1_init(struct dst_func **funcp);
185 isc_result_t dst__hmacsha224_init(struct dst_func **funcp);
186 isc_result_t dst__hmacsha256_init(struct dst_func **funcp);
187 isc_result_t dst__hmacsha384_init(struct dst_func **funcp);
188 isc_result_t dst__hmacsha512_init(struct dst_func **funcp);
189 isc_result_t dst__opensslrsa_init(struct dst_func **funcp,
190 unsigned char algorithm);
191 isc_result_t dst__openssldsa_init(struct dst_func **funcp);
192 isc_result_t dst__openssldh_init(struct dst_func **funcp);
193 isc_result_t dst__gssapi_init(struct dst_func **funcp);
198 void dst__openssl_destroy(void);
201 * Memory allocators using the DST memory pool.
203 void * dst__mem_alloc(size_t size);
204 void dst__mem_free(void *ptr);
205 void * dst__mem_realloc(void *ptr, size_t size);
208 * Entropy retriever using the DST entropy pool.
210 isc_result_t dst__entropy_getdata(void *buf, unsigned int len,
211 isc_boolean_t pseudo);
214 * Entropy status hook.
216 unsigned int dst__entropy_status(void);
220 #endif /* DST_DST_INTERNAL_H */