diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2013-06-27 01:03:19 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2013-06-27 01:03:19 +0200 |
commit | 1f5e81f8f83087082108cf9449068ec4c2a3125e (patch) | |
tree | a3bb9d33dc2da4d68f109aeb18699f5adced15fa | |
parent | f6205c6ab786f14e3515dfc0bfdb958ada8ed0e9 (diff) | |
download | busybox-w32-1f5e81f8f83087082108cf9449068ec4c2a3125e.tar.gz busybox-w32-1f5e81f8f83087082108cf9449068ec4c2a3125e.tar.bz2 busybox-w32-1f5e81f8f83087082108cf9449068ec4c2a3125e.zip |
md5/sha512: a better fix for strict aliasing warnings
The locations *are* well-aligned for direct stores
on any architecture.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | include/platform.h | 1 | ||||
-rw-r--r-- | libbb/hash_md5_sha.c | 6 |
2 files changed, 4 insertions, 3 deletions
diff --git a/include/platform.h b/include/platform.h index 917d87dd6..0fa9f6182 100644 --- a/include/platform.h +++ b/include/platform.h | |||
@@ -208,6 +208,7 @@ typedef int bb__aliased_int FIX_ALIASING; | |||
208 | typedef long bb__aliased_long FIX_ALIASING; | 208 | typedef long bb__aliased_long FIX_ALIASING; |
209 | typedef uint16_t bb__aliased_uint16_t FIX_ALIASING; | 209 | typedef uint16_t bb__aliased_uint16_t FIX_ALIASING; |
210 | typedef uint32_t bb__aliased_uint32_t FIX_ALIASING; | 210 | typedef uint32_t bb__aliased_uint32_t FIX_ALIASING; |
211 | typedef uint64_t bb__aliased_uint64_t FIX_ALIASING; | ||
211 | 212 | ||
212 | /* NB: unaligned parameter should be a pointer, aligned one - | 213 | /* NB: unaligned parameter should be a pointer, aligned one - |
213 | * a lvalue. This makes it more likely to not swap them by mistake | 214 | * a lvalue. This makes it more likely to not swap them by mistake |
diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index e10cb391d..3f743ac75 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c | |||
@@ -84,7 +84,7 @@ static void FAST_FUNC common64_end(md5_ctx_t *ctx, int swap_needed) | |||
84 | if (swap_needed) | 84 | if (swap_needed) |
85 | t = bb_bswap_64(t); | 85 | t = bb_bswap_64(t); |
86 | /* wbuffer is suitably aligned for this */ | 86 | /* wbuffer is suitably aligned for this */ |
87 | memcpy(&ctx->wbuffer[64 - 8], &t, sizeof(t)); | 87 | *(bb__aliased_uint64_t *) (&ctx->wbuffer[64 - 8]) = t; |
88 | } | 88 | } |
89 | ctx->process_block(ctx); | 89 | ctx->process_block(ctx); |
90 | if (remaining >= 8) | 90 | if (remaining >= 8) |
@@ -883,10 +883,10 @@ void FAST_FUNC sha512_end(sha512_ctx_t *ctx, void *resbuf) | |||
883 | uint64_t t; | 883 | uint64_t t; |
884 | t = ctx->total64[0] << 3; | 884 | t = ctx->total64[0] << 3; |
885 | t = SWAP_BE64(t); | 885 | t = SWAP_BE64(t); |
886 | memcpy(&ctx->wbuffer[128 - 8], &t, sizeof(t)); | 886 | *(bb__aliased_uint64_t *) (&ctx->wbuffer[128 - 8]) = t; |
887 | t = (ctx->total64[1] << 3) | (ctx->total64[0] >> 61); | 887 | t = (ctx->total64[1] << 3) | (ctx->total64[0] >> 61); |
888 | t = SWAP_BE64(t); | 888 | t = SWAP_BE64(t); |
889 | memcpy(&ctx->wbuffer[128 - 16], &t, sizeof(t)); | 889 | *(bb__aliased_uint64_t *) (&ctx->wbuffer[128 - 16]) = t; |
890 | } | 890 | } |
891 | sha512_process_block128(ctx); | 891 | sha512_process_block128(ctx); |
892 | if (remaining >= 16) | 892 | if (remaining >= 16) |