"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.16.7/lib/isc/iterated_hash.c" (4 Sep 2020, 1585 Bytes) of package /linux/misc/dns/bind9/9.16.7/bind-9.16.7.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 "iterated_hash.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 <stdio.h>
   13 
   14 #include <isc/iterated_hash.h>
   15 #include <isc/md.h>
   16 #include <isc/util.h>
   17 
   18 int
   19 isc_iterated_hash(unsigned char *out, const unsigned int hashalg,
   20           const int iterations, const unsigned char *salt,
   21           const int saltlength, const unsigned char *in,
   22           const int inlength) {
   23     isc_md_t *md;
   24     isc_result_t result;
   25     int n = 0;
   26     unsigned int outlength = 0;
   27     size_t len;
   28     const unsigned char *buf;
   29 
   30     REQUIRE(out != NULL);
   31 
   32     if (hashalg != 1) {
   33         return (0);
   34     }
   35 
   36     if ((md = isc_md_new()) == NULL) {
   37         return (0);
   38     }
   39 
   40     len = inlength;
   41     buf = in;
   42     do {
   43         result = isc_md_init(md, ISC_MD_SHA1);
   44         if (result != ISC_R_SUCCESS) {
   45             goto md_fail;
   46         }
   47         result = isc_md_update(md, buf, len);
   48         if (result != ISC_R_SUCCESS) {
   49             goto md_fail;
   50         }
   51         result = isc_md_update(md, salt, saltlength);
   52         if (result != ISC_R_SUCCESS) {
   53             goto md_fail;
   54         }
   55         result = isc_md_final(md, out, &outlength);
   56         if (result != ISC_R_SUCCESS) {
   57             goto md_fail;
   58         }
   59         result = isc_md_reset(md);
   60         if (result != ISC_R_SUCCESS) {
   61             goto md_fail;
   62         }
   63         buf = out;
   64         len = outlength;
   65     } while (n++ < iterations);
   66 
   67     isc_md_free(md);
   68 
   69     return (outlength);
   70 md_fail:
   71     isc_md_free(md);
   72     return (0);
   73 }
   74 #undef RETERR