1 // SPDX-License-Identifier: BSD-2-Clause
2 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3  *
4  * LibTomCrypt is a library that provides various cryptographic
5  * algorithms in a highly modular and flexible manner.
6  *
7  * The library is free for all purposes without any express
8  * guarantee it works.
9  */
10 
11 /**
12    @file gcm_mult_h.c
13    GCM implementation, do the GF mult, by Tom St Denis
14 */
15 #include "tomcrypt_private.h"
16 
17 #if defined(LTC_GCM_MODE)
18 /**
19   GCM multiply by H
20   @param gcm   The GCM state which holds the H value
21   @param I     The value to multiply H by
22  */
gcm_mult_h(const gcm_state * gcm,unsigned char * I)23 void gcm_mult_h(const gcm_state *gcm, unsigned char *I)
24 {
25    unsigned char T[16];
26 #ifdef LTC_GCM_TABLES
27    int x;
28 #ifdef LTC_GCM_TABLES_SSE2
29    asm("movdqa (%0),%%xmm0"::"r"(&gcm->PC[0][I[0]][0]));
30    for (x = 1; x < 16; x++) {
31       asm("pxor (%0),%%xmm0"::"r"(&gcm->PC[x][I[x]][0]));
32    }
33    asm("movdqa %%xmm0,(%0)"::"r"(&T));
34 #else
35    int y;
36    XMEMCPY(T, &gcm->PC[0][I[0]][0], 16);
37    for (x = 1; x < 16; x++) {
38 #ifdef LTC_FAST
39        for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
40            *(LTC_FAST_TYPE_PTR_CAST(T + y)) ^= *(LTC_FAST_TYPE_PTR_CAST(&gcm->PC[x][I[x]][y]));
41        }
42 #else
43        for (y = 0; y < 16; y++) {
44            T[y] ^= gcm->PC[x][I[x]][y];
45        }
46 #endif /* LTC_FAST */
47    }
48 #endif /* LTC_GCM_TABLES_SSE2 */
49 #else
50    gcm_gf_mult(gcm->H, I, T);
51 #endif
52    XMEMCPY(I, T, 16);
53 }
54 #endif
55 
56 /* ref:         $Format:%D$ */
57 /* git commit:  $Format:%H$ */
58 /* commit time: $Format:%ai$ */
59