ds_43.c revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff/*
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * Copyright (C) 2002, 2004, 2005, 2007, 2009-2016 Internet Systems Consortium, Inc. ("ISC")
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff *
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * This Source Code Form is subject to the terms of the Mozilla Public
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * License, v. 2.0. If a copy of the MPL was not distributed with this
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * file, You can obtain one at http://mozilla.org/MPL/2.0/.
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff */
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff/* $Id$ */
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff/* RFC3658 */
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff#ifndef RDATA_GENERIC_DS_43_C
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff#define RDATA_GENERIC_DS_43_C
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff#define RRTYPE_DS_ATTRIBUTES \
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff (DNS_RDATATYPEATTR_DNSSEC|DNS_RDATATYPEATTR_ATPARENT)
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff#include <isc/sha1.h>
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff#include <isc/sha2.h>
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
c803787146cadcb2d7e10cbf4491f3be513dfa1aMichael Graff#include <dns/ds.h>
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff#include "dst_gost.h"
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graffstatic inline isc_result_t
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graffgeneric_fromtext_ds(ARGS_FROMTEXT) {
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff isc_token_t token;
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff unsigned char c;
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff int length;
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff UNUSED(type);
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff UNUSED(rdclass);
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graff UNUSED(origin);
f181f94ec8da8b1dbcc6353e8be965ea4a5ea282Michael Graff UNUSED(options);
21e7034ec046105c00a0dab86c83732e2e77ad99Michael Graff UNUSED(callbacks);
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff /*
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff * Key tag.
f181f94ec8da8b1dbcc6353e8be965ea4a5ea282Michael Graff */
3ac63b472022ff92691d1fe69ac715a729671965Michael Graff RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff ISC_FALSE));
fe14eafefa91fada7cea0a55b09196c01477406cBob Halley if (token.value.as_ulong > 0xffffU)
e45d323a2a0f4ca08d4b139546e60a5fa7bd3f0cMichael Graff RETTOK(ISC_R_RANGE);
29f28fe573d4b3b318b3b026d567c1eb86738015Michael Graff RETERR(uint16_tobuffer(token.value.as_ulong, target));
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graff
11efdeb076d65fa9f0c5fc067dc040e7c99dfba6Michael Graff /*
21e7034ec046105c00a0dab86c83732e2e77ad99Michael Graff * Algorithm.
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff */
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graff RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graff ISC_FALSE));
11efdeb076d65fa9f0c5fc067dc040e7c99dfba6Michael Graff RETTOK(dns_secalg_fromtext(&c, &token.value.as_textregion));
11efdeb076d65fa9f0c5fc067dc040e7c99dfba6Michael Graff RETERR(mem_tobuffer(target, &c, 1));
439c0011e642fb1d26011116144af698125262dbMichael Graff
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff /*
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * Digest type.
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff */
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff ISC_FALSE));
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff RETTOK(dns_dsdigest_fromtext(&c, &token.value.as_textregion));
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff RETERR(mem_tobuffer(target, &c, 1));
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff /*
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff * Digest.
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff */
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff switch (c) {
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff case DNS_DSDIGEST_SHA1:
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff length = ISC_SHA1_DIGESTLENGTH;
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff break;
fe14eafefa91fada7cea0a55b09196c01477406cBob Halley case DNS_DSDIGEST_SHA256:
fe14eafefa91fada7cea0a55b09196c01477406cBob Halley length = ISC_SHA256_DIGESTLENGTH;
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff break;
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff#ifdef ISC_GOST_DIGESTLENGTH
ebdd11e84734e28ddd64562e82a7c646a58a04f4Michael Graff case DNS_DSDIGEST_GOST:
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff length = ISC_GOST_DIGESTLENGTH;
ebdd11e84734e28ddd64562e82a7c646a58a04f4Michael Graff break;
ebdd11e84734e28ddd64562e82a7c646a58a04f4Michael Graff#endif
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff case DNS_DSDIGEST_SHA384:
84c46a7acb961cac19c0d857bfdd00f3383a9bc6Michael Graff length = ISC_SHA384_DIGESTLENGTH;
84c46a7acb961cac19c0d857bfdd00f3383a9bc6Michael Graff break;
3ac63b472022ff92691d1fe69ac715a729671965Michael Graff default:
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff length = -1;
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff break;
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff }
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff return (isc_hex_tobuffer(lexer, target, length));
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff}
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graffstatic inline isc_result_t
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Grafffromtext_ds(ARGS_FROMTEXT) {
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff REQUIRE(type == dns_rdatatype_ds);
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff
fe14eafefa91fada7cea0a55b09196c01477406cBob Halley return (generic_fromtext_ds(rdclass, type, lexer, origin, options,
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff target, callbacks));
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff}
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graffstatic inline isc_result_t
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graffgeneric_totext_ds(ARGS_TOTEXT) {
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff isc_region_t sr;
439c0011e642fb1d26011116144af698125262dbMichael Graff char buf[sizeof("64000 ")];
11efdeb076d65fa9f0c5fc067dc040e7c99dfba6Michael Graff unsigned int n;
3ac63b472022ff92691d1fe69ac715a729671965Michael Graff
11efdeb076d65fa9f0c5fc067dc040e7c99dfba6Michael Graff REQUIRE(rdata->length != 0);
3ac63b472022ff92691d1fe69ac715a729671965Michael Graff
84c46a7acb961cac19c0d857bfdd00f3383a9bc6Michael Graff UNUSED(tctx);
3ac63b472022ff92691d1fe69ac715a729671965Michael Graff
84c46a7acb961cac19c0d857bfdd00f3383a9bc6Michael Graff dns_rdata_toregion(rdata, &sr);
84c46a7acb961cac19c0d857bfdd00f3383a9bc6Michael Graff
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff /*
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff * Key tag.
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff */
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graff n = uint16_fromregion(&sr);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff isc_region_consume(&sr, 2);
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff sprintf(buf, "%u ", n);
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff RETERR(str_totext(buf, target));
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff /*
2992344aacdb08e4af936c176d49ef789f5673ddMichael Graff * Algorithm.
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff */
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff n = uint8_fromregion(&sr);
fe14eafefa91fada7cea0a55b09196c01477406cBob Halley isc_region_consume(&sr, 1);
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff sprintf(buf, "%u ", n);
f181f94ec8da8b1dbcc6353e8be965ea4a5ea282Michael Graff RETERR(str_totext(buf, target));
f181f94ec8da8b1dbcc6353e8be965ea4a5ea282Michael Graff
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff /*
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff * Digest type.
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff */
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff n = uint8_fromregion(&sr);
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff isc_region_consume(&sr, 1);
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff sprintf(buf, "%u", n);
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff RETERR(str_totext(buf, target));
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff /*
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff * Digest.
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff */
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff RETERR(str_totext(" (", target));
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff RETERR(str_totext(tctx->linebreak, target));
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff if ((tctx->flags & DNS_STYLEFLAG_NOCRYPTO) == 0) {
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff if (tctx->width == 0) /* No splitting */
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff RETERR(isc_hex_totext(&sr, 0, "", target));
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff else
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff RETERR(isc_hex_totext(&sr, tctx->width - 2,
1f90c108282533a23b8362c34bcde4267c1eb4b1Michael Graff tctx->linebreak, target));
4281fe4a80af7402613f0d5c3eeff8829a4ede1fMichael Graff } else
ebdd11e84734e28ddd64562e82a7c646a58a04f4Michael Graff RETERR(str_totext("[omitted]", target));
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff RETERR(str_totext(" )", target));
fe14eafefa91fada7cea0a55b09196c01477406cBob Halley return (ISC_R_SUCCESS);
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff}
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff
59e22acc4f79ff481f7bfa46ef0558957ae53cfcMichael Graffstatic inline isc_result_t
59e22acc4f79ff481f7bfa46ef0558957ae53cfcMichael Grafftotext_ds(ARGS_TOTEXT) {
fe14eafefa91fada7cea0a55b09196c01477406cBob Halley
c803787146cadcb2d7e10cbf4491f3be513dfa1aMichael Graff REQUIRE(rdata->type == dns_rdatatype_ds);
d43c2cc7bc4022701f141e299ea8f3fb1d0640c2Michael Graff
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff return (generic_totext_ds(rdata, tctx, target));
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff}
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graffstatic inline isc_result_t
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graffgeneric_fromwire_ds(ARGS_FROMWIRE) {
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff isc_region_t sr;
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff UNUSED(type);
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff UNUSED(rdclass);
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff UNUSED(dctx);
fe14eafefa91fada7cea0a55b09196c01477406cBob Halley UNUSED(options);
fe14eafefa91fada7cea0a55b09196c01477406cBob Halley
14b98cb34eda66c87ce41a207704a2c232280eafMichael Graff isc_buffer_activeregion(source, &sr);
fe14eafefa91fada7cea0a55b09196c01477406cBob Halley
fe14eafefa91fada7cea0a55b09196c01477406cBob Halley /*
fe14eafefa91fada7cea0a55b09196c01477406cBob Halley * Check digest lengths if we know them.
fe14eafefa91fada7cea0a55b09196c01477406cBob Halley */
fe14eafefa91fada7cea0a55b09196c01477406cBob Halley if (sr.length < 4 ||
fe14eafefa91fada7cea0a55b09196c01477406cBob Halley (sr.base[3] == DNS_DSDIGEST_SHA1 &&
fe14eafefa91fada7cea0a55b09196c01477406cBob Halley sr.length < 4 + ISC_SHA1_DIGESTLENGTH) ||
fe14eafefa91fada7cea0a55b09196c01477406cBob Halley (sr.base[3] == DNS_DSDIGEST_SHA256 &&
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff sr.length < 4 + ISC_SHA256_DIGESTLENGTH) ||
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff#ifdef ISC_GOST_DIGESTLENGTH
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff (sr.base[3] == DNS_DSDIGEST_GOST &&
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff sr.length < 4 + ISC_GOST_DIGESTLENGTH) ||
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff#endif
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff (sr.base[3] == DNS_DSDIGEST_SHA384 &&
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff sr.length < 4 + ISC_SHA384_DIGESTLENGTH))
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff return (ISC_R_UNEXPECTEDEND);
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff /*
d43c2cc7bc4022701f141e299ea8f3fb1d0640c2Michael Graff * Only copy digest lengths if we know them.
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * If there is extra data dns_rdata_fromwire() will
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * detect that.
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff */
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff if (sr.base[3] == DNS_DSDIGEST_SHA1)
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff sr.length = 4 + ISC_SHA1_DIGESTLENGTH;
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff else if (sr.base[3] == DNS_DSDIGEST_SHA256)
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff sr.length = 4 + ISC_SHA256_DIGESTLENGTH;
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff#ifdef ISC_GOST_DIGESTLENGTH
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff else if (sr.base[3] == DNS_DSDIGEST_GOST)
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff sr.length = 4 + ISC_GOST_DIGESTLENGTH;
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff#endif
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff else if (sr.base[3] == DNS_DSDIGEST_SHA384)
439c0011e642fb1d26011116144af698125262dbMichael Graff sr.length = 4 + ISC_SHA384_DIGESTLENGTH;
d8590892d10fc9528b0dde7e2781935e7b8d7a87Michael Graff
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff isc_buffer_forward(source, sr.length);
d43c2cc7bc4022701f141e299ea8f3fb1d0640c2Michael Graff return (mem_tobuffer(target, sr.base, sr.length));
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff}
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graffstatic inline isc_result_t
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Grafffromwire_ds(ARGS_FROMWIRE) {
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff REQUIRE(type == dns_rdatatype_ds);
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff return (generic_fromwire_ds(rdclass, type, source, dctx, options,
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff target));
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff}
439c0011e642fb1d26011116144af698125262dbMichael Graff
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graffstatic inline isc_result_t
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Grafftowire_ds(ARGS_TOWIRE) {
f181f94ec8da8b1dbcc6353e8be965ea4a5ea282Michael Graff isc_region_t sr;
f181f94ec8da8b1dbcc6353e8be965ea4a5ea282Michael Graff
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff REQUIRE(rdata->type == dns_rdatatype_ds);
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff REQUIRE(rdata->length != 0);
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff UNUSED(cctx);
d43c2cc7bc4022701f141e299ea8f3fb1d0640c2Michael Graff
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff dns_rdata_toregion(rdata, &sr);
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff return (mem_tobuffer(target, sr.base, sr.length));
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff}
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graffstatic inline int
d8590892d10fc9528b0dde7e2781935e7b8d7a87Michael Graffcompare_ds(ARGS_COMPARE) {
439c0011e642fb1d26011116144af698125262dbMichael Graff isc_region_t r1;
439c0011e642fb1d26011116144af698125262dbMichael Graff isc_region_t r2;
439c0011e642fb1d26011116144af698125262dbMichael Graff
439c0011e642fb1d26011116144af698125262dbMichael Graff REQUIRE(rdata1->type == rdata2->type);
f36a81c88493985ee2d1c53cc6fe88f4b00dbbc8Michael Graff REQUIRE(rdata1->rdclass == rdata2->rdclass);
439c0011e642fb1d26011116144af698125262dbMichael Graff REQUIRE(rdata1->type == dns_rdatatype_ds);
439c0011e642fb1d26011116144af698125262dbMichael Graff REQUIRE(rdata1->length != 0);
439c0011e642fb1d26011116144af698125262dbMichael Graff REQUIRE(rdata2->length != 0);
c803787146cadcb2d7e10cbf4491f3be513dfa1aMichael Graff
c803787146cadcb2d7e10cbf4491f3be513dfa1aMichael Graff dns_rdata_toregion(rdata1, &r1);
439c0011e642fb1d26011116144af698125262dbMichael Graff dns_rdata_toregion(rdata2, &r2);
439c0011e642fb1d26011116144af698125262dbMichael Graff return (isc_region_compare(&r1, &r2));
59e22acc4f79ff481f7bfa46ef0558957ae53cfcMichael Graff}
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graffstatic inline isc_result_t
e883738546c7c73b761bce8a15e08661863d3ae1Michael Graffgeneric_fromstruct_ds(ARGS_FROMSTRUCT) {
e883738546c7c73b761bce8a15e08661863d3ae1Michael Graff dns_rdata_ds_t *ds = source;
fe14eafefa91fada7cea0a55b09196c01477406cBob Halley
439c0011e642fb1d26011116144af698125262dbMichael Graff REQUIRE(source != NULL);
439c0011e642fb1d26011116144af698125262dbMichael Graff REQUIRE(ds->common.rdtype == type);
439c0011e642fb1d26011116144af698125262dbMichael Graff REQUIRE(ds->common.rdclass == rdclass);
439c0011e642fb1d26011116144af698125262dbMichael Graff
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff UNUSED(type);
439c0011e642fb1d26011116144af698125262dbMichael Graff UNUSED(rdclass);
439c0011e642fb1d26011116144af698125262dbMichael Graff
c803787146cadcb2d7e10cbf4491f3be513dfa1aMichael Graff switch (ds->digest_type) {
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff case DNS_DSDIGEST_SHA1:
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff REQUIRE(ds->length == ISC_SHA1_DIGESTLENGTH);
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff break;
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff case DNS_DSDIGEST_SHA256:
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff REQUIRE(ds->length == ISC_SHA256_DIGESTLENGTH);
439c0011e642fb1d26011116144af698125262dbMichael Graff break;
439c0011e642fb1d26011116144af698125262dbMichael Graff#ifdef ISC_GOST_DIGESTLENGTH
439c0011e642fb1d26011116144af698125262dbMichael Graff case DNS_DSDIGEST_GOST:
439c0011e642fb1d26011116144af698125262dbMichael Graff REQUIRE(ds->length == ISC_GOST_DIGESTLENGTH);
d8590892d10fc9528b0dde7e2781935e7b8d7a87Michael Graff break;
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff#endif
4281fe4a80af7402613f0d5c3eeff8829a4ede1fMichael Graff case DNS_DSDIGEST_SHA384:
4281fe4a80af7402613f0d5c3eeff8829a4ede1fMichael Graff REQUIRE(ds->length == ISC_SHA384_DIGESTLENGTH);
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff break;
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff }
14b98cb34eda66c87ce41a207704a2c232280eafMichael Graff
14b98cb34eda66c87ce41a207704a2c232280eafMichael Graff RETERR(uint16_tobuffer(ds->key_tag, target));
e883738546c7c73b761bce8a15e08661863d3ae1Michael Graff RETERR(uint8_tobuffer(ds->algorithm, target));
e883738546c7c73b761bce8a15e08661863d3ae1Michael Graff RETERR(uint8_tobuffer(ds->digest_type, target));
14b98cb34eda66c87ce41a207704a2c232280eafMichael Graff
14b98cb34eda66c87ce41a207704a2c232280eafMichael Graff return (mem_tobuffer(target, ds->digest, ds->length));
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff}
3ac63b472022ff92691d1fe69ac715a729671965Michael Graff
651228967966ba4fb2e52f92d1207c790af4b130Michael Graffstatic inline isc_result_t
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Grafffromstruct_ds(ARGS_FROMSTRUCT) {
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff REQUIRE(type == dns_rdatatype_ds);
e883738546c7c73b761bce8a15e08661863d3ae1Michael Graff
e883738546c7c73b761bce8a15e08661863d3ae1Michael Graff return (generic_fromstruct_ds(rdclass, type, source, target));
14b98cb34eda66c87ce41a207704a2c232280eafMichael Graff}
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff
4281fe4a80af7402613f0d5c3eeff8829a4ede1fMichael Graffstatic inline isc_result_t
4281fe4a80af7402613f0d5c3eeff8829a4ede1fMichael Graffgeneric_tostruct_ds(ARGS_TOSTRUCT) {
4281fe4a80af7402613f0d5c3eeff8829a4ede1fMichael Graff dns_rdata_ds_t *ds = target;
4281fe4a80af7402613f0d5c3eeff8829a4ede1fMichael Graff isc_region_t region;
4281fe4a80af7402613f0d5c3eeff8829a4ede1fMichael Graff
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff REQUIRE(target != NULL);
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff REQUIRE(rdata->length != 0);
897c9ddb4d745b2bfecf98b17e5487bb6656299aMichael Graff REQUIRE(ds->common.rdtype == rdata->type);
4281fe4a80af7402613f0d5c3eeff8829a4ede1fMichael Graff REQUIRE(ds->common.rdclass == rdata->rdclass);
4281fe4a80af7402613f0d5c3eeff8829a4ede1fMichael Graff REQUIRE(!ISC_LINK_LINKED(&ds->common, link));
4281fe4a80af7402613f0d5c3eeff8829a4ede1fMichael Graff
4281fe4a80af7402613f0d5c3eeff8829a4ede1fMichael Graff dns_rdata_toregion(rdata, &region);
14b98cb34eda66c87ce41a207704a2c232280eafMichael Graff
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff ds->key_tag = uint16_fromregion(&region);
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff isc_region_consume(&region, 2);
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff ds->algorithm = uint8_fromregion(&region);
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff isc_region_consume(&region, 1);
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff ds->digest_type = uint8_fromregion(&region);
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff isc_region_consume(&region, 1);
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff ds->length = region.length;
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff ds->digest = mem_maybedup(mctx, region.base, region.length);
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff if (ds->digest == NULL)
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff return (ISC_R_NOMEMORY);
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff ds->mctx = mctx;
517274e709a3c730cd42f37dc1260dde95d1ea38Michael Graff return (ISC_R_SUCCESS);
517274e709a3c730cd42f37dc1260dde95d1ea38Michael Graff}
517274e709a3c730cd42f37dc1260dde95d1ea38Michael Graff
517274e709a3c730cd42f37dc1260dde95d1ea38Michael Graffstatic inline isc_result_t
517274e709a3c730cd42f37dc1260dde95d1ea38Michael Grafftostruct_ds(ARGS_TOSTRUCT) {
517274e709a3c730cd42f37dc1260dde95d1ea38Michael Graff dns_rdata_ds_t *ds = target;
59e22acc4f79ff481f7bfa46ef0558957ae53cfcMichael Graff
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff REQUIRE(rdata->type == dns_rdatatype_ds);
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff REQUIRE(target != NULL);
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff ds->common.rdclass = rdata->rdclass;
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff ds->common.rdtype = rdata->type;
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff ISC_LINK_INIT(&ds->common, link);
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff return (generic_tostruct_ds(rdata, target, mctx));
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff}
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graffstatic inline void
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Grafffreestruct_ds(ARGS_FREESTRUCT) {
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff dns_rdata_ds_t *ds = source;
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff REQUIRE(ds != NULL);
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff REQUIRE(ds->common.rdtype == dns_rdatatype_ds);
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff if (ds->mctx == NULL)
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff return;
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff if (ds->digest != NULL)
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff isc_mem_free(ds->mctx, ds->digest);
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff ds->mctx = NULL;
65f6d2e1c1fce0989c13c2efb44b8dd26cd977f3Michael Graff}
3d12fa7e76c02d06e1adeaa7846b60378a3cd204Michael Graff
3d12fa7e76c02d06e1adeaa7846b60378a3cd204Michael Graffstatic inline isc_result_t
78854e02c127f31ab90f56da0531542004b45377Michael Graffadditionaldata_ds(ARGS_ADDLDATA) {
78854e02c127f31ab90f56da0531542004b45377Michael Graff REQUIRE(rdata->type == dns_rdatatype_ds);
78854e02c127f31ab90f56da0531542004b45377Michael Graff
78854e02c127f31ab90f56da0531542004b45377Michael Graff UNUSED(rdata);
78854e02c127f31ab90f56da0531542004b45377Michael Graff UNUSED(add);
21e7034ec046105c00a0dab86c83732e2e77ad99Michael Graff UNUSED(arg);
21e7034ec046105c00a0dab86c83732e2e77ad99Michael Graff
21e7034ec046105c00a0dab86c83732e2e77ad99Michael Graff return (ISC_R_SUCCESS);
21e7034ec046105c00a0dab86c83732e2e77ad99Michael Graff}
21e7034ec046105c00a0dab86c83732e2e77ad99Michael Graff
21e7034ec046105c00a0dab86c83732e2e77ad99Michael Graffstatic inline isc_result_t
21e7034ec046105c00a0dab86c83732e2e77ad99Michael Graffdigest_ds(ARGS_DIGEST) {
21e7034ec046105c00a0dab86c83732e2e77ad99Michael Graff isc_region_t r;
21e7034ec046105c00a0dab86c83732e2e77ad99Michael Graff
21e7034ec046105c00a0dab86c83732e2e77ad99Michael Graff REQUIRE(rdata->type == dns_rdatatype_ds);
21e7034ec046105c00a0dab86c83732e2e77ad99Michael Graff
21e7034ec046105c00a0dab86c83732e2e77ad99Michael Graff dns_rdata_toregion(rdata, &r);
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff return ((digest)(arg, &r));
d1fb73ada84ee15ea078c80b1cd0ca8ddc6aa856Michael Graff}
d1fb73ada84ee15ea078c80b1cd0ca8ddc6aa856Michael Graff
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graffstatic inline isc_boolean_t
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graffcheckowner_ds(ARGS_CHECKOWNER) {
d1fb73ada84ee15ea078c80b1cd0ca8ddc6aa856Michael Graff
d1fb73ada84ee15ea078c80b1cd0ca8ddc6aa856Michael Graff REQUIRE(type == dns_rdatatype_ds);
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff UNUSED(name);
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff UNUSED(type);
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff UNUSED(rdclass);
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff UNUSED(wildcard);
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff
d1fb73ada84ee15ea078c80b1cd0ca8ddc6aa856Michael Graff return (ISC_TRUE);
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff}
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graffstatic inline isc_boolean_t
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graffchecknames_ds(ARGS_CHECKNAMES) {
d1fb73ada84ee15ea078c80b1cd0ca8ddc6aa856Michael Graff
59e22acc4f79ff481f7bfa46ef0558957ae53cfcMichael Graff REQUIRE(rdata->type == dns_rdatatype_ds);
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff UNUSED(rdata);
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff UNUSED(owner);
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff UNUSED(bad);
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff
d1fb73ada84ee15ea078c80b1cd0ca8ddc6aa856Michael Graff return (ISC_TRUE);
d1fb73ada84ee15ea078c80b1cd0ca8ddc6aa856Michael Graff}
59e22acc4f79ff481f7bfa46ef0558957ae53cfcMichael Graff
59e22acc4f79ff481f7bfa46ef0558957ae53cfcMichael Graffstatic inline int
59e22acc4f79ff481f7bfa46ef0558957ae53cfcMichael Graffcasecompare_ds(ARGS_COMPARE) {
59e22acc4f79ff481f7bfa46ef0558957ae53cfcMichael Graff return (compare_ds(rdata1, rdata2));
528829aa8ad69238e674cd81078bc14d4199691bMichael Graff}
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff#endif /* RDATA_GENERIC_DS_43_C */
59e22acc4f79ff481f7bfa46ef0558957ae53cfcMichael Graff