2 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
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
13 * This file uses the low level AES functions (which are deprecated for
14 * non-internal use) in order to implement provider AES ciphers.
16 #include "internal/deprecated.h"
18 #include "cipher_aes_ccm.h"
20 #define AES_HW_CCM_SET_KEY_FN(fn_set_enc_key, fn_blk, fn_ccm_enc, fn_ccm_dec) \
21 fn_set_enc_key(key, keylen * 8, &actx->ccm.ks.ks); \
22 CRYPTO_ccm128_init(&ctx->ccm_ctx, ctx->m, ctx->l, &actx->ccm.ks.ks, \
23 (block128_f)fn_blk); \
24 ctx->str = ctx->enc ? (ccm128_f)fn_ccm_enc : (ccm128_f)fn_ccm_dec; \
27 static int ccm_generic_aes_initkey(PROV_CCM_CTX
*ctx
, const unsigned char *key
,
30 PROV_AES_CCM_CTX
*actx
= (PROV_AES_CCM_CTX
*)ctx
;
34 AES_HW_CCM_SET_KEY_FN(HWAES_set_encrypt_key
, HWAES_encrypt
, NULL
, NULL
);
36 #endif /* HWAES_CAPABLE */
40 AES_HW_CCM_SET_KEY_FN(vpaes_set_encrypt_key
, vpaes_encrypt
, NULL
, NULL
);
44 AES_HW_CCM_SET_KEY_FN(AES_set_encrypt_key
, AES_encrypt
, NULL
, NULL
)
49 static const PROV_CCM_HW aes_ccm
= {
50 ccm_generic_aes_initkey
,
51 ossl_ccm_generic_setiv
,
52 ossl_ccm_generic_setaad
,
53 ossl_ccm_generic_auth_encrypt
,
54 ossl_ccm_generic_auth_decrypt
,
55 ossl_ccm_generic_gettag
58 #if defined(S390X_aes_128_CAPABLE)
59 # include "cipher_aes_ccm_hw_s390x.inc"
60 #elif defined(AESNI_CAPABLE)
61 # include "cipher_aes_ccm_hw_aesni.inc"
62 #elif defined(SPARC_AES_CAPABLE)
63 # include "cipher_aes_ccm_hw_t4.inc"
65 const PROV_CCM_HW
*ossl_prov_aes_hw_ccm(size_t keybits
)