Merge from vendor branch GCC:
[dragonfly.git] / contrib / bind-9.3 / lib / dns / dst_internal.h
1 /*
2  * Portions Copyright (C) 2004  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.4.1 2004/12/09 04:07:16 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 struct dst_key {
50         unsigned int    magic;
51         dns_name_t *    key_name;       /* name of the key */
52         unsigned int    key_size;       /* size of the key in bits */
53         unsigned int    key_proto;      /* protocols this key is used for */
54         unsigned int    key_alg;        /* algorithm of the key */
55         isc_uint32_t    key_flags;      /* flags of the public key */
56         isc_uint16_t    key_id;         /* identifier of the key */
57         dns_rdataclass_t key_class;     /* class of the key record */
58         isc_mem_t       *mctx;          /* memory context */
59         void *          opaque;         /* pointer to key in crypto pkg fmt */
60         dst_func_t *    func;           /* crypto package specific functions */
61 };
62
63 struct dst_context {
64         unsigned int magic;
65         dst_key_t *key;
66         isc_mem_t *mctx;
67         void *opaque;
68 };
69
70 struct dst_func {
71         /*
72          * Context functions
73          */
74         isc_result_t (*createctx)(dst_key_t *key, dst_context_t *dctx);
75         void (*destroyctx)(dst_context_t *dctx);
76         isc_result_t (*adddata)(dst_context_t *dctx, const isc_region_t *data);
77
78         /*
79          * Key operations
80          */
81         isc_result_t (*sign)(dst_context_t *dctx, isc_buffer_t *sig);
82         isc_result_t (*verify)(dst_context_t *dctx, const isc_region_t *sig);
83         isc_result_t (*computesecret)(const dst_key_t *pub,
84                                       const dst_key_t *priv,
85                                       isc_buffer_t *secret);
86         isc_boolean_t (*compare)(const dst_key_t *key1, const dst_key_t *key2);
87         isc_boolean_t (*paramcompare)(const dst_key_t *key1,
88                                       const dst_key_t *key2);
89         isc_result_t (*generate)(dst_key_t *key, int parms);
90         isc_boolean_t (*isprivate)(const dst_key_t *key);
91         void (*destroy)(dst_key_t *key);
92
93         /* conversion functions */
94         isc_result_t (*todns)(const dst_key_t *key, isc_buffer_t *data);
95         isc_result_t (*fromdns)(dst_key_t *key, isc_buffer_t *data);
96         isc_result_t (*tofile)(const dst_key_t *key, const char *directory);
97         isc_result_t (*parse)(dst_key_t *key, isc_lex_t *lexer);
98
99         /* cleanup */
100         void (*cleanup)(void);
101 };
102
103 /*
104  * Initializers
105  */
106 isc_result_t dst__openssl_init(void);
107
108 isc_result_t dst__hmacmd5_init(struct dst_func **funcp);
109 isc_result_t dst__opensslrsa_init(struct dst_func **funcp);
110 isc_result_t dst__openssldsa_init(struct dst_func **funcp);
111 isc_result_t dst__openssldh_init(struct dst_func **funcp);
112 isc_result_t dst__gssapi_init(struct dst_func **funcp);
113
114 /*
115  * Destructors
116  */
117 void dst__openssl_destroy(void);
118
119 /*
120  * Memory allocators using the DST memory pool.
121  */
122 void * dst__mem_alloc(size_t size);
123 void   dst__mem_free(void *ptr);
124 void * dst__mem_realloc(void *ptr, size_t size);
125
126 /*
127  * Entropy retriever using the DST entropy pool.
128  */
129 isc_result_t dst__entropy_getdata(void *buf, unsigned int len,
130                                   isc_boolean_t pseudo);
131
132 ISC_LANG_ENDDECLS
133
134 #endif /* DST_DST_INTERNAL_H */