Keep options ordered alphabetical
[exim.git] / src / src / pdkim / sha1.c
index 81b862f8f9e4f883f9910f104383117af7e09598..96f4e7b57dd75b36618ebcd42526d2958aeb7e01 100644 (file)
@@ -1,3 +1,7 @@
+#include "crypt_ver.h"
+
+#ifdef SHA_POLARSSL    /* remainder of file */
+
 /*
  *  FIPS-180-1 compliant SHA-1 implementation
  *
  *  http://www.itl.nist.gov/fipspubs/fip180-1.htm
  */
 
-#include "sha1.h"
+#include "polarssl/config.h"
+
+#if defined(POLARSSL_SHA1_C)
+
+#include "polarssl/sha1.h"
 
 #include <string.h>
 #include <stdio.h>
@@ -58,6 +66,7 @@
 
 /*
  * SHA-1 context setup
+ * Called from pdkim_parse_sig_header() pdkim_feed_finish() pdkim_init_sign()
  */
 void sha1_starts( sha1_context *ctx )
 {
@@ -229,6 +238,7 @@ static void sha1_process( sha1_context *ctx, const unsigned char data[64] )
 
 /*
  * SHA-1 process buffer
+ * Called from pdkim_feed_finish() & pdkim_finish_bodyhash()
  */
 void sha1_update( sha1_context *ctx, const unsigned char *input, int ilen )
 {
@@ -281,6 +291,7 @@ static const unsigned char sha1_padding[64] =
 
 /*
  * SHA-1 final digest
+ * Called from pdkim_feed_finish() & pdkim_finish_bodyhash()
  */
 void sha1_finish( sha1_context *ctx, unsigned char output[20] )
 {
@@ -308,127 +319,5 @@ void sha1_finish( sha1_context *ctx, unsigned char output[20] )
     PUT_ULONG_BE( ctx->state[4], output, 16 );
 }
 
-/*
- * output = SHA-1( input buffer )
- */
-void sha1( const unsigned char *input, int ilen, unsigned char output[20] )
-{
-    sha1_context ctx;
-
-    sha1_starts( &ctx );
-    sha1_update( &ctx, input, ilen );
-    sha1_finish( &ctx, output );
-
-    memset( &ctx, 0, sizeof( sha1_context ) );
-}
-
-/*
- * output = SHA-1( file contents )
- */
-int sha1_file( const char *path, unsigned char output[20] )
-{
-    FILE *f;
-    size_t n;
-    sha1_context ctx;
-    unsigned char buf[1024];
-
-    if( ( f = fopen( path, "rb" ) ) == NULL )
-        return( 1 );
-
-    sha1_starts( &ctx );
-
-    while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 )
-        sha1_update( &ctx, buf, (int) n );
-
-    sha1_finish( &ctx, output );
-
-    memset( &ctx, 0, sizeof( sha1_context ) );
-
-    if( ferror( f ) != 0 )
-    {
-        fclose( f );
-        return( 2 );
-    }
-
-    fclose( f );
-    return( 0 );
-}
-
-/*
- * SHA-1 HMAC context setup
- */
-void sha1_hmac_starts( sha1_context *ctx, const unsigned char *key, int keylen )
-{
-    int i;
-    unsigned char sum[20];
-
-    if( keylen > 64 )
-    {
-        sha1( key, keylen, sum );
-        keylen = 20;
-        key = sum;
-    }
-
-    memset( ctx->ipad, 0x36, 64 );
-    memset( ctx->opad, 0x5C, 64 );
-
-    for( i = 0; i < keylen; i++ )
-    {
-        ctx->ipad[i] = (unsigned char)( ctx->ipad[i] ^ key[i] );
-        ctx->opad[i] = (unsigned char)( ctx->opad[i] ^ key[i] );
-    }
-
-    sha1_starts( ctx );
-    sha1_update( ctx, ctx->ipad, 64 );
-
-    memset( sum, 0, sizeof( sum ) );
-}
-
-/*
- * SHA-1 HMAC process buffer
- */
-void sha1_hmac_update( sha1_context *ctx, const unsigned char *input, int ilen )
-{
-    sha1_update( ctx, input, ilen );
-}
-
-/*
- * SHA-1 HMAC final digest
- */
-void sha1_hmac_finish( sha1_context *ctx, unsigned char output[20] )
-{
-    unsigned char tmpbuf[20];
-
-    sha1_finish( ctx, tmpbuf );
-    sha1_starts( ctx );
-    sha1_update( ctx, ctx->opad, 64 );
-    sha1_update( ctx, tmpbuf, 20 );
-    sha1_finish( ctx, output );
-
-    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( const unsigned char *key, int keylen,
-                const unsigned char *input, int ilen,
-                unsigned char output[20] )
-{
-    sha1_context ctx;
-
-    sha1_hmac_starts( &ctx, key, keylen );
-    sha1_hmac_update( &ctx, input, ilen );
-    sha1_hmac_finish( &ctx, output );
-
-    memset( &ctx, 0, sizeof( sha1_context ) );
-}
+#endif
+#endif