2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2000-2002 Internet Software Consortium.
5 * Permission to use, copy, modify, and 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 DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: dst.h,v 1.1.4.1 2004/12/09 04:07:19 marka Exp $ */
25 #include <dns/types.h>
34 * The dst_key structure is opaque. Applications should use the accessor
35 * functions provided to retrieve key attributes. If an application needs
36 * to set attributes, new accessor functions will be written.
39 typedef struct dst_key dst_key_t;
40 typedef struct dst_context dst_context_t;
42 /* DST algorithm codes */
43 #define DST_ALG_UNKNOWN 0
44 #define DST_ALG_RSAMD5 1
45 #define DST_ALG_RSA DST_ALG_RSAMD5 /* backwards compatibility */
49 #define DST_ALG_RSASHA1 5
50 #define DST_ALG_HMACMD5 157
51 #define DST_ALG_GSSAPI 160
52 #define DST_ALG_PRIVATE 254
53 #define DST_ALG_EXPAND 255
54 #define DST_MAX_ALGS 255
56 /* A buffer of this size is large enough to hold any key */
57 #define DST_KEY_MAXSIZE 1280
60 * A buffer of this size is large enough to hold the textual representation
63 #define DST_KEY_MAXTEXTSIZE 2048
65 /* 'Type' for dst_read_key() */
66 #define DST_TYPE_KEY 0x1000000 /* KEY key */
67 #define DST_TYPE_PRIVATE 0x2000000
68 #define DST_TYPE_PUBLIC 0x4000000
75 dst_lib_init(isc_mem_t *mctx, isc_entropy_t *ectx, unsigned int eflags);
77 * Initializes the DST subsystem.
80 * "mctx" is a valid memory context
81 * "ectx" is a valid entropy context
88 * DST is properly initialized.
92 dst_lib_destroy(void);
94 * Releases all resources allocated by DST.
98 dst_algorithm_supported(unsigned int alg);
100 * Checks that a given algorithm is supported by DST.
108 dst_context_create(dst_key_t *key, isc_mem_t *mctx, dst_context_t **dctxp);
110 * Creates a context to be used for a sign or verify operation.
113 * "key" is a valid key.
114 * "mctx" is a valid memory context.
115 * dctxp != NULL && *dctxp == NULL
122 * *dctxp will contain a usable context.
126 dst_context_destroy(dst_context_t **dctxp);
128 * Destroys all memory associated with a context.
131 * *dctxp != NULL && *dctxp == NULL
138 dst_context_adddata(dst_context_t *dctx, const isc_region_t *data);
140 * Incrementally adds data to the context to be used in a sign or verify
144 * "dctx" is a valid context
145 * "data" is a valid region
150 * all other errors indicate failure
154 dst_context_sign(dst_context_t *dctx, isc_buffer_t *sig);
156 * Computes a signature using the data and key stored in the context.
159 * "dctx" is a valid context.
160 * "sig" is a valid buffer.
164 * DST_R_VERIFYFAILURE
165 * all other errors indicate failure
168 * "sig" will contain the signature
172 dst_context_verify(dst_context_t *dctx, isc_region_t *sig);
174 * Verifies the signature using the data and key stored in the context.
177 * "dctx" is a valid context.
178 * "sig" is a valid region.
182 * all other errors indicate failure
185 * "sig" will contain the signature
189 dst_key_computesecret(const dst_key_t *pub, const dst_key_t *priv,
190 isc_buffer_t *secret);
192 * Computes a shared secret from two (Diffie-Hellman) keys.
195 * "pub" is a valid key that can be used to derive a shared secret
196 * "priv" is a valid private key that can be used to derive a shared secret
197 * "secret" is a valid buffer
201 * any other result indicates failure
204 * If successful, secret will contain the derived shared secret.
208 dst_key_fromfile(dns_name_t *name, dns_keytag_t id, unsigned int alg, int type,
209 const char *directory, isc_mem_t *mctx, dst_key_t **keyp);
211 * Reads a key from permanent storage. The key can either be a public or
212 * private key, and is specified by name, algorithm, and id. If a private key
213 * is specified, the public key must also be present. If directory is NULL,
214 * the current directory is assumed.
217 * "name" is a valid absolute dns name.
218 * "id" is a valid key tag identifier.
219 * "alg" is a supported key algorithm.
220 * "type" is DST_TYPE_PUBLIC, DST_TYPE_PRIVATE, or the bitwise union.
221 * DST_TYPE_KEY look for a KEY record otherwise DNSKEY
222 * "mctx" is a valid memory context.
223 * "keyp" is not NULL and "*keyp" is NULL.
227 * any other result indicates failure
230 * If successful, *keyp will contain a valid key.
234 dst_key_fromnamedfile(const char *filename, int type, isc_mem_t *mctx,
237 * Reads a key from permanent storage. The key can either be a public or
238 * key, and is specified by filename. If a private key is specified, the
239 * public key must also be present.
242 * "filename" is not NULL
243 * "type" is DST_TYPE_PUBLIC, DST_TYPE_PRIVATE, or the bitwise union
244 * DST_TYPE_KEY look for a KEY record otherwise DNSKEY
245 * "mctx" is a valid memory context
246 * "keyp" is not NULL and "*keyp" is NULL.
250 * any other result indicates failure
253 * If successful, *keyp will contain a valid key.
257 dst_key_tofile(const dst_key_t *key, int type, const char *directory);
259 * Writes a key to permanent storage. The key can either be a public or
260 * private key. Public keys are written in DNS format and private keys
261 * are written as a set of base64 encoded values. If directory is NULL,
262 * the current directory is assumed.
265 * "key" is a valid key.
266 * "type" is DST_TYPE_PUBLIC, DST_TYPE_PRIVATE, or the bitwise union
270 * any other result indicates failure
274 dst_key_fromdns(dns_name_t *name, dns_rdataclass_t rdclass,
275 isc_buffer_t *source, isc_mem_t *mctx, dst_key_t **keyp);
277 * Converts a DNS KEY record into a DST key.
280 * "name" is a valid absolute dns name.
281 * "source" is a valid buffer. There must be at least 4 bytes available.
282 * "mctx" is a valid memory context.
283 * "keyp" is not NULL and "*keyp" is NULL.
287 * any other result indicates failure
290 * If successful, *keyp will contain a valid key, and the consumed
291 * pointer in data will be advanced.
295 dst_key_todns(const dst_key_t *key, isc_buffer_t *target);
297 * Converts a DST key into a DNS KEY record.
300 * "key" is a valid key.
301 * "target" is a valid buffer. There must be at least 4 bytes unused.
305 * any other result indicates failure
308 * If successful, the used pointer in 'target' is advanced by at least 4.
312 dst_key_frombuffer(dns_name_t *name, unsigned int alg,
313 unsigned int flags, unsigned int protocol,
314 dns_rdataclass_t rdclass,
315 isc_buffer_t *source, isc_mem_t *mctx, dst_key_t **keyp);
317 * Converts a buffer containing DNS KEY RDATA into a DST key.
320 * "name" is a valid absolute dns name.
321 * "alg" is a supported key algorithm.
322 * "source" is a valid buffer.
323 * "mctx" is a valid memory context.
324 * "keyp" is not NULL and "*keyp" is NULL.
328 * any other result indicates failure
331 * If successful, *keyp will contain a valid key, and the consumed
332 * pointer in source will be advanced.
336 dst_key_tobuffer(const dst_key_t *key, isc_buffer_t *target);
338 * Converts a DST key into DNS KEY RDATA format.
341 * "key" is a valid key.
342 * "target" is a valid buffer.
346 * any other result indicates failure
349 * If successful, the used pointer in 'target' is advanced.
353 dst_key_privatefrombuffer(dst_key_t *key, isc_buffer_t *buffer);
355 * Converts a public key into a private key, reading the private key
356 * information from the buffer. The buffer should contain the same data
357 * as the .private key file would.
360 * "key" is a valid public key.
361 * "buffer" is not NULL.
365 * any other result indicates failure
368 * If successful, key will contain a valid private key.
373 dst_key_fromgssapi(dns_name_t *name, void *opaque, isc_mem_t *mctx,
376 * Converts a GSSAPI opaque context id into a DST key.
379 * "name" is a valid absolute dns name.
380 * "opaque" is a GSSAPI context id.
381 * "mctx" is a valid memory context.
382 * "keyp" is not NULL and "*keyp" is NULL.
386 * any other result indicates failure
389 * If successful, *keyp will contain a valid key and be responsible for
394 dst_key_generate(dns_name_t *name, unsigned int alg,
395 unsigned int bits, unsigned int param,
396 unsigned int flags, unsigned int protocol,
397 dns_rdataclass_t rdclass,
398 isc_mem_t *mctx, dst_key_t **keyp);
400 * Generate a DST key (or keypair) with the supplied parameters. The
401 * interpretation of the "param" field depends on the algorithm:
404 * !0 use Fermat4 (2^16 + 1)
406 * 0 default - use well known prime if bits == 768 or 1024,
407 * otherwise use 2 as the generator.
408 * !0 use this value as the generator.
411 * 0 default - require good entropy
412 * !0 lack of good entropy is ok
415 * "name" is a valid absolute dns name.
416 * "keyp" is not NULL and "*keyp" is NULL.
420 * any other result indicates failure
423 * If successful, *keyp will contain a valid key.
427 dst_key_compare(const dst_key_t *key1, const dst_key_t *key2);
429 * Compares two DST keys.
432 * "key1" is a valid key.
433 * "key2" is a valid key.
441 dst_key_paramcompare(const dst_key_t *key1, const dst_key_t *key2);
443 * Compares the parameters of two DST keys. This is used to determine if
444 * two (Diffie-Hellman) keys can be used to derive a shared secret.
447 * "key1" is a valid key.
448 * "key2" is a valid key.
456 dst_key_free(dst_key_t **keyp);
458 * Release all memory associated with the key.
461 * "keyp" is not NULL and "*keyp" is a valid key.
464 * All memory associated with "*keyp" will be freed.
469 * Accessor functions to obtain key fields.
472 * "key" is a valid key.
475 dst_key_name(const dst_key_t *key);
478 dst_key_size(const dst_key_t *key);
481 dst_key_proto(const dst_key_t *key);
484 dst_key_alg(const dst_key_t *key);
487 dst_key_flags(const dst_key_t *key);
490 dst_key_id(const dst_key_t *key);
493 dst_key_class(const dst_key_t *key);
496 dst_key_isprivate(const dst_key_t *key);
499 dst_key_iszonekey(const dst_key_t *key);
502 dst_key_isnullkey(const dst_key_t *key);
505 dst_key_buildfilename(const dst_key_t *key, int type,
506 const char *directory, isc_buffer_t *out);
508 * Generates the filename used by dst to store the specified key.
509 * If directory is NULL, the current directory is assumed.
512 * "key" is a valid key
513 * "type" is either DST_TYPE_PUBLIC, DST_TYPE_PRIVATE, or 0 for no suffix.
514 * "out" is a valid buffer
517 * the file name will be written to "out", and the used pointer will
522 dst_key_sigsize(const dst_key_t *key, unsigned int *n);
524 * Computes the size of a signature generated by the given key.
527 * "key" is a valid key.
532 * DST_R_UNSUPPORTEDALG
535 * "n" stores the size of a generated signature
539 dst_key_secretsize(const dst_key_t *key, unsigned int *n);
541 * Computes the size of a shared secret generated by the given key.
544 * "key" is a valid key.
549 * DST_R_UNSUPPORTEDALG
552 * "n" stores the size of a generated shared secret
556 dst_region_computeid(const isc_region_t *source, unsigned int alg);
558 * Computes the key id of the key stored in the provided region with the
562 * "source" contains a valid, non-NULL region.
570 #endif /* DST_DST_H */