From 021da95379d3d6e88a0e6005c27b8b9b8f910402 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 31 Jul 2024 13:28:00 +0200 Subject: [PATCH] Update md5.h / md5.c from upstream OpenBSD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit md5.h: 1.1 → 1.3 md5.c: 1.1 → 1.4 Changes are minimal, as upstream itself changed bzero() → memset(). Note that the new bzero_explicit() function call in upstream has been changed to a memset() function call, in the absence of a widely available memset_explicit() function for now. Also update the URL of the OpenBSD source repository. --- lib/md5.c | 13 ++++++------- lib/md5.h | 14 ++++++-------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/lib/md5.c b/lib/md5.c index 2344fb9c..e6c00f12 100644 --- a/lib/md5.c +++ b/lib/md5.c @@ -1,7 +1,7 @@ #include "md5.h" /* The below was retrieved from - * http://www.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/crypto/md5.c?rev=1.1 + * https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/crypto/md5.c?rev=1.4 * with the following changes: * #includes commented out. * Support context->count as uint32_t[2] instead of uint64_t @@ -71,8 +71,9 @@ MD5Init(MD5_CTX *ctx) * of bytes. */ void -MD5Update(MD5_CTX *ctx, uint8_t const *input, size_t len) +MD5Update(MD5_CTX *ctx, const void *inputptr, size_t len) { + const uint8_t *input = inputptr; size_t have, need; /* Check how many bytes we already have and how many more we need. */ @@ -133,10 +134,8 @@ MD5Final(unsigned char digest[MD5_DIGEST_LENGTH], MD5_CTX *ctx) MD5Update(ctx, PADDING, padlen - 8); /* padlen - 8 <= 64 */ MD5Update(ctx, count, 8); - if (digest != NULL) { - for (i = 0; i < 4; i++) - PUT_32BIT_LE(digest + i * 4, ctx->state[i]); - } + for (i = 0; i < 4; i++) + PUT_32BIT_LE(digest + i * 4, ctx->state[i]); memset(ctx, 0, sizeof(*ctx)); /* in case it's sensitive */ } @@ -159,7 +158,7 @@ MD5Final(unsigned char digest[MD5_DIGEST_LENGTH], MD5_CTX *ctx) * the data and converts bytes into longwords for this routine. */ void -MD5Transform(uint32_t state[4], uint8_t const block[MD5_BLOCK_LENGTH]) +MD5Transform(uint32_t state[4], const uint8_t block[MD5_BLOCK_LENGTH]) { uint32_t a, b, c, d, in[MD5_BLOCK_LENGTH / 4]; diff --git a/lib/md5.h b/lib/md5.h index 4302a3f8..b51bc42c 100644 --- a/lib/md5.h +++ b/lib/md5.h @@ -41,7 +41,7 @@ #define MD5Transform librad_MD5Transform /* The below was retrieved from - * http://www.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/crypto/md5.h?rev=1.1 + * https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/crypto/md5.h?rev=1.3 * With the following changes: uint64_t => uint32_t[2] * Commented out #include * Commented out the __BEGIN and __END _DECLS, and the __attributes. @@ -63,20 +63,18 @@ #define MD5_DIGEST_LENGTH 16 typedef struct MD5Context { - uint32_t state[4]; //!< State. - uint32_t count[2]; //!< Number of bits, mod 2^64. - uint8_t buffer[MD5_BLOCK_LENGTH]; //!< Input buffer. + uint32_t state[4]; /* state */ + uint32_t count[2]; /* number of bits, mod 2^64 */ + uint8_t buffer[MD5_BLOCK_LENGTH]; /* input buffer */ } MD5_CTX; -/* include */ - /* __BEGIN_DECLS */ void MD5Init(MD5_CTX *); -void MD5Update(MD5_CTX *, uint8_t const *, size_t) +void MD5Update(MD5_CTX *, const void *, size_t) /* __attribute__((__bounded__(__string__,2,3)))*/; void MD5Final(uint8_t [MD5_DIGEST_LENGTH], MD5_CTX *) /* __attribute__((__bounded__(__minbytes__,1,MD5_DIGEST_LENGTH)))*/; -void MD5Transform(uint32_t [4], uint8_t const [MD5_BLOCK_LENGTH]) +void MD5Transform(uint32_t [4], const uint8_t [MD5_BLOCK_LENGTH]) /* __attribute__((__bounded__(__minbytes__,1,4)))*/ /* __attribute__((__bounded__(__minbytes__,2,MD5_BLOCK_LENGTH)))*/; /* __END_DECLS */