xref: /netbsd-src/external/mpl/bind/dist/lib/isccc/include/isccc/cc.h (revision bcda20f65a8566e103791ec395f7f499ef322704)
1 /*	$NetBSD: cc.h,v 1.8 2025/01/26 16:25:44 christos Exp $	*/
2 
3 /*
4  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5  *
6  * SPDX-License-Identifier: MPL-2.0 AND ISC
7  *
8  * This Source Code Form is subject to the terms of the Mozilla Public
9  * License, v. 2.0. If a copy of the MPL was not distributed with this
10  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
11  *
12  * See the COPYRIGHT file distributed with this work for additional
13  * information regarding copyright ownership.
14  */
15 
16 /*
17  * Copyright (C) 2001 Nominum, Inc.
18  *
19  * Permission to use, copy, modify, and/or distribute this software for any
20  * purpose with or without fee is hereby granted, provided that the above
21  * copyright notice and this permission notice appear in all copies.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NOMINUM DISCLAIMS ALL
24  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
25  * OF MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY
26  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
27  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
28  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
29  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
30  */
31 
32 #pragma once
33 
34 /*! \file isccc/cc.h */
35 
36 #include <inttypes.h>
37 #include <stdbool.h>
38 
39 #include <isc/buffer.h>
40 #include <isc/lang.h>
41 
42 #include <dst/dst.h>
43 
44 #include <isccc/types.h>
45 
46 ISC_LANG_BEGINDECLS
47 
48 /*%
49  * The HMAC algorithms supported by isccc_cc_fromwire and
50  * isccc_cc_towire as implemented in DST.
51  */
52 #define ISCCC_ALG_UNKNOWN    0
53 #define ISCCC_ALG_HMACMD5    DST_ALG_HMACMD5
54 #define ISCCC_ALG_HMACSHA1   DST_ALG_HMACSHA1
55 #define ISCCC_ALG_HMACSHA224 DST_ALG_HMACSHA224
56 #define ISCCC_ALG_HMACSHA256 DST_ALG_HMACSHA256
57 #define ISCCC_ALG_HMACSHA384 DST_ALG_HMACSHA384
58 #define ISCCC_ALG_HMACSHA512 DST_ALG_HMACSHA512
59 
60 /*% Maximum Datagram Package */
61 #define ISCCC_CC_MAXDGRAMPACKET 4096
62 
63 /*% Message Type String */
64 #define ISCCC_CCMSGTYPE_STRING 0x00
65 /*% Message Type Binary Data */
66 #define ISCCC_CCMSGTYPE_BINARYDATA 0x01
67 /*% Message Type Table */
68 #define ISCCC_CCMSGTYPE_TABLE 0x02
69 /*% Message Type List */
70 #define ISCCC_CCMSGTYPE_LIST 0x03
71 
72 /*% Send to Wire */
73 isc_result_t
74 isccc_cc_towire(isccc_sexpr_t *alist, isc_buffer_t **buffer, uint32_t algorithm,
75 		isccc_region_t *secret);
76 
77 /*% Get From Wire */
78 isc_result_t
79 isccc_cc_fromwire(isccc_region_t *source, isccc_sexpr_t **alistp,
80 		  uint32_t algorithm, isccc_region_t *secret);
81 
82 /*% Create Message */
83 isc_result_t
84 isccc_cc_createmessage(uint32_t version, const char *from, const char *to,
85 		       uint32_t serial, isccc_time_t now, isccc_time_t expires,
86 		       isccc_sexpr_t **alistp);
87 
88 /*% Create Acknowledgment */
89 isc_result_t
90 isccc_cc_createack(isccc_sexpr_t *message, bool ok, isccc_sexpr_t **ackp);
91 
92 /*% Is Ack? */
93 bool
94 isccc_cc_isack(isccc_sexpr_t *message);
95 
96 /*% Is Reply? */
97 bool
98 isccc_cc_isreply(isccc_sexpr_t *message);
99 
100 /*% Create Response */
101 isc_result_t
102 isccc_cc_createresponse(isccc_sexpr_t *message, isccc_time_t now,
103 			isccc_time_t expires, isccc_sexpr_t **alistp);
104 
105 /*% Define String */
106 isccc_sexpr_t *
107 isccc_cc_definestring(isccc_sexpr_t *alist, const char *key, const char *str);
108 
109 /*% Define uint 32 */
110 isccc_sexpr_t *
111 isccc_cc_defineuint32(isccc_sexpr_t *alist, const char *key, uint32_t i);
112 
113 /*% Lookup String */
114 isc_result_t
115 isccc_cc_lookupstring(isccc_sexpr_t *alist, const char *key, char **strp);
116 
117 /*% Lookup uint 32 */
118 isc_result_t
119 isccc_cc_lookupuint32(isccc_sexpr_t *alist, const char *key, uint32_t *uintp);
120 
121 /*% Create Symbol Table */
122 isc_result_t
123 isccc_cc_createsymtab(isccc_symtab_t **symtabp);
124 
125 /*% Clean up Symbol Table */
126 void
127 isccc_cc_cleansymtab(isccc_symtab_t *symtab, isccc_time_t now);
128 
129 /*% Check for Duplicates */
130 isc_result_t
131 isccc_cc_checkdup(isccc_symtab_t *symtab, isccc_sexpr_t *message,
132 		  isccc_time_t now);
133 
134 ISC_LANG_ENDDECLS
135