From f591b09da5c04b2ad0ab82041f05c178b3306b52 Mon Sep 17 00:00:00 2001 From: "Carsten Haitzler (Rasterman)" Date: Sun, 12 Feb 2017 13:55:18 +0900 Subject: [PATCH] e ervything md5 code - fix warnings about alignment gcc on arm is actually validly complaining about us using int * ptrs to point to char * data and thus it likely be unaligned, so work in reverse. make the data int * aligned and when needed mess with it as char * data byte by byte. warnings gone. --- src/modules/everything/md5.c | 27 +++++++++++++++------------ src/modules/everything/md5.h | 2 +- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/modules/everything/md5.c b/src/modules/everything/md5.c index fdc44cdf8..8219f0636 100644 --- a/src/modules/everything/md5.c +++ b/src/modules/everything/md5.c @@ -82,8 +82,9 @@ MD5Update(MD5_CTX *ctx, unsigned char const *buf, unsigned len) if (t) { - unsigned char *p = (unsigned char *)ctx->in + t; + unsigned char *p = (void *)ctx->in; + p += t; t = 64 - t; if (len < t) { @@ -91,8 +92,8 @@ MD5Update(MD5_CTX *ctx, unsigned char const *buf, unsigned len) return; } memcpy(p, buf, t); - byteReverse(ctx->in, 16); - MD5Transform(ctx->buf, (uint32_t *)ctx->in); + byteReverse((void *)ctx->in, 16); + MD5Transform(ctx->buf, ctx->in); buf += t; len -= t; } @@ -100,8 +101,8 @@ MD5Update(MD5_CTX *ctx, unsigned char const *buf, unsigned len) while (len >= 64) { memcpy(ctx->in, buf, 64); - byteReverse(ctx->in, 16); - MD5Transform(ctx->buf, (uint32_t *)ctx->in); + byteReverse((void *)ctx->in, 16); + MD5Transform(ctx->buf, ctx->in); buf += 64; len -= 64; } @@ -126,7 +127,8 @@ MD5Final(unsigned char digest[16], MD5_CTX *ctx) /* Set the first char of padding to 0x80. This is safe since there is always at least one byte free */ - p = ctx->in + count; + p = (void *)ctx->in; + p += count; *p++ = 0x80; /* Bytes of padding needed to make 64 bytes */ @@ -137,8 +139,8 @@ MD5Final(unsigned char digest[16], MD5_CTX *ctx) { /* Two lots of padding: Pad the first block to 64 bytes */ memset(p, 0, count); - byteReverse(ctx->in, 16); - MD5Transform(ctx->buf, (uint32_t *)ctx->in); + byteReverse((void *)ctx->in, 16); + MD5Transform(ctx->buf, ctx->in); /* Now fill the next block with 56 bytes */ memset(ctx->in, 0, 56); @@ -147,13 +149,14 @@ MD5Final(unsigned char digest[16], MD5_CTX *ctx) /* Pad block to 56 bytes */ memset(p, 0, count - 8); } - byteReverse(ctx->in, 14); + byteReverse((void *)ctx->in, 14); /* Append length in bits and transform */ - ctx->in[14] = ctx->bits[0]; - ctx->in[15] = ctx->bits[1]; + p = (void *)ctx->in; + p[14] = ctx->bits[0]; + p[15] = ctx->bits[1]; - MD5Transform(ctx->buf, (uint32_t *)ctx->in); + MD5Transform(ctx->buf, ctx->in); byteReverse((unsigned char *)ctx->buf, 4); memcpy(digest, ctx->buf, 16); memset((char *)ctx, 0, sizeof(*ctx)); /* In case it's sensitive */ diff --git a/src/modules/everything/md5.h b/src/modules/everything/md5.h index 348fcd654..d4e073079 100644 --- a/src/modules/everything/md5.h +++ b/src/modules/everything/md5.h @@ -9,7 +9,7 @@ typedef struct MD5Context { uint32_t buf[4]; uint32_t bits[2]; - unsigned char in[64]; + uint32_t in[16]; } MD5_CTX; extern void MD5Init(MD5_CTX *context);