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