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

md5.c: Another round of cleanup #31

Merged
merged 1 commit into from
Oct 18, 2023
Merged
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
19 changes: 2 additions & 17 deletions md5/md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,24 @@
*/

#include <stdint.h>

#include "config.h"

#if HAVE_STRING_H || STDC_HEADERS
#include <string.h> /* for memcpy() */
#endif

#include "md5.h"

void byteReverse(unsigned char *buf, unsigned longs);

#ifndef ASM_MD5
/*
* Note: this code is harmless on little-endian machines.
*/
void byteReverse(unsigned char *buf, unsigned longs)
{
uint32_t t;
do {
t = (uint32_t)((unsigned)buf[3]<<8 | buf[2]) << 16 |
const uint32_t t = (uint32_t)((unsigned)buf[3]<<8 | buf[2]) << 16 |
((unsigned)buf[1]<<8 | buf[0]);
*(uint32_t *)buf = t;
buf += 4;
} while (--longs);
}
#endif

/*
* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
Expand All @@ -66,19 +58,15 @@ MD5Init(struct MD5Context *ctx)
void
MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
{
uint32_t t;

/* Update bitcount */

t = ctx->bits[0];
uint32_t t = ctx->bits[0];
if ((ctx->bits[0] = t + ((uint32_t)len << 3)) < t)
ctx->bits[1]++; /* Carry from low to high */
ctx->bits[1] += len >> 29;

t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */

/* Handle any leading odd-sized chunks */

if ( t ) {
unsigned char *p = (unsigned char *)ctx->in + t;

Expand Down Expand Up @@ -155,8 +143,6 @@ MD5Final(unsigned char digest[16], struct MD5Context *ctx)
memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */
}

#ifndef ASM_MD5

/* The four core functions - F1 is optimized somewhat */

/* #define F1(x, y, z) (x & y | ~x & z) */
Expand Down Expand Up @@ -255,4 +241,3 @@ MD5Transform(uint32_t buf[4], uint32_t const in[16])
buf[2] += c;
buf[3] += d;
}
#endif