Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / dns / rdata / generic / nsec3param_51.c
blob8de54f4a766f550ed31753792bebdda25383d1e6
1 /* $NetBSD: nsec3param_51.c,v 1.4 2014/12/10 04:37:59 christos Exp $ */
3 /*
4 * Copyright (C) 2008, 2009 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 /* Id: nsec3param_51.c,v 1.7 2009/12/04 21:09:34 marka Exp */
22 * Copyright (C) 2004 Nominet, Ltd.
24 * Permission to use, copy, modify, and distribute this software for any
25 * purpose with or without fee is hereby granted, provided that the above
26 * copyright notice and this permission notice appear in all copies.
28 * THE SOFTWARE IS PROVIDED "AS IS" AND NOMINET DISCLAIMS ALL WARRANTIES WITH
29 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
30 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
31 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
32 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
33 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
34 * PERFORMANCE OF THIS SOFTWARE.
37 /* RFC 5155 */
39 #ifndef RDATA_GENERIC_NSEC3PARAM_51_C
40 #define RDATA_GENERIC_NSEC3PARAM_51_C
42 #include <isc/iterated_hash.h>
43 #include <isc/base32.h>
45 #define RRTYPE_NSEC3PARAM_ATTRIBUTES (DNS_RDATATYPEATTR_DNSSEC)
47 static inline isc_result_t
48 fromtext_nsec3param(ARGS_FROMTEXT) {
49 isc_token_t token;
50 unsigned int flags = 0;
51 unsigned char hashalg;
53 REQUIRE(type == 51);
55 UNUSED(type);
56 UNUSED(rdclass);
57 UNUSED(callbacks);
58 UNUSED(origin);
59 UNUSED(options);
61 /* Hash. */
62 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
63 ISC_FALSE));
64 RETTOK(dns_hashalg_fromtext(&hashalg, &token.value.as_textregion));
65 RETERR(uint8_tobuffer(hashalg, target));
67 /* Flags. */
68 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
69 ISC_FALSE));
70 flags = token.value.as_ulong;
71 if (flags > 255U)
72 RETTOK(ISC_R_RANGE);
73 RETERR(uint8_tobuffer(flags, target));
75 /* Iterations. */
76 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
77 ISC_FALSE));
78 if (token.value.as_ulong > 0xffffU)
79 RETTOK(ISC_R_RANGE);
80 RETERR(uint16_tobuffer(token.value.as_ulong, target));
82 /* Salt. */
83 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
84 ISC_FALSE));
85 if (token.value.as_textregion.length > (255*2))
86 RETTOK(DNS_R_TEXTTOOLONG);
87 if (strcmp(DNS_AS_STR(token), "-") == 0) {
88 RETERR(uint8_tobuffer(0, target));
89 } else {
90 RETERR(uint8_tobuffer(strlen(DNS_AS_STR(token)) / 2, target));
91 RETERR(isc_hex_decodestring(DNS_AS_STR(token), target));
94 return (ISC_R_SUCCESS);
97 static inline isc_result_t
98 totext_nsec3param(ARGS_TOTEXT) {
99 isc_region_t sr;
100 unsigned int i, j;
101 unsigned char hash;
102 unsigned char flags;
103 char buf[sizeof("65535 ")];
104 isc_uint32_t iterations;
106 REQUIRE(rdata->type == 51);
107 REQUIRE(rdata->length != 0);
109 UNUSED(tctx);
111 dns_rdata_toregion(rdata, &sr);
113 hash = uint8_fromregion(&sr);
114 isc_region_consume(&sr, 1);
116 flags = uint8_fromregion(&sr);
117 isc_region_consume(&sr, 1);
119 iterations = uint16_fromregion(&sr);
120 isc_region_consume(&sr, 2);
122 sprintf(buf, "%u ", hash);
123 RETERR(str_totext(buf, target));
125 sprintf(buf, "%u ", flags);
126 RETERR(str_totext(buf, target));
128 sprintf(buf, "%u ", iterations);
129 RETERR(str_totext(buf, target));
131 j = uint8_fromregion(&sr);
132 isc_region_consume(&sr, 1);
133 INSIST(j <= sr.length);
135 if (j != 0) {
136 i = sr.length;
137 sr.length = j;
138 RETERR(isc_hex_totext(&sr, 1, "", target));
139 sr.length = i - j;
140 } else
141 RETERR(str_totext("-", target));
143 return (ISC_R_SUCCESS);
146 static inline isc_result_t
147 fromwire_nsec3param(ARGS_FROMWIRE) {
148 isc_region_t sr, rr;
149 unsigned int saltlen;
151 REQUIRE(type == 51);
153 UNUSED(type);
154 UNUSED(rdclass);
155 UNUSED(options);
156 UNUSED(dctx);
158 isc_buffer_activeregion(source, &sr);
159 rr = sr;
161 /* hash(1), flags(1), iterations(2), saltlen(1) */
162 if (sr.length < 5U)
163 RETERR(DNS_R_FORMERR);
164 saltlen = sr.base[4];
165 isc_region_consume(&sr, 5);
167 if (sr.length < saltlen)
168 RETERR(DNS_R_FORMERR);
169 isc_region_consume(&sr, saltlen);
170 RETERR(mem_tobuffer(target, rr.base, rr.length));
171 isc_buffer_forward(source, rr.length);
172 return (ISC_R_SUCCESS);
175 static inline isc_result_t
176 towire_nsec3param(ARGS_TOWIRE) {
177 isc_region_t sr;
179 REQUIRE(rdata->type == 51);
180 REQUIRE(rdata->length != 0);
182 UNUSED(cctx);
184 dns_rdata_toregion(rdata, &sr);
185 return (mem_tobuffer(target, sr.base, sr.length));
188 static inline int
189 compare_nsec3param(ARGS_COMPARE) {
190 isc_region_t r1;
191 isc_region_t r2;
193 REQUIRE(rdata1->type == rdata2->type);
194 REQUIRE(rdata1->rdclass == rdata2->rdclass);
195 REQUIRE(rdata1->type == 51);
196 REQUIRE(rdata1->length != 0);
197 REQUIRE(rdata2->length != 0);
199 dns_rdata_toregion(rdata1, &r1);
200 dns_rdata_toregion(rdata2, &r2);
201 return (isc_region_compare(&r1, &r2));
204 static inline isc_result_t
205 fromstruct_nsec3param(ARGS_FROMSTRUCT) {
206 dns_rdata_nsec3param_t *nsec3param = source;
208 REQUIRE(type == 51);
209 REQUIRE(source != NULL);
210 REQUIRE(nsec3param->common.rdtype == type);
211 REQUIRE(nsec3param->common.rdclass == rdclass);
213 UNUSED(type);
214 UNUSED(rdclass);
216 RETERR(uint8_tobuffer(nsec3param->hash, target));
217 RETERR(uint8_tobuffer(nsec3param->flags, target));
218 RETERR(uint16_tobuffer(nsec3param->iterations, target));
219 RETERR(uint8_tobuffer(nsec3param->salt_length, target));
220 RETERR(mem_tobuffer(target, nsec3param->salt,
221 nsec3param->salt_length));
222 return (ISC_R_SUCCESS);
225 static inline isc_result_t
226 tostruct_nsec3param(ARGS_TOSTRUCT) {
227 isc_region_t region;
228 dns_rdata_nsec3param_t *nsec3param = target;
230 REQUIRE(rdata->type == 51);
231 REQUIRE(target != NULL);
232 REQUIRE(rdata->length != 0);
234 nsec3param->common.rdclass = rdata->rdclass;
235 nsec3param->common.rdtype = rdata->type;
236 ISC_LINK_INIT(&nsec3param->common, link);
238 region.base = rdata->data;
239 region.length = rdata->length;
240 nsec3param->hash = uint8_consume_fromregion(&region);
241 nsec3param->flags = uint8_consume_fromregion(&region);
242 nsec3param->iterations = uint16_consume_fromregion(&region);
244 nsec3param->salt_length = uint8_consume_fromregion(&region);
245 nsec3param->salt = mem_maybedup(mctx, region.base,
246 nsec3param->salt_length);
247 if (nsec3param->salt == NULL)
248 return (ISC_R_NOMEMORY);
249 isc_region_consume(&region, nsec3param->salt_length);
251 nsec3param->mctx = mctx;
252 return (ISC_R_SUCCESS);
255 static inline void
256 freestruct_nsec3param(ARGS_FREESTRUCT) {
257 dns_rdata_nsec3param_t *nsec3param = source;
259 REQUIRE(source != NULL);
260 REQUIRE(nsec3param->common.rdtype == 51);
262 if (nsec3param->mctx == NULL)
263 return;
265 if (nsec3param->salt != NULL)
266 isc_mem_free(nsec3param->mctx, nsec3param->salt);
267 nsec3param->mctx = NULL;
270 static inline isc_result_t
271 additionaldata_nsec3param(ARGS_ADDLDATA) {
272 REQUIRE(rdata->type == 51);
274 UNUSED(rdata);
275 UNUSED(add);
276 UNUSED(arg);
278 return (ISC_R_SUCCESS);
281 static inline isc_result_t
282 digest_nsec3param(ARGS_DIGEST) {
283 isc_region_t r;
285 REQUIRE(rdata->type == 51);
287 dns_rdata_toregion(rdata, &r);
288 return ((digest)(arg, &r));
291 static inline isc_boolean_t
292 checkowner_nsec3param(ARGS_CHECKOWNER) {
294 REQUIRE(type == 51);
296 UNUSED(name);
297 UNUSED(type);
298 UNUSED(rdclass);
299 UNUSED(wildcard);
301 return (ISC_TRUE);
304 static inline isc_boolean_t
305 checknames_nsec3param(ARGS_CHECKNAMES) {
307 REQUIRE(rdata->type == 51);
309 UNUSED(rdata);
310 UNUSED(owner);
311 UNUSED(bad);
313 return (ISC_TRUE);
316 static inline int
317 casecompare_nsec3param(ARGS_COMPARE) {
318 return (compare_nsec3param(rdata1, rdata2));
321 #endif /* RDATA_GENERIC_NSEC3PARAM_51_C */