Merge from vendor branch LESS:
[dragonfly.git] / contrib / bind-9.3 / lib / bind / include / isc / dst.h
1 #ifndef DST_H
2 #define DST_H
3
4 #ifndef HAS_DST_KEY
5 typedef struct dst_key {
6         char    *dk_key_name;   /* name of the key */
7         int     dk_key_size;    /* this is the size of the key in bits */
8         int     dk_proto;       /* what protocols this key can be used for */
9         int     dk_alg;         /* algorithm number from key record */
10         u_int32_t dk_flags;     /* and the flags of the public key */
11         u_int16_t dk_id;        /* identifier of the key */
12 } DST_KEY;
13 #endif /* HAS_DST_KEY */
14
15 /*
16  * do not taint namespace
17  */
18 #define dst_bsafe_init          __dst_bsafe_init
19 #define dst_buffer_to_key       __dst_buffer_to_key
20 #define dst_check_algorithm     __dst_check_algorithm
21 #define dst_compare_keys        __dst_compare_keys
22 #define dst_cylink_init         __dst_cylink_init
23 #define dst_dnskey_to_key       __dst_dnskey_to_key
24 #define dst_eay_dss_init        __dst_eay_dss_init
25 #define dst_free_key            __dst_free_key
26 #define dst_generate_key        __dst_generate_key
27 #define dst_hmac_md5_init       __dst_hmac_md5_init
28 #define dst_init                __dst_init
29 #define dst_key_to_buffer       __dst_key_to_buffer
30 #define dst_key_to_dnskey       __dst_key_to_dnskey
31 #define dst_read_key            __dst_read_key
32 #define dst_rsaref_init         __dst_rsaref_init
33 #define dst_s_build_filename    __dst_s_build_filename
34 #define dst_s_calculate_bits    __dst_s_calculate_bits
35 #define dst_s_conv_bignum_b64_to_u8     __dst_s_conv_bignum_b64_to_u8
36 #define dst_s_conv_bignum_u8_to_b64     __dst_s_conv_bignum_u8_to_b64
37 #define dst_s_dns_key_id        __dst_s_dns_key_id
38 #define dst_s_dump              __dst_s_dump
39 #define dst_s_filename_length   __dst_s_filename_length
40 #define dst_s_fopen             __dst_s_fopen
41 #define dst_s_get_int16         __dst_s_get_int16
42 #define dst_s_get_int32         __dst_s_get_int32
43 #define dst_s_id_calc           __dst_s_id_calc
44 #define dst_s_put_int16         __dst_s_put_int16
45 #define dst_s_put_int32         __dst_s_put_int32
46 #define dst_s_quick_random      __dst_s_quick_random
47 #define dst_s_quick_random_set  __dst_s_quick_random_set
48 #define dst_s_random            __dst_s_random
49 #define dst_s_semi_random       __dst_s_semi_random
50 #define dst_s_verify_str        __dst_s_verify_str
51 #define dst_sig_size            __dst_sig_size
52 #define dst_sign_data           __dst_sign_data
53 #define dst_verify_data         __dst_verify_data
54 #define dst_write_key           __dst_write_key
55
56 /* 
57  * DST Crypto API defintions 
58  */
59 void     dst_init(void);
60 int      dst_check_algorithm(const int);
61
62 int dst_sign_data(const int,            /* specifies INIT/UPDATE/FINAL/ALL */
63                   DST_KEY *,            /* the key to use */
64                   void **,              /* pointer to state structure */
65                   const u_char *,       /* data to be signed */
66                   const int,            /* length of input data */
67                   u_char *,             /* buffer to write signature to */
68                   const int);           /* size of output buffer */
69
70 int dst_verify_data(const int,          /* specifies INIT/UPDATE/FINAL/ALL */
71                     DST_KEY *,          /* the key to use */
72                     void **,            /* pointer to state structure */
73                     const u_char *,     /* data to be verified */
74                     const int,          /* length of input data */
75                     const u_char *,     /* buffer containing signature */
76                     const int);         /* length of signature */
77
78
79 DST_KEY *dst_read_key(const char *,     /* name of key */
80                       const u_int16_t,  /* key tag identifier */
81                       const int,        /* key algorithm */
82                       const int);       /* Private/PublicKey wanted*/
83
84 int      dst_write_key(const DST_KEY *, /* key to write out */
85                        const int);      /* Public/Private */
86
87 DST_KEY *dst_dnskey_to_key(const char *,        /* KEY record name */
88                            const u_char *,      /* KEY RDATA */
89                            const int);          /* size of input buffer*/
90
91
92 int      dst_key_to_dnskey(const DST_KEY *,     /* key to translate */
93                            u_char *,            /* output buffer */
94                            const int);          /* size of out_storage*/
95
96
97 DST_KEY *dst_buffer_to_key(const char *,        /* name of the key */
98                            const int,           /* algorithm */
99                            const int,           /* dns flags */
100                            const int,           /* dns protocol */
101                            const u_char *,      /* key in dns wire fmt */
102                            const int);          /* size of key */
103
104
105 int     dst_key_to_buffer(DST_KEY *, u_char *, int);
106
107 DST_KEY *dst_generate_key(const char *,         /* name of new key */
108                           const int,            /* key algorithm to generate */
109                           const int,            /* size of new key */
110                           const int,            /* alg dependent parameter*/
111                           const int,            /* key DNS flags */
112                           const int);           /* key DNS protocol */
113
114 DST_KEY *dst_free_key(DST_KEY *);
115 int      dst_compare_keys(const DST_KEY *, const DST_KEY *);
116
117 int     dst_sig_size(DST_KEY *);
118
119
120 /* support for dns key tags/ids */
121 u_int16_t dst_s_dns_key_id(const u_char *, const int);
122 u_int16_t dst_s_id_calc(const u_char *, const int);
123
124 /* Used by callers as well as by the library.  */
125 #define RAW_KEY_SIZE    8192        /* large enough to store any key */
126
127 /* DST_API control flags */
128 /* These are used used in functions dst_sign_data and dst_verify_data */
129 #define SIG_MODE_INIT           1  /* initialize digest */
130 #define SIG_MODE_UPDATE         2  /* add data to digest */
131 #define SIG_MODE_FINAL          4  /* generate/verify signature */
132 #define SIG_MODE_ALL            (SIG_MODE_INIT|SIG_MODE_UPDATE|SIG_MODE_FINAL)
133
134 /* Flags for dst_read_private_key()  */
135 #define DST_FORCE_READ          0x1000000
136 #define DST_CAN_SIGN            0x010F
137 #define DST_NO_AUTHEN           0x8000
138 #define DST_EXTEND_FLAG         0x1000
139 #define DST_STANDARD            0
140 #define DST_PRIVATE             0x2000000
141 #define DST_PUBLIC              0x4000000
142 #define DST_RAND_SEMI           1
143 #define DST_RAND_STD            2
144 #define DST_RAND_KEY            3
145 #define DST_RAND_DSS            4
146
147
148 /* DST algorithm codes */
149 #define KEY_RSA                 1
150 #define KEY_DH                  2
151 #define KEY_DSA                 3
152 #define KEY_PRIVATE             254
153 #define KEY_EXPAND              255
154 #define KEY_HMAC_MD5            157
155 #define KEY_HMAC_SHA1           158
156 #define UNKNOWN_KEYALG          0
157 #define DST_MAX_ALGS            KEY_HMAC_SHA1
158
159 /* DST constants to locations in KEY record  changes in new KEY record */
160 #define DST_FLAGS_SIZE          2
161 #define DST_KEY_PROT            2
162 #define DST_KEY_ALG             3
163 #define DST_EXT_FLAG            4
164 #define DST_KEY_START           4
165
166 #ifndef SIGN_F_NOKEY 
167 #define SIGN_F_NOKEY            0xC000
168 #endif
169
170 /* error codes from dst routines */
171 #define SIGN_INIT_FAILURE       (-23)
172 #define SIGN_UPDATE_FAILURE     (-24)
173 #define SIGN_FINAL_FAILURE      (-25)
174 #define VERIFY_INIT_FAILURE     (-26)
175 #define VERIFY_UPDATE_FAILURE   (-27)
176 #define VERIFY_FINAL_FAILURE    (-28)
177 #define MISSING_KEY_OR_SIGNATURE (-30)
178 #define UNSUPPORTED_KEYALG      (-31)
179
180 #endif /* DST_H */