Cleanup ciphers and Add 3des ciphers.
[openssl.git] / providers / common / ciphers / cipher_aes_ccm_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 /* AES CCM mode */
11
12 #include "cipher_locl.h"
13 #include "internal/ciphers/cipher_ccm.h"
14
15 #define AES_HW_CCM_SET_KEY_FN(fn_set_enc_key, fn_blk, fn_ccm_enc, fn_ccm_dec)  \
16     fn_set_enc_key(key, keylen * 8, &actx->ccm.ks.ks);                         \
17     CRYPTO_ccm128_init(&ctx->ccm_ctx, ctx->m, ctx->l, &actx->ccm.ks.ks,        \
18                        (block128_f)fn_blk);                                    \
19     ctx->str = ctx->enc ? (ccm128_f)fn_ccm_enc : (ccm128_f)fn_ccm_dec;         \
20     ctx->key_set = 1;
21
22 static int ccm_generic_aes_initkey(PROV_CCM_CTX *ctx, const unsigned char *key,
23                                    size_t keylen)
24 {
25     PROV_AES_CCM_CTX *actx = (PROV_AES_CCM_CTX *)ctx;
26
27 #ifdef HWAES_CAPABLE
28     if (HWAES_CAPABLE) {
29         AES_HW_CCM_SET_KEY_FN(HWAES_set_encrypt_key, HWAES_encrypt, NULL, NULL);
30     } else
31 #endif /* HWAES_CAPABLE */
32
33 #ifdef VPAES_CAPABLE
34     if (VPAES_CAPABLE) {
35         AES_HW_CCM_SET_KEY_FN(vpaes_set_encrypt_key, vpaes_encrypt, NULL, NULL);
36     } else
37 #endif
38     {
39         AES_HW_CCM_SET_KEY_FN(AES_set_encrypt_key, AES_encrypt, NULL, NULL)
40     }
41     return 1;
42 }
43
44 static const PROV_CCM_HW aes_ccm = {
45     ccm_generic_aes_initkey,
46     ccm_generic_setiv,
47     ccm_generic_setaad,
48     ccm_generic_auth_encrypt,
49     ccm_generic_auth_decrypt,
50     ccm_generic_gettag
51 };
52
53 #if defined(S390X_aes_128_CAPABLE)
54 # include "cipher_aes_ccm_hw_s390x.inc"
55 #elif defined(AESNI_CAPABLE)
56 # include "cipher_aes_ccm_hw_aesni.inc"
57 #elif defined(SPARC_AES_CAPABLE)
58 # include "cipher_aes_ccm_hw_t4.inc"
59 #else
60 const PROV_CCM_HW *PROV_AES_HW_ccm(size_t keybits)
61 {
62     return &aes_ccm;
63 }
64 #endif