"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.17.5/lib/dns/key.c" (4 Sep 2020, 3631 Bytes) of package /linux/misc/dns/bind9/9.17.5/bind-9.17.5.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "key.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
    3  *
    4  * This Source Code Form is subject to the terms of the Mozilla Public
    5  * License, v. 2.0. If a copy of the MPL was not distributed with this
    6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    7  *
    8  * See the COPYRIGHT file distributed with this work for additional
    9  * information regarding copyright ownership.
   10  */
   11 
   12 #include <inttypes.h>
   13 #include <stdbool.h>
   14 #include <stddef.h>
   15 #include <stdlib.h>
   16 
   17 #include <isc/region.h>
   18 #include <isc/util.h>
   19 
   20 #include <dns/keyvalues.h>
   21 
   22 #include <dst/dst.h>
   23 
   24 #include "dst_internal.h"
   25 
   26 uint16_t
   27 dst_region_computeid(const isc_region_t *source) {
   28     uint32_t ac;
   29     const unsigned char *p;
   30     int size;
   31 
   32     REQUIRE(source != NULL);
   33     REQUIRE(source->length >= 4);
   34 
   35     p = source->base;
   36     size = source->length;
   37 
   38     for (ac = 0; size > 1; size -= 2, p += 2) {
   39         ac += ((*p) << 8) + *(p + 1);
   40     }
   41 
   42     if (size > 0) {
   43         ac += ((*p) << 8);
   44     }
   45     ac += (ac >> 16) & 0xffff;
   46 
   47     return ((uint16_t)(ac & 0xffff));
   48 }
   49 
   50 uint16_t
   51 dst_region_computerid(const isc_region_t *source) {
   52     uint32_t ac;
   53     const unsigned char *p;
   54     int size;
   55 
   56     REQUIRE(source != NULL);
   57     REQUIRE(source->length >= 4);
   58 
   59     p = source->base;
   60     size = source->length;
   61 
   62     ac = ((*p) << 8) + *(p + 1);
   63     ac |= DNS_KEYFLAG_REVOKE;
   64     for (size -= 2, p += 2; size > 1; size -= 2, p += 2) {
   65         ac += ((*p) << 8) + *(p + 1);
   66     }
   67 
   68     if (size > 0) {
   69         ac += ((*p) << 8);
   70     }
   71     ac += (ac >> 16) & 0xffff;
   72 
   73     return ((uint16_t)(ac & 0xffff));
   74 }
   75 
   76 dns_name_t *
   77 dst_key_name(const dst_key_t *key) {
   78     REQUIRE(VALID_KEY(key));
   79     return (key->key_name);
   80 }
   81 
   82 unsigned int
   83 dst_key_size(const dst_key_t *key) {
   84     REQUIRE(VALID_KEY(key));
   85     return (key->key_size);
   86 }
   87 
   88 unsigned int
   89 dst_key_proto(const dst_key_t *key) {
   90     REQUIRE(VALID_KEY(key));
   91     return (key->key_proto);
   92 }
   93 
   94 unsigned int
   95 dst_key_alg(const dst_key_t *key) {
   96     REQUIRE(VALID_KEY(key));
   97     return (key->key_alg);
   98 }
   99 
  100 uint32_t
  101 dst_key_flags(const dst_key_t *key) {
  102     REQUIRE(VALID_KEY(key));
  103     return (key->key_flags);
  104 }
  105 
  106 dns_keytag_t
  107 dst_key_id(const dst_key_t *key) {
  108     REQUIRE(VALID_KEY(key));
  109     return (key->key_id);
  110 }
  111 
  112 dns_keytag_t
  113 dst_key_rid(const dst_key_t *key) {
  114     REQUIRE(VALID_KEY(key));
  115     return (key->key_rid);
  116 }
  117 
  118 dns_rdataclass_t
  119 dst_key_class(const dst_key_t *key) {
  120     REQUIRE(VALID_KEY(key));
  121     return (key->key_class);
  122 }
  123 
  124 bool
  125 dst_key_iszonekey(const dst_key_t *key) {
  126     REQUIRE(VALID_KEY(key));
  127 
  128     if ((key->key_flags & DNS_KEYTYPE_NOAUTH) != 0) {
  129         return (false);
  130     }
  131     if ((key->key_flags & DNS_KEYFLAG_OWNERMASK) != DNS_KEYOWNER_ZONE) {
  132         return (false);
  133     }
  134     if (key->key_proto != DNS_KEYPROTO_DNSSEC &&
  135         key->key_proto != DNS_KEYPROTO_ANY) {
  136         return (false);
  137     }
  138     return (true);
  139 }
  140 
  141 bool
  142 dst_key_isnullkey(const dst_key_t *key) {
  143     REQUIRE(VALID_KEY(key));
  144 
  145     if ((key->key_flags & DNS_KEYFLAG_TYPEMASK) != DNS_KEYTYPE_NOKEY) {
  146         return (false);
  147     }
  148     if ((key->key_flags & DNS_KEYFLAG_OWNERMASK) != DNS_KEYOWNER_ZONE) {
  149         return (false);
  150     }
  151     if (key->key_proto != DNS_KEYPROTO_DNSSEC &&
  152         key->key_proto != DNS_KEYPROTO_ANY) {
  153         return (false);
  154     }
  155     return (true);
  156 }
  157 
  158 void
  159 dst_key_setbits(dst_key_t *key, uint16_t bits) {
  160     unsigned int maxbits;
  161     REQUIRE(VALID_KEY(key));
  162     if (bits != 0) {
  163         RUNTIME_CHECK(dst_key_sigsize(key, &maxbits) == ISC_R_SUCCESS);
  164         maxbits *= 8;
  165         REQUIRE(bits <= maxbits);
  166     }
  167     key->key_bits = bits;
  168 }
  169 
  170 uint16_t
  171 dst_key_getbits(const dst_key_t *key) {
  172     REQUIRE(VALID_KEY(key));
  173     return (key->key_bits);
  174 }
  175 
  176 void
  177 dst_key_setttl(dst_key_t *key, dns_ttl_t ttl) {
  178     REQUIRE(VALID_KEY(key));
  179     key->key_ttl = ttl;
  180 }
  181 
  182 dns_ttl_t
  183 dst_key_getttl(const dst_key_t *key) {
  184     REQUIRE(VALID_KEY(key));
  185     return (key->key_ttl);
  186 }
  187 
  188 /*! \file */