/*
* FIPS-180-2 compliant SHA-256 implementation
*
- * Copyright (C) 2006-2009, Paul Bakker <polarssl_maintainer at polarssl.org>
- * All rights reserved.
+ * Copyright (C) 2006-2010, Brainspark B.V.
+ *
+ * This file is part of PolarSSL (http://www.polarssl.org)
+ * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
*
- * Joined copyright on original XySSL code with: Christophe Devine
+ * 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://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
*/
-/* $Cambridge: exim/src/src/pdkim/sha2.c,v 1.3 2009/12/07 13:05:07 tom Exp $ */
-
#include "sha2.h"
#include <string.h>
ctx->is224 = is224;
}
-static void sha2_process( sha2_context *ctx, unsigned char data[64] )
+static void sha2_process( sha2_context *ctx, const unsigned char data[64] )
{
unsigned long temp1, temp2, W[64];
unsigned long A, B, C, D, E, F, G, H;
/*
* SHA-256 process buffer
*/
-void sha2_update( sha2_context *ctx, unsigned char *input, int ilen )
+void sha2_update( sha2_context *ctx, const unsigned char *input, int ilen )
{
int fill;
unsigned long left;
/*
* output = SHA-256( input buffer )
*/
-void sha2( unsigned char *input, int ilen,
+void sha2( const unsigned char *input, int ilen,
unsigned char output[32], int is224 )
{
sha2_context ctx;
/*
* output = SHA-256( file contents )
*/
-int sha2_file( char *path, unsigned char output[32], int is224 )
+int sha2_file( const char *path, unsigned char output[32], int is224 )
{
FILE *f;
size_t n;
/*
* SHA-256 HMAC context setup
*/
-void sha2_hmac_starts( sha2_context *ctx, unsigned char *key, int keylen,
+void sha2_hmac_starts( sha2_context *ctx, const unsigned char *key, int keylen,
int is224 )
{
int i;
/*
* SHA-256 HMAC process buffer
*/
-void sha2_hmac_update( sha2_context *ctx, unsigned char *input, int ilen )
+void sha2_hmac_update( sha2_context *ctx, const unsigned char *input, int ilen )
{
sha2_update( ctx, input, ilen );
}
memset( tmpbuf, 0, sizeof( tmpbuf ) );
}
+/*
+ * SHA-256 HMAC context reset
+ */
+void sha2_hmac_reset( sha2_context *ctx )
+{
+ sha2_starts( ctx, ctx->is224 );
+ sha2_update( ctx, ctx->ipad, 64 );
+}
+
/*
* output = HMAC-SHA-256( hmac key, input buffer )
*/
-void sha2_hmac( unsigned char *key, int keylen,
- unsigned char *input, int ilen,
+void sha2_hmac( const unsigned char *key, int keylen,
+ const unsigned char *input, int ilen,
unsigned char output[32], int is224 )
{
sha2_context ctx;