Deprecate the low level AES functions
[openssl.git] / providers / implementations / ciphers / cipher_aes_gcm_hw.c
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 /*
13  * This file uses the low level AES functions (which are deprecated for
14  * non-internal use) in order to implement provider AES ciphers.
15  */
16 #include "internal/deprecated.h"
17
18 #include "cipher_aes_gcm.h"
19
20 static int generic_aes_gcm_initkey(PROV_GCM_CTX *ctx, const unsigned char *key,
21                                    size_t keylen)
22 {
23     PROV_AES_GCM_CTX *actx = (PROV_AES_GCM_CTX *)ctx;
24     AES_KEY *ks = &actx->ks.ks;
25
26 # ifdef HWAES_CAPABLE
27     if (HWAES_CAPABLE) {
28 #  ifdef HWAES_ctr32_encrypt_blocks
29         GCM_HW_SET_KEY_CTR_FN(ks, HWAES_set_encrypt_key, HWAES_encrypt,
30                               HWAES_ctr32_encrypt_blocks);
31 #  else
32         GCM_HW_SET_KEY_CTR_FN(ks, HWAES_set_encrypt_key, HWAES_encrypt, NULL);
33 #  endif /* HWAES_ctr32_encrypt_blocks */
34     } else
35 # endif /* HWAES_CAPABLE */
36
37 # ifdef BSAES_CAPABLE
38     if (BSAES_CAPABLE) {
39         GCM_HW_SET_KEY_CTR_FN(ks, AES_set_encrypt_key, AES_encrypt,
40                               bsaes_ctr32_encrypt_blocks);
41     } else
42 # endif /* BSAES_CAPABLE */
43
44 # ifdef VPAES_CAPABLE
45     if (VPAES_CAPABLE) {
46         GCM_HW_SET_KEY_CTR_FN(ks, vpaes_set_encrypt_key, vpaes_encrypt, NULL);
47     } else
48 # endif /* VPAES_CAPABLE */
49
50     {
51 # ifdef AES_CTR_ASM
52         GCM_HW_SET_KEY_CTR_FN(ks, AES_set_encrypt_key, AES_encrypt,
53                               AES_ctr32_encrypt);
54 # else
55         GCM_HW_SET_KEY_CTR_FN(ks, AES_set_encrypt_key, AES_encrypt, NULL);
56 # endif /* AES_CTR_ASM */
57     }
58     ctx->key_set = 1;
59     return 1;
60 }
61
62 static const PROV_GCM_HW aes_gcm = {
63     generic_aes_gcm_initkey,
64     gcm_setiv,
65     gcm_aad_update,
66     gcm_cipher_update,
67     gcm_cipher_final,
68     gcm_one_shot
69 };
70
71 #if defined(S390X_aes_128_CAPABLE)
72 # include "cipher_aes_gcm_hw_s390x.inc"
73 #elif defined(AESNI_CAPABLE)
74 # include "cipher_aes_gcm_hw_aesni.inc"
75 #elif defined(SPARC_AES_CAPABLE)
76 # include "cipher_aes_gcm_hw_t4.inc"
77 #elif defined(AES_PMULL_CAPABLE) && defined(AES_GCM_ASM)
78 # include "cipher_aes_gcm_hw_armv8.inc"
79 #else
80 const PROV_GCM_HW *PROV_AES_HW_gcm(size_t keybits)
81 {
82     return &aes_gcm;
83 }
84 #endif
85