Go to the documentation of this file.
58 #include "../../internal.h"
66 #define GCM_MUL(ctx, Xi) gcm_gmult_nohw((ctx)->Xi.u, (ctx)->gcm_key.Htable)
67 #define GHASH(ctx, in, len) \
68 gcm_ghash_nohw((ctx)->Xi.u, (ctx)->gcm_key.Htable, in, len)
72 #define GHASH_CHUNK (3 * 1024)
74 #if defined(GHASH_ASM_X86_64) || defined(GHASH_ASM_X86)
75 static inline void gcm_reduce_1bit(
u128 *V) {
76 if (
sizeof(crypto_word_t) == 8) {
78 V->
hi = (V->
lo << 63) | (V->
hi >> 1);
79 V->
lo = (V->
lo >> 1) ^
T;
82 V->
hi = (V->
lo << 63) | (V->
hi >> 1);
101 Htable[3].
hi = V.
hi ^ Htable[2].
hi, Htable[3].
lo = V.
lo ^ Htable[2].
lo;
103 Htable[5].
hi = V.
hi ^ Htable[1].
hi, Htable[5].
lo = V.
lo ^ Htable[1].
lo;
104 Htable[6].
hi = V.
hi ^ Htable[2].
hi, Htable[6].
lo = V.
lo ^ Htable[2].
lo;
105 Htable[7].
hi = V.
hi ^ Htable[3].
hi, Htable[7].
lo = V.
lo ^ Htable[3].
lo;
107 Htable[9].
hi = V.
hi ^ Htable[1].
hi, Htable[9].
lo = V.
lo ^ Htable[1].
lo;
108 Htable[10].
hi = V.
hi ^ Htable[2].
hi, Htable[10].
lo = V.
lo ^ Htable[2].
lo;
109 Htable[11].
hi = V.
hi ^ Htable[3].
hi, Htable[11].
lo = V.
lo ^ Htable[3].
lo;
110 Htable[12].
hi = V.
hi ^ Htable[4].
hi, Htable[12].
lo = V.
lo ^ Htable[4].
lo;
111 Htable[13].
hi = V.
hi ^ Htable[5].
hi, Htable[13].
lo = V.
lo ^ Htable[5].
lo;
112 Htable[14].
hi = V.
hi ^ Htable[6].
hi, Htable[14].
lo = V.
lo ^ Htable[6].
lo;
113 Htable[15].
hi = V.
hi ^ Htable[7].
hi, Htable[15].
lo = V.
lo ^ Htable[7].
lo;
118 for (
int i = 0;
i < 16;
i++) {
119 for (
int j = 0;
j <
i;
j++) {
121 Hbytes[16*
i +
j] = Hbytes[16*
j +
i];
122 Hbytes[16*
j +
i] =
tmp;
126 #endif // GHASH_ASM_X86_64 || GHASH_ASM_X86
130 #define GCM_MUL(ctx, Xi) (*gcm_gmult_p)((ctx)->Xi.u, (ctx)->gcm_key.Htable)
132 #define GHASH(ctx, in, len) \
133 (*gcm_ghash_p)((ctx)->Xi.u, (ctx)->gcm_key.Htable, in, len)
134 #endif // GCM_FUNCREF
137 u128 *out_key,
u128 out_table[16],
int *out_is_avx,
154 #if defined(GHASH_ASM_X86_64)
156 if (((OPENSSL_ia32cap_get()[1] >> 22) & 0x41) == 0x41) {
168 if (gcm_ssse3_capable()) {
174 #elif defined(GHASH_ASM_X86)
181 if (gcm_ssse3_capable()) {
187 #elif defined(GHASH_ASM_ARM)
188 if (gcm_pmull_capable()) {
189 gcm_init_v8(out_table,
H.u);
190 *out_mult = gcm_gmult_v8;
191 *out_hash = gcm_ghash_v8;
195 if (gcm_neon_capable()) {
196 gcm_init_neon(out_table,
H.u);
197 *out_mult = gcm_gmult_neon;
198 *out_hash = gcm_ghash_neon;
201 #elif defined(GHASH_ASM_PPC64LE)
202 if (CRYPTO_is_PPC64LE_vcrypto_capable()) {
203 gcm_init_p8(out_table,
H.u);
204 *out_mult = gcm_gmult_p8;
205 *out_hash = gcm_ghash_p8;
222 (*block)(ghash_key, ghash_key, aes_key);
226 gcm_key->
Htable, &is_avx, ghash_key);
234 void (*gcm_gmult_p)(
uint64_t Xi[2],
const u128 Htable[16]) =
256 for (
size_t i = 0;
i < 16; ++
i) {
257 ctx->Yi.c[
i] ^= iv[
i];
264 for (
size_t i = 0;
i <
len; ++
i) {
265 ctx->Yi.c[
i] ^= iv[
i];
283 void (*gcm_gmult_p)(
uint64_t Xi[2],
const u128 Htable[16]) =
286 size_t len) =
ctx->gcm_key.ghash;
294 if (alen > (
UINT64_C(1) << 61) || (
sizeof(
len) == 8 && alen <
len)) {
297 ctx->len.u[0] = alen;
299 unsigned n =
ctx->ares;
302 ctx->Xi.c[
n] ^= *(aad++);
316 if (len_blocks != 0) {
325 for (
size_t i = 0;
i <
len; ++
i) {
326 ctx->Xi.c[
i] ^= aad[
i];
338 void (*gcm_gmult_p)(
uint64_t Xi[2],
const u128 Htable[16]) =
341 size_t len) =
ctx->gcm_key.ghash;
346 (
sizeof(
len) == 8 && mlen <
len)) {
349 ctx->len.u[1] = mlen;
357 unsigned n =
ctx->mres;
380 for (
size_t i = 0;
i < 16;
i +=
sizeof(crypto_word_t)) {
383 ctx->EKi.t[
i /
sizeof(crypto_word_t)]);
393 if (len_blocks != 0) {
398 for (
size_t i = 0;
i < 16;
i +=
sizeof(crypto_word_t)) {
401 ctx->EKi.t[
i /
sizeof(crypto_word_t)]);
424 const unsigned char *
in,
unsigned char *
out,
428 void (*gcm_gmult_p)(
uint64_t Xi[2],
const u128 Htable[16]) =
431 size_t len) =
ctx->gcm_key.ghash;
436 (
sizeof(
len) == 8 && mlen <
len)) {
439 ctx->len.u[1] = mlen;
447 unsigned n =
ctx->mres;
473 for (
size_t i = 0;
i < 16;
i +=
sizeof(crypto_word_t)) {
476 ctx->EKi.t[
i /
sizeof(crypto_word_t)]);
485 if (len_blocks != 0) {
491 for (
size_t i = 0;
i < 16;
i +=
sizeof(crypto_word_t)) {
494 ctx->EKi.t[
i /
sizeof(crypto_word_t)]);
521 void (*gcm_gmult_p)(
uint64_t Xi[2],
const u128 Htable[16]) =
524 size_t len) =
ctx->gcm_key.ghash;
529 (
sizeof(
len) == 8 && mlen <
len)) {
532 ctx->len.u[1] = mlen;
540 unsigned n =
ctx->mres;
555 #if defined(AESNI_GCM)
557 if (
ctx->gcm_key.use_aesni_gcm_crypt &&
len > 0) {
578 if (len_blocks != 0) {
579 size_t j = len_blocks / 16;
582 ctr += (
unsigned int)j;
607 void (*gcm_gmult_p)(
uint64_t Xi[2],
const u128 Htable[16]) =
610 size_t len) =
ctx->gcm_key.ghash;
615 (
sizeof(
len) == 8 && mlen <
len)) {
618 ctx->len.u[1] = mlen;
626 unsigned n =
ctx->mres;
643 #if defined(AESNI_GCM)
645 if (
ctx->gcm_key.use_aesni_gcm_crypt &&
len > 0) {
666 if (len_blocks != 0) {
667 size_t j = len_blocks / 16;
671 ctr += (
unsigned int)j;
695 void (*gcm_gmult_p)(
uint64_t Xi[2],
const u128 Htable[16]) =
707 ctx->Xi.u[0] ^=
ctx->EK0.u[0];
708 ctx->Xi.u[1] ^=
ctx->EK0.u[1];
723 #if defined(OPENSSL_X86) || defined(OPENSSL_X86_64)
725 #if defined(GHASH_ASM_X86) || defined(GHASH_ASM_X86_64)
726 const uint32_t *ia32cap = OPENSSL_ia32cap_get();
727 return (ia32cap[0] & (1 << 24)) &&
728 (ia32cap[1] & (1 << 1));
int CRYPTO_gcm128_finish(GCM128_CONTEXT *ctx, const uint8_t *tag, size_t len)
static uint64_t CRYPTO_bswap8(uint64_t x)
OPENSSL_EXPORT pem_password_cb void * u
void CRYPTO_gcm128_setiv(GCM128_CONTEXT *ctx, const AES_KEY *key, const uint8_t *iv, size_t len)
void CRYPTO_ghash_init(gmult_func *out_mult, ghash_func *out_hash, u128 *out_key, u128 out_table[16], int *out_is_avx, const uint8_t gcm_key[16])
static void CRYPTO_store_word_le(void *out, crypto_word_t v)
static void * OPENSSL_memset(void *dst, int c, size_t n)
#define T(upbtypeconst, upbtype, ctype, default_value)
#define aesni_gcm_encrypt
int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx, const AES_KEY *key, const unsigned char *in, unsigned char *out, size_t len)
void(* ghash_func)(uint64_t Xi[2], const u128 Htable[16], const uint8_t *inp, size_t len)
static uint32_t CRYPTO_bswap4(uint32_t x)
#define crypto_gcm_clmul_enabled
static void * tag(intptr_t t)
unsigned use_aesni_gcm_crypt
void CRYPTO_gcm128_init_key(GCM128_KEY *gcm_key, const AES_KEY *aes_key, block128_f block, int block_is_hwaes)
void(* ctr128_f)(const uint8_t *in, uint8_t *out, size_t blocks, const AES_KEY *key, const uint8_t ivec[16])
int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx, const AES_KEY *key, const uint8_t *in, uint8_t *out, size_t len, ctr128_f stream)
unsigned __int64 uint64_t
static void * OPENSSL_memcpy(void *dst, const void *src, size_t n)
int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx, const AES_KEY *key, const uint8_t *in, uint8_t *out, size_t len)
#define aesni_gcm_decrypt
static const size_t kSizeTWithoutLower4Bits
int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx, const AES_KEY *key, const uint8_t *in, uint8_t *out, size_t len, ctr128_f stream)
#define GHASH(ctx, in, len)
void(* gmult_func)(uint64_t Xi[2], const u128 Htable[16])
void CRYPTO_gcm128_tag(GCM128_CONTEXT *ctx, unsigned char *tag, size_t len)
if(p->owned &&p->wrapped !=NULL)
int CRYPTO_gcm128_aad(GCM128_CONTEXT *ctx, const uint8_t *aad, size_t len)
void(* block128_f)(const uint8_t in[16], uint8_t out[16], const AES_KEY *key)
static crypto_word_t CRYPTO_load_word_le(const void *in)
grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:59:23