EXPAND_LISTMATCH_RHS plumbed into build makefiles.
[exim.git] / src / src / pdkim / sha1.c
index f118f4eb18db4e3400a1521856695428afb4eabc..81b862f8f9e4f883f9910f104383117af7e09598 100644 (file)
@@ -1,9 +1,12 @@
 /*
  *  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
@@ -25,8 +28,6 @@
  *  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>
@@ -70,7 +71,7 @@ void sha1_starts( sha1_context *ctx )
     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;
 
@@ -229,7 +230,7 @@ static void sha1_process( sha1_context *ctx, unsigned char data[64] )
 /*
  * 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;
@@ -310,7 +311,7 @@ void sha1_finish( sha1_context *ctx, unsigned char output[20] )
 /*
  * 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;
 
@@ -324,7 +325,7 @@ void sha1_oneshot( unsigned char *input, int ilen, unsigned char output[20] )
 /*
  * 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;
@@ -356,14 +357,14 @@ int sha1_file( char *path, unsigned char output[20] )
 /*
  * 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;
     }
@@ -386,7 +387,7 @@ void sha1_hmac_starts( sha1_context *ctx, unsigned char *key, int keylen )
 /*
  * 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 );
 }
@@ -407,11 +408,20 @@ void sha1_hmac_finish( sha1_context *ctx, unsigned char output[20] )
     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;