bind9/lib/isc/iterated_hash.c

44 lines
1 KiB
C
Raw Normal View History

2008-04-04 19:47:01 -04:00
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
2008-04-04 19:47:01 -04:00
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
2008-04-04 19:47:01 -04:00
*/
2009-02-18 18:47:48 -05:00
/* $Id: iterated_hash.c,v 1.6 2009/02/18 23:47:48 tbox Exp $ */
2009-02-18 01:44:58 -05:00
#include "config.h"
2008-04-04 19:47:01 -04:00
2008-04-04 01:34:07 -04:00
#include <stdio.h>
#include <isc/sha1.h>
#include <isc/iterated_hash.h>
int
isc_iterated_hash(unsigned char out[ISC_SHA1_DIGESTLENGTH],
unsigned int hashalg, int iterations,
2008-04-04 19:47:01 -04:00
const unsigned char *salt, int saltlength,
const unsigned char *in, int inlength)
2008-04-04 01:34:07 -04:00
{
isc_sha1_t ctx;
int n = 0;
if (hashalg != 1)
return (0);
do {
isc_sha1_init(&ctx);
isc_sha1_update(&ctx, in, inlength);
isc_sha1_update(&ctx, salt, saltlength);
isc_sha1_final(&ctx, out);
in = out;
inlength = ISC_SHA1_DIGESTLENGTH;
} while (n++ < iterations);
return (ISC_SHA1_DIGESTLENGTH);
}