/*
* FIPS-180-1 compliant SHA-1 implementation
*
- * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
+ * Copyright (C) 2006-2010, Brainspark B.V.
*
- * Copyright (C) 2009 Paul Bakker <polarssl_maintainer at polarssl dot org>
+ * This file is part of PolarSSL (http://www.polarssl.org)
+ * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
+ *
+ * All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* http://www.itl.nist.gov/fipspubs/fip180-1.htm
*/
-/* $Cambridge: exim/src/src/pdkim/sha1.c,v 1.2 2009/06/10 07:34:05 tom Exp $ */
-
#include "sha1.h"
#include <string.h>
ctx->state[4] = 0xC3D2E1F0;
}
-static void sha1_process( sha1_context *ctx, unsigned char data[64] )
+static void sha1_process( sha1_context *ctx, const unsigned char data[64] )
{
unsigned long temp, W[16], A, B, C, D, E;
/*
* SHA-1 process buffer
*/
-void sha1_update( sha1_context *ctx, unsigned char *input, int ilen )
+void sha1_update( sha1_context *ctx, const unsigned char *input, int ilen )
{
int fill;
unsigned long left;
/*
* output = SHA-1( input buffer )
*/
-void sha1_oneshot( unsigned char *input, int ilen, unsigned char output[20] )
+void sha1( const unsigned char *input, int ilen, unsigned char output[20] )
{
sha1_context ctx;
/*
* output = SHA-1( file contents )
*/
-int sha1_file( char *path, unsigned char output[20] )
+int sha1_file( const char *path, unsigned char output[20] )
{
FILE *f;
size_t n;
/*
* SHA-1 HMAC context setup
*/
-void sha1_hmac_starts( sha1_context *ctx, unsigned char *key, int keylen )
+void sha1_hmac_starts( sha1_context *ctx, const unsigned char *key, int keylen )
{
int i;
unsigned char sum[20];
if( keylen > 64 )
{
- sha1_oneshot( key, keylen, sum );
+ sha1( key, keylen, sum );
keylen = 20;
key = sum;
}
/*
* SHA-1 HMAC process buffer
*/
-void sha1_hmac_update( sha1_context *ctx, unsigned char *input, int ilen )
+void sha1_hmac_update( sha1_context *ctx, const unsigned char *input, int ilen )
{
sha1_update( ctx, input, ilen );
}
memset( tmpbuf, 0, sizeof( tmpbuf ) );
}
+/*
+ * SHA1 HMAC context reset
+ */
+void sha1_hmac_reset( sha1_context *ctx )
+{
+ sha1_starts( ctx );
+ sha1_update( ctx, ctx->ipad, 64 );
+}
+
/*
* output = HMAC-SHA-1( hmac key, input buffer )
*/
-void sha1_hmac( unsigned char *key, int keylen,
- unsigned char *input, int ilen,
+void sha1_hmac( const unsigned char *key, int keylen,
+ const unsigned char *input, int ilen,
unsigned char output[20] )
{
sha1_context ctx;