1/*
2 * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10/* Dispatch functions for AES GCM mode */
11
12#include "cipher_aes_gcm.h"
13
14static int generic_aes_gcm_initkey(PROV_GCM_CTX *ctx, const unsigned char *key,
15 size_t keylen)
16{
17 PROV_AES_GCM_CTX *actx = (PROV_AES_GCM_CTX *)ctx;
18 AES_KEY *ks = &actx->ks.ks;
19
20# ifdef HWAES_CAPABLE
21 if (HWAES_CAPABLE) {
22# ifdef HWAES_ctr32_encrypt_blocks
23 GCM_HW_SET_KEY_CTR_FN(ks, HWAES_set_encrypt_key, HWAES_encrypt,
24 HWAES_ctr32_encrypt_blocks);
25# else
26 GCM_HW_SET_KEY_CTR_FN(ks, HWAES_set_encrypt_key, HWAES_encrypt, NULL);
27# endif /* HWAES_ctr32_encrypt_blocks */
28 } else
29# endif /* HWAES_CAPABLE */
30
31# ifdef BSAES_CAPABLE
32 if (BSAES_CAPABLE) {
33 GCM_HW_SET_KEY_CTR_FN(ks, AES_set_encrypt_key, AES_encrypt,
34 bsaes_ctr32_encrypt_blocks);
35 } else
36# endif /* BSAES_CAPABLE */
37
38# ifdef VPAES_CAPABLE
39 if (VPAES_CAPABLE) {
40 GCM_HW_SET_KEY_CTR_FN(ks, vpaes_set_encrypt_key, vpaes_encrypt, NULL);
41 } else
42# endif /* VPAES_CAPABLE */
43
44 {
45# ifdef AES_CTR_ASM
46 GCM_HW_SET_KEY_CTR_FN(ks, AES_set_encrypt_key, AES_encrypt,
47 AES_ctr32_encrypt);
48# else
49 GCM_HW_SET_KEY_CTR_FN(ks, AES_set_encrypt_key, AES_encrypt, NULL);
50# endif /* AES_CTR_ASM */
51 }
52 ctx->key_set = 1;
53 return 1;
54}
55
56static const PROV_GCM_HW aes_gcm = {
57 generic_aes_gcm_initkey,
58 gcm_setiv,
59 gcm_aad_update,
60 gcm_cipher_update,
61 gcm_cipher_final,
62 gcm_one_shot
63};
64
65#if defined(S390X_aes_128_CAPABLE)
66# include "cipher_aes_gcm_hw_s390x.inc"
67#elif defined(AESNI_CAPABLE)
68# include "cipher_aes_gcm_hw_aesni.inc"
69#elif defined(SPARC_AES_CAPABLE)
70# include "cipher_aes_gcm_hw_t4.inc"
71#else
72const PROV_GCM_HW *PROV_AES_HW_gcm(size_t keybits)
73{
74 return &aes_gcm;
75}
76#endif
77
78