4 * Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 2001 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: key.c,v 1.8 2007/06/19 23:47:16 tbox Exp */
27 #include <isc/region.h>
30 #include <dns/keyvalues.h>
34 #include "dst_internal.h"
37 dst_region_computeid(const isc_region_t
*source
, unsigned int alg
) {
39 const unsigned char *p
;
42 REQUIRE(source
!= NULL
);
43 REQUIRE(source
->length
>= 4);
46 size
= source
->length
;
48 if (alg
== DST_ALG_RSAMD5
)
49 return ((p
[size
- 3] << 8) + p
[size
- 2]);
51 for (ac
= 0; size
> 1; size
-= 2, p
+= 2)
52 ac
+= ((*p
) << 8) + *(p
+ 1);
56 ac
+= (ac
>> 16) & 0xffff;
58 return ((isc_uint16_t
)(ac
& 0xffff));
62 dst_key_name(const dst_key_t
*key
) {
63 REQUIRE(VALID_KEY(key
));
64 return (key
->key_name
);
68 dst_key_size(const dst_key_t
*key
) {
69 REQUIRE(VALID_KEY(key
));
70 return (key
->key_size
);
74 dst_key_proto(const dst_key_t
*key
) {
75 REQUIRE(VALID_KEY(key
));
76 return (key
->key_proto
);
80 dst_key_alg(const dst_key_t
*key
) {
81 REQUIRE(VALID_KEY(key
));
82 return (key
->key_alg
);
86 dst_key_flags(const dst_key_t
*key
) {
87 REQUIRE(VALID_KEY(key
));
88 return (key
->key_flags
);
92 dst_key_id(const dst_key_t
*key
) {
93 REQUIRE(VALID_KEY(key
));
98 dst_key_class(const dst_key_t
*key
) {
99 REQUIRE(VALID_KEY(key
));
100 return (key
->key_class
);
104 dst_key_iszonekey(const dst_key_t
*key
) {
105 REQUIRE(VALID_KEY(key
));
107 if ((key
->key_flags
& DNS_KEYTYPE_NOAUTH
) != 0)
109 if ((key
->key_flags
& DNS_KEYFLAG_OWNERMASK
) != DNS_KEYOWNER_ZONE
)
111 if (key
->key_proto
!= DNS_KEYPROTO_DNSSEC
&&
112 key
->key_proto
!= DNS_KEYPROTO_ANY
)
118 dst_key_isnullkey(const dst_key_t
*key
) {
119 REQUIRE(VALID_KEY(key
));
121 if ((key
->key_flags
& DNS_KEYFLAG_TYPEMASK
) != DNS_KEYTYPE_NOKEY
)
123 if ((key
->key_flags
& DNS_KEYFLAG_OWNERMASK
) != DNS_KEYOWNER_ZONE
)
125 if (key
->key_proto
!= DNS_KEYPROTO_DNSSEC
&&
126 key
->key_proto
!= DNS_KEYPROTO_ANY
)
132 dst_key_setbits(dst_key_t
*key
, isc_uint16_t bits
) {
133 unsigned int maxbits
;
134 REQUIRE(VALID_KEY(key
));
136 RUNTIME_CHECK(dst_key_sigsize(key
, &maxbits
) == ISC_R_SUCCESS
);
138 REQUIRE(bits
<= maxbits
);
140 key
->key_bits
= bits
;
144 dst_key_getbits(const dst_key_t
*key
) {
145 REQUIRE(VALID_KEY(key
));
146 return (key
->key_bits
);