vendor/BIND: Update to 9.5.2-P3
[dragonfly.git] / contrib / bind / lib / dns / dst_internal.h
blobecbcedaff27a910a82b67098ecde99e3b6a7aac8
1 /*
2 * Portions Copyright (C) 2004-2007 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.9 2007/08/28 07:20:42 tbox Exp $ */
34 #ifndef DST_DST_INTERNAL_H
35 #define DST_DST_INTERNAL_H 1
37 #include <isc/lang.h>
38 #include <isc/buffer.h>
39 #include <isc/int.h>
40 #include <isc/magic.h>
41 #include <isc/region.h>
42 #include <isc/types.h>
43 #include <isc/md5.h>
44 #include <isc/sha1.h>
45 #include <isc/hmacmd5.h>
46 #include <isc/hmacsha.h>
48 #include <dst/dst.h>
50 #ifdef OPENSSL
51 #include <openssl/dh.h>
52 #include <openssl/dsa.h>
53 #include <openssl/err.h>
54 #include <openssl/objects.h>
55 #include <openssl/rsa.h>
56 #endif
58 ISC_LANG_BEGINDECLS
60 #define KEY_MAGIC ISC_MAGIC('D','S','T','K')
61 #define CTX_MAGIC ISC_MAGIC('D','S','T','C')
63 #define VALID_KEY(x) ISC_MAGIC_VALID(x, KEY_MAGIC)
64 #define VALID_CTX(x) ISC_MAGIC_VALID(x, CTX_MAGIC)
66 extern isc_mem_t *dst__memory_pool;
68 /***
69 *** Types
70 ***/
72 typedef struct dst_func dst_func_t;
74 typedef struct dst_hmacmd5_key dst_hmacmd5_key_t;
75 typedef struct dst_hmacsha1_key dst_hmacsha1_key_t;
76 typedef struct dst_hmacsha224_key dst_hmacsha224_key_t;
77 typedef struct dst_hmacsha256_key dst_hmacsha256_key_t;
78 typedef struct dst_hmacsha384_key dst_hmacsha384_key_t;
79 typedef struct dst_hmacsha512_key dst_hmacsha512_key_t;
81 /*% DST Key Structure */
82 struct dst_key {
83 unsigned int magic;
84 dns_name_t * key_name; /*%< name of the key */
85 unsigned int key_size; /*%< size of the key in bits */
86 unsigned int key_proto; /*%< protocols this key is used for */
87 unsigned int key_alg; /*%< algorithm of the key */
88 isc_uint32_t key_flags; /*%< flags of the public key */
89 isc_uint16_t key_id; /*%< identifier of the key */
90 isc_uint16_t key_bits; /*%< hmac digest bits */
91 dns_rdataclass_t key_class; /*%< class of the key record */
92 isc_mem_t *mctx; /*%< memory context */
93 union {
94 void *generic;
95 gss_ctx_id_t gssctx;
96 #ifdef OPENSSL
97 RSA *rsa;
98 DSA *dsa;
99 DH *dh;
100 #endif
101 dst_hmacmd5_key_t *hmacmd5;
102 dst_hmacsha1_key_t *hmacsha1;
103 dst_hmacsha224_key_t *hmacsha224;
104 dst_hmacsha256_key_t *hmacsha256;
105 dst_hmacsha384_key_t *hmacsha384;
106 dst_hmacsha512_key_t *hmacsha512;
108 } keydata; /*%< pointer to key in crypto pkg fmt */
109 dst_func_t * func; /*%< crypto package specific functions */
112 struct dst_context {
113 unsigned int magic;
114 dst_key_t *key;
115 isc_mem_t *mctx;
116 union {
117 void *generic;
118 dst_gssapi_signverifyctx_t *gssctx;
119 isc_md5_t *md5ctx;
120 isc_sha1_t *sha1ctx;
121 isc_hmacmd5_t *hmacmd5ctx;
122 isc_hmacsha1_t *hmacsha1ctx;
123 isc_hmacsha224_t *hmacsha224ctx;
124 isc_hmacsha256_t *hmacsha256ctx;
125 isc_hmacsha384_t *hmacsha384ctx;
126 isc_hmacsha512_t *hmacsha512ctx;
127 } ctxdata;
130 struct dst_func {
132 * Context functions
134 isc_result_t (*createctx)(dst_key_t *key, dst_context_t *dctx);
135 void (*destroyctx)(dst_context_t *dctx);
136 isc_result_t (*adddata)(dst_context_t *dctx, const isc_region_t *data);
139 * Key operations
141 isc_result_t (*sign)(dst_context_t *dctx, isc_buffer_t *sig);
142 isc_result_t (*verify)(dst_context_t *dctx, const isc_region_t *sig);
143 isc_result_t (*computesecret)(const dst_key_t *pub,
144 const dst_key_t *priv,
145 isc_buffer_t *secret);
146 isc_boolean_t (*compare)(const dst_key_t *key1, const dst_key_t *key2);
147 isc_boolean_t (*paramcompare)(const dst_key_t *key1,
148 const dst_key_t *key2);
149 isc_result_t (*generate)(dst_key_t *key, int parms);
150 isc_boolean_t (*isprivate)(const dst_key_t *key);
151 void (*destroy)(dst_key_t *key);
153 /* conversion functions */
154 isc_result_t (*todns)(const dst_key_t *key, isc_buffer_t *data);
155 isc_result_t (*fromdns)(dst_key_t *key, isc_buffer_t *data);
156 isc_result_t (*tofile)(const dst_key_t *key, const char *directory);
157 isc_result_t (*parse)(dst_key_t *key, isc_lex_t *lexer);
159 /* cleanup */
160 void (*cleanup)(void);
164 * Initializers
166 isc_result_t dst__openssl_init(void);
168 isc_result_t dst__hmacmd5_init(struct dst_func **funcp);
169 isc_result_t dst__hmacsha1_init(struct dst_func **funcp);
170 isc_result_t dst__hmacsha224_init(struct dst_func **funcp);
171 isc_result_t dst__hmacsha256_init(struct dst_func **funcp);
172 isc_result_t dst__hmacsha384_init(struct dst_func **funcp);
173 isc_result_t dst__hmacsha512_init(struct dst_func **funcp);
174 isc_result_t dst__opensslrsa_init(struct dst_func **funcp);
175 isc_result_t dst__openssldsa_init(struct dst_func **funcp);
176 isc_result_t dst__openssldh_init(struct dst_func **funcp);
177 isc_result_t dst__gssapi_init(struct dst_func **funcp);
180 * Destructors
182 void dst__openssl_destroy(void);
185 * Memory allocators using the DST memory pool.
187 void * dst__mem_alloc(size_t size);
188 void dst__mem_free(void *ptr);
189 void * dst__mem_realloc(void *ptr, size_t size);
192 * Entropy retriever using the DST entropy pool.
194 isc_result_t dst__entropy_getdata(void *buf, unsigned int len,
195 isc_boolean_t pseudo);
198 * Entropy status hook.
200 unsigned int dst__entropy_status(void);
202 ISC_LANG_ENDDECLS
204 #endif /* DST_DST_INTERNAL_H */
205 /*! \file */