Detect FPU by checking CPUID features.
[dragonfly.git] / contrib / bind-9.5.2 / lib / dns / rdata / generic / dlv_32769.c
blob957f038f87785e927f5134286e6b733e3d839888
1 /*
2 * Copyright (C) 2004, 2006, 2007 Internet Systems Consortium, Inc. ("ISC")
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
17 /* $Id: dlv_32769.c,v 1.6 2007/06/18 23:47:43 tbox Exp $ */
19 /* draft-ietf-dnsext-delegation-signer-05.txt */
21 #ifndef RDATA_GENERIC_DLV_32769_C
22 #define RDATA_GENERIC_DLV_32769_C
24 #define RRTYPE_DLV_ATTRIBUTES 0
26 #include <isc/sha1.h>
27 #include <isc/sha2.h>
29 #include <dns/ds.h>
32 static inline isc_result_t
33 fromtext_dlv(ARGS_FROMTEXT) {
34 isc_token_t token;
35 unsigned char c;
36 int length;
38 REQUIRE(type == 32769);
40 UNUSED(type);
41 UNUSED(rdclass);
42 UNUSED(origin);
43 UNUSED(options);
44 UNUSED(callbacks);
47 * Key tag.
49 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
50 ISC_FALSE));
51 if (token.value.as_ulong > 0xffffU)
52 RETTOK(ISC_R_RANGE);
53 RETERR(uint16_tobuffer(token.value.as_ulong, target));
56 * Algorithm.
58 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
59 ISC_FALSE));
60 if (token.value.as_ulong > 0xffU)
61 RETTOK(ISC_R_RANGE);
62 RETERR(uint8_tobuffer(token.value.as_ulong, target));
65 * Digest type.
67 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
68 ISC_FALSE));
69 if (token.value.as_ulong > 0xffU)
70 RETTOK(ISC_R_RANGE);
71 RETERR(uint8_tobuffer(token.value.as_ulong, target));
72 c = (unsigned char) token.value.as_ulong;
75 * Digest.
77 if (c == DNS_DSDIGEST_SHA1)
78 length = ISC_SHA1_DIGESTLENGTH;
79 else if (c == DNS_DSDIGEST_SHA256)
80 length = ISC_SHA256_DIGESTLENGTH;
81 else
82 length = -1;
83 return (isc_hex_tobuffer(lexer, target, -1));
86 static inline isc_result_t
87 totext_dlv(ARGS_TOTEXT) {
88 isc_region_t sr;
89 char buf[sizeof("64000 ")];
90 unsigned int n;
92 REQUIRE(rdata->type == 32769);
93 REQUIRE(rdata->length != 0);
95 UNUSED(tctx);
97 dns_rdata_toregion(rdata, &sr);
100 * Key tag.
102 n = uint16_fromregion(&sr);
103 isc_region_consume(&sr, 2);
104 sprintf(buf, "%u ", n);
105 RETERR(str_totext(buf, target));
108 * Algorithm.
110 n = uint8_fromregion(&sr);
111 isc_region_consume(&sr, 1);
112 sprintf(buf, "%u ", n);
113 RETERR(str_totext(buf, target));
116 * Digest type.
118 n = uint8_fromregion(&sr);
119 isc_region_consume(&sr, 1);
120 sprintf(buf, "%u", n);
121 RETERR(str_totext(buf, target));
124 * Digest.
126 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
127 RETERR(str_totext(" (", target));
128 RETERR(str_totext(tctx->linebreak, target));
129 RETERR(isc_hex_totext(&sr, tctx->width - 2, tctx->linebreak, target));
130 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
131 RETERR(str_totext(" )", target));
132 return (ISC_R_SUCCESS);
135 static inline isc_result_t
136 fromwire_dlv(ARGS_FROMWIRE) {
137 isc_region_t sr;
139 REQUIRE(type == 32769);
141 UNUSED(type);
142 UNUSED(rdclass);
143 UNUSED(dctx);
144 UNUSED(options);
146 isc_buffer_activeregion(source, &sr);
149 * Check digest lengths if we know them.
151 if (sr.length < 4 ||
152 (sr.base[3] == DNS_DSDIGEST_SHA1 &&
153 sr.length < 4 + ISC_SHA1_DIGESTLENGTH) ||
154 (sr.base[3] == DNS_DSDIGEST_SHA256 &&
155 sr.length < 4 + ISC_SHA256_DIGESTLENGTH))
156 return (ISC_R_UNEXPECTEDEND);
159 * Only copy digest lengths if we know them.
160 * If there is extra data dns_rdata_fromwire() will
161 * detect that.
163 if (sr.base[3] == DNS_DSDIGEST_SHA1)
164 sr.length = 4 + ISC_SHA1_DIGESTLENGTH;
165 else if (sr.base[3] == DNS_DSDIGEST_SHA256)
166 sr.length = 4 + ISC_SHA256_DIGESTLENGTH;
168 isc_buffer_forward(source, sr.length);
169 return (mem_tobuffer(target, sr.base, sr.length));
172 static inline isc_result_t
173 towire_dlv(ARGS_TOWIRE) {
174 isc_region_t sr;
176 REQUIRE(rdata->type == 32769);
177 REQUIRE(rdata->length != 0);
179 UNUSED(cctx);
181 dns_rdata_toregion(rdata, &sr);
182 return (mem_tobuffer(target, sr.base, sr.length));
185 static inline int
186 compare_dlv(ARGS_COMPARE) {
187 isc_region_t r1;
188 isc_region_t r2;
190 REQUIRE(rdata1->type == rdata2->type);
191 REQUIRE(rdata1->rdclass == rdata2->rdclass);
192 REQUIRE(rdata1->type == 32769);
193 REQUIRE(rdata1->length != 0);
194 REQUIRE(rdata2->length != 0);
196 dns_rdata_toregion(rdata1, &r1);
197 dns_rdata_toregion(rdata2, &r2);
198 return (isc_region_compare(&r1, &r2));
201 static inline isc_result_t
202 fromstruct_dlv(ARGS_FROMSTRUCT) {
203 dns_rdata_dlv_t *dlv = source;
205 REQUIRE(type == 32769);
206 REQUIRE(source != NULL);
207 REQUIRE(dlv->common.rdtype == type);
208 REQUIRE(dlv->common.rdclass == rdclass);
209 switch (dlv->digest_type) {
210 case DNS_DSDIGEST_SHA1:
211 REQUIRE(dlv->length == ISC_SHA1_DIGESTLENGTH);
212 break;
213 case DNS_DSDIGEST_SHA256:
214 REQUIRE(dlv->length == ISC_SHA256_DIGESTLENGTH);
215 break;
218 UNUSED(type);
219 UNUSED(rdclass);
221 RETERR(uint16_tobuffer(dlv->key_tag, target));
222 RETERR(uint8_tobuffer(dlv->algorithm, target));
223 RETERR(uint8_tobuffer(dlv->digest_type, target));
225 return (mem_tobuffer(target, dlv->digest, dlv->length));
228 static inline isc_result_t
229 tostruct_dlv(ARGS_TOSTRUCT) {
230 dns_rdata_dlv_t *dlv = target;
231 isc_region_t region;
233 REQUIRE(rdata->type == 32769);
234 REQUIRE(target != NULL);
235 REQUIRE(rdata->length != 0);
237 dlv->common.rdclass = rdata->rdclass;
238 dlv->common.rdtype = rdata->type;
239 ISC_LINK_INIT(&dlv->common, link);
241 dns_rdata_toregion(rdata, &region);
243 dlv->key_tag = uint16_fromregion(&region);
244 isc_region_consume(&region, 2);
245 dlv->algorithm = uint8_fromregion(&region);
246 isc_region_consume(&region, 1);
247 dlv->digest_type = uint8_fromregion(&region);
248 isc_region_consume(&region, 1);
249 dlv->length = region.length;
251 dlv->digest = mem_maybedup(mctx, region.base, region.length);
252 if (dlv->digest == NULL)
253 return (ISC_R_NOMEMORY);
255 dlv->mctx = mctx;
256 return (ISC_R_SUCCESS);
259 static inline void
260 freestruct_dlv(ARGS_FREESTRUCT) {
261 dns_rdata_dlv_t *dlv = source;
263 REQUIRE(dlv != NULL);
264 REQUIRE(dlv->common.rdtype == 32769);
266 if (dlv->mctx == NULL)
267 return;
269 if (dlv->digest != NULL)
270 isc_mem_free(dlv->mctx, dlv->digest);
271 dlv->mctx = NULL;
274 static inline isc_result_t
275 additionaldata_dlv(ARGS_ADDLDATA) {
276 REQUIRE(rdata->type == 32769);
278 UNUSED(rdata);
279 UNUSED(add);
280 UNUSED(arg);
282 return (ISC_R_SUCCESS);
285 static inline isc_result_t
286 digest_dlv(ARGS_DIGEST) {
287 isc_region_t r;
289 REQUIRE(rdata->type == 32769);
291 dns_rdata_toregion(rdata, &r);
293 return ((digest)(arg, &r));
296 static inline isc_boolean_t
297 checkowner_dlv(ARGS_CHECKOWNER) {
299 REQUIRE(type == 32769);
301 UNUSED(name);
302 UNUSED(type);
303 UNUSED(rdclass);
304 UNUSED(wildcard);
306 return (ISC_TRUE);
309 static inline isc_boolean_t
310 checknames_dlv(ARGS_CHECKNAMES) {
312 REQUIRE(rdata->type == 32769);
314 UNUSED(rdata);
315 UNUSED(owner);
316 UNUSED(bad);
318 return (ISC_TRUE);
321 #endif /* RDATA_GENERIC_DLV_32769_C */