Commit b2e54bcdac68d48f4a5919ece045fe4d0f741f96

Guillem Jover 2023-04-09T00:10:07

Sync MD5 changes from OpenBSD

diff --git a/include/md5.h b/include/md5.h
index 596b276..a6d5ed4 100644
--- a/include/md5.h
+++ b/include/md5.h
@@ -1,4 +1,4 @@
-/*	$OpenBSD: md5.h,v 1.15 2004/05/03 17:30:14 millert Exp $	*/
+/*	$OpenBSD: md5.h,v 1.17 2012/12/05 23:19:57 deraadt Exp $	*/
 
 /*
  * This code implements the MD5 message-digest algorithm.
diff --git a/src/md5.c b/src/md5.c
index a6877bc..450415b 100644
--- a/src/md5.c
+++ b/src/md5.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: md5.c,v 1.7 2004/05/28 15:10:27 millert Exp $	*/
+/*	$OpenBSD: md5.c,v 1.12 2020/10/13 04:42:28 guenther Exp $	*/
 
 /*
  * This code implements the MD5 message-digest algorithm.
@@ -39,7 +39,7 @@
 	(cp)[1] = (value) >> 8;						\
 	(cp)[0] = (value); } while (0)
 
-static uint8_t PADDING[MD5_BLOCK_LENGTH] = {
+static const uint8_t PADDING[MD5_BLOCK_LENGTH] = {
 	0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@@ -128,11 +128,9 @@ MD5Final(unsigned char digest[MD5_DIGEST_LENGTH], MD5_CTX *ctx)
 	int i;
 
 	MD5Pad(ctx);
-	if (digest != NULL) {
-		for (i = 0; i < 4; i++)
-			PUT_32BIT_LE(digest + i * 4, ctx->state[i]);
-		memset(ctx, 0, sizeof(*ctx));
-	}
+	for (i = 0; i < 4; i++)
+		PUT_32BIT_LE(digest + i * 4, ctx->state[i]);
+	memset(ctx, 0, sizeof(*ctx));
 }