cvs updates from Wed Dec 15 17:45:22 EST 2010
[tridge/bind9.git] / lib / dns / include / dst / dst.h
1 /*
2  * Copyright (C) 2004-2010  Internet Systems Consortium, Inc. ("ISC")
3  * 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 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.
16  */
17
18 /* $Id: dst.h,v 1.27 2010/12/09 04:31:57 tbox Exp $ */
19
20 #ifndef DST_DST_H
21 #define DST_DST_H 1
22
23 /*! \file dst/dst.h */
24
25 #include <isc/lang.h>
26 #include <isc/stdtime.h>
27
28 #include <dns/types.h>
29 #include <dns/name.h>
30 #include <dns/secalg.h>
31
32 #include <dst/gssapi.h>
33
34 ISC_LANG_BEGINDECLS
35
36 /***
37  *** Types
38  ***/
39
40 /*%
41  * The dst_key structure is opaque.  Applications should use the accessor
42  * functions provided to retrieve key attributes.  If an application needs
43  * to set attributes, new accessor functions will be written.
44  */
45
46 typedef struct dst_key          dst_key_t;
47 typedef struct dst_context      dst_context_t;
48
49 /* DST algorithm codes */
50 #define DST_ALG_UNKNOWN         0
51 #define DST_ALG_RSAMD5          1
52 #define DST_ALG_RSA             DST_ALG_RSAMD5  /*%< backwards compatibility */
53 #define DST_ALG_DH              2
54 #define DST_ALG_DSA             3
55 #define DST_ALG_ECC             4
56 #define DST_ALG_RSASHA1         5
57 #define DST_ALG_NSEC3DSA        6
58 #define DST_ALG_NSEC3RSASHA1    7
59 #define DST_ALG_RSASHA256       8
60 #define DST_ALG_RSASHA512       10
61 #define DST_ALG_HMACMD5         157
62 #define DST_ALG_GSSAPI          160
63 #define DST_ALG_HMACSHA1        161     /* XXXMPA */
64 #define DST_ALG_HMACSHA224      162     /* XXXMPA */
65 #define DST_ALG_HMACSHA256      163     /* XXXMPA */
66 #define DST_ALG_HMACSHA384      164     /* XXXMPA */
67 #define DST_ALG_HMACSHA512      165     /* XXXMPA */
68 #define DST_ALG_PRIVATE         254
69 #define DST_ALG_EXPAND          255
70 #define DST_MAX_ALGS            255
71
72 /*% A buffer of this size is large enough to hold any key */
73 #define DST_KEY_MAXSIZE         1280
74
75 /*%
76  * A buffer of this size is large enough to hold the textual representation
77  * of any key
78  */
79 #define DST_KEY_MAXTEXTSIZE     2048
80
81 /*% 'Type' for dst_read_key() */
82 #define DST_TYPE_KEY            0x1000000       /* KEY key */
83 #define DST_TYPE_PRIVATE        0x2000000
84 #define DST_TYPE_PUBLIC         0x4000000
85
86 /* Key timing metadata definitions */
87 #define DST_TIME_CREATED        0
88 #define DST_TIME_PUBLISH        1
89 #define DST_TIME_ACTIVATE       2
90 #define DST_TIME_REVOKE         3
91 #define DST_TIME_INACTIVE       4
92 #define DST_TIME_DELETE         5
93 #define DST_TIME_DSPUBLISH      6
94 #define DST_MAX_TIMES           6
95
96 /* Numeric metadata definitions */
97 #define DST_NUM_PREDECESSOR     0
98 #define DST_NUM_SUCCESSOR       1
99 #define DST_NUM_MAXTTL          2
100 #define DST_NUM_ROLLPERIOD      3
101 #define DST_MAX_NUMERIC         3
102
103 /*
104  * Current format version number of the private key parser.
105  *
106  * When parsing a key file with the same major number but a higher minor
107  * number, the key parser will ignore any fields it does not recognize.
108  * Thus, DST_MINOR_VERSION should be incremented whenever new
109  * fields are added to the private key file (such as new metadata).
110  *
111  * When rewriting these keys, those fields will be dropped, and the
112  * format version set back to the current one..
113  *
114  * When a key is seen with a higher major number, the key parser will
115  * reject it as invalid.  Thus, DST_MAJOR_VERSION should be incremented
116  * and DST_MINOR_VERSION set to zero whenever there is a format change
117  * which is not backward compatible to previous versions of the dst_key
118  * parser, such as change in the syntax of an existing field, the removal
119  * of a currently mandatory field, or a new field added which would
120  * alter the functioning of the key if it were absent.
121  */
122 #define DST_MAJOR_VERSION       1
123 #define DST_MINOR_VERSION       3
124
125 /***
126  *** Functions
127  ***/
128
129 isc_result_t
130 dst_lib_init(isc_mem_t *mctx, isc_entropy_t *ectx, unsigned int eflags);
131
132 isc_result_t
133 dst_lib_init2(isc_mem_t *mctx, isc_entropy_t *ectx,
134               const char *engine, unsigned int eflags);
135 /*%<
136  * Initializes the DST subsystem.
137  *
138  * Requires:
139  * \li  "mctx" is a valid memory context
140  * \li  "ectx" is a valid entropy context
141  *
142  * Returns:
143  * \li  ISC_R_SUCCESS
144  * \li  ISC_R_NOMEMORY
145  * \li  DST_R_NOENGINE
146  *
147  * Ensures:
148  * \li  DST is properly initialized.
149  */
150
151 void
152 dst_lib_destroy(void);
153 /*%<
154  * Releases all resources allocated by DST.
155  */
156
157 isc_boolean_t
158 dst_algorithm_supported(unsigned int alg);
159 /*%<
160  * Checks that a given algorithm is supported by DST.
161  *
162  * Returns:
163  * \li  ISC_TRUE
164  * \li  ISC_FALSE
165  */
166
167 isc_result_t
168 dst_context_create(dst_key_t *key, isc_mem_t *mctx, dst_context_t **dctxp);
169 /*%<
170  * Creates a context to be used for a sign or verify operation.
171  *
172  * Requires:
173  * \li  "key" is a valid key.
174  * \li  "mctx" is a valid memory context.
175  * \li  dctxp != NULL && *dctxp == NULL
176  *
177  * Returns:
178  * \li  ISC_R_SUCCESS
179  * \li  ISC_R_NOMEMORY
180  *
181  * Ensures:
182  * \li  *dctxp will contain a usable context.
183  */
184
185 void
186 dst_context_destroy(dst_context_t **dctxp);
187 /*%<
188  * Destroys all memory associated with a context.
189  *
190  * Requires:
191  * \li  *dctxp != NULL && *dctxp == NULL
192  *
193  * Ensures:
194  * \li  *dctxp == NULL
195  */
196
197 isc_result_t
198 dst_context_adddata(dst_context_t *dctx, const isc_region_t *data);
199 /*%<
200  * Incrementally adds data to the context to be used in a sign or verify
201  * operation.
202  *
203  * Requires:
204  * \li  "dctx" is a valid context
205  * \li  "data" is a valid region
206  *
207  * Returns:
208  * \li  ISC_R_SUCCESS
209  * \li  DST_R_SIGNFAILURE
210  * \li  all other errors indicate failure
211  */
212
213 isc_result_t
214 dst_context_sign(dst_context_t *dctx, isc_buffer_t *sig);
215 /*%<
216  * Computes a signature using the data and key stored in the context.
217  *
218  * Requires:
219  * \li  "dctx" is a valid context.
220  * \li  "sig" is a valid buffer.
221  *
222  * Returns:
223  * \li  ISC_R_SUCCESS
224  * \li  DST_R_VERIFYFAILURE
225  * \li  all other errors indicate failure
226  *
227  * Ensures:
228  * \li  "sig" will contain the signature
229  */
230
231 isc_result_t
232 dst_context_verify(dst_context_t *dctx, isc_region_t *sig);
233 /*%<
234  * Verifies the signature using the data and key stored in the context.
235  *
236  * Requires:
237  * \li  "dctx" is a valid context.
238  * \li  "sig" is a valid region.
239  *
240  * Returns:
241  * \li  ISC_R_SUCCESS
242  * \li  all other errors indicate failure
243  *
244  * Ensures:
245  * \li  "sig" will contain the signature
246  */
247
248 isc_result_t
249 dst_key_computesecret(const dst_key_t *pub, const dst_key_t *priv,
250                       isc_buffer_t *secret);
251 /*%<
252  * Computes a shared secret from two (Diffie-Hellman) keys.
253  *
254  * Requires:
255  * \li  "pub" is a valid key that can be used to derive a shared secret
256  * \li  "priv" is a valid private key that can be used to derive a shared secret
257  * \li  "secret" is a valid buffer
258  *
259  * Returns:
260  * \li  ISC_R_SUCCESS
261  * \li  any other result indicates failure
262  *
263  * Ensures:
264  * \li  If successful, secret will contain the derived shared secret.
265  */
266
267 isc_result_t
268 dst_key_fromfile(dns_name_t *name, dns_keytag_t id, unsigned int alg, int type,
269                  const char *directory, isc_mem_t *mctx, dst_key_t **keyp);
270 /*%<
271  * Reads a key from permanent storage.  The key can either be a public or
272  * private key, and is specified by name, algorithm, and id.  If a private key
273  * is specified, the public key must also be present.  If directory is NULL,
274  * the current directory is assumed.
275  *
276  * Requires:
277  * \li  "name" is a valid absolute dns name.
278  * \li  "id" is a valid key tag identifier.
279  * \li  "alg" is a supported key algorithm.
280  * \li  "type" is DST_TYPE_PUBLIC, DST_TYPE_PRIVATE, or the bitwise union.
281  *                DST_TYPE_KEY look for a KEY record otherwise DNSKEY
282  * \li  "mctx" is a valid memory context.
283  * \li  "keyp" is not NULL and "*keyp" is NULL.
284  *
285  * Returns:
286  * \li  ISC_R_SUCCESS
287  * \li  any other result indicates failure
288  *
289  * Ensures:
290  * \li  If successful, *keyp will contain a valid key.
291  */
292
293 isc_result_t
294 dst_key_fromnamedfile(const char *filename, const char *dirname,
295                       int type, isc_mem_t *mctx, dst_key_t **keyp);
296 /*%<
297  * Reads a key from permanent storage.  The key can either be a public or
298  * key, and is specified by filename.  If a private key is specified, the
299  * public key must also be present.
300  *
301  * If 'dirname' is not NULL, and 'filename' is a relative path,
302  * then the file is looked up relative to the given directory.
303  * If 'filename' is an absolute path, 'dirname' is ignored.
304  *
305  * Requires:
306  * \li  "filename" is not NULL
307  * \li  "type" is DST_TYPE_PUBLIC, DST_TYPE_PRIVATE, or the bitwise union
308  *                DST_TYPE_KEY look for a KEY record otherwise DNSKEY
309  * \li  "mctx" is a valid memory context
310  * \li  "keyp" is not NULL and "*keyp" is NULL.
311  *
312  * Returns:
313  * \li  ISC_R_SUCCESS
314  * \li  any other result indicates failure
315  *
316  * Ensures:
317  * \li  If successful, *keyp will contain a valid key.
318  */
319
320
321 isc_result_t
322 dst_key_read_public(const char *filename, int type,
323                     isc_mem_t *mctx, dst_key_t **keyp);
324 /*%<
325  * Reads a public key from permanent storage.  The key must be a public key.
326  *
327  * Requires:
328  * \li  "filename" is not NULL
329  * \li  "type" is DST_TYPE_KEY look for a KEY record otherwise DNSKEY
330  * \li  "mctx" is a valid memory context
331  * \li  "keyp" is not NULL and "*keyp" is NULL.
332  *
333  * Returns:
334  * \li  ISC_R_SUCCESS
335  * \li  DST_R_BADKEYTYPE if the key type is not the expected one
336  * \li  ISC_R_UNEXPECTEDTOKEN if the file can not be parsed as a public key
337  * \li  any other result indicates failure
338  *
339  * Ensures:
340  * \li  If successful, *keyp will contain a valid key.
341  */
342
343 isc_result_t
344 dst_key_tofile(const dst_key_t *key, int type, const char *directory);
345 /*%<
346  * Writes a key to permanent storage.  The key can either be a public or
347  * private key.  Public keys are written in DNS format and private keys
348  * are written as a set of base64 encoded values.  If directory is NULL,
349  * the current directory is assumed.
350  *
351  * Requires:
352  * \li  "key" is a valid key.
353  * \li  "type" is DST_TYPE_PUBLIC, DST_TYPE_PRIVATE, or the bitwise union
354  *
355  * Returns:
356  * \li  ISC_R_SUCCESS
357  * \li  any other result indicates failure
358  */
359
360 isc_result_t
361 dst_key_fromdns(dns_name_t *name, dns_rdataclass_t rdclass,
362                 isc_buffer_t *source, isc_mem_t *mctx, dst_key_t **keyp);
363 /*%<
364  * Converts a DNS KEY record into a DST key.
365  *
366  * Requires:
367  * \li  "name" is a valid absolute dns name.
368  * \li  "source" is a valid buffer.  There must be at least 4 bytes available.
369  * \li  "mctx" is a valid memory context.
370  * \li  "keyp" is not NULL and "*keyp" is NULL.
371  *
372  * Returns:
373  * \li  ISC_R_SUCCESS
374  * \li  any other result indicates failure
375  *
376  * Ensures:
377  * \li  If successful, *keyp will contain a valid key, and the consumed
378  *      pointer in data will be advanced.
379  */
380
381 isc_result_t
382 dst_key_todns(const dst_key_t *key, isc_buffer_t *target);
383 /*%<
384  * Converts a DST key into a DNS KEY record.
385  *
386  * Requires:
387  * \li  "key" is a valid key.
388  * \li  "target" is a valid buffer.  There must be at least 4 bytes unused.
389  *
390  * Returns:
391  * \li  ISC_R_SUCCESS
392  * \li  any other result indicates failure
393  *
394  * Ensures:
395  * \li  If successful, the used pointer in 'target' is advanced by at least 4.
396  */
397
398 isc_result_t
399 dst_key_frombuffer(dns_name_t *name, unsigned int alg,
400                    unsigned int flags, unsigned int protocol,
401                    dns_rdataclass_t rdclass,
402                    isc_buffer_t *source, isc_mem_t *mctx, dst_key_t **keyp);
403 /*%<
404  * Converts a buffer containing DNS KEY RDATA into a DST key.
405  *
406  * Requires:
407  *\li   "name" is a valid absolute dns name.
408  *\li   "alg" is a supported key algorithm.
409  *\li   "source" is a valid buffer.
410  *\li   "mctx" is a valid memory context.
411  *\li   "keyp" is not NULL and "*keyp" is NULL.
412  *
413  * Returns:
414  *\li   ISC_R_SUCCESS
415  * \li  any other result indicates failure
416  *
417  * Ensures:
418  *\li   If successful, *keyp will contain a valid key, and the consumed
419  *      pointer in source will be advanced.
420  */
421
422 isc_result_t
423 dst_key_tobuffer(const dst_key_t *key, isc_buffer_t *target);
424 /*%<
425  * Converts a DST key into DNS KEY RDATA format.
426  *
427  * Requires:
428  *\li   "key" is a valid key.
429  *\li   "target" is a valid buffer.
430  *
431  * Returns:
432  *\li   ISC_R_SUCCESS
433  * \li  any other result indicates failure
434  *
435  * Ensures:
436  *\li   If successful, the used pointer in 'target' is advanced.
437  */
438
439 isc_result_t
440 dst_key_privatefrombuffer(dst_key_t *key, isc_buffer_t *buffer);
441 /*%<
442  * Converts a public key into a private key, reading the private key
443  * information from the buffer.  The buffer should contain the same data
444  * as the .private key file would.
445  *
446  * Requires:
447  *\li   "key" is a valid public key.
448  *\li   "buffer" is not NULL.
449  *
450  * Returns:
451  *\li   ISC_R_SUCCESS
452  * \li  any other result indicates failure
453  *
454  * Ensures:
455  *\li   If successful, key will contain a valid private key.
456  */
457
458 gss_ctx_id_t
459 dst_key_getgssctx(const dst_key_t *key);
460 /*%<
461  * Returns the opaque key data.
462  * Be cautions when using this value unless you know what you are doing.
463  *
464  * Requires:
465  *\li   "key" is not NULL.
466  *
467  * Returns:
468  *\li   gssctx key data, possibly NULL.
469  */
470
471 isc_result_t
472 dst_key_fromgssapi(dns_name_t *name, gss_ctx_id_t gssctx, isc_mem_t *mctx,
473                    dst_key_t **keyp);
474 /*%<
475  * Converts a GSSAPI opaque context id into a DST key.
476  *
477  * Requires:
478  *\li   "name" is a valid absolute dns name.
479  *\li   "gssctx" is a GSSAPI context id.
480  *\li   "mctx" is a valid memory context.
481  *\li   "keyp" is not NULL and "*keyp" is NULL.
482  *
483  * Returns:
484  *\li   ISC_R_SUCCESS
485  * \li  any other result indicates failure
486  *
487  * Ensures:
488  *\li   If successful, *keyp will contain a valid key and be responsible for
489  *      the context id.
490  */
491
492 isc_result_t
493 dst_key_fromlabel(dns_name_t *name, int alg, unsigned int flags,
494                   unsigned int protocol, dns_rdataclass_t rdclass,
495                   const char *engine, const char *label, const char *pin,
496                   isc_mem_t *mctx, dst_key_t **keyp);
497
498 isc_result_t
499 dst_key_generate(dns_name_t *name, unsigned int alg,
500                  unsigned int bits, unsigned int param,
501                  unsigned int flags, unsigned int protocol,
502                  dns_rdataclass_t rdclass,
503                  isc_mem_t *mctx, dst_key_t **keyp);
504
505 isc_result_t
506 dst_key_generate2(dns_name_t *name, unsigned int alg,
507                   unsigned int bits, unsigned int param,
508                   unsigned int flags, unsigned int protocol,
509                   dns_rdataclass_t rdclass,
510                   isc_mem_t *mctx, dst_key_t **keyp,
511                   void (*callback)(int));
512 /*%<
513  * Generate a DST key (or keypair) with the supplied parameters.  The
514  * interpretation of the "param" field depends on the algorithm:
515  * \code
516  *      RSA:    exponent
517  *              0       use exponent 3
518  *              !0      use Fermat4 (2^16 + 1)
519  *      DH:     generator
520  *              0       default - use well known prime if bits == 768 or 1024,
521  *                      otherwise use 2 as the generator.
522  *              !0      use this value as the generator.
523  *      DSA:    unused
524  *      HMACMD5: entropy
525  *              0       default - require good entropy
526  *              !0      lack of good entropy is ok
527  *\endcode
528  *
529  * Requires:
530  *\li   "name" is a valid absolute dns name.
531  *\li   "keyp" is not NULL and "*keyp" is NULL.
532  *
533  * Returns:
534  *\li   ISC_R_SUCCESS
535  * \li  any other result indicates failure
536  *
537  * Ensures:
538  *\li   If successful, *keyp will contain a valid key.
539  */
540
541 isc_boolean_t
542 dst_key_compare(const dst_key_t *key1, const dst_key_t *key2);
543 /*%<
544  * Compares two DST keys.  Returns true if they match, false otherwise.
545  *
546  * Keys ARE NOT considered to match if one of them is the revoked version
547  * of the other.
548  *
549  * Requires:
550  *\li   "key1" is a valid key.
551  *\li   "key2" is a valid key.
552  *
553  * Returns:
554  *\li   ISC_TRUE
555  * \li  ISC_FALSE
556  */
557
558 isc_boolean_t
559 dst_key_pubcompare(const dst_key_t *key1, const dst_key_t *key2,
560                    isc_boolean_t match_revoked_key);
561 /*%<
562  * Compares only the public portions of two DST keys.  Returns true
563  * if they match, false otherwise.  This allows us, for example, to
564  * determine whether a public key found in a zone matches up with a
565  * key pair found on disk.
566  *
567  * If match_revoked_key is TRUE, then keys ARE considered to match if one
568  * of them is the revoked version of the other. Otherwise, they are not.
569  *
570  * Requires:
571  *\li   "key1" is a valid key.
572  *\li   "key2" is a valid key.
573  *
574  * Returns:
575  *\li   ISC_TRUE
576  * \li  ISC_FALSE
577  */
578
579 isc_boolean_t
580 dst_key_paramcompare(const dst_key_t *key1, const dst_key_t *key2);
581 /*%<
582  * Compares the parameters of two DST keys.  This is used to determine if
583  * two (Diffie-Hellman) keys can be used to derive a shared secret.
584  *
585  * Requires:
586  *\li   "key1" is a valid key.
587  *\li   "key2" is a valid key.
588  *
589  * Returns:
590  *\li   ISC_TRUE
591  * \li  ISC_FALSE
592  */
593
594 void
595 dst_key_attach(dst_key_t *source, dst_key_t **target);
596 /*
597  * Attach to a existing key increasing the reference count.
598  *
599  * Requires:
600  *\li 'source' to be a valid key.
601  *\li 'target' to be non-NULL and '*target' to be NULL.
602  */
603
604 void
605 dst_key_free(dst_key_t **keyp);
606 /*%<
607  * Decrement the key's reference counter and, when it reaches zero,
608  * release all memory associated with the key.
609  *
610  * Requires:
611  *\li   "keyp" is not NULL and "*keyp" is a valid key.
612  *\li   reference counter greater than zero.
613  *
614  * Ensures:
615  *\li   All memory associated with "*keyp" will be freed.
616  *\li   *keyp == NULL
617  */
618
619 /*%<
620  * Accessor functions to obtain key fields.
621  *
622  * Require:
623  *\li   "key" is a valid key.
624  */
625 dns_name_t *
626 dst_key_name(const dst_key_t *key);
627
628 unsigned int
629 dst_key_size(const dst_key_t *key);
630
631 unsigned int
632 dst_key_proto(const dst_key_t *key);
633
634 unsigned int
635 dst_key_alg(const dst_key_t *key);
636
637 isc_uint32_t
638 dst_key_flags(const dst_key_t *key);
639
640 dns_keytag_t
641 dst_key_id(const dst_key_t *key);
642
643 dns_rdataclass_t
644 dst_key_class(const dst_key_t *key);
645
646 isc_boolean_t
647 dst_key_isprivate(const dst_key_t *key);
648
649 isc_boolean_t
650 dst_key_iszonekey(const dst_key_t *key);
651
652 isc_boolean_t
653 dst_key_isnullkey(const dst_key_t *key);
654
655 isc_result_t
656 dst_key_buildfilename(const dst_key_t *key, int type,
657                       const char *directory, isc_buffer_t *out);
658 /*%<
659  * Generates the filename used by dst to store the specified key.
660  * If directory is NULL, the current directory is assumed.
661  *
662  * Requires:
663  *\li   "key" is a valid key
664  *\li   "type" is either DST_TYPE_PUBLIC, DST_TYPE_PRIVATE, or 0 for no suffix.
665  *\li   "out" is a valid buffer
666  *
667  * Ensures:
668  *\li   the file name will be written to "out", and the used pointer will
669  *              be advanced.
670  */
671
672 isc_result_t
673 dst_key_sigsize(const dst_key_t *key, unsigned int *n);
674 /*%<
675  * Computes the size of a signature generated by the given key.
676  *
677  * Requires:
678  *\li   "key" is a valid key.
679  *\li   "n" is not NULL
680  *
681  * Returns:
682  *\li   #ISC_R_SUCCESS
683  *\li   DST_R_UNSUPPORTEDALG
684  *
685  * Ensures:
686  *\li   "n" stores the size of a generated signature
687  */
688
689 isc_result_t
690 dst_key_secretsize(const dst_key_t *key, unsigned int *n);
691 /*%<
692  * Computes the size of a shared secret generated by the given key.
693  *
694  * Requires:
695  *\li   "key" is a valid key.
696  *\li   "n" is not NULL
697  *
698  * Returns:
699  *\li   #ISC_R_SUCCESS
700  *\li   DST_R_UNSUPPORTEDALG
701  *
702  * Ensures:
703  *\li   "n" stores the size of a generated shared secret
704  */
705
706 isc_uint16_t
707 dst_region_computeid(const isc_region_t *source, unsigned int alg);
708 /*%<
709  * Computes the key id of the key stored in the provided region with the
710  * given algorithm.
711  *
712  * Requires:
713  *\li   "source" contains a valid, non-NULL region.
714  *
715  * Returns:
716  *\li   the key id
717  */
718
719 isc_uint16_t
720 dst_key_getbits(const dst_key_t *key);
721 /*%<
722  * Get the number of digest bits required (0 == MAX).
723  *
724  * Requires:
725  *      "key" is a valid key.
726  */
727
728 void
729 dst_key_setbits(dst_key_t *key, isc_uint16_t bits);
730 /*%<
731  * Set the number of digest bits required (0 == MAX).
732  *
733  * Requires:
734  *      "key" is a valid key.
735  */
736
737 isc_result_t
738 dst_key_setflags(dst_key_t *key, isc_uint32_t flags);
739 /*
740  * Set the key flags, and recompute the key ID.
741  *
742  * Requires:
743  *      "key" is a valid key.
744  */
745
746 isc_result_t
747 dst_key_getnum(const dst_key_t *key, int type, isc_uint32_t *valuep);
748 /*%<
749  * Get a member of the numeric metadata array and place it in '*valuep'.
750  *
751  * Requires:
752  *      "key" is a valid key.
753  *      "type" is no larger than DST_MAX_NUMERIC
754  *      "timep" is not null.
755  */
756
757 void
758 dst_key_setnum(dst_key_t *key, int type, isc_uint32_t value);
759 /*%<
760  * Set a member of the numeric metadata array.
761  *
762  * Requires:
763  *      "key" is a valid key.
764  *      "type" is no larger than DST_MAX_NUMERIC
765  */
766
767 void
768 dst_key_unsetnum(dst_key_t *key, int type);
769 /*%<
770  * Flag a member of the numeric metadata array as "not set".
771  *
772  * Requires:
773  *      "key" is a valid key.
774  *      "type" is no larger than DST_MAX_NUMERIC
775  */
776
777 isc_result_t
778 dst_key_gettime(const dst_key_t *key, int type, isc_stdtime_t *timep);
779 /*%<
780  * Get a member of the timing metadata array and place it in '*timep'.
781  *
782  * Requires:
783  *      "key" is a valid key.
784  *      "type" is no larger than DST_MAX_TIMES
785  *      "timep" is not null.
786  */
787
788 void
789 dst_key_settime(dst_key_t *key, int type, isc_stdtime_t when);
790 /*%<
791  * Set a member of the timing metadata array.
792  *
793  * Requires:
794  *      "key" is a valid key.
795  *      "type" is no larger than DST_MAX_TIMES
796  */
797
798 void
799 dst_key_unsettime(dst_key_t *key, int type);
800 /*%<
801  * Flag a member of the timing metadata array as "not set".
802  *
803  * Requires:
804  *      "key" is a valid key.
805  *      "type" is no larger than DST_MAX_TIMES
806  */
807
808 isc_result_t
809 dst_key_getprivateformat(const dst_key_t *key, int *majorp, int *minorp);
810 /*%<
811  * Get the private key format version number.  (If the key does not have
812  * a private key associated with it, the version will be 0.0.)  The major
813  * version number is placed in '*majorp', and the minor version number in
814  * '*minorp'.
815  *
816  * Requires:
817  *      "key" is a valid key.
818  *      "majorp" is not NULL.
819  *      "minorp" is not NULL.
820  */
821
822 void
823 dst_key_setprivateformat(dst_key_t *key, int major, int minor);
824 /*%<
825  * Set the private key format version number.
826  *
827  * Requires:
828  *      "key" is a valid key.
829  */
830
831 #define DST_KEY_FORMATSIZE (DNS_NAME_FORMATSIZE + DNS_SECALG_FORMATSIZE + 7)
832
833 void
834 dst_key_format(dst_key_t *key, char *cp, unsigned int size);
835 /*%<
836  * Write the uniquely identifying information about the key (name,
837  * algorithm, key ID) into a string 'cp' of size 'size'.
838  */
839
840 ISC_LANG_ENDDECLS
841
842 #endif /* DST_DST_H */