2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2002, 2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: ds.c,v 1.4.2.1 2004/03/08 02:07:53 marka Exp $ */
24 #include <isc/buffer.h>
25 #include <isc/region.h>
30 #include <dns/fixedname.h>
32 #include <dns/rdata.h>
33 #include <dns/rdatastruct.h>
34 #include <dns/result.h>
39 dns_ds_buildrdata(dns_name_t
*owner
, dns_rdata_t
*key
,
40 unsigned int digest_type
, unsigned char *buffer
,
44 dns_fixedname_t fname
;
46 unsigned char digest
[ISC_SHA1_DIGESTLENGTH
];
52 REQUIRE(key
->type
== dns_rdatatype_dnskey
);
54 if (digest_type
!= DNS_DSDIGEST_SHA1
)
55 return (ISC_R_NOTIMPLEMENTED
);
57 dns_fixedname_init(&fname
);
58 name
= dns_fixedname_name(&fname
);
59 (void)dns_name_downcase(owner
, name
, NULL
);
61 memset(buffer
, 0, DNS_DS_BUFFERSIZE
);
62 isc_buffer_init(&b
, buffer
, DNS_DS_BUFFERSIZE
);
65 dns_name_toregion(name
, &r
);
66 isc_sha1_update(&sha1
, r
.base
, r
.length
);
67 dns_rdata_toregion(key
, &r
);
68 INSIST(r
.length
>= 4);
69 isc_sha1_update(&sha1
, r
.base
, r
.length
);
70 isc_sha1_final(&sha1
, digest
);
73 ds
.common
.rdclass
= key
->rdclass
;
74 ds
.common
.rdtype
= dns_rdatatype_ds
;
75 ds
.algorithm
= r
.base
[3];
76 ds
.key_tag
= dst_region_computeid(&r
, ds
.algorithm
);
77 ds
.digest_type
= DNS_DSDIGEST_SHA1
;
78 ds
.length
= ISC_SHA1_DIGESTLENGTH
;
81 return (dns_rdata_fromstruct(rdata
, key
->rdclass
, dns_rdatatype_ds
,