boringssl/crypto/fipsmodule/modes
David Benjamin 104306f587 Remove STRICT_ALIGNMENT code from modes.
STRICT_ALIGNMENT is a remnant of OpenSSL code would cast pointers to
size_t* and load more than one byte at a time. Not all architectures
support unaligned access, so it did an alignment check and only enterred
this path if aligned or the underlying architecture didn't care.

This is UB. Unaligned casts in C are undefined on all architectures, so
we switch these to memcpy some time ago. Compilers can optimize memcpy
to the unaligned accesses we wanted. That left our modes logic as:

- If STRICT_ALIGNMENT is 1 and things are unaligned, work byte-by-byte.

- Otherwise, use the memcpy-based word-by-word code, which now works
  independent of STRICT_ALIGNMENT.

Remove the first check to simplify things. On x86, x86_64, and aarch64,
STRICT_ALIGNMENT is zero and this is a no-op. ARM is more complex. Per
[0], ARMv7 and up support unaligned access. ARMv5 do not. ARMv6 does,
but can run in a mode where it looks more like ARMv5.

For ARMv7 and up, STRICT_ALIGNMENT should have been zero, but was one.
Thus this change should be an improvement for ARMv7 (right now unaligned
inputs lose bsaes-armv7). The Android NDK does not even support the
pre-ARMv7 ABI anymore[1]. Nonetheless, Cronet still supports ARMv6 as a
library. It builds with -march=armv6 which GCC interprets as supporting
unaligned access, so it too did not want this code.

For completeness, should anyone still care about ARMv5 or be building
with an overly permissive -march flag, GCC does appear unable to inline
the memcpy calls. However, GCC also does not interpret
(uintptr_t)ptr % sizeof(size_t) as an alignment assertion, so such
consumers have already been paying for the memcpy here and throughout
the library.

In general, C's arcane pointer rules mean we must resort to memcpy
often, so, realistically, we must require that the compiler optimize
memcpy well.

[0] https://medium.com/@iLevex/the-curious-case-of-unaligned-access-on-arm-5dd0ebe24965
[1] https://developer.android.com/ndk/guides/abis#armeabi

Change-Id: I3c7dea562adaeb663032e395499e69530dd8e145
Reviewed-on: https://boringssl-review.googlesource.com/c/34873
Reviewed-by: Adam Langley <agl@google.com>
2019-02-14 17:39:36 +00:00
..
asm Fix the order of Windows unwind codes. 2019-02-05 19:38:23 +00:00
cbc.c Remove STRICT_ALIGNMENT code from modes. 2019-02-14 17:39:36 +00:00
ccm.c Fix undefined block128_f, etc., casts. 2018-10-01 17:35:02 +00:00
cfb.c Remove STRICT_ALIGNMENT code from modes. 2019-02-14 17:39:36 +00:00
ctr.c Remove STRICT_ALIGNMENT code from modes. 2019-02-14 17:39:36 +00:00
gcm_test.cc Add ABI tests for aesni-gcm-x86_64.pl. 2019-02-11 20:08:38 +00:00
gcm_tests.txt
gcm.c Remove STRICT_ALIGNMENT code from modes. 2019-02-14 17:39:36 +00:00
internal.h Remove STRICT_ALIGNMENT code from modes. 2019-02-14 17:39:36 +00:00
ofb.c Modernize OPENSSL_COMPILE_ASSERT, part 2. 2018-11-14 16:06:37 +00:00
polyval.c Run the comment converter on libcrypto. 2017-08-18 21:49:04 +00:00