From d8598ce03fe9294a03f90db9a47ca367564bc47f Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Sat, 9 Feb 2019 21:50:21 +0000 Subject: [PATCH] Remove non-STRICT_ALIGNMENT code from xts.c. Independent of the underlying CPU architecture, casting unaligned pointers to uint64_t* is undefined. Just use a memcpy. The compiler should be able to optimize that itself. Change-Id: I39210871fca3eaf1f4b1d205b2bb0c337116d9cc Reviewed-on: https://boringssl-review.googlesource.com/c/34872 Reviewed-by: Adam Langley --- decrepit/xts/xts.c | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/decrepit/xts/xts.c b/decrepit/xts/xts.c index bc2a1b23..a433c3be 100644 --- a/decrepit/xts/xts.c +++ b/decrepit/xts/xts.c @@ -80,23 +80,13 @@ static size_t CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, if (!enc && (len % 16)) len -= 16; while (len >= 16) { -#if STRICT_ALIGNMENT OPENSSL_memcpy(scratch.c, inp, 16); scratch.u[0] ^= tweak.u[0]; scratch.u[1] ^= tweak.u[1]; -#else - scratch.u[0] = ((uint64_t *)inp)[0] ^ tweak.u[0]; - scratch.u[1] = ((uint64_t *)inp)[1] ^ tweak.u[1]; -#endif (*ctx->block1)(scratch.c, scratch.c, ctx->key1); -#if STRICT_ALIGNMENT scratch.u[0] ^= tweak.u[0]; scratch.u[1] ^= tweak.u[1]; OPENSSL_memcpy(out, scratch.c, 16); -#else - ((uint64_t *)out)[0] = scratch.u[0] ^= tweak.u[0]; - ((uint64_t *)out)[1] = scratch.u[1] ^= tweak.u[1]; -#endif inp += 16; out += 16; len -= 16; @@ -134,14 +124,9 @@ static size_t CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, carry = (unsigned int)(tweak.u[0] >> 63); tweak1.u[0] = (tweak.u[0] << 1) ^ res; tweak1.u[1] = (tweak.u[1] << 1) | carry; -#if STRICT_ALIGNMENT OPENSSL_memcpy(scratch.c, inp, 16); scratch.u[0] ^= tweak1.u[0]; scratch.u[1] ^= tweak1.u[1]; -#else - scratch.u[0] = ((uint64_t *)inp)[0] ^ tweak1.u[0]; - scratch.u[1] = ((uint64_t *)inp)[1] ^ tweak1.u[1]; -#endif (*ctx->block1)(scratch.c, scratch.c, ctx->key1); scratch.u[0] ^= tweak1.u[0]; scratch.u[1] ^= tweak1.u[1]; @@ -154,14 +139,9 @@ static size_t CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, scratch.u[0] ^= tweak.u[0]; scratch.u[1] ^= tweak.u[1]; (*ctx->block1)(scratch.c, scratch.c, ctx->key1); -#if STRICT_ALIGNMENT scratch.u[0] ^= tweak.u[0]; scratch.u[1] ^= tweak.u[1]; OPENSSL_memcpy(out, scratch.c, 16); -#else - ((uint64_t *)out)[0] = scratch.u[0] ^ tweak.u[0]; - ((uint64_t *)out)[1] = scratch.u[1] ^ tweak.u[1]; -#endif } return 1;