[Pkg-telepathy-commits] [libnice] 58/265: stun: Make the MD5 code strict-aliasing correct
Simon McVittie
smcv at debian.org
Wed May 14 12:04:52 UTC 2014
This is an automated email from the git hooks/post-receive script.
smcv pushed a commit to branch debian
in repository libnice.
commit 344b7b67ec7f7dfd10bed9d397db57d0940f7c79
Author: Olivier Crête <olivier.crete at collabora.com>
Date: Sun Jan 19 16:56:35 2014 -0500
stun: Make the MD5 code strict-aliasing correct
---
stun/md5.c | 30 +++++++++++++++---------------
stun/md5.h | 5 ++++-
2 files changed, 19 insertions(+), 16 deletions(-)
diff --git a/stun/md5.c b/stun/md5.c
index 514279f..8993cdf 100644
--- a/stun/md5.c
+++ b/stun/md5.c
@@ -92,7 +92,7 @@ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
/* Handle any leading odd-sized chunks */
if (t) {
- unsigned char *p = (unsigned char *) ctx->in + t;
+ unsigned char *p = (unsigned char *) ctx->in.u8 + t;
t = 64 - t;
if (len < t) {
@@ -100,24 +100,24 @@ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
return;
}
memcpy(p, buf, t);
- byteReverse(ctx->in, 16);
- MD5Transform(ctx->buf, (uint32_t *) ctx->in);
+ byteReverse(ctx->in.u8, 16);
+ MD5Transform(ctx->buf, ctx->in.u32);
buf += t;
len -= t;
}
/* Process data in 64-byte chunks */
while (len >= 64) {
- memcpy(ctx->in, buf, 64);
- byteReverse(ctx->in, 16);
- MD5Transform(ctx->buf, (uint32_t *) ctx->in);
+ memcpy(ctx->in.u8, buf, 64);
+ byteReverse(ctx->in.u8, 16);
+ MD5Transform(ctx->buf, ctx->in.u32);
buf += 64;
len -= 64;
}
/* Handle any remaining bytes of data. */
- memcpy(ctx->in, buf, len);
+ memcpy(ctx->in.u8, buf, len);
}
/*
@@ -134,7 +134,7 @@ void MD5Final(unsigned char digest[16], struct MD5Context *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 = ctx->in.u8 + count;
*p++ = 0x80;
/* Bytes of padding needed to make 64 bytes */
@@ -144,22 +144,22 @@ void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
if (count < 8) {
/* 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(ctx->in.u8, 16);
+ MD5Transform(ctx->buf, ctx->in.u32);
/* Now fill the next block with 56 bytes */
- memset(ctx->in, 0, 56);
+ memset(ctx->in.u8, 0, 56);
} else {
/* Pad block to 56 bytes */
memset(p, 0, count - 8);
}
- byteReverse(ctx->in, 14);
+ byteReverse(ctx->in.u8, 14);
/* Append length in bits and transform */
- ((uint32_t *) ctx->in)[14] = ctx->bits[0];
- ((uint32_t *) ctx->in)[15] = ctx->bits[1];
+ ctx->in.u32[14] = ctx->bits[0];
+ ctx->in.u32[15] = ctx->bits[1];
- MD5Transform(ctx->buf, (uint32_t *) ctx->in);
+ MD5Transform(ctx->buf, ctx->in.u32);
byteReverse((unsigned char *) ctx->buf, 4);
memcpy(digest, ctx->buf, 16);
memset(ctx, 0, sizeof(struct MD5Context)); /* In case it's sensitive */
diff --git a/stun/md5.h b/stun/md5.h
index fd9f4ce..ccd065e 100644
--- a/stun/md5.h
+++ b/stun/md5.h
@@ -27,7 +27,10 @@
struct MD5Context {
uint32_t buf[4];
uint32_t bits[2];
- uint8_t in[64];
+ union {
+ uint8_t u8[64];
+ uint32_t u32[16];
+ } in;
};
typedef struct MD5Context MD5_CTX;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-telepathy/libnice.git
More information about the Pkg-telepathy-commits
mailing list