Const-ify hashKey

pull/461/head
Jeffrey Walton 2017-07-31 04:27:22 -04:00
parent 6145d52b22
commit eafdae9025
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
2 changed files with 9 additions and 12 deletions

View File

@ -279,7 +279,7 @@ uint64x2_t GCM_Multiply_PMULL(const uint64x2_t &x, const uint64x2_t &h, const ui
return GCM_Reduce_PMULL(c0, c1, c2, r); return GCM_Reduce_PMULL(c0, c1, c2, r);
} }
void GCM_SetKeyWithoutResync_PMULL(byte *mulTable, byte *hashKey, unsigned int tableSize) void GCM_SetKeyWithoutResync_PMULL(const byte *hashKey, byte *mulTable, unsigned int tableSize)
{ {
const uint64x2_t r = s_clmulConstants[0]; const uint64x2_t r = s_clmulConstants[0];
const uint64x2_t t = vreinterpretq_u64_u8(vrev64q_u8(vld1q_u8(hashKey))); const uint64x2_t t = vreinterpretq_u64_u8(vrev64q_u8(vld1q_u8(hashKey)));
@ -472,10 +472,10 @@ __m128i GCM_Multiply_CLMUL(const __m128i &x, const __m128i &h, const __m128i &r)
return GCM_Reduce_CLMUL(c0, c1, c2, r); return GCM_Reduce_CLMUL(c0, c1, c2, r);
} }
void GCM_SetKeyWithoutResync_CLMUL(byte *mulTable, byte *hashKey, unsigned int tableSize) void GCM_SetKeyWithoutResync_CLMUL(const byte *hashKey, byte *mulTable, unsigned int tableSize)
{ {
const __m128i r = s_clmulConstants[0]; const __m128i r = s_clmulConstants[0];
const __m128i h0 = _mm_shuffle_epi8(_mm_load_si128((__m128i *)(void *)hashKey), s_clmulConstants[1]); const __m128i h0 = _mm_shuffle_epi8(_mm_load_si128((const __m128i *)(const void *)hashKey), s_clmulConstants[1]);
__m128i h = h0; __m128i h = h0;
unsigned int i; unsigned int i;

15
gcm.cpp
View File

@ -89,10 +89,9 @@ inline static void SSE2_Xor16(byte *a, const byte *b, const byte *c)
#endif #endif
#if CRYPTOPP_CLMUL_AVAILABLE #if CRYPTOPP_CLMUL_AVAILABLE
extern __m128i GCM_Multiply_CLMUL(const __m128i &x, const __m128i &h, const __m128i &r); extern __m128i GCM_Multiply_CLMUL(const __m128i &x, const __m128i &h, const __m128i &r);
extern __m128i GCM_Reduce_CLMUL(__m128i c0, __m128i c1, __m128i c2, const __m128i &r); extern __m128i GCM_Reduce_CLMUL(__m128i c0, __m128i c1, __m128i c2, const __m128i &r);
extern void GCM_SetKeyWithoutResync_CLMUL(byte *mulTable, byte *hashKey, unsigned int tableSize); extern void GCM_SetKeyWithoutResync_CLMUL(const byte *hashKey, byte *mulTable, unsigned int tableSize);
extern void GCM_ReverseHashBufferIfNeeded_CLMUL(byte *hashBuffer); extern void GCM_ReverseHashBufferIfNeeded_CLMUL(byte *hashBuffer);
extern size_t GCM_AuthenticateBlocks_CLMUL(const byte *data, size_t len, const byte *mtable, byte *hbuffer); extern size_t GCM_AuthenticateBlocks_CLMUL(const byte *data, size_t len, const byte *mtable, byte *hbuffer);
@ -104,14 +103,12 @@ const word64 s_clmulConstants64[] = {
const __m128i *s_clmulConstants = (const __m128i *)(const void *)s_clmulConstants64; const __m128i *s_clmulConstants = (const __m128i *)(const void *)s_clmulConstants64;
const unsigned int s_cltableSizeInBlocks = 8; const unsigned int s_cltableSizeInBlocks = 8;
#endif // CRYPTOPP_CLMUL_AVAILABLE
#endif
#if CRYPTOPP_ARM_PMULL_AVAILABLE #if CRYPTOPP_ARM_PMULL_AVAILABLE
extern size_t GCM_AuthenticateBlocks_PMULL(const byte *data, size_t len, const byte *mtable, byte *hbuffer); extern size_t GCM_AuthenticateBlocks_PMULL(const byte *data, size_t len, const byte *mtable, byte *hbuffer);
extern uint64x2_t GCM_Multiply_PMULL(const uint64x2_t &x, const uint64x2_t &h, const uint64x2_t &r); extern uint64x2_t GCM_Multiply_PMULL(const uint64x2_t &x, const uint64x2_t &h, const uint64x2_t &r);
extern void GCM_SetKeyWithoutResync_PMULL(byte *mulTable, byte *hashKey, unsigned int tableSize); extern void GCM_SetKeyWithoutResync_PMULL(const byte *hashKey, byte *mulTable, unsigned int tableSize);
CRYPTOPP_ALIGN_DATA(16) CRYPTOPP_ALIGN_DATA(16)
const word64 s_clmulConstants64[] = { const word64 s_clmulConstants64[] = {
@ -122,7 +119,7 @@ const word64 s_clmulConstants64[] = {
const uint64x2_t *s_clmulConstants = (const uint64x2_t *)s_clmulConstants64; const uint64x2_t *s_clmulConstants = (const uint64x2_t *)s_clmulConstants64;
const unsigned int s_cltableSizeInBlocks = 8; const unsigned int s_cltableSizeInBlocks = 8;
#endif #endif // CRYPTOPP_ARM_PMULL_AVAILABLE
void GCM_Base::SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs &params) void GCM_Base::SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs &params)
{ {
@ -172,13 +169,13 @@ void GCM_Base::SetKeyWithoutResync(const byte *userKey, size_t keylength, const
#if CRYPTOPP_CLMUL_AVAILABLE #if CRYPTOPP_CLMUL_AVAILABLE
if (HasCLMUL()) if (HasCLMUL())
{ {
GCM_SetKeyWithoutResync_CLMUL(mulTable, hashKey, tableSize); GCM_SetKeyWithoutResync_CLMUL(hashKey, mulTable, tableSize);
return; return;
} }
#elif CRYPTOPP_ARM_PMULL_AVAILABLE #elif CRYPTOPP_ARM_PMULL_AVAILABLE
if (HasPMULL()) if (HasPMULL())
{ {
GCM_SetKeyWithoutResync_PMULL(mulTable, hashKey, tableSize); GCM_SetKeyWithoutResync_PMULL(hashKey, mulTable, tableSize);
return; return;
} }
#endif #endif