aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/crypto
diff options
context:
space:
mode:
authorGravatar Carlos Cabanero <cc@blink.sh>2016-12-07 16:03:50 -0500
committerGravatar John Hood <cgull@glup.org>2017-01-05 00:14:36 -0500
commit0ceb4f26f4bf10656ea55f72e2388159c761d737 (patch)
tree43de1bf3c972788a292d25457d72a46cb3c85859 /src/crypto
parent9bb9de8ae5962a7bd6735faa2dc714da1d55304b (diff)
Memory Alignment issues on ARM processors
Unaligned data on ARM architectures do not perform efficiently unaligned memory access, and in the case of ARMv7 and iOS it completely breaks. The OCB algorithm dereferences a uint64x2_t pointer, and is replaced by a memcpy to avoid penalties when trying to align it. More info https://brewx.qualcomm.com/bws/content/gi/common/appseng/en/knowledgebase/docs/kb95.html
Diffstat (limited to 'src/crypto')
-rw-r--r--src/crypto/ocb.cc5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/crypto/ocb.cc b/src/crypto/ocb.cc
index 8660264..4e97d40 100644
--- a/src/crypto/ocb.cc
+++ b/src/crypto/ocb.cc
@@ -271,8 +271,9 @@
static block gen_offset(uint64_t KtopStr[3], unsigned bot) {
const union { unsigned x; unsigned char endian; } little = { 1 };
const int64x2_t k64 = {-64,-64};
- uint64x2_t hi = *(uint64x2_t *)(KtopStr+0); /* hi = A B */
- uint64x2_t lo = *(uint64x2_t *)(KtopStr+1); /* hi = B C */
+ uint64x2_t hi, lo;
+ memcpy(&hi, KtopStr, sizeof(hi));
+ memcpy(&lo, KtopStr+1, sizeof(lo));
int64x2_t ls = vdupq_n_s64(bot);
int64x2_t rs = vqaddq_s64(k64,ls);
block rval = (block)veorq_u64(vshlq_u64(hi,ls),vshlq_u64(lo,rs));