commit 7b3e010b6159017b65a1621478fc7b22e34df119
parent f59775676f908fecdd71fe9a3190b47f77c36621
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date: Tue, 18 May 2021 20:05:06 +0300
sha-1 minor improvements
Diffstat:
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/src/microhttpd/sha1.c b/src/microhttpd/sha1.c
@@ -55,11 +55,6 @@ MHD_SHA1_init (void *ctx_)
/**
- * Number of bytes in single SHA-1 word
- */
-#define SHA1_BYTES_IN_WORD (32 / 8)
-
-/**
* Base of SHA-1 transformation.
* Gets full 512 bits / 64 bytes block of data and updates hash values;
* @param H hash values
@@ -322,7 +317,7 @@ MHD_SHA1_finish (void *ctx_,
num_bits = ctx->count << 3;
/* Note: (count & (SHA1_BLOCK_SIZE-1))
- equal (count % SHA1_BLOCK_SIZE) for this block size. */
+ equals (count % SHA1_BLOCK_SIZE) for this block size. */
bytes_have = (unsigned) (ctx->count & (SHA1_BLOCK_SIZE - 1));
/* Input data must be padded with bit "1" and with length of data in bits.
diff --git a/src/microhttpd/sha1.h b/src/microhttpd/sha1.h
@@ -28,7 +28,7 @@
#include "mhd_options.h"
#include <stdint.h>
-#include <stddef.h>
+#include <stddef.h> /* for size_t */
/**
* SHA-1 digest is kept internally as 5 32-bit words.
@@ -36,9 +36,19 @@
#define _SHA1_DIGEST_LENGTH 5
/**
+ * Number of bytes in single SHA-1 word
+ */
+#define SHA1_WORD_SIZE_BITS 32
+
+/**
+ * Number of bytes in single SHA-1 word
+ */
+#define SHA1_BYTES_IN_WORD (SHA1_WORD_SIZE_BITS / 8)
+
+/**
* Size of SHA-1 digest in bytes
*/
-#define SHA1_DIGEST_SIZE (_SHA1_DIGEST_LENGTH * 4)
+#define SHA1_DIGEST_SIZE (_SHA1_DIGEST_LENGTH * SHA1_BYTES_IN_WORD)
/**
* Size of SHA-1 digest string in chars including termination NUL