Skip to content

Commit

Permalink
Memory Alignment issues on ARM processors
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Carlos Cabanero authored and cgull committed Jan 5, 2017
1 parent 9bb9de8 commit 0ceb4f2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/crypto/ocb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 0ceb4f2

Please sign in to comment.