xref: /freebsd/contrib/unbound/validator/val_sigcrypt.h (revision 5685098846d7f11ad642d9804d94dc7429a7b212)
1b7579f77SDag-Erling Smørgrav /*
2b7579f77SDag-Erling Smørgrav  * validator/val_sigcrypt.h - validator signature crypto functions.
3b7579f77SDag-Erling Smørgrav  *
4b7579f77SDag-Erling Smørgrav  * Copyright (c) 2007, NLnet Labs. All rights reserved.
5b7579f77SDag-Erling Smørgrav  *
6b7579f77SDag-Erling Smørgrav  * This software is open source.
7b7579f77SDag-Erling Smørgrav  *
8b7579f77SDag-Erling Smørgrav  * Redistribution and use in source and binary forms, with or without
9b7579f77SDag-Erling Smørgrav  * modification, are permitted provided that the following conditions
10b7579f77SDag-Erling Smørgrav  * are met:
11b7579f77SDag-Erling Smørgrav  *
12b7579f77SDag-Erling Smørgrav  * Redistributions of source code must retain the above copyright notice,
13b7579f77SDag-Erling Smørgrav  * this list of conditions and the following disclaimer.
14b7579f77SDag-Erling Smørgrav  *
15b7579f77SDag-Erling Smørgrav  * Redistributions in binary form must reproduce the above copyright notice,
16b7579f77SDag-Erling Smørgrav  * this list of conditions and the following disclaimer in the documentation
17b7579f77SDag-Erling Smørgrav  * and/or other materials provided with the distribution.
18b7579f77SDag-Erling Smørgrav  *
19b7579f77SDag-Erling Smørgrav  * Neither the name of the NLNET LABS nor the names of its contributors may
20b7579f77SDag-Erling Smørgrav  * be used to endorse or promote products derived from this software without
21b7579f77SDag-Erling Smørgrav  * specific prior written permission.
22b7579f77SDag-Erling Smørgrav  *
23b7579f77SDag-Erling Smørgrav  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2417d15b25SDag-Erling Smørgrav  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2517d15b25SDag-Erling Smørgrav  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2617d15b25SDag-Erling Smørgrav  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2717d15b25SDag-Erling Smørgrav  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2817d15b25SDag-Erling Smørgrav  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
2917d15b25SDag-Erling Smørgrav  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
3017d15b25SDag-Erling Smørgrav  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
3117d15b25SDag-Erling Smørgrav  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
3217d15b25SDag-Erling Smørgrav  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3317d15b25SDag-Erling Smørgrav  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34b7579f77SDag-Erling Smørgrav  */
35b7579f77SDag-Erling Smørgrav 
36b7579f77SDag-Erling Smørgrav /**
37b7579f77SDag-Erling Smørgrav  * \file
38b7579f77SDag-Erling Smørgrav  *
39b7579f77SDag-Erling Smørgrav  * This file contains helper functions for the validator module.
40b7579f77SDag-Erling Smørgrav  * The functions help with signature verification and checking, the
41b7579f77SDag-Erling Smørgrav  * bridging between RR wireformat data and crypto calls.
42b7579f77SDag-Erling Smørgrav  */
43b7579f77SDag-Erling Smørgrav 
44b7579f77SDag-Erling Smørgrav #ifndef VALIDATOR_VAL_SIGCRYPT_H
45b7579f77SDag-Erling Smørgrav #define VALIDATOR_VAL_SIGCRYPT_H
46b7579f77SDag-Erling Smørgrav #include "util/data/packed_rrset.h"
47838e13ceSDag-Erling Smørgrav #include "sldns/pkthdr.h"
48a39a5a69SCy Schubert #include "sldns/rrdef.h"
49b7579f77SDag-Erling Smørgrav struct val_env;
50b7579f77SDag-Erling Smørgrav struct module_env;
51838e13ceSDag-Erling Smørgrav struct module_qstate;
52b7579f77SDag-Erling Smørgrav struct ub_packed_rrset_key;
533005e0a3SDag-Erling Smørgrav struct rbtree_type;
54b7579f77SDag-Erling Smørgrav struct regional;
5517d15b25SDag-Erling Smørgrav struct sldns_buffer;
56b7579f77SDag-Erling Smørgrav 
57b7579f77SDag-Erling Smørgrav /** number of entries in algorithm needs array */
58b7579f77SDag-Erling Smørgrav #define ALGO_NEEDS_MAX 256
59b7579f77SDag-Erling Smørgrav 
60b7579f77SDag-Erling Smørgrav /**
61b7579f77SDag-Erling Smørgrav  * Storage for algorithm needs.  DNSKEY algorithms.
62b7579f77SDag-Erling Smørgrav  */
63b7579f77SDag-Erling Smørgrav struct algo_needs {
64b7579f77SDag-Erling Smørgrav 	/** the algorithms (8-bit) with each a number.
65b7579f77SDag-Erling Smørgrav 	 * 0: not marked.
66b7579f77SDag-Erling Smørgrav 	 * 1: marked 'necessary but not yet fulfilled'
67b7579f77SDag-Erling Smørgrav 	 * 2: marked bogus.
68b7579f77SDag-Erling Smørgrav 	 * Indexed by algorithm number.
69b7579f77SDag-Erling Smørgrav 	 */
70b7579f77SDag-Erling Smørgrav 	uint8_t needs[ALGO_NEEDS_MAX];
71b7579f77SDag-Erling Smørgrav 	/** the number of entries in the array that are unfulfilled */
72b7579f77SDag-Erling Smørgrav 	size_t num;
73b7579f77SDag-Erling Smørgrav };
74b7579f77SDag-Erling Smørgrav 
75b7579f77SDag-Erling Smørgrav /**
76b7579f77SDag-Erling Smørgrav  * Initialize algo needs structure, set algos from rrset as needed.
77b7579f77SDag-Erling Smørgrav  * Results are added to an existing need structure.
78b7579f77SDag-Erling Smørgrav  * @param n: struct with storage.
79b7579f77SDag-Erling Smørgrav  * @param dnskey: algos from this struct set as necessary. DNSKEY set.
80b7579f77SDag-Erling Smørgrav  * @param sigalg: adds to signalled algorithm list too.
81b7579f77SDag-Erling Smørgrav  */
82b7579f77SDag-Erling Smørgrav void algo_needs_init_dnskey_add(struct algo_needs* n,
83b7579f77SDag-Erling Smørgrav 	struct ub_packed_rrset_key* dnskey, uint8_t* sigalg);
84b7579f77SDag-Erling Smørgrav 
85b7579f77SDag-Erling Smørgrav /**
86b7579f77SDag-Erling Smørgrav  * Initialize algo needs structure from a signalled algo list.
87b7579f77SDag-Erling Smørgrav  * @param n: struct with storage.
88b7579f77SDag-Erling Smørgrav  * @param sigalg: signalled algorithm list, numbers ends with 0.
89b7579f77SDag-Erling Smørgrav  */
90b7579f77SDag-Erling Smørgrav void algo_needs_init_list(struct algo_needs* n, uint8_t* sigalg);
91b7579f77SDag-Erling Smørgrav 
92b7579f77SDag-Erling Smørgrav /**
93b7579f77SDag-Erling Smørgrav  * Initialize algo needs structure, set algos from rrset as needed.
94b7579f77SDag-Erling Smørgrav  * @param n: struct with storage.
95b7579f77SDag-Erling Smørgrav  * @param ds: algos from this struct set as necessary. DS set.
96b7579f77SDag-Erling Smørgrav  * @param fav_ds_algo: filter to use only this DS algo.
97b7579f77SDag-Erling Smørgrav  * @param sigalg: list of signalled algos, constructed as output,
98b7579f77SDag-Erling Smørgrav  *	provide size ALGO_NEEDS_MAX+1. list of algonumbers, ends with a zero.
99b7579f77SDag-Erling Smørgrav  */
100b7579f77SDag-Erling Smørgrav void algo_needs_init_ds(struct algo_needs* n, struct ub_packed_rrset_key* ds,
101b7579f77SDag-Erling Smørgrav 	int fav_ds_algo, uint8_t* sigalg);
102b7579f77SDag-Erling Smørgrav 
103b7579f77SDag-Erling Smørgrav /**
104b7579f77SDag-Erling Smørgrav  * Mark this algorithm as a success, sec_secure, and see if we are done.
105b7579f77SDag-Erling Smørgrav  * @param n: storage structure processed.
106b7579f77SDag-Erling Smørgrav  * @param algo: the algorithm processed to be secure.
107b7579f77SDag-Erling Smørgrav  * @return if true, processing has finished successfully, we are satisfied.
108b7579f77SDag-Erling Smørgrav  */
109b7579f77SDag-Erling Smørgrav int algo_needs_set_secure(struct algo_needs* n, uint8_t algo);
110b7579f77SDag-Erling Smørgrav 
111b7579f77SDag-Erling Smørgrav /**
112b7579f77SDag-Erling Smørgrav  * Mark this algorithm a failure, sec_bogus.  It can later be overridden
113b7579f77SDag-Erling Smørgrav  * by a success for this algorithm (with a different signature).
114b7579f77SDag-Erling Smørgrav  * @param n: storage structure processed.
115b7579f77SDag-Erling Smørgrav  * @param algo: the algorithm processed to be bogus.
116b7579f77SDag-Erling Smørgrav  */
117b7579f77SDag-Erling Smørgrav void algo_needs_set_bogus(struct algo_needs* n, uint8_t algo);
118b7579f77SDag-Erling Smørgrav 
119b7579f77SDag-Erling Smørgrav /**
120b7579f77SDag-Erling Smørgrav  * See how many algorithms are missing (not bogus or secure, but not processed)
121b7579f77SDag-Erling Smørgrav  * @param n: storage structure processed.
122b7579f77SDag-Erling Smørgrav  * @return number of algorithms missing after processing.
123b7579f77SDag-Erling Smørgrav  */
124b7579f77SDag-Erling Smørgrav size_t algo_needs_num_missing(struct algo_needs* n);
125b7579f77SDag-Erling Smørgrav 
126b7579f77SDag-Erling Smørgrav /**
127b7579f77SDag-Erling Smørgrav  * See which algo is missing.
128b7579f77SDag-Erling Smørgrav  * @param n: struct after processing.
129b7579f77SDag-Erling Smørgrav  * @return if 0 an algorithm was bogus, if a number, this algorithm was
130b7579f77SDag-Erling Smørgrav  *   missing.  So on 0, report why that was bogus, on number report a missing
131b7579f77SDag-Erling Smørgrav  *   algorithm.  There could be multiple missing, this reports the first one.
132b7579f77SDag-Erling Smørgrav  */
133b7579f77SDag-Erling Smørgrav int algo_needs_missing(struct algo_needs* n);
134b7579f77SDag-Erling Smørgrav 
135b7579f77SDag-Erling Smørgrav /**
136b7579f77SDag-Erling Smørgrav  * Format error reason for algorithm missing.
137b7579f77SDag-Erling Smørgrav  * @param alg: DNSKEY-algorithm missing.
138b7579f77SDag-Erling Smørgrav  * @param reason: destination.
139b7579f77SDag-Erling Smørgrav  * @param s: string, appended with 'with algorithm ..'.
140*56850988SCy Schubert  * @param reasonbuf: buffer to use for fail reason string print.
141*56850988SCy Schubert  * @param reasonlen: length of reasonbuf.
142b7579f77SDag-Erling Smørgrav  */
143*56850988SCy Schubert void algo_needs_reason(int alg, char** reason, char* s, char* reasonbuf,
144*56850988SCy Schubert 	size_t reasonlen);
145b7579f77SDag-Erling Smørgrav 
146b7579f77SDag-Erling Smørgrav /**
147b7579f77SDag-Erling Smørgrav  * Check if dnskey matches a DS digest
148b7579f77SDag-Erling Smørgrav  * Does not check dnskey-keyid footprint, just the digest.
149b7579f77SDag-Erling Smørgrav  * @param env: module environment. Uses scratch space.
150b7579f77SDag-Erling Smørgrav  * @param dnskey_rrset: DNSKEY rrset.
151b7579f77SDag-Erling Smørgrav  * @param dnskey_idx: index of RR in rrset.
152b7579f77SDag-Erling Smørgrav  * @param ds_rrset: DS rrset
153b7579f77SDag-Erling Smørgrav  * @param ds_idx: index of RR in DS rrset.
154b7579f77SDag-Erling Smørgrav  * @return true if it matches, false on error, not supported or no match.
155b7579f77SDag-Erling Smørgrav  */
156b7579f77SDag-Erling Smørgrav int ds_digest_match_dnskey(struct module_env* env,
157b7579f77SDag-Erling Smørgrav 	struct ub_packed_rrset_key* dnskey_rrset, size_t dnskey_idx,
158b7579f77SDag-Erling Smørgrav 	struct ub_packed_rrset_key* ds_rrset, size_t ds_idx);
159b7579f77SDag-Erling Smørgrav 
160b7579f77SDag-Erling Smørgrav /**
161b7579f77SDag-Erling Smørgrav  * Get dnskey keytag, footprint value
162b7579f77SDag-Erling Smørgrav  * @param dnskey_rrset: DNSKEY rrset.
163b7579f77SDag-Erling Smørgrav  * @param dnskey_idx: index of RR in rrset.
164b7579f77SDag-Erling Smørgrav  * @return the keytag or 0 for badly formatted DNSKEYs.
165b7579f77SDag-Erling Smørgrav  */
166b7579f77SDag-Erling Smørgrav uint16_t dnskey_calc_keytag(struct ub_packed_rrset_key* dnskey_rrset,
167b7579f77SDag-Erling Smørgrav 	size_t dnskey_idx);
168b7579f77SDag-Erling Smørgrav 
169b7579f77SDag-Erling Smørgrav /**
170b7579f77SDag-Erling Smørgrav  * Get DS keytag, footprint value that matches the DNSKEY keytag it signs.
171b7579f77SDag-Erling Smørgrav  * @param ds_rrset: DS rrset
172b7579f77SDag-Erling Smørgrav  * @param ds_idx: index of RR in DS rrset.
173b7579f77SDag-Erling Smørgrav  * @return the keytag or 0 for badly formatted DSs.
174b7579f77SDag-Erling Smørgrav  */
175b7579f77SDag-Erling Smørgrav uint16_t ds_get_keytag(struct ub_packed_rrset_key* ds_rrset, size_t ds_idx);
176b7579f77SDag-Erling Smørgrav 
177b7579f77SDag-Erling Smørgrav /**
178b7579f77SDag-Erling Smørgrav  * See if DNSKEY algorithm is supported
179b7579f77SDag-Erling Smørgrav  * @param dnskey_rrset: DNSKEY rrset.
180b7579f77SDag-Erling Smørgrav  * @param dnskey_idx: index of RR in rrset.
181b7579f77SDag-Erling Smørgrav  * @return true if supported.
182b7579f77SDag-Erling Smørgrav  */
183b7579f77SDag-Erling Smørgrav int dnskey_algo_is_supported(struct ub_packed_rrset_key* dnskey_rrset,
184b7579f77SDag-Erling Smørgrav 	size_t dnskey_idx);
185b7579f77SDag-Erling Smørgrav 
186b7579f77SDag-Erling Smørgrav /**
1875469a995SCy Schubert  * See if the DNSKEY size at that algorithm is supported.
1885469a995SCy Schubert  * @param dnskey_rrset: DNSKEY rrset.
1895469a995SCy Schubert  * @param dnskey_idx: index of RR in rrset.
1905469a995SCy Schubert  * @return true if supported.
1915469a995SCy Schubert  */
1925469a995SCy Schubert int dnskey_size_is_supported(struct ub_packed_rrset_key* dnskey_rrset,
1935469a995SCy Schubert 	size_t dnskey_idx);
1945469a995SCy Schubert 
1955469a995SCy Schubert /**
1965469a995SCy Schubert  * See if the DNSKEY size at that algorithm is supported for all the
1975469a995SCy Schubert  * RRs in the DNSKEY RRset.
1985469a995SCy Schubert  * @param dnskey_rrset: DNSKEY rrset.
1995469a995SCy Schubert  * @return true if supported.
2005469a995SCy Schubert  */
2015469a995SCy Schubert int dnskeyset_size_is_supported(struct ub_packed_rrset_key* dnskey_rrset);
2025469a995SCy Schubert 
2035469a995SCy Schubert /**
204b7579f77SDag-Erling Smørgrav  * See if DS digest algorithm is supported
205b7579f77SDag-Erling Smørgrav  * @param ds_rrset: DS rrset
206b7579f77SDag-Erling Smørgrav  * @param ds_idx: index of RR in DS rrset.
207b7579f77SDag-Erling Smørgrav  * @return true if supported.
208b7579f77SDag-Erling Smørgrav  */
209b7579f77SDag-Erling Smørgrav int ds_digest_algo_is_supported(struct ub_packed_rrset_key* ds_rrset,
210b7579f77SDag-Erling Smørgrav 	size_t ds_idx);
211b7579f77SDag-Erling Smørgrav 
212b7579f77SDag-Erling Smørgrav /**
213b7579f77SDag-Erling Smørgrav  * Get DS RR digest algorithm
214b7579f77SDag-Erling Smørgrav  * @param ds_rrset: DS rrset.
215b7579f77SDag-Erling Smørgrav  * @param ds_idx: which DS.
216b7579f77SDag-Erling Smørgrav  * @return algorithm or 0 if DS too short.
217b7579f77SDag-Erling Smørgrav  */
218b7579f77SDag-Erling Smørgrav int ds_get_digest_algo(struct ub_packed_rrset_key* ds_rrset, size_t ds_idx);
219b7579f77SDag-Erling Smørgrav 
220b7579f77SDag-Erling Smørgrav /**
221b7579f77SDag-Erling Smørgrav  * See if DS key algorithm is supported
222b7579f77SDag-Erling Smørgrav  * @param ds_rrset: DS rrset
223b7579f77SDag-Erling Smørgrav  * @param ds_idx: index of RR in DS rrset.
224b7579f77SDag-Erling Smørgrav  * @return true if supported.
225b7579f77SDag-Erling Smørgrav  */
226b7579f77SDag-Erling Smørgrav int ds_key_algo_is_supported(struct ub_packed_rrset_key* ds_rrset,
227b7579f77SDag-Erling Smørgrav 	size_t ds_idx);
228b7579f77SDag-Erling Smørgrav 
229b7579f77SDag-Erling Smørgrav /**
230b7579f77SDag-Erling Smørgrav  * Get DS RR key algorithm. This value should match with the DNSKEY algo.
231b7579f77SDag-Erling Smørgrav  * @param k: DS rrset.
232b7579f77SDag-Erling Smørgrav  * @param idx: which DS.
233b7579f77SDag-Erling Smørgrav  * @return algorithm or 0 if DS too short.
234b7579f77SDag-Erling Smørgrav  */
235b7579f77SDag-Erling Smørgrav int ds_get_key_algo(struct ub_packed_rrset_key* k, size_t idx);
236b7579f77SDag-Erling Smørgrav 
237b7579f77SDag-Erling Smørgrav /**
238b7579f77SDag-Erling Smørgrav  * Get DNSKEY RR signature algorithm
239b7579f77SDag-Erling Smørgrav  * @param k: DNSKEY rrset.
240b7579f77SDag-Erling Smørgrav  * @param idx: which DNSKEY RR.
241b7579f77SDag-Erling Smørgrav  * @return algorithm or 0 if DNSKEY too short.
242b7579f77SDag-Erling Smørgrav  */
243b7579f77SDag-Erling Smørgrav int dnskey_get_algo(struct ub_packed_rrset_key* k, size_t idx);
244b7579f77SDag-Erling Smørgrav 
245b7579f77SDag-Erling Smørgrav /**
246b7579f77SDag-Erling Smørgrav  * Get DNSKEY RR flags
247b7579f77SDag-Erling Smørgrav  * @param k: DNSKEY rrset.
248b7579f77SDag-Erling Smørgrav  * @param idx: which DNSKEY RR.
249b7579f77SDag-Erling Smørgrav  * @return flags or 0 if DNSKEY too short.
250b7579f77SDag-Erling Smørgrav  */
251b7579f77SDag-Erling Smørgrav uint16_t dnskey_get_flags(struct ub_packed_rrset_key* k, size_t idx);
252b7579f77SDag-Erling Smørgrav 
253b7579f77SDag-Erling Smørgrav /**
254b7579f77SDag-Erling Smørgrav  * Verify rrset against dnskey rrset.
255b7579f77SDag-Erling Smørgrav  * @param env: module environment, scratch space is used.
256b7579f77SDag-Erling Smørgrav  * @param ve: validator environment, date settings.
257b7579f77SDag-Erling Smørgrav  * @param rrset: to be validated.
258b7579f77SDag-Erling Smørgrav  * @param dnskey: DNSKEY rrset, keyset to try.
259b7579f77SDag-Erling Smørgrav  * @param sigalg: if nonNULL provide downgrade protection otherwise one
260b7579f77SDag-Erling Smørgrav  *   algorithm is enough.
261b7579f77SDag-Erling Smørgrav  * @param reason: if bogus, a string returned, fixed or alloced in scratch.
262a39a5a69SCy Schubert  * @param reason_bogus: EDE (RFC8914) code paired with the reason of failure.
263838e13ceSDag-Erling Smørgrav  * @param section: section of packet where this rrset comes from.
264838e13ceSDag-Erling Smørgrav  * @param qstate: qstate with region.
265b76ef9a7SCy Schubert  * @param verified: if not NULL the number of RRSIG validations is returned.
266*56850988SCy Schubert  * @param reasonbuf: buffer to use for fail reason string print.
267*56850988SCy Schubert  * @param reasonlen: length of reasonbuf.
268b7579f77SDag-Erling Smørgrav  * @return SECURE if one key in the set verifies one rrsig.
269b7579f77SDag-Erling Smørgrav  *	UNCHECKED on allocation errors, unsupported algorithms, malformed data,
270b7579f77SDag-Erling Smørgrav  *	and BOGUS on verification failures (no keys match any signatures).
271b7579f77SDag-Erling Smørgrav  */
272b7579f77SDag-Erling Smørgrav enum sec_status dnskeyset_verify_rrset(struct module_env* env,
273b7579f77SDag-Erling Smørgrav 	struct val_env* ve, struct ub_packed_rrset_key* rrset,
274a39a5a69SCy Schubert 	struct ub_packed_rrset_key* dnskey, uint8_t* sigalg,
275a39a5a69SCy Schubert 	char** reason, sldns_ede_code *reason_bogus,
276*56850988SCy Schubert 	sldns_pkt_section section, struct module_qstate* qstate, int* verified,
277*56850988SCy Schubert 	char* reasonbuf, size_t reasonlen);
278a39a5a69SCy Schubert 
279b7579f77SDag-Erling Smørgrav /**
280b7579f77SDag-Erling Smørgrav  * verify rrset against one specific dnskey (from rrset)
281b7579f77SDag-Erling Smørgrav  * @param env: module environment, scratch space is used.
282b7579f77SDag-Erling Smørgrav  * @param ve: validator environment, date settings.
283b7579f77SDag-Erling Smørgrav  * @param rrset: to be validated.
284b7579f77SDag-Erling Smørgrav  * @param dnskey: DNSKEY rrset, keyset.
285b7579f77SDag-Erling Smørgrav  * @param dnskey_idx: which key from the rrset to try.
286b7579f77SDag-Erling Smørgrav  * @param reason: if bogus, a string returned, fixed or alloced in scratch.
287a39a5a69SCy Schubert  * @param reason_bogus: EDE (RFC8914) code paired with the reason of failure.
288838e13ceSDag-Erling Smørgrav  * @param section: section of packet where this rrset comes from.
289838e13ceSDag-Erling Smørgrav  * @param qstate: qstate with region.
290b7579f77SDag-Erling Smørgrav  * @return secure if *this* key signs any of the signatures on rrset.
291b7579f77SDag-Erling Smørgrav  *	unchecked on error or and bogus on bad signature.
292b7579f77SDag-Erling Smørgrav  */
293a39a5a69SCy Schubert enum sec_status dnskey_verify_rrset(struct module_env* env, struct val_env* ve,
294a39a5a69SCy Schubert         struct ub_packed_rrset_key* rrset, struct ub_packed_rrset_key* dnskey,
295a39a5a69SCy Schubert 	size_t dnskey_idx, char** reason, sldns_ede_code *reason_bogus,
296838e13ceSDag-Erling Smørgrav 	sldns_pkt_section section, struct module_qstate* qstate);
297b7579f77SDag-Erling Smørgrav 
298b7579f77SDag-Erling Smørgrav /**
299b7579f77SDag-Erling Smørgrav  * verify rrset, with specific dnskey(from set), for a specific rrsig
300b7579f77SDag-Erling Smørgrav  * @param region: scratch region used for temporary allocation.
301b7579f77SDag-Erling Smørgrav  * @param buf: scratch buffer used for canonicalized rrset data.
302b7579f77SDag-Erling Smørgrav  * @param ve: validator environment, date settings.
303b7579f77SDag-Erling Smørgrav  * @param now: current time for validation (can be overridden).
304b7579f77SDag-Erling Smørgrav  * @param rrset: to be validated.
305b7579f77SDag-Erling Smørgrav  * @param dnskey: DNSKEY rrset, keyset.
306b7579f77SDag-Erling Smørgrav  * @param dnskey_idx: which key from the rrset to try.
307b7579f77SDag-Erling Smørgrav  * @param sig_idx: which signature to try to validate.
308b7579f77SDag-Erling Smørgrav  * @param sortree: pass NULL at start, the sorted rrset order is returned.
309b7579f77SDag-Erling Smørgrav  * 	pass it again for the same rrset.
310b7579f77SDag-Erling Smørgrav  * @param buf_canon: if true, the buffer is already canonical.
311b7579f77SDag-Erling Smørgrav  * 	pass false at start. pass old value only for same rrset and same
312b7579f77SDag-Erling Smørgrav  * 	signature (but perhaps different key) for reuse.
313b7579f77SDag-Erling Smørgrav  * @param reason: if bogus, a string returned, fixed or alloced in scratch.
314a39a5a69SCy Schubert  * @param reason_bogus: EDE (8914) code paired with the reason of failure.
315838e13ceSDag-Erling Smørgrav  * @param section: section of packet where this rrset comes from.
316838e13ceSDag-Erling Smørgrav  * @param qstate: qstate with region.
317b7579f77SDag-Erling Smørgrav  * @return secure if this key signs this signature. unchecked on error or
318b7579f77SDag-Erling Smørgrav  *	bogus if it did not validate.
319b7579f77SDag-Erling Smørgrav  */
320b7579f77SDag-Erling Smørgrav enum sec_status dnskey_verify_rrset_sig(struct regional* region,
32117d15b25SDag-Erling Smørgrav         struct sldns_buffer* buf, struct val_env* ve, time_t now,
322b7579f77SDag-Erling Smørgrav         struct ub_packed_rrset_key* rrset, struct ub_packed_rrset_key* dnskey,
323b7579f77SDag-Erling Smørgrav         size_t dnskey_idx, size_t sig_idx,
324a39a5a69SCy Schubert         struct rbtree_type** sortree, int* buf_canon,
325a39a5a69SCy Schubert         char** reason, sldns_ede_code *reason_bogus,
326838e13ceSDag-Erling Smørgrav         sldns_pkt_section section, struct module_qstate* qstate);
327b7579f77SDag-Erling Smørgrav 
328b7579f77SDag-Erling Smørgrav /**
329b7579f77SDag-Erling Smørgrav  * canonical compare for two tree entries
330b7579f77SDag-Erling Smørgrav  */
331b7579f77SDag-Erling Smørgrav int canonical_tree_compare(const void* k1, const void* k2);
332b7579f77SDag-Erling Smørgrav 
33317d15b25SDag-Erling Smørgrav /**
33417d15b25SDag-Erling Smørgrav  * Compare two rrsets and see if they are the same, canonicalised.
33517d15b25SDag-Erling Smørgrav  * The rrsets are not altered.
33617d15b25SDag-Erling Smørgrav  * @param region: temporary region.
33717d15b25SDag-Erling Smørgrav  * @param k1: rrset1
33817d15b25SDag-Erling Smørgrav  * @param k2: rrset2
33917d15b25SDag-Erling Smørgrav  * @return true if equal.
34017d15b25SDag-Erling Smørgrav  */
34117d15b25SDag-Erling Smørgrav int rrset_canonical_equal(struct regional* region,
34217d15b25SDag-Erling Smørgrav 	struct ub_packed_rrset_key* k1, struct ub_packed_rrset_key* k2);
34317d15b25SDag-Erling Smørgrav 
3445469a995SCy Schubert /**
3455469a995SCy Schubert  * Canonicalize an rrset into the buffer.  For an auth zone record, so
3465469a995SCy Schubert  * this does not use a signature, or the RRSIG TTL or the wildcard label
3475469a995SCy Schubert  * count from the RRSIG.
3485469a995SCy Schubert  * @param region: temporary region.
3495469a995SCy Schubert  * @param buf: the buffer to use.
3505469a995SCy Schubert  * @param k: the rrset to insert.
3515469a995SCy Schubert  * @return false on alloc error.
3525469a995SCy Schubert  */
3535469a995SCy Schubert int rrset_canonicalize_to_buffer(struct regional* region,
3545469a995SCy Schubert 	struct sldns_buffer* buf, struct ub_packed_rrset_key* k);
3555469a995SCy Schubert 
356b7579f77SDag-Erling Smørgrav #endif /* VALIDATOR_VAL_SIGCRYPT_H */
357