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 <agl@google.com>
This commit is contained in:
David Benjamin 2019-02-09 21:50:21 +00:00 committed by Adam Langley
parent 4d8e1ce5e9
commit d8598ce03f

View File

@ -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;