From 976bd44433bc9bf698df8bb2cf9f073f4fb05344 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Mon, 10 Oct 2005 17:40:27 +0200
Subject: [PATCH] (sha1_block): Deleted function; inlined where used.
 (SHA1_INCR): New macro for incrementing the block count.

Rev: src/nettle/sha1.c:1.12
---
 sha1.c | 35 ++++++++++++++---------------------
 1 file changed, 14 insertions(+), 21 deletions(-)

diff --git a/sha1.c b/sha1.c
index cd81eb7e..e0498f70 100644
--- a/sha1.c
+++ b/sha1.c
@@ -78,16 +78,7 @@ sha1_init(struct sha1_ctx *ctx)
   ctx->index = 0;
 }
 
-/* FIXME: Inline where used? */
-static void
-sha1_block(struct sha1_ctx *ctx, const uint8_t *block)
-{
-  /* Update block count */
-  if (!++ctx->count_low)
-    ++ctx->count_high;
-
-  _nettle_sha1_compress(ctx->digest, block);
-}
+#define SHA1_INCR(ctx) ((ctx)->count_high += !++(ctx)->count_low)
 
 void
 sha1_update(struct sha1_ctx *ctx,
@@ -105,14 +96,19 @@ sha1_update(struct sha1_ctx *ctx,
       else
 	{
 	  memcpy(ctx->block + ctx->index, buffer, left);
-	  sha1_block(ctx, ctx->block);
+
+	  _nettle_sha1_compress(ctx->digest, ctx->block);
+	  SHA1_INCR(ctx);
+
 	  buffer += left;
 	  length -= left;
 	}
     }
   while (length >= SHA1_DATA_SIZE)
     {
-      sha1_block(ctx, buffer);
+      _nettle_sha1_compress(ctx->digest, buffer);
+      SHA1_INCR(ctx);
+
       buffer += SHA1_DATA_SIZE;
       length -= SHA1_DATA_SIZE;
     }
@@ -130,13 +126,6 @@ sha1_final(struct sha1_ctx *ctx)
   uint32_t bitcount_high;
   uint32_t bitcount_low;
   unsigned i;
-
-  /* The calls to sha1_block increments the block counter, so compute
-     the bit length first. */
-
-  /* There are 512 = 2^9 bits in one block */  
-  bitcount_high = (ctx->count_high << 9) | (ctx->count_low >> 23);
-  bitcount_low = (ctx->count_low << 9) | (ctx->index << 3);
   
   i = ctx->index;
   
@@ -151,19 +140,23 @@ sha1_final(struct sha1_ctx *ctx)
 	 pad with another one */
       memset(ctx->block + i, 0, SHA1_DATA_SIZE - i);
       
-      sha1_block(ctx, ctx->block);
+      _nettle_sha1_compress(ctx->digest, ctx->block);
       i = 0;
     }
   if (i < (SHA1_DATA_SIZE - 8))
     memset(ctx->block + i, 0, (SHA1_DATA_SIZE - 8) - i);
 
+  /* There are 512 = 2^9 bits in one block */  
+  bitcount_high = (ctx->count_high << 9) | (ctx->count_low >> 23);
+  bitcount_low = (ctx->count_low << 9) | (ctx->index << 3);
+
   /* This is slightly inefficient, as the numbers are converted to
      big-endian format, and will be converted back by the compression
      function. It's probably not worth the effort to fix this. */
   WRITE_UINT32(ctx->block + (SHA1_DATA_SIZE - 8), bitcount_high);
   WRITE_UINT32(ctx->block + (SHA1_DATA_SIZE - 4), bitcount_low);
 
-  sha1_block(ctx, ctx->block);
+  _nettle_sha1_compress(ctx->digest, ctx->block);
 }
 
 void
-- 
GitLab