Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / dns / key.c
blob8921abd08bc270000c9c2cc1a8d3f39a36c29458
1 /* $NetBSD: key.c,v 1.5 2014/12/10 04:37:58 christos Exp $ */
3 /*
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 */
22 #include <config.h>
24 #include <stddef.h>
25 #include <stdlib.h>
27 #include <isc/region.h>
28 #include <isc/util.h>
30 #include <dns/keyvalues.h>
32 #include <dst/dst.h>
34 #include "dst_internal.h"
36 isc_uint16_t
37 dst_region_computeid(const isc_region_t *source, unsigned int alg) {
38 isc_uint32_t ac;
39 const unsigned char *p;
40 int size;
42 REQUIRE(source != NULL);
43 REQUIRE(source->length >= 4);
45 p = source->base;
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);
54 if (size > 0)
55 ac += ((*p) << 8);
56 ac += (ac >> 16) & 0xffff;
58 return ((isc_uint16_t)(ac & 0xffff));
61 isc_uint16_t
62 dst_region_computerid(const isc_region_t *source, unsigned int alg) {
63 isc_uint32_t ac;
64 const unsigned char *p;
65 int size;
67 REQUIRE(source != NULL);
68 REQUIRE(source->length >= 4);
70 p = source->base;
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);
81 if (size > 0)
82 ac += ((*p) << 8);
83 ac += (ac >> 16) & 0xffff;
85 return ((isc_uint16_t)(ac & 0xffff));
88 dns_name_t *
89 dst_key_name(const dst_key_t *key) {
90 REQUIRE(VALID_KEY(key));
91 return (key->key_name);
94 unsigned int
95 dst_key_size(const dst_key_t *key) {
96 REQUIRE(VALID_KEY(key));
97 return (key->key_size);
100 unsigned int
101 dst_key_proto(const dst_key_t *key) {
102 REQUIRE(VALID_KEY(key));
103 return (key->key_proto);
106 unsigned int
107 dst_key_alg(const dst_key_t *key) {
108 REQUIRE(VALID_KEY(key));
109 return (key->key_alg);
112 isc_uint32_t
113 dst_key_flags(const dst_key_t *key) {
114 REQUIRE(VALID_KEY(key));
115 return (key->key_flags);
118 dns_keytag_t
119 dst_key_id(const dst_key_t *key) {
120 REQUIRE(VALID_KEY(key));
121 return (key->key_id);
124 dns_keytag_t
125 dst_key_rid(const dst_key_t *key) {
126 REQUIRE(VALID_KEY(key));
127 return (key->key_rid);
130 dns_rdataclass_t
131 dst_key_class(const dst_key_t *key) {
132 REQUIRE(VALID_KEY(key));
133 return (key->key_class);
136 isc_boolean_t
137 dst_key_iszonekey(const dst_key_t *key) {
138 REQUIRE(VALID_KEY(key));
140 if ((key->key_flags & DNS_KEYTYPE_NOAUTH) != 0)
141 return (ISC_FALSE);
142 if ((key->key_flags & DNS_KEYFLAG_OWNERMASK) != DNS_KEYOWNER_ZONE)
143 return (ISC_FALSE);
144 if (key->key_proto != DNS_KEYPROTO_DNSSEC &&
145 key->key_proto != DNS_KEYPROTO_ANY)
146 return (ISC_FALSE);
147 return (ISC_TRUE);
150 isc_boolean_t
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)
155 return (ISC_FALSE);
156 if ((key->key_flags & DNS_KEYFLAG_OWNERMASK) != DNS_KEYOWNER_ZONE)
157 return (ISC_FALSE);
158 if (key->key_proto != DNS_KEYPROTO_DNSSEC &&
159 key->key_proto != DNS_KEYPROTO_ANY)
160 return (ISC_FALSE);
161 return (ISC_TRUE);
164 void
165 dst_key_setbits(dst_key_t *key, isc_uint16_t bits) {
166 unsigned int maxbits;
167 REQUIRE(VALID_KEY(key));
168 if (bits != 0) {
169 RUNTIME_CHECK(dst_key_sigsize(key, &maxbits) == ISC_R_SUCCESS);
170 maxbits *= 8;
171 REQUIRE(bits <= maxbits);
173 key->key_bits = bits;
176 isc_uint16_t
177 dst_key_getbits(const dst_key_t *key) {
178 REQUIRE(VALID_KEY(key));
179 return (key->key_bits);
182 void
183 dst_key_setttl(dst_key_t *key, dns_ttl_t ttl) {
184 REQUIRE(VALID_KEY(key));
185 key->key_ttl = ttl;
188 dns_ttl_t
189 dst_key_getttl(const dst_key_t *key) {
190 REQUIRE(VALID_KEY(key));
191 return (key->key_ttl);
194 /*! \file */