Path: blob/master/libs/tomcrypt/src/encauth/gcm/gcm_mult_h.c
5972 views
/* LibTomCrypt, modular cryptographic library -- Tom St Denis1*2* LibTomCrypt is a library that provides various cryptographic3* algorithms in a highly modular and flexible manner.4*5* The library is free for all purposes without any express6* guarantee it works.7*/89/**10@file gcm_mult_h.c11GCM implementation, do the GF mult, by Tom St Denis12*/13#include "tomcrypt.h"1415#if defined(LTC_GCM_MODE)16/**17GCM multiply by H18@param gcm The GCM state which holds the H value19@param I The value to multiply H by20*/21void gcm_mult_h(gcm_state *gcm, unsigned char *I)22{23unsigned char T[16];24#ifdef LTC_GCM_TABLES25int x;26#ifdef LTC_GCM_TABLES_SSE227asm("movdqa (%0),%%xmm0"::"r"(&gcm->PC[0][I[0]][0]));28for (x = 1; x < 16; x++) {29asm("pxor (%0),%%xmm0"::"r"(&gcm->PC[x][I[x]][0]));30}31asm("movdqa %%xmm0,(%0)"::"r"(&T));32#else33int y;34XMEMCPY(T, &gcm->PC[0][I[0]][0], 16);35for (x = 1; x < 16; x++) {36#ifdef LTC_FAST37for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {38*(LTC_FAST_TYPE_PTR_CAST(T + y)) ^= *(LTC_FAST_TYPE_PTR_CAST(&gcm->PC[x][I[x]][y]));39}40#else41for (y = 0; y < 16; y++) {42T[y] ^= gcm->PC[x][I[x]][y];43}44#endif /* LTC_FAST */45}46#endif /* LTC_GCM_TABLES_SSE2 */47#else48gcm_gf_mult(gcm->H, I, T);49#endif50XMEMCPY(I, T, 16);51}52#endif535455