2 * Portions Copyright (C) 2004-2012 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.
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>
44 #include <isc/refcount.h>
47 #include <isc/stdtime.h>
48 #include <isc/hmacmd5.h>
49 #include <isc/hmacsha.h>
56 #include <openssl/dh.h>
57 #include <openssl/dsa.h>
58 #include <openssl/err.h>
59 #include <openssl/evp.h>
60 #include <openssl/objects.h>
61 #include <openssl/rsa.h>
66 #define KEY_MAGIC ISC_MAGIC('D','S','T','K')
67 #define CTX_MAGIC ISC_MAGIC('D','S','T','C')
69 #define VALID_KEY(x) ISC_MAGIC_VALID(x, KEY_MAGIC)
70 #define VALID_CTX(x) ISC_MAGIC_VALID(x, CTX_MAGIC)
72 extern isc_mem_t *dst__memory_pool;
78 typedef struct dst_func dst_func_t;
80 typedef struct dst_hmacmd5_key dst_hmacmd5_key_t;
81 typedef struct dst_hmacsha1_key dst_hmacsha1_key_t;
82 typedef struct dst_hmacsha224_key dst_hmacsha224_key_t;
83 typedef struct dst_hmacsha256_key dst_hmacsha256_key_t;
84 typedef struct dst_hmacsha384_key dst_hmacsha384_key_t;
85 typedef struct dst_hmacsha512_key dst_hmacsha512_key_t;
87 /*% DST Key Structure */
91 dns_name_t * key_name; /*%< name of the key */
92 unsigned int key_size; /*%< size of the key in bits */
93 unsigned int key_proto; /*%< protocols this key is used for */
94 unsigned int key_alg; /*%< algorithm of the key */
95 isc_uint32_t key_flags; /*%< flags of the public key */
96 isc_uint16_t key_id; /*%< identifier of the key */
97 isc_uint16_t key_rid; /*%< identifier of the key when
99 isc_uint16_t key_bits; /*%< hmac digest bits */
100 dns_rdataclass_t key_class; /*%< class of the key record */
101 isc_mem_t *mctx; /*%< memory context */
102 char *engine; /*%< engine name (HSM) */
103 char *label; /*%< engine label (HSM) */
108 #if !defined(USE_EVP) || !USE_EVP
115 dst_hmacmd5_key_t *hmacmd5;
116 dst_hmacsha1_key_t *hmacsha1;
117 dst_hmacsha224_key_t *hmacsha224;
118 dst_hmacsha256_key_t *hmacsha256;
119 dst_hmacsha384_key_t *hmacsha384;
120 dst_hmacsha512_key_t *hmacsha512;
122 } keydata; /*%< pointer to key in crypto pkg fmt */
124 isc_stdtime_t times[DST_MAX_TIMES + 1]; /*%< timing metadata */
125 isc_boolean_t timeset[DST_MAX_TIMES + 1]; /*%< data set? */
126 isc_stdtime_t nums[DST_MAX_NUMERIC + 1]; /*%< numeric metadata */
127 isc_boolean_t numset[DST_MAX_NUMERIC + 1]; /*%< data set? */
129 int fmt_major; /*%< private key format, major version */
130 int fmt_minor; /*%< private key format, minor version */
132 dst_func_t * func; /*%< crypto package specific functions */
133 isc_buffer_t *key_tkeytoken; /*%< TKEY token data */
140 isc_logcategory_t *category;
143 dst_gssapi_signverifyctx_t *gssctx;
146 isc_sha256_t *sha256ctx;
147 isc_sha512_t *sha512ctx;
148 isc_hmacmd5_t *hmacmd5ctx;
149 isc_hmacsha1_t *hmacsha1ctx;
150 isc_hmacsha224_t *hmacsha224ctx;
151 isc_hmacsha256_t *hmacsha256ctx;
152 isc_hmacsha384_t *hmacsha384ctx;
153 isc_hmacsha512_t *hmacsha512ctx;
155 EVP_MD_CTX *evp_md_ctx;
164 isc_result_t (*createctx)(dst_key_t *key, dst_context_t *dctx);
165 void (*destroyctx)(dst_context_t *dctx);
166 isc_result_t (*adddata)(dst_context_t *dctx, const isc_region_t *data);
171 isc_result_t (*sign)(dst_context_t *dctx, isc_buffer_t *sig);
172 isc_result_t (*verify)(dst_context_t *dctx, const isc_region_t *sig);
173 isc_result_t (*computesecret)(const dst_key_t *pub,
174 const dst_key_t *priv,
175 isc_buffer_t *secret);
176 isc_boolean_t (*compare)(const dst_key_t *key1, const dst_key_t *key2);
177 isc_boolean_t (*paramcompare)(const dst_key_t *key1,
178 const dst_key_t *key2);
179 isc_result_t (*generate)(dst_key_t *key, int parms,
180 void (*callback)(int));
181 isc_boolean_t (*isprivate)(const dst_key_t *key);
182 void (*destroy)(dst_key_t *key);
184 /* conversion functions */
185 isc_result_t (*todns)(const dst_key_t *key, isc_buffer_t *data);
186 isc_result_t (*fromdns)(dst_key_t *key, isc_buffer_t *data);
187 isc_result_t (*tofile)(const dst_key_t *key, const char *directory);
188 isc_result_t (*parse)(dst_key_t *key,
193 void (*cleanup)(void);
195 isc_result_t (*fromlabel)(dst_key_t *key, const char *engine,
196 const char *label, const char *pin);
197 isc_result_t (*dump)(dst_key_t *key, isc_mem_t *mctx, char **buffer,
199 isc_result_t (*restore)(dst_key_t *key, const char *keystr);
205 isc_result_t dst__openssl_init(const char *engine);
207 isc_result_t dst__hmacmd5_init(struct dst_func **funcp);
208 isc_result_t dst__hmacsha1_init(struct dst_func **funcp);
209 isc_result_t dst__hmacsha224_init(struct dst_func **funcp);
210 isc_result_t dst__hmacsha256_init(struct dst_func **funcp);
211 isc_result_t dst__hmacsha384_init(struct dst_func **funcp);
212 isc_result_t dst__hmacsha512_init(struct dst_func **funcp);
213 isc_result_t dst__opensslrsa_init(struct dst_func **funcp,
214 unsigned char algorithm);
215 isc_result_t dst__openssldsa_init(struct dst_func **funcp);
216 isc_result_t dst__openssldh_init(struct dst_func **funcp);
217 isc_result_t dst__gssapi_init(struct dst_func **funcp);
218 #ifdef HAVE_OPENSSL_GOST
219 isc_result_t dst__opensslgost_init(struct dst_func **funcp);
221 #ifdef HAVE_OPENSSL_ECDSA
222 isc_result_t dst__opensslecdsa_init(struct dst_func **funcp);
228 void dst__openssl_destroy(void);
231 * Memory allocators using the DST memory pool.
233 void * dst__mem_alloc(size_t size);
234 void dst__mem_free(void *ptr);
235 void * dst__mem_realloc(void *ptr, size_t size);
238 * Entropy retriever using the DST entropy pool.
240 isc_result_t dst__entropy_getdata(void *buf, unsigned int len,
241 isc_boolean_t pseudo);
244 * Entropy status hook.
246 unsigned int dst__entropy_status(void);
250 #endif /* DST_DST_INTERNAL_H */