| 223 | #endif |
| 224 | |
| 225 | void GCM_Base::SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms) |
| 226 | { |
| 227 | BlockCipher &blockCipher = AccessBlockCipher(); |
| 228 | blockCipher.SetKey(userKey, keylength, params); |
| 229 | |
| 230 | if (blockCipher.BlockSize() != REQUIRED_BLOCKSIZE) |
| 231 | throw InvalidArgument(AlgorithmName() + ": block size of underlying block cipher is not 16"); |
| 232 | |
| 233 | int tableSize, i, j, k; |
| 234 | |
| 235 | #if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE |
| 236 | if (HasCLMUL()) |
| 237 | { |
| 238 | // Avoid "parameter not used" error and suppress Coverity finding |
| 239 | (void)params.GetIntValue(Name::TableSize(), tableSize); |
| 240 | tableSize = s_clmulTableSizeInBlocks * REQUIRED_BLOCKSIZE; |
| 241 | } |
| 242 | else |
| 243 | #elif CRYPTOPP_BOOL_ARM_CRYPTO_INTRINSICS_AVAILABLE |
| 244 | if (HasPMULL()) |
| 245 | { |
| 246 | // Avoid "parameter not used" error and suppress Coverity finding |
| 247 | (void)params.GetIntValue(Name::TableSize(), tableSize); |
| 248 | tableSize = s_clmulTableSizeInBlocks * REQUIRED_BLOCKSIZE; |
| 249 | } |
| 250 | else |
| 251 | #endif |
| 252 | { |
| 253 | if (params.GetIntValue(Name::TableSize(), tableSize)) |
| 254 | tableSize = (tableSize >= 64*1024) ? 64*1024 : 2*1024; |
| 255 | else |
| 256 | tableSize = (GetTablesOption() == GCM_64K_Tables) ? 64*1024 : 2*1024; |
| 257 | |
| 258 | #if defined(_MSC_VER) && (_MSC_VER < 1400) |
| 259 | // VC 2003 workaround: compiler generates bad code for 64K tables |
| 260 | tableSize = 2*1024; |
| 261 | #endif |
| 262 | } |
| 263 | |
| 264 | m_buffer.resize(3*REQUIRED_BLOCKSIZE + tableSize); |
| 265 | byte *table = MulTable(); |
| 266 | byte *hashKey = HashKey(); |
| 267 | memset(hashKey, 0, REQUIRED_BLOCKSIZE); |
| 268 | blockCipher.ProcessBlock(hashKey); |
| 269 | |
| 270 | #if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE |
| 271 | if (HasCLMUL()) |
| 272 | { |
| 273 | const __m128i r = s_clmulConstants[0]; |
| 274 | __m128i h0 = _mm_shuffle_epi8(_mm_load_si128((__m128i *)(void *)hashKey), s_clmulConstants[1]); |
| 275 | __m128i h = h0; |
| 276 | |
| 277 | for (i=0; i<tableSize; i+=32) |
| 278 | { |
| 279 | __m128i h1 = CLMUL_GF_Mul(h, h0, r); |
| 280 | _mm_storel_epi64((__m128i *)(void *)(table+i), h); |
| 281 | _mm_storeu_si128((__m128i *)(void *)(table+i+16), h1); |
| 282 | _mm_storeu_si128((__m128i *)(void *)(table+i+8), h); |
nothing calls this directly
no test coverage detected