From eae01d4ba18782a997edec2ff79976313c7dc415 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Thu, 27 Feb 1997 14:55:46 +0100
Subject: [PATCH] Bugfixes in sha_copy and shs_update

Rev: src/modules/_Crypto/lib/sha.c:1.5
---
 src/modules/_Crypto/lib/sha.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/modules/_Crypto/lib/sha.c b/src/modules/_Crypto/lib/sha.c
index 7b0ab15612..60f8fb5742 100644
--- a/src/modules/_Crypto/lib/sha.c
+++ b/src/modules/_Crypto/lib/sha.c
@@ -39,7 +39,11 @@ void sha_copy(struct sha_ctx *dest, struct sha_ctx *src)
 
   dest->count_l=src->count_l;
   dest->count_h=src->count_h;
-  for(i=0; i<SHA_DIGESTLEN; i++) dest->digest[i]=src->digest[i];
+  for(i=0; i<SHA_DIGESTLEN; i++)
+    dest->digest[i]=src->digest[i];
+  for(i=0; i < src->index; i++)
+    dest->block[i] = src->block[i];
+  dest->index = src->index;
 }
 
 
@@ -269,13 +273,13 @@ static void sha_block(struct sha_ctx *ctx, unsigned INT8 *block)
     ++ctx->count_h;
 
   /* Endian independent conversion */
-  for (i = 0; i<16; i++, block += 4)
+  for (i = 0; i<SHA_DATALEN; i++, block += 4)
     data[i] = STRING2INT(block);
 
   sha_transform(ctx, data);
 }
 
-void sha_update(struct sha_ctx *ctx, unsigned INT8 *buffer, INT32 len)
+void sha_update(struct sha_ctx *ctx, unsigned INT8 *buffer, unsigned INT32 len)
 {
   if (ctx->index)
     { /* Try to fill partial block */
@@ -341,8 +345,8 @@ void sha_final(struct sha_ctx *ctx)
     for (i = words ; i < SHA_DATALEN - 2; i++)
       data[i] = 0;
   /* Theres 512 = 2^9 bits in one block */
-  data[SHA_DATALEN-2] = ctx->count_h << 9;
-  data[SHA_DATALEN-1] = ctx->count_l << 9 | ctx->index << 3;
+  data[SHA_DATALEN-2] = (ctx->count_h << 9) | (ctx->count_l >> 23);
+  data[SHA_DATALEN-1] = (ctx->count_l << 9) | (ctx->index << 3);
   sha_transform(ctx, data);
 }
 
-- 
GitLab