From 7d7afc3b89798e7df87a8044e465c83b17fd498d Mon Sep 17 00:00:00 2001 From: Adam Langley Date: Tue, 16 Aug 2016 10:56:02 -0700 Subject: [PATCH] Drop STRICT_ALIGNMENT code in ofb.c. By using memcpy, GCC can already optimise things so that the compiled code is identical on x86-64. Thus we don't need to worry about having different versions for platforms with, and without, strict alignment. (Thanks to Emil Mikulic.) Change-Id: I08bc5fa9b67aa369be2dd2e29e4229fb5b5ff40c Reviewed-on: https://boringssl-review.googlesource.com/10381 Commit-Queue: Adam Langley Commit-Queue: David Benjamin Reviewed-by: David Benjamin CQ-Verified: CQ bot account: commit-bot@chromium.org --- crypto/modes/ofb.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/crypto/modes/ofb.c b/crypto/modes/ofb.c index 2c5bdc9a..0ee95ca4 100644 --- a/crypto/modes/ofb.c +++ b/crypto/modes/ofb.c @@ -49,6 +49,7 @@ #include #include +#include #include "internal.h" @@ -68,27 +69,15 @@ void CRYPTO_ofb128_encrypt(const uint8_t *in, uint8_t *out, size_t len, n = (n + 1) % 16; } -#if STRICT_ALIGNMENT - if (((size_t)in | (size_t)out | (size_t)ivec) % sizeof(size_t) != 0) { - size_t l = 0; - while (l < len) { - if (n == 0) { - (*block)(ivec, ivec, key); - } - out[l] = in[l] ^ ivec[n]; - ++l; - n = (n + 1) % 16; - } - - *num = n; - return; - } -#endif - while (len >= 16) { (*block)(ivec, ivec, key); for (; n < 16; n += sizeof(size_t)) { - *(size_t *)(out + n) = *(size_t *)(in + n) ^ *(size_t *)(ivec + n); + size_t a, b; + memcpy(&a, in + n, sizeof(size_t)); + memcpy(&b, ivec + n, sizeof(size_t)); + + const size_t c = a ^ b; + memcpy(out + n, &c, sizeof(size_t)); } len -= 16; out += 16;