1 1.1 christos /* $NetBSD: dst_parse.h,v 1.1 2024/02/18 20:57:31 christos Exp $ */ 2 1.1 christos 3 1.1 christos /* 4 1.1 christos * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 5 1.1 christos * 6 1.1 christos * SPDX-License-Identifier: MPL-2.0 AND ISC 7 1.1 christos * 8 1.1 christos * This Source Code Form is subject to the terms of the Mozilla Public 9 1.1 christos * License, v. 2.0. If a copy of the MPL was not distributed with this 10 1.1 christos * file, you can obtain one at https://mozilla.org/MPL/2.0/. 11 1.1 christos * 12 1.1 christos * See the COPYRIGHT file distributed with this work for additional 13 1.1 christos * information regarding copyright ownership. 14 1.1 christos */ 15 1.1 christos 16 1.1 christos /* 17 1.1 christos * Copyright (C) Network Associates, Inc. 18 1.1 christos * 19 1.1 christos * Permission to use, copy, modify, and/or distribute this software for any 20 1.1 christos * purpose with or without fee is hereby granted, provided that the above 21 1.1 christos * copyright notice and this permission notice appear in all copies. 22 1.1 christos * 23 1.1 christos * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NETWORK ASSOCIATES DISCLAIMS 24 1.1 christos * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 25 1.1 christos * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE 26 1.1 christos * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 27 1.1 christos * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 28 1.1 christos * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR 29 1.1 christos * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 30 1.1 christos */ 31 1.1 christos 32 1.1 christos /*! \file */ 33 1.1 christos #ifndef DST_DST_PARSE_H 34 1.1 christos #define DST_DST_PARSE_H 1 35 1.1 christos 36 1.1 christos #include <isc/lang.h> 37 1.1 christos 38 1.1 christos #include <dst/dst.h> 39 1.1 christos 40 1.1 christos #define MAXFIELDSIZE 512 41 1.1 christos 42 1.1 christos /* 43 1.1 christos * Maximum number of fields in a private file is 18 (12 algorithm- 44 1.1 christos * specific fields for RSA, plus 6 generic fields). 45 1.1 christos */ 46 1.1 christos #define MAXFIELDS 12 + 6 47 1.1 christos 48 1.1 christos #define TAG_SHIFT 4 49 1.1 christos #define TAG_ALG(tag) ((unsigned int)(tag) >> TAG_SHIFT) 50 1.1 christos #define TAG(alg, off) (((alg) << TAG_SHIFT) + (off)) 51 1.1 christos 52 1.1 christos /* These are used by RSA-SHA1, RSASHA256 and RSASHA512 */ 53 1.1 christos #define RSA_NTAGS 11 54 1.1 christos #define TAG_RSA_MODULUS ((DST_ALG_RSA << TAG_SHIFT) + 0) 55 1.1 christos #define TAG_RSA_PUBLICEXPONENT ((DST_ALG_RSA << TAG_SHIFT) + 1) 56 1.1 christos #define TAG_RSA_PRIVATEEXPONENT ((DST_ALG_RSA << TAG_SHIFT) + 2) 57 1.1 christos #define TAG_RSA_PRIME1 ((DST_ALG_RSA << TAG_SHIFT) + 3) 58 1.1 christos #define TAG_RSA_PRIME2 ((DST_ALG_RSA << TAG_SHIFT) + 4) 59 1.1 christos #define TAG_RSA_EXPONENT1 ((DST_ALG_RSA << TAG_SHIFT) + 5) 60 1.1 christos #define TAG_RSA_EXPONENT2 ((DST_ALG_RSA << TAG_SHIFT) + 6) 61 1.1 christos #define TAG_RSA_COEFFICIENT ((DST_ALG_RSA << TAG_SHIFT) + 7) 62 1.1 christos #define TAG_RSA_ENGINE ((DST_ALG_RSA << TAG_SHIFT) + 8) 63 1.1 christos #define TAG_RSA_LABEL ((DST_ALG_RSA << TAG_SHIFT) + 9) 64 1.1 christos 65 1.1 christos #define DH_NTAGS 4 66 1.1 christos #define TAG_DH_PRIME ((DST_ALG_DH << TAG_SHIFT) + 0) 67 1.1 christos #define TAG_DH_GENERATOR ((DST_ALG_DH << TAG_SHIFT) + 1) 68 1.1 christos #define TAG_DH_PRIVATE ((DST_ALG_DH << TAG_SHIFT) + 2) 69 1.1 christos #define TAG_DH_PUBLIC ((DST_ALG_DH << TAG_SHIFT) + 3) 70 1.1 christos 71 1.1 christos #define ECDSA_NTAGS 4 72 1.1 christos #define TAG_ECDSA_PRIVATEKEY ((DST_ALG_ECDSA256 << TAG_SHIFT) + 0) 73 1.1 christos #define TAG_ECDSA_ENGINE ((DST_ALG_ECDSA256 << TAG_SHIFT) + 1) 74 1.1 christos #define TAG_ECDSA_LABEL ((DST_ALG_ECDSA256 << TAG_SHIFT) + 2) 75 1.1 christos 76 1.1 christos #define EDDSA_NTAGS 4 77 1.1 christos #define TAG_EDDSA_PRIVATEKEY ((DST_ALG_ED25519 << TAG_SHIFT) + 0) 78 1.1 christos #define TAG_EDDSA_ENGINE ((DST_ALG_ED25519 << TAG_SHIFT) + 1) 79 1.1 christos #define TAG_EDDSA_LABEL ((DST_ALG_ED25519 << TAG_SHIFT) + 2) 80 1.1 christos 81 1.1 christos #define OLD_HMACMD5_NTAGS 1 82 1.1 christos #define HMACMD5_NTAGS 2 83 1.1 christos #define TAG_HMACMD5_KEY ((DST_ALG_HMACMD5 << TAG_SHIFT) + 0) 84 1.1 christos #define TAG_HMACMD5_BITS ((DST_ALG_HMACMD5 << TAG_SHIFT) + 1) 85 1.1 christos 86 1.1 christos #define HMACSHA1_NTAGS 2 87 1.1 christos #define TAG_HMACSHA1_KEY ((DST_ALG_HMACSHA1 << TAG_SHIFT) + 0) 88 1.1 christos #define TAG_HMACSHA1_BITS ((DST_ALG_HMACSHA1 << TAG_SHIFT) + 1) 89 1.1 christos 90 1.1 christos #define HMACSHA224_NTAGS 2 91 1.1 christos #define TAG_HMACSHA224_KEY ((DST_ALG_HMACSHA224 << TAG_SHIFT) + 0) 92 1.1 christos #define TAG_HMACSHA224_BITS ((DST_ALG_HMACSHA224 << TAG_SHIFT) + 1) 93 1.1 christos 94 1.1 christos #define HMACSHA256_NTAGS 2 95 1.1 christos #define TAG_HMACSHA256_KEY ((DST_ALG_HMACSHA256 << TAG_SHIFT) + 0) 96 1.1 christos #define TAG_HMACSHA256_BITS ((DST_ALG_HMACSHA256 << TAG_SHIFT) + 1) 97 1.1 christos 98 1.1 christos #define HMACSHA384_NTAGS 2 99 1.1 christos #define TAG_HMACSHA384_KEY ((DST_ALG_HMACSHA384 << TAG_SHIFT) + 0) 100 1.1 christos #define TAG_HMACSHA384_BITS ((DST_ALG_HMACSHA384 << TAG_SHIFT) + 1) 101 1.1 christos 102 1.1 christos #define HMACSHA512_NTAGS 2 103 1.1 christos #define TAG_HMACSHA512_KEY ((DST_ALG_HMACSHA512 << TAG_SHIFT) + 0) 104 1.1 christos #define TAG_HMACSHA512_BITS ((DST_ALG_HMACSHA512 << TAG_SHIFT) + 1) 105 1.1 christos 106 1.1 christos struct dst_private_element { 107 1.1 christos unsigned short tag; 108 1.1 christos unsigned short length; 109 1.1 christos unsigned char *data; 110 1.1 christos }; 111 1.1 christos 112 1.1 christos typedef struct dst_private_element dst_private_element_t; 113 1.1 christos 114 1.1 christos struct dst_private { 115 1.1 christos unsigned short nelements; 116 1.1 christos dst_private_element_t elements[MAXFIELDS]; 117 1.1 christos }; 118 1.1 christos 119 1.1 christos typedef struct dst_private dst_private_t; 120 1.1 christos 121 1.1 christos ISC_LANG_BEGINDECLS 122 1.1 christos 123 1.1 christos void 124 1.1 christos dst__privstruct_free(dst_private_t *priv, isc_mem_t *mctx); 125 1.1 christos 126 1.1 christos isc_result_t 127 1.1 christos dst__privstruct_parse(dst_key_t *key, unsigned int alg, isc_lex_t *lex, 128 1.1 christos isc_mem_t *mctx, dst_private_t *priv); 129 1.1 christos 130 1.1 christos isc_result_t 131 1.1 christos dst__privstruct_writefile(const dst_key_t *key, const dst_private_t *priv, 132 1.1 christos const char *directory); 133 1.1 christos 134 1.1 christos ISC_LANG_ENDDECLS 135 1.1 christos 136 1.1 christos #endif /* DST_DST_PARSE_H */ 137