Skip to content

Commit

Permalink
Update md5.h / md5.c from upstream OpenBSD
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
DimitriPapadopoulos committed Jul 31, 2024
1 parent 5a7c776 commit 021da95
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
13 changes: 6 additions & 7 deletions lib/md5.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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 */
}

Expand All @@ -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];

Expand Down
14 changes: 6 additions & 8 deletions lib/md5.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <sys/cdefs.h>
* Commented out the __BEGIN and __END _DECLS, and the __attributes.
Expand All @@ -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 <sys/cdefs.h> */

/* __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 */
Expand Down

0 comments on commit 021da95

Please sign in to comment.