[PATCH 1/4] lib: Fix strict-aliasing warning in md5 code.
Andreas Schneider
asn at samba.org
Thu Jan 9 07:23:40 MST 2014
If the compiler detects strict aliasing problems it isn't able to
optimize the code.
Signed-off-by: Andreas Schneider <asn at samba.org>
---
lib/crypto/md5.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/lib/crypto/md5.c b/lib/crypto/md5.c
index b834c91..352f80f 100644
--- a/lib/crypto/md5.c
+++ b/lib/crypto/md5.c
@@ -137,9 +137,12 @@ _PUBLIC_ void MD5Final(uint8_t digest[16], MD5_CTX *ctx)
}
byteReverse(ctx->in, 14);
- /* Append length in bits and transform */
- ((uint32_t *) ctx->in)[14] = ctx->bits[0];
- ((uint32_t *) ctx->in)[15] = ctx->bits[1];
+ /* Append length in bits and transform.
+ * Use memcpy to avoid strict-aliasing problems.
+ * This way it can be optimized.
+ */
+ memcpy(&ctx->in[14 * sizeof(uint32_t)], &ctx->bits[0], sizeof(uint32_t));
+ memcpy(&ctx->in[15 * sizeof(uint32_t)], &ctx->bits[1], sizeof(uint32_t));
MD5Transform(ctx->buf, (uint32_t *) ctx->in);
byteReverse((uint8_t *) ctx->buf, 4);
--
1.8.5.2
More information about the samba-technical
mailing list