diff --git a/vmac.cpp b/vmac.cpp index d4338712..b508834c 100644 --- a/vmac.cpp +++ b/vmac.cpp @@ -47,6 +47,8 @@ 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"); @@ -168,13 +170,15 @@ __attribute__ ((noinline)) // Intel Compiler 9.1 workaround #endif VMAC_Base::VHASH_Update_SSE2(const word64 *data, size_t blocksRemainingInWord64, int tagPart) { - const word64 *nhK = m_nhKey(); - word64 *polyS = m_polyState(); - word32 L1KeyLength = m_L1KeyLength; - + assert(IsAlignedOn(m_polyState(),GetAlignmentOf())); + assert(IsAlignedOn(m_nhKey(),GetAlignmentOf())); CRYPTOPP_UNUSED(data); CRYPTOPP_UNUSED(tagPart); CRYPTOPP_UNUSED(L1KeyLength); CRYPTOPP_UNUSED(blocksRemainingInWord64); + const word64 *nhK = m_nhKey(); + word64 *polyS = (word64*)(void*)m_polyState(); + word32 L1KeyLength = m_L1KeyLength; + #ifdef __GNUC__ word32 temp; __asm__ __volatile__ @@ -532,6 +536,9 @@ template #endif void VMAC_Base::VHASH_Update_Template(const word64 *data, size_t blocksRemainingInWord64) { + assert(IsAlignedOn(m_polyState(),GetAlignmentOf())); + assert(IsAlignedOn(m_nhKey(),GetAlignmentOf())); + #define INNER_LOOP_ITERATION(j) {\ word64 d0 = ConditionalByteReverse(LITTLE_ENDIAN_ORDER, data[i+2*j+0]);\ word64 d1 = ConditionalByteReverse(LITTLE_ENDIAN_ORDER, data[i+2*j+1]);\ @@ -546,7 +553,7 @@ void VMAC_Base::VHASH_Update_Template(const word64 *data, size_t blocksRemaining size_t L1KeyLengthInWord64 = m_L1KeyLength / 8; size_t innerLoopEnd = L1KeyLengthInWord64; const word64 *nhK = m_nhKey(); - word64 *polyS = m_polyState(); + word64 *polyS = (word64*)(void*)m_polyState(); bool isFirstBlock = true; size_t i; @@ -861,6 +868,8 @@ static word64 L3Hash(const word64 *input, const word64 *l3Key, size_t len) void VMAC_Base::TruncatedFinal(byte *mac, size_t size) { + assert(IsAlignedOn(DataBuf(),GetAlignmentOf())); + assert(IsAlignedOn(m_polyState(),GetAlignmentOf())); size_t len = ModPowerOf2(GetBitCountLo()/8, m_L1KeyLength); if (len) diff --git a/vmac.h b/vmac.h index 335afc30..bae39971 100644 --- a/vmac.h +++ b/vmac.h @@ -41,7 +41,7 @@ protected: size_t HashMultipleBlocks(const word64 *input, size_t length); void Init() {} word64* StateBuf() {return NULL;} - word64* DataBuf() {return (word64 *)m_data();} + word64* DataBuf() {return (word64 *)(void*)m_data();} void VHASH_Update_SSE2(const word64 *data, size_t blocksRemainingInWord64, int tagPart); #if !(defined(_MSC_VER) && _MSC_VER < 1300) // can't use function template here with VC6