From cdcff65a350895bf81bc245d71ed27866a34787c Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Mon, 25 Jan 2016 00:12:37 -0500 Subject: [PATCH] Cleared -Wcast-align (Issue 122) --- gcm.cpp | 14 +++++++++----- vmac.cpp | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/gcm.cpp b/gcm.cpp index e74c7408..18067eac 100644 --- a/gcm.cpp +++ b/gcm.cpp @@ -89,8 +89,11 @@ inline static void SSE2_Xor16(byte *a, const byte *b, const byte *c) inline static void Xor16(byte *a, const byte *b, const byte *c) { - ((word64 *)a)[0] = ((word64 *)b)[0] ^ ((word64 *)c)[0]; - ((word64 *)a)[1] = ((word64 *)b)[1] ^ ((word64 *)c)[1]; + assert(IsAlignedOn(a,GetAlignmentOf())); + assert(IsAlignedOn(b,GetAlignmentOf())); + assert(IsAlignedOn(c,GetAlignmentOf())); + ((word64 *)(void *)a)[0] = ((word64 *)(void *)b)[0] ^ ((word64 *)(void *)c)[0]; + ((word64 *)(void *)a)[1] = ((word64 *)(void *)b)[1] ^ ((word64 *)(void *)c)[1]; } #if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE @@ -436,7 +439,8 @@ size_t GCM_Base::AuthenticateBlocks(const byte *data, size_t len) #endif typedef BlockGetAndPut Block; - word64 *hashBuffer = (word64 *)HashBuffer(); + word64 *hashBuffer = (word64 *)(void *)HashBuffer(); + assert(IsAlignedOn(hashBuffer,GetAlignmentOf())); switch (2*(m_buffer.size()>=64*1024) #if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE || defined(CRYPTOPP_X64_MASM_AVAILABLE) @@ -459,7 +463,7 @@ size_t GCM_Base::AuthenticateBlocks(const byte *data, size_t len) data += HASH_BLOCKSIZE; len -= HASH_BLOCKSIZE; - #define READ_TABLE_WORD64_COMMON(a, b, c, d) *(word64 *)(table+(a*1024)+(b*256)+c+d*8) + #define READ_TABLE_WORD64_COMMON(a, b, c, d) *(word64 *)(void *)(table+(a*1024)+(b*256)+c+d*8) #ifdef IS_LITTLE_ENDIAN #if CRYPTOPP_BOOL_SLOW_WORD64 @@ -530,7 +534,7 @@ size_t GCM_Base::AuthenticateBlocks(const byte *data, size_t len) #undef READ_TABLE_WORD64_COMMON #undef READ_TABLE_WORD64 - #define READ_TABLE_WORD64_COMMON(a, c, d) *(word64 *)(table+(a)*256*16+(c)+(d)*8) + #define READ_TABLE_WORD64_COMMON(a, c, d) *(word64 *)(void *)(table+(a)*256*16+(c)+(d)*8) #ifdef IS_LITTLE_ENDIAN #if CRYPTOPP_BOOL_SLOW_WORD64 diff --git a/vmac.cpp b/vmac.cpp index b508834c..c3c97cfe 100644 --- a/vmac.cpp +++ b/vmac.cpp @@ -47,8 +47,6 @@ static const word128 m126 = (word128(m62)<<64)|m64; /* 126-bit mask */ void VMAC_Base::UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs ¶ms) { - assert(IsAlignedOn(m_l3Key(),GetAlignmentOf())); - int digestLength = params.GetIntValueWithDefault(Name::DigestSize(), DefaultDigestSize()); if (digestLength != 8 && digestLength != 16) throw InvalidArgument("VMAC: DigestSize must be 8 or 16"); @@ -89,6 +87,8 @@ void VMAC_Base::UncheckedSetKey(const byte *userKey, unsigned int keylength, con in[0] = 0xE0; in[15] = 0; word64 *l3Key = m_l3Key(); + assert(IsAlignedOn(l3Key,GetAlignmentOf())); + for (i = 0; i <= (size_t)m_is128; i++) do {