]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - contrib/bind9/lib/dns/dst_internal.h
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / contrib / bind9 / lib / dns / dst_internal.h
1 /*
2  * Portions Copyright (C) 2004-2006  Internet Systems Consortium, Inc. ("ISC")
3  * Portions Copyright (C) 2000-2002  Internet Software Consortium.
4  * Portions Copyright (C) 1995-2000 by Network Associates, Inc.
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NETWORK ASSOCIATES DISCLAIMS
11  * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE
13  * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
16  * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18
19 /* $Id: dst_internal.h,v 1.1.6.5 2006/01/27 23:57:44 marka Exp $ */
20
21 #ifndef DST_DST_INTERNAL_H
22 #define DST_DST_INTERNAL_H 1
23
24 #include <isc/lang.h>
25 #include <isc/buffer.h>
26 #include <isc/int.h>
27 #include <isc/magic.h>
28 #include <isc/region.h>
29 #include <isc/types.h>
30
31 #include <dst/dst.h>
32
33 ISC_LANG_BEGINDECLS
34
35 #define KEY_MAGIC       ISC_MAGIC('D','S','T','K')
36 #define CTX_MAGIC       ISC_MAGIC('D','S','T','C')
37
38 #define VALID_KEY(x) ISC_MAGIC_VALID(x, KEY_MAGIC)
39 #define VALID_CTX(x) ISC_MAGIC_VALID(x, CTX_MAGIC)
40
41 extern isc_mem_t *dst__memory_pool;
42
43 /***
44  *** Types
45  ***/
46
47 typedef struct dst_func dst_func_t;
48
49 /*% DST Key Structure */
50 struct dst_key {
51         unsigned int    magic;
52         dns_name_t *    key_name;       /*%< name of the key */
53         unsigned int    key_size;       /*%< size of the key in bits */
54         unsigned int    key_proto;      /*%< protocols this key is used for */
55         unsigned int    key_alg;        /*%< algorithm of the key */
56         isc_uint32_t    key_flags;      /*%< flags of the public key */
57         isc_uint16_t    key_id;         /*%< identifier of the key */
58         isc_uint16_t    key_bits;       /*%< hmac digest bits */
59         dns_rdataclass_t key_class;     /*%< class of the key record */
60         isc_mem_t       *mctx;          /*%< memory context */
61         void *          opaque;         /*%< pointer to key in crypto pkg fmt */
62         dst_func_t *    func;           /*%< crypto package specific functions */
63 };
64
65 struct dst_context {
66         unsigned int magic;
67         dst_key_t *key;
68         isc_mem_t *mctx;
69         void *opaque;
70 };
71
72 struct dst_func {
73         /*
74          * Context functions
75          */
76         isc_result_t (*createctx)(dst_key_t *key, dst_context_t *dctx);
77         void (*destroyctx)(dst_context_t *dctx);
78         isc_result_t (*adddata)(dst_context_t *dctx, const isc_region_t *data);
79
80         /*
81          * Key operations
82          */
83         isc_result_t (*sign)(dst_context_t *dctx, isc_buffer_t *sig);
84         isc_result_t (*verify)(dst_context_t *dctx, const isc_region_t *sig);
85         isc_result_t (*computesecret)(const dst_key_t *pub,
86                                       const dst_key_t *priv,
87                                       isc_buffer_t *secret);
88         isc_boolean_t (*compare)(const dst_key_t *key1, const dst_key_t *key2);
89         isc_boolean_t (*paramcompare)(const dst_key_t *key1,
90                                       const dst_key_t *key2);
91         isc_result_t (*generate)(dst_key_t *key, int parms);
92         isc_boolean_t (*isprivate)(const dst_key_t *key);
93         void (*destroy)(dst_key_t *key);
94
95         /* conversion functions */
96         isc_result_t (*todns)(const dst_key_t *key, isc_buffer_t *data);
97         isc_result_t (*fromdns)(dst_key_t *key, isc_buffer_t *data);
98         isc_result_t (*tofile)(const dst_key_t *key, const char *directory);
99         isc_result_t (*parse)(dst_key_t *key, isc_lex_t *lexer);
100
101         /* cleanup */
102         void (*cleanup)(void);
103 };
104
105 /*%
106  * Initializers
107  */
108 isc_result_t dst__openssl_init(void);
109
110 isc_result_t dst__hmacmd5_init(struct dst_func **funcp);
111 isc_result_t dst__hmacsha1_init(struct dst_func **funcp);
112 isc_result_t dst__hmacsha224_init(struct dst_func **funcp);
113 isc_result_t dst__hmacsha256_init(struct dst_func **funcp);
114 isc_result_t dst__hmacsha384_init(struct dst_func **funcp);
115 isc_result_t dst__hmacsha512_init(struct dst_func **funcp);
116 isc_result_t dst__opensslrsa_init(struct dst_func **funcp);
117 isc_result_t dst__openssldsa_init(struct dst_func **funcp);
118 isc_result_t dst__openssldh_init(struct dst_func **funcp);
119 isc_result_t dst__gssapi_init(struct dst_func **funcp);
120
121 /*%
122  * Destructors
123  */
124 void dst__openssl_destroy(void);
125
126 /*%
127  * Memory allocators using the DST memory pool.
128  */
129 void * dst__mem_alloc(size_t size);
130 void   dst__mem_free(void *ptr);
131 void * dst__mem_realloc(void *ptr, size_t size);
132
133 /*%
134  * Entropy retriever using the DST entropy pool.
135  */
136 isc_result_t dst__entropy_getdata(void *buf, unsigned int len,
137                                   isc_boolean_t pseudo);
138
139 ISC_LANG_ENDDECLS
140
141 #endif /* DST_DST_INTERNAL_H */
142 /*! \file */