Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update md5.h / md5.c from upstream OpenBSD #127

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/md5.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#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
* u_int* to uint*
* explicit_bzero() to memset()
*/

/*
Expand Down Expand Up @@ -71,8 +72,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 +135,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 */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's where upstream introduced a bzero_explicit() call, which we keep translating into a memset() call.

}

Expand All @@ -159,7 +159,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
8 changes: 3 additions & 5 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 @@ -68,15 +68,13 @@ typedef struct MD5Context {
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