key.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004-2007, 2011  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 2001  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id: key.c,v 1.11 2011/10/20 21:20:02 marka Exp $ */
00019 
00020 #include <config.h>
00021 
00022 #include <stddef.h>
00023 #include <stdlib.h>
00024 
00025 #include <isc/region.h>
00026 #include <isc/util.h>
00027 
00028 #include <dns/keyvalues.h>
00029 
00030 #include <dst/dst.h>
00031 
00032 #include "dst_internal.h"
00033 
00034 isc_uint16_t
00035 dst_region_computeid(const isc_region_t *source, unsigned int alg) {
00036         isc_uint32_t ac;
00037         const unsigned char *p;
00038         int size;
00039 
00040         REQUIRE(source != NULL);
00041         REQUIRE(source->length >= 4);
00042 
00043         p = source->base;
00044         size = source->length;
00045 
00046         if (alg == DST_ALG_RSAMD5)
00047                 return ((p[size - 3] << 8) + p[size - 2]);
00048 
00049         for (ac = 0; size > 1; size -= 2, p += 2)
00050                 ac += ((*p) << 8) + *(p + 1);
00051 
00052         if (size > 0)
00053                 ac += ((*p) << 8);
00054         ac += (ac >> 16) & 0xffff;
00055 
00056         return ((isc_uint16_t)(ac & 0xffff));
00057 }
00058 
00059 isc_uint16_t
00060 dst_region_computerid(const isc_region_t *source, unsigned int alg) {
00061         isc_uint32_t ac;
00062         const unsigned char *p;
00063         int size;
00064 
00065         REQUIRE(source != NULL);
00066         REQUIRE(source->length >= 4);
00067 
00068         p = source->base;
00069         size = source->length;
00070 
00071         if (alg == DST_ALG_RSAMD5)
00072                 return ((p[size - 3] << 8) + p[size - 2]);
00073 
00074         ac = ((*p) << 8) + *(p + 1);
00075         ac |= DNS_KEYFLAG_REVOKE;
00076         for (size -= 2, p +=2; size > 1; size -= 2, p += 2)
00077                 ac += ((*p) << 8) + *(p + 1);
00078 
00079         if (size > 0)
00080                 ac += ((*p) << 8);
00081         ac += (ac >> 16) & 0xffff;
00082 
00083         return ((isc_uint16_t)(ac & 0xffff));
00084 }
00085 
00086 dns_name_t *
00087 dst_key_name(const dst_key_t *key) {
00088         REQUIRE(VALID_KEY(key));
00089         return (key->key_name);
00090 }
00091 
00092 unsigned int
00093 dst_key_size(const dst_key_t *key) {
00094         REQUIRE(VALID_KEY(key));
00095         return (key->key_size);
00096 }
00097 
00098 unsigned int
00099 dst_key_proto(const dst_key_t *key) {
00100         REQUIRE(VALID_KEY(key));
00101         return (key->key_proto);
00102 }
00103 
00104 unsigned int
00105 dst_key_alg(const dst_key_t *key) {
00106         REQUIRE(VALID_KEY(key));
00107         return (key->key_alg);
00108 }
00109 
00110 isc_uint32_t
00111 dst_key_flags(const dst_key_t *key) {
00112         REQUIRE(VALID_KEY(key));
00113         return (key->key_flags);
00114 }
00115 
00116 dns_keytag_t
00117 dst_key_id(const dst_key_t *key) {
00118         REQUIRE(VALID_KEY(key));
00119         return (key->key_id);
00120 }
00121 
00122 dns_keytag_t
00123 dst_key_rid(const dst_key_t *key) {
00124         REQUIRE(VALID_KEY(key));
00125         return (key->key_rid);
00126 }
00127 
00128 dns_rdataclass_t
00129 dst_key_class(const dst_key_t *key) {
00130         REQUIRE(VALID_KEY(key));
00131         return (key->key_class);
00132 }
00133 
00134 isc_boolean_t
00135 dst_key_iszonekey(const dst_key_t *key) {
00136         REQUIRE(VALID_KEY(key));
00137 
00138         if ((key->key_flags & DNS_KEYTYPE_NOAUTH) != 0)
00139                 return (ISC_FALSE);
00140         if ((key->key_flags & DNS_KEYFLAG_OWNERMASK) != DNS_KEYOWNER_ZONE)
00141                 return (ISC_FALSE);
00142         if (key->key_proto != DNS_KEYPROTO_DNSSEC &&
00143             key->key_proto != DNS_KEYPROTO_ANY)
00144                 return (ISC_FALSE);
00145         return (ISC_TRUE);
00146 }
00147 
00148 isc_boolean_t
00149 dst_key_isnullkey(const dst_key_t *key) {
00150         REQUIRE(VALID_KEY(key));
00151 
00152         if ((key->key_flags & DNS_KEYFLAG_TYPEMASK) != DNS_KEYTYPE_NOKEY)
00153                 return (ISC_FALSE);
00154         if ((key->key_flags & DNS_KEYFLAG_OWNERMASK) != DNS_KEYOWNER_ZONE)
00155                 return (ISC_FALSE);
00156         if (key->key_proto != DNS_KEYPROTO_DNSSEC &&
00157             key->key_proto != DNS_KEYPROTO_ANY)
00158                 return (ISC_FALSE);
00159         return (ISC_TRUE);
00160 }
00161 
00162 void
00163 dst_key_setbits(dst_key_t *key, isc_uint16_t bits) {
00164         unsigned int maxbits;
00165         REQUIRE(VALID_KEY(key));
00166         if (bits != 0) {
00167                 RUNTIME_CHECK(dst_key_sigsize(key, &maxbits) == ISC_R_SUCCESS);
00168                 maxbits *= 8;
00169                 REQUIRE(bits <= maxbits);
00170         }
00171         key->key_bits = bits;
00172 }
00173 
00174 isc_uint16_t
00175 dst_key_getbits(const dst_key_t *key) {
00176         REQUIRE(VALID_KEY(key));
00177         return (key->key_bits);
00178 }
00179 
00180 void
00181 dst_key_setttl(dst_key_t *key, dns_ttl_t ttl) {
00182         REQUIRE(VALID_KEY(key));
00183         key->key_ttl = ttl;
00184 }
00185 
00186 dns_ttl_t
00187 dst_key_getttl(const dst_key_t *key) {
00188         REQUIRE(VALID_KEY(key));
00189         return (key->key_ttl);
00190 }
00191 
00192 /*! \file */

Generated on Tue Apr 28 17:40:57 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha