iterated_hash.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006, 2008, 2009  Internet Systems Consortium, Inc. ("ISC")
00003  *
00004  * Permission to use, copy, modify, and/or distribute this software for any
00005  * purpose with or without fee is hereby granted, provided that the above
00006  * copyright notice and this permission notice appear in all copies.
00007  *
00008  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00009  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00010  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00011  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00012  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00013  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00014  * PERFORMANCE OF THIS SOFTWARE.
00015  */
00016 
00017 /* $Id: iterated_hash.c,v 1.6 2009/02/18 23:47:48 tbox Exp $ */
00018 
00019 #include "config.h"
00020 
00021 #include <stdio.h>
00022 
00023 #include <isc/sha1.h>
00024 #include <isc/iterated_hash.h>
00025 
00026 int
00027 isc_iterated_hash(unsigned char out[ISC_SHA1_DIGESTLENGTH],
00028                   unsigned int hashalg, int iterations,
00029                   const unsigned char *salt, int saltlength,
00030                   const unsigned char *in, int inlength)
00031 {
00032         isc_sha1_t ctx;
00033         int n = 0;
00034 
00035         if (hashalg != 1)
00036                 return (0);
00037 
00038         do {
00039                 isc_sha1_init(&ctx);
00040                 isc_sha1_update(&ctx, in, inlength);
00041                 isc_sha1_update(&ctx, salt, saltlength);
00042                 isc_sha1_final(&ctx, out);
00043                 in = out;
00044                 inlength = ISC_SHA1_DIGESTLENGTH;
00045         } while (n++ < iterations);
00046 
00047         return (ISC_SHA1_DIGESTLENGTH);
00048 }

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