diff --git a/camellia.cpp b/camellia.cpp index 1c37d4e8..8d0b4d4e 100644 --- a/camellia.cpp +++ b/camellia.cpp @@ -91,11 +91,15 @@ void Camellia::Base::UncheckedSetKey(const byte *key, unsigned int keylen, const kwl = (word64(k0) << 32) | k1; \ kwr = (word64(k2) << 32) | k3 #define KS_ROUND_0(i) \ - *(word64*)CALC_ADDR(ks32, i+EFI(0)) = kwl; \ - *(word64*)CALC_ADDR(ks32, i+EFI(1)) = kwr + assert(IsAlignedOn(CALC_ADDR(ks32, i+EFI(0)),GetAlignmentOf())); \ + assert(IsAlignedOn(CALC_ADDR(ks32, i+EFI(1)),GetAlignmentOf())); \ + *(word64*)(void*)CALC_ADDR(ks32, i+EFI(0)) = kwl; \ + *(word64*)(void*)CALC_ADDR(ks32, i+EFI(1)) = kwr #define KS_ROUND(i, r, which) \ - if (which & (1<> (64 - (r%64))); \ - if (which & (1<64))) *(word64*)CALC_ADDR(ks32, i+EFI(r>64)) = (kwl << (r%64)) | (kwr >> (64 - (r%64))) + assert(IsAlignedOn(CALC_ADDR(ks32, i+EFI(r<64)),GetAlignmentOf())); \ + assert(IsAlignedOn(CALC_ADDR(ks32, i+EFI(r>64)),GetAlignmentOf())); \ + if (which & (1<> (64 - (r%64))); \ + if (which & (1<64))) *(word64*)(void*)CALC_ADDR(ks32, i+EFI(r>64)) = (kwl << (r%64)) | (kwr >> (64 - (r%64))) #else // SSE2 version is 30% faster on Intel Core 2. Doesn't seem worth the hassle of maintenance, but left here // #if'd out in case someone needs it. @@ -216,9 +220,11 @@ void Camellia::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBloc const int cacheLineSize = GetCacheLineSize(); unsigned int i; word32 u = 0; + + assert(IsAlignedOn(s1,GetAlignmentOf())); for (i=0; i<256; i+=cacheLineSize) - u &= *(const word32 *)(s1+i); - u &= *(const word32 *)(s1+252); + u &= *(const word32 *)(void*)(s1+i); + u &= *(const word32 *)(void*)(s1+252); lh |= u; ll |= u; SLOW_ROUND(lh, ll, rh, rl, KS(1,0), KS(1,1)) diff --git a/camellia.h b/camellia.h index 832bceac..b6c4535d 100644 --- a/camellia.h +++ b/camellia.h @@ -31,7 +31,7 @@ class Camellia : public Camellia_Info, public BlockCipherDocumentation void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; protected: - static const byte s1[256]; + CRYPTOPP_ALIGN_DATA(4) static const byte s1[256]; static const word32 SP[4][256]; unsigned int m_rounds;