]> CyberLeo.Net >> Repos - FreeBSD/stable/8.git/blob - contrib/bind9/lib/dns/dst_internal.h
Update to version 9.6-ESV-R6, the latest from ISC, which contains numerous
[FreeBSD/stable/8.git] / contrib / bind9 / lib / dns / dst_internal.h
1 /*
2  * Portions Copyright (C) 2004-2008, 2010, 2012  Internet Systems Consortium, Inc. ("ISC")
3  * Portions Copyright (C) 2000-2002  Internet Software Consortium.
4  *
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.
8  *
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.
16  *
17  * Portions Copyright (C) 1995-2000 by Network Associates, Inc.
18  *
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.
22  *
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.
30  */
31
32 /* $Id$ */
33
34 #ifndef DST_DST_INTERNAL_H
35 #define DST_DST_INTERNAL_H 1
36
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/refcount.h>
45 #include <isc/sha1.h>
46 #include <isc/sha2.h>
47 #include <isc/hmacmd5.h>
48 #include <isc/hmacsha.h>
49
50 #include <dst/dst.h>
51
52 #ifdef OPENSSL
53 #include <openssl/dh.h>
54 #include <openssl/dsa.h>
55 #include <openssl/err.h>
56 #include <openssl/evp.h>
57 #include <openssl/objects.h>
58 #include <openssl/rsa.h>
59 #endif
60
61 ISC_LANG_BEGINDECLS
62
63 #define KEY_MAGIC       ISC_MAGIC('D','S','T','K')
64 #define CTX_MAGIC       ISC_MAGIC('D','S','T','C')
65
66 #define VALID_KEY(x) ISC_MAGIC_VALID(x, KEY_MAGIC)
67 #define VALID_CTX(x) ISC_MAGIC_VALID(x, CTX_MAGIC)
68
69 extern isc_mem_t *dst__memory_pool;
70
71 /***
72  *** Types
73  ***/
74
75 typedef struct dst_func dst_func_t;
76
77 typedef struct dst_hmacmd5_key    dst_hmacmd5_key_t;
78 typedef struct dst_hmacsha1_key   dst_hmacsha1_key_t;
79 typedef struct dst_hmacsha224_key dst_hmacsha224_key_t;
80 typedef struct dst_hmacsha256_key dst_hmacsha256_key_t;
81 typedef struct dst_hmacsha384_key dst_hmacsha384_key_t;
82 typedef struct dst_hmacsha512_key dst_hmacsha512_key_t;
83
84 /*% DST Key Structure */
85 struct dst_key {
86         unsigned int    magic;
87         isc_refcount_t  refs;
88         dns_name_t *    key_name;       /*%< name of the key */
89         unsigned int    key_size;       /*%< size of the key in bits */
90         unsigned int    key_proto;      /*%< protocols this key is used for */
91         unsigned int    key_alg;        /*%< algorithm of the key */
92         isc_uint32_t    key_flags;      /*%< flags of the public key */
93         isc_uint16_t    key_id;         /*%< identifier of the key */
94         isc_uint16_t    key_bits;       /*%< hmac digest bits */
95         dns_rdataclass_t key_class;     /*%< class of the key record */
96         isc_mem_t       *mctx;          /*%< memory context */
97         char            *engine;        /*%< engine name (HSM) */
98         char            *label;         /*%< engine label (HSM) */
99         union {
100                 void *generic;
101                 gss_ctx_id_t gssctx;
102 #ifdef OPENSSL
103 #if !defined(USE_EVP) || !USE_EVP
104                 RSA *rsa;
105 #endif
106                 DSA *dsa;
107                 DH *dh;
108                 EVP_PKEY *pkey;
109 #endif
110                 dst_hmacmd5_key_t *hmacmd5;
111                 dst_hmacsha1_key_t *hmacsha1;
112                 dst_hmacsha224_key_t *hmacsha224;
113                 dst_hmacsha256_key_t *hmacsha256;
114                 dst_hmacsha384_key_t *hmacsha384;
115                 dst_hmacsha512_key_t *hmacsha512;
116
117         } keydata;                      /*%< pointer to key in crypto pkg fmt */
118         dst_func_t *    func;           /*%< crypto package specific functions */
119 };
120
121 struct dst_context {
122         unsigned int magic;
123         dst_key_t *key;
124         isc_mem_t *mctx;
125         union {
126                 void *generic;
127                 dst_gssapi_signverifyctx_t *gssctx;
128                 isc_md5_t *md5ctx;
129                 isc_sha1_t *sha1ctx;
130                 isc_sha256_t *sha256ctx;
131                 isc_sha512_t *sha512ctx;
132                 isc_hmacmd5_t *hmacmd5ctx;
133                 isc_hmacsha1_t *hmacsha1ctx;
134                 isc_hmacsha224_t *hmacsha224ctx;
135                 isc_hmacsha256_t *hmacsha256ctx;
136                 isc_hmacsha384_t *hmacsha384ctx;
137                 isc_hmacsha512_t *hmacsha512ctx;
138 #ifdef OPENSSL
139                 EVP_MD_CTX *evp_md_ctx;
140 #endif
141         } ctxdata;
142 };
143
144 struct dst_func {
145         /*
146          * Context functions
147          */
148         isc_result_t (*createctx)(dst_key_t *key, dst_context_t *dctx);
149         void (*destroyctx)(dst_context_t *dctx);
150         isc_result_t (*adddata)(dst_context_t *dctx, const isc_region_t *data);
151
152         /*
153          * Key operations
154          */
155         isc_result_t (*sign)(dst_context_t *dctx, isc_buffer_t *sig);
156         isc_result_t (*verify)(dst_context_t *dctx, const isc_region_t *sig);
157         isc_result_t (*computesecret)(const dst_key_t *pub,
158                                       const dst_key_t *priv,
159                                       isc_buffer_t *secret);
160         isc_boolean_t (*compare)(const dst_key_t *key1, const dst_key_t *key2);
161         isc_boolean_t (*paramcompare)(const dst_key_t *key1,
162                                       const dst_key_t *key2);
163         isc_result_t (*generate)(dst_key_t *key, int parms);
164         isc_boolean_t (*isprivate)(const dst_key_t *key);
165         void (*destroy)(dst_key_t *key);
166
167         /* conversion functions */
168         isc_result_t (*todns)(const dst_key_t *key, isc_buffer_t *data);
169         isc_result_t (*fromdns)(dst_key_t *key, isc_buffer_t *data);
170         isc_result_t (*tofile)(const dst_key_t *key, const char *directory);
171         isc_result_t (*parse)(dst_key_t *key, isc_lex_t *lexer);
172
173         /* cleanup */
174         void (*cleanup)(void);
175
176         isc_result_t (*fromlabel)(dst_key_t *key, const char *engine,
177                                   const char *label, const char *pin);
178 };
179
180 /*%
181  * Initializers
182  */
183 isc_result_t dst__openssl_init(void);
184
185 isc_result_t dst__hmacmd5_init(struct dst_func **funcp);
186 isc_result_t dst__hmacsha1_init(struct dst_func **funcp);
187 isc_result_t dst__hmacsha224_init(struct dst_func **funcp);
188 isc_result_t dst__hmacsha256_init(struct dst_func **funcp);
189 isc_result_t dst__hmacsha384_init(struct dst_func **funcp);
190 isc_result_t dst__hmacsha512_init(struct dst_func **funcp);
191 isc_result_t dst__opensslrsa_init(struct dst_func **funcp,
192                                   unsigned char algorithm);
193 isc_result_t dst__openssldsa_init(struct dst_func **funcp);
194 isc_result_t dst__openssldh_init(struct dst_func **funcp);
195 isc_result_t dst__gssapi_init(struct dst_func **funcp);
196
197 /*%
198  * Destructors
199  */
200 void dst__openssl_destroy(void);
201
202 /*%
203  * Memory allocators using the DST memory pool.
204  */
205 void * dst__mem_alloc(size_t size);
206 void   dst__mem_free(void *ptr);
207 void * dst__mem_realloc(void *ptr, size_t size);
208
209 /*%
210  * Entropy retriever using the DST entropy pool.
211  */
212 isc_result_t dst__entropy_getdata(void *buf, unsigned int len,
213                                   isc_boolean_t pseudo);
214
215 /*
216  * Entropy status hook.
217  */
218 unsigned int dst__entropy_status(void);
219
220 ISC_LANG_ENDDECLS
221
222 #endif /* DST_DST_INTERNAL_H */
223 /*! \file */