From 05d6defd776cb19f1136254575d7e4b84bf7f665 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sat, 7 Sep 2013 16:40:51 -0700 Subject: [PATCH] Quick quirk to support unaligned input for aes256estream. --- .../aes256estream/hongjun/aes256-ctr.c | 21 +++++++++++++++++++ .../aes256estream/hongjun/aes256.h | 2 -- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/libsodium/crypto_stream/aes256estream/hongjun/aes256-ctr.c b/src/libsodium/crypto_stream/aes256estream/hongjun/aes256-ctr.c index 4a724b5a..7341af71 100644 --- a/src/libsodium/crypto_stream/aes256estream/hongjun/aes256-ctr.c +++ b/src/libsodium/crypto_stream/aes256estream/hongjun/aes256-ctr.c @@ -117,6 +117,27 @@ partial_precompute_tworounds(ECRYPT_ctx* ctx) /* ------------------------------------------------------------------------- */ +#if defined(CPU_X86) || defined(CPU_X86_64) || defined(CPU_PPC) || defined(CPU_Z390) +# undef CPU_ALIGNED_ACCESS_REQUIRED +#else +# define CPU_ALIGNED_ACCESS_REQUIRED +#endif + +#ifndef CPU_ALIGNED_ACCESS_REQUIRED +# define UNALIGNED_U32_READ(P, I) (((const u32 *)(const void *) (P))[(I)]) +#else +static inline uint32_t +UNALIGNED_U32_READ(const u8 * const p, const size_t i) +{ + uint32_t t; + (void) sizeof(int[sizeof(*p) == sizeof(char) ? 1 : -1]); + memcpy(&t, p + i * (sizeof t / sizeof *p), sizeof t); + return t; +} +#endif + +/* ------------------------------------------------------------------------- */ + static void ECRYPT_process_bytes(int action, ECRYPT_ctx* ctx, const u8* input, u8* output, u32 msglen) diff --git a/src/libsodium/crypto_stream/aes256estream/hongjun/aes256.h b/src/libsodium/crypto_stream/aes256estream/hongjun/aes256.h index 1d98293c..9b54f247 100644 --- a/src/libsodium/crypto_stream/aes256estream/hongjun/aes256.h +++ b/src/libsodium/crypto_stream/aes256estream/hongjun/aes256.h @@ -156,5 +156,3 @@ round(ctx,j0,j1,j2,j3,k0,k1,k2,k3,13);\ last_round(ctx,k0,k1,k2,k3,(output),14);\ } - -#define UNALIGNED_U32_READ(P, I) (((const u32 *)(const void *) (P))[(I)])