diff options
author | Andreas Schneider <asn@samba.org> | 2014-01-09 14:50:18 +0100 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2014-01-09 20:42:54 +0100 |
commit | 615efa4ae84373ae8aefb36fcf7583338665429a (patch) | |
tree | 38a53351c208769a1af69e7d0aa297fc7d37ad5b /lib/crypto | |
parent | 044f8f71903084717271038d931d7dd47e8e74c3 (diff) | |
download | samba-615efa4ae84373ae8aefb36fcf7583338665429a.tar.gz |
lib: Fix strict-aliasing warning in md5 code.
If the compiler detects strict aliasing problems it isn't able to
optimize the code.
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Günther Deschner <gd@samba.org>
Diffstat (limited to 'lib/crypto')
-rw-r--r-- | lib/crypto/md5.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/crypto/md5.c b/lib/crypto/md5.c index b834c912dfb..352f80f5d11 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); |