Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / dns / rdata / generic / cds_59.c
blob65c686d89573872c3ad355596dae8add0b8b6483
1 /* $NetBSD: cds_59.c,v 1.1.1.4 2015/07/08 15:38:03 christos Exp $ */
3 /*
4 * Copyright (C) 2014, 2015 Internet Systems Consortium, Inc. ("ISC")
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
19 /* draft-ietf-dnsop-delegation-trust-maintainance-14 */
21 #ifndef RDATA_GENERIC_CDS_59_C
22 #define RDATA_GENERIC_CDS_59_C
24 #define RRTYPE_CDS_ATTRIBUTES 0
26 #include <isc/sha1.h>
27 #include <isc/sha2.h>
29 #include <dns/ds.h>
31 #include "dst_gost.h"
33 static inline isc_result_t
34 fromtext_cds(ARGS_FROMTEXT) {
35 isc_token_t token;
36 unsigned char c;
37 int length;
39 REQUIRE(type == 59);
41 UNUSED(type);
42 UNUSED(rdclass);
43 UNUSED(origin);
44 UNUSED(options);
45 UNUSED(callbacks);
48 * Key tag.
50 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
51 ISC_FALSE));
52 if (token.value.as_ulong > 0xffffU)
53 RETTOK(ISC_R_RANGE);
54 RETERR(uint16_tobuffer(token.value.as_ulong, target));
57 * Algorithm.
59 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
60 ISC_FALSE));
61 RETTOK(dns_secalg_fromtext(&c, &token.value.as_textregion));
62 RETERR(mem_tobuffer(target, &c, 1));
65 * Digest type.
67 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
68 ISC_FALSE));
69 RETTOK(dns_dsdigest_fromtext(&c, &token.value.as_textregion));
70 RETERR(mem_tobuffer(target, &c, 1));
73 * Digest.
75 switch (c) {
76 case DNS_DSDIGEST_SHA1:
77 length = ISC_SHA1_DIGESTLENGTH;
78 break;
79 case DNS_DSDIGEST_SHA256:
80 length = ISC_SHA256_DIGESTLENGTH;
81 break;
82 #ifdef ISC_GOST_DIGESTLENGTH
83 case DNS_DSDIGEST_GOST:
84 length = ISC_GOST_DIGESTLENGTH;
85 break;
86 #endif
87 case DNS_DSDIGEST_SHA384:
88 length = ISC_SHA384_DIGESTLENGTH;
89 break;
90 default:
91 length = -1;
92 break;
94 return (isc_hex_tobuffer(lexer, target, length));
97 static inline isc_result_t
98 totext_cds(ARGS_TOTEXT) {
99 isc_region_t sr;
100 char buf[sizeof("64000 ")];
101 unsigned int n;
103 REQUIRE(rdata->type == 59);
104 REQUIRE(rdata->length != 0);
106 UNUSED(tctx);
108 dns_rdata_toregion(rdata, &sr);
111 * Key tag.
113 n = uint16_fromregion(&sr);
114 isc_region_consume(&sr, 2);
115 sprintf(buf, "%u ", n);
116 RETERR(str_totext(buf, target));
119 * Algorithm.
121 n = uint8_fromregion(&sr);
122 isc_region_consume(&sr, 1);
123 sprintf(buf, "%u ", n);
124 RETERR(str_totext(buf, target));
127 * Digest type.
129 n = uint8_fromregion(&sr);
130 isc_region_consume(&sr, 1);
131 sprintf(buf, "%u", n);
132 RETERR(str_totext(buf, target));
135 * Digest.
137 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
138 RETERR(str_totext(" (", target));
139 RETERR(str_totext(tctx->linebreak, target));
140 if ((tctx->flags & DNS_STYLEFLAG_NOCRYPTO) == 0) {
141 if (tctx->width == 0) /* No splitting */
142 RETERR(isc_hex_totext(&sr, 0, "", target));
143 else
144 RETERR(isc_hex_totext(&sr, tctx->width - 2,
145 tctx->linebreak, target));
146 } else
147 RETERR(str_totext("[omitted]", target));
148 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
149 RETERR(str_totext(" )", target));
150 return (ISC_R_SUCCESS);
153 static inline isc_result_t
154 fromwire_cds(ARGS_FROMWIRE) {
155 isc_region_t sr;
157 REQUIRE(type == 59);
159 UNUSED(type);
160 UNUSED(rdclass);
161 UNUSED(dctx);
162 UNUSED(options);
164 isc_buffer_activeregion(source, &sr);
167 * Check digest lengths if we know them.
169 if (sr.length < 4 ||
170 (sr.base[3] == DNS_DSDIGEST_SHA1 &&
171 sr.length < 4 + ISC_SHA1_DIGESTLENGTH) ||
172 (sr.base[3] == DNS_DSDIGEST_SHA256 &&
173 sr.length < 4 + ISC_SHA256_DIGESTLENGTH) ||
174 #ifdef ISC_GOST_DIGESTLENGTH
175 (sr.base[3] == DNS_DSDIGEST_GOST &&
176 sr.length < 4 + ISC_GOST_DIGESTLENGTH) ||
177 #endif
178 (sr.base[3] == DNS_DSDIGEST_SHA384 &&
179 sr.length < 4 + ISC_SHA384_DIGESTLENGTH))
180 return (ISC_R_UNEXPECTEDEND);
183 * Only copy digest lengths if we know them.
184 * If there is extra data dns_rdata_fromwire() will
185 * detect that.
187 if (sr.base[3] == DNS_DSDIGEST_SHA1)
188 sr.length = 4 + ISC_SHA1_DIGESTLENGTH;
189 else if (sr.base[3] == DNS_DSDIGEST_SHA256)
190 sr.length = 4 + ISC_SHA256_DIGESTLENGTH;
191 #ifdef ISC_GOST_DIGESTLENGTH
192 else if (sr.base[3] == DNS_DSDIGEST_GOST)
193 sr.length = 4 + ISC_GOST_DIGESTLENGTH;
194 #endif
195 else if (sr.base[3] == DNS_DSDIGEST_SHA384)
196 sr.length = 4 + ISC_SHA384_DIGESTLENGTH;
198 isc_buffer_forward(source, sr.length);
199 return (mem_tobuffer(target, sr.base, sr.length));
202 static inline isc_result_t
203 towire_cds(ARGS_TOWIRE) {
204 isc_region_t sr;
206 REQUIRE(rdata->type == 59);
207 REQUIRE(rdata->length != 0);
209 UNUSED(cctx);
211 dns_rdata_toregion(rdata, &sr);
212 return (mem_tobuffer(target, sr.base, sr.length));
215 static inline int
216 compare_cds(ARGS_COMPARE) {
217 isc_region_t r1;
218 isc_region_t r2;
220 REQUIRE(rdata1->type == rdata2->type);
221 REQUIRE(rdata1->rdclass == rdata2->rdclass);
222 REQUIRE(rdata1->type == 59);
223 REQUIRE(rdata1->length != 0);
224 REQUIRE(rdata2->length != 0);
226 dns_rdata_toregion(rdata1, &r1);
227 dns_rdata_toregion(rdata2, &r2);
228 return (isc_region_compare(&r1, &r2));
231 static inline isc_result_t
232 fromstruct_cds(ARGS_FROMSTRUCT) {
233 dns_rdata_cds_t *ds = source;
235 REQUIRE(type == 59);
236 REQUIRE(source != NULL);
237 REQUIRE(ds->common.rdtype == type);
238 REQUIRE(ds->common.rdclass == rdclass);
239 switch (ds->digest_type) {
240 case DNS_DSDIGEST_SHA1:
241 REQUIRE(ds->length == ISC_SHA1_DIGESTLENGTH);
242 break;
243 case DNS_DSDIGEST_SHA256:
244 REQUIRE(ds->length == ISC_SHA256_DIGESTLENGTH);
245 break;
246 #ifdef ISC_GOST_DIGESTLENGTH
247 case DNS_DSDIGEST_GOST:
248 REQUIRE(ds->length == ISC_GOST_DIGESTLENGTH);
249 break;
250 #endif
251 case DNS_DSDIGEST_SHA384:
252 REQUIRE(ds->length == ISC_SHA384_DIGESTLENGTH);
253 break;
256 UNUSED(type);
257 UNUSED(rdclass);
259 RETERR(uint16_tobuffer(ds->key_tag, target));
260 RETERR(uint8_tobuffer(ds->algorithm, target));
261 RETERR(uint8_tobuffer(ds->digest_type, target));
263 return (mem_tobuffer(target, ds->digest, ds->length));
266 static inline isc_result_t
267 tostruct_cds(ARGS_TOSTRUCT) {
268 dns_rdata_cds_t *ds = target;
269 isc_region_t region;
271 REQUIRE(rdata->type == 59);
272 REQUIRE(target != NULL);
273 REQUIRE(rdata->length != 0);
275 ds->common.rdclass = rdata->rdclass;
276 ds->common.rdtype = rdata->type;
277 ISC_LINK_INIT(&ds->common, link);
279 dns_rdata_toregion(rdata, &region);
281 ds->key_tag = uint16_fromregion(&region);
282 isc_region_consume(&region, 2);
283 ds->algorithm = uint8_fromregion(&region);
284 isc_region_consume(&region, 1);
285 ds->digest_type = uint8_fromregion(&region);
286 isc_region_consume(&region, 1);
287 ds->length = region.length;
289 ds->digest = mem_maybedup(mctx, region.base, region.length);
290 if (ds->digest == NULL)
291 return (ISC_R_NOMEMORY);
293 ds->mctx = mctx;
294 return (ISC_R_SUCCESS);
297 static inline void
298 freestruct_cds(ARGS_FREESTRUCT) {
299 dns_rdata_cds_t *ds = source;
301 REQUIRE(ds != NULL);
302 REQUIRE(ds->common.rdtype == 59);
304 if (ds->mctx == NULL)
305 return;
307 if (ds->digest != NULL)
308 isc_mem_free(ds->mctx, ds->digest);
309 ds->mctx = NULL;
312 static inline isc_result_t
313 additionaldata_cds(ARGS_ADDLDATA) {
314 REQUIRE(rdata->type == 59);
316 UNUSED(rdata);
317 UNUSED(add);
318 UNUSED(arg);
320 return (ISC_R_SUCCESS);
323 static inline isc_result_t
324 digest_cds(ARGS_DIGEST) {
325 isc_region_t r;
327 REQUIRE(rdata->type == 59);
329 dns_rdata_toregion(rdata, &r);
331 return ((digest)(arg, &r));
334 static inline isc_boolean_t
335 checkowner_cds(ARGS_CHECKOWNER) {
337 REQUIRE(type == 59);
339 UNUSED(name);
340 UNUSED(type);
341 UNUSED(rdclass);
342 UNUSED(wildcard);
344 return (ISC_TRUE);
347 static inline isc_boolean_t
348 checknames_cds(ARGS_CHECKNAMES) {
350 REQUIRE(rdata->type == 59);
352 UNUSED(rdata);
353 UNUSED(owner);
354 UNUSED(bad);
356 return (ISC_TRUE);
359 static inline int
360 casecompare_cds(ARGS_COMPARE) {
361 return (compare_cds(rdata1, rdata2));
364 #endif /* RDATA_GENERIC_CDS_59_C */