summaryrefslogtreecommitdiff
path: root/src/aes/ao_aes.c
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2016-12-17 20:58:36 -0800
committerBdale Garbee <bdale@gag.com>2017-01-25 12:21:43 -0700
commitfe25510fc23031f1a3c1b42edd37067d1989a9f6 (patch)
tree3cdc98d2c3d1c8d9bd95045771be7d15226d246b /src/aes/ao_aes.c
parent4163d88ed36ce8863218366f1fb504f7061a4ca5 (diff)
altos/arm: Align data so that gcc 5.4 doesn't do byte-accesses. Add -Wcast-align
Gcc 5.4.1 tracks alignment of data through assignments, so that a uint32_t pointer which comes from byte-aligned uint8_t data: extern uint8_t foo[]; uint32_t *q = (void *) foo; Fetches and stores through this pointer are done bytewise. This is slow (meh), but if q references a device register, things to bad very quickly. This patch works around this bug in the compiler by adding __attribute__((aligned(4))) tags to some variables, or changing them from uint8_t to uint32_t. Places doing this will now be caught as I've added -Wcast-align to the compiler flags. That required adding (void *) casts, after the relevant code was checked to make sure the compiler could tell that the addresses were aligned. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/aes/ao_aes.c')
-rw-r--r--src/aes/ao_aes.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/aes/ao_aes.c b/src/aes/ao_aes.c
index a04174c6..fd90c5bf 100644
--- a/src/aes/ao_aes.c
+++ b/src/aes/ao_aes.c
@@ -359,10 +359,10 @@ void xrijndaelDecrypt(word32 block[], roundkey *rkk)
#endif
uint8_t ao_aes_mutex;
-static uint8_t key[16];
+static word32 key[16/4];
static roundkey rkk;
-static uint8_t iv[16];
+static word32 iv[16/4];
void
ao_aes_set_mode(enum ao_aes_mode mode)
@@ -389,10 +389,11 @@ ao_aes_run(__xdata uint8_t *in,
__xdata uint8_t *out)
{
uint8_t i;
+ uint8_t *_iv = (uint8_t *) iv;
for (i = 0; i < 16; i++)
- iv[i] ^= in[i];
- xrijndaelEncrypt((word32 *) iv, &rkk);
+ _iv[i] ^= in[i];
+ xrijndaelEncrypt(iv, &rkk);
if (out)
memcpy(out, iv, 16);
}