1 /* $NetBSD: key.c,v 1.5 2014/12/10 04:37:58 christos Exp $ */
4 * Copyright (C) 2004-2007, 2011 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.11 2011/10/20 21:20:02 marka 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_region_computerid(const isc_region_t
*source
, unsigned int alg
) {
64 const unsigned char *p
;
67 REQUIRE(source
!= NULL
);
68 REQUIRE(source
->length
>= 4);
71 size
= source
->length
;
73 if (alg
== DST_ALG_RSAMD5
)
74 return ((p
[size
- 3] << 8) + p
[size
- 2]);
76 ac
= ((*p
) << 8) + *(p
+ 1);
77 ac
|= DNS_KEYFLAG_REVOKE
;
78 for (size
-= 2, p
+=2; size
> 1; size
-= 2, p
+= 2)
79 ac
+= ((*p
) << 8) + *(p
+ 1);
83 ac
+= (ac
>> 16) & 0xffff;
85 return ((isc_uint16_t
)(ac
& 0xffff));
89 dst_key_name(const dst_key_t
*key
) {
90 REQUIRE(VALID_KEY(key
));
91 return (key
->key_name
);
95 dst_key_size(const dst_key_t
*key
) {
96 REQUIRE(VALID_KEY(key
));
97 return (key
->key_size
);
101 dst_key_proto(const dst_key_t
*key
) {
102 REQUIRE(VALID_KEY(key
));
103 return (key
->key_proto
);
107 dst_key_alg(const dst_key_t
*key
) {
108 REQUIRE(VALID_KEY(key
));
109 return (key
->key_alg
);
113 dst_key_flags(const dst_key_t
*key
) {
114 REQUIRE(VALID_KEY(key
));
115 return (key
->key_flags
);
119 dst_key_id(const dst_key_t
*key
) {
120 REQUIRE(VALID_KEY(key
));
121 return (key
->key_id
);
125 dst_key_rid(const dst_key_t
*key
) {
126 REQUIRE(VALID_KEY(key
));
127 return (key
->key_rid
);
131 dst_key_class(const dst_key_t
*key
) {
132 REQUIRE(VALID_KEY(key
));
133 return (key
->key_class
);
137 dst_key_iszonekey(const dst_key_t
*key
) {
138 REQUIRE(VALID_KEY(key
));
140 if ((key
->key_flags
& DNS_KEYTYPE_NOAUTH
) != 0)
142 if ((key
->key_flags
& DNS_KEYFLAG_OWNERMASK
) != DNS_KEYOWNER_ZONE
)
144 if (key
->key_proto
!= DNS_KEYPROTO_DNSSEC
&&
145 key
->key_proto
!= DNS_KEYPROTO_ANY
)
151 dst_key_isnullkey(const dst_key_t
*key
) {
152 REQUIRE(VALID_KEY(key
));
154 if ((key
->key_flags
& DNS_KEYFLAG_TYPEMASK
) != DNS_KEYTYPE_NOKEY
)
156 if ((key
->key_flags
& DNS_KEYFLAG_OWNERMASK
) != DNS_KEYOWNER_ZONE
)
158 if (key
->key_proto
!= DNS_KEYPROTO_DNSSEC
&&
159 key
->key_proto
!= DNS_KEYPROTO_ANY
)
165 dst_key_setbits(dst_key_t
*key
, isc_uint16_t bits
) {
166 unsigned int maxbits
;
167 REQUIRE(VALID_KEY(key
));
169 RUNTIME_CHECK(dst_key_sigsize(key
, &maxbits
) == ISC_R_SUCCESS
);
171 REQUIRE(bits
<= maxbits
);
173 key
->key_bits
= bits
;
177 dst_key_getbits(const dst_key_t
*key
) {
178 REQUIRE(VALID_KEY(key
));
179 return (key
->key_bits
);
183 dst_key_setttl(dst_key_t
*key
, dns_ttl_t ttl
) {
184 REQUIRE(VALID_KEY(key
));
189 dst_key_getttl(const dst_key_t
*key
) {
190 REQUIRE(VALID_KEY(key
));
191 return (key
->key_ttl
);