Path: blob/main/crypto/openssl/providers/implementations/ciphers/cipher_aes_ccm_hw.c
48383 views
/*1* Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved.2*3* Licensed under the Apache License 2.0 (the "License"). You may not use4* this file except in compliance with the License. You can obtain a copy5* in the file LICENSE in the source distribution or at6* https://www.openssl.org/source/license.html7*/89/* AES CCM mode */1011/*12* This file uses the low level AES functions (which are deprecated for13* non-internal use) in order to implement provider AES ciphers.14*/15#include "internal/deprecated.h"1617#include "cipher_aes_ccm.h"1819#define AES_HW_CCM_SET_KEY_FN(fn_set_enc_key, fn_blk, fn_ccm_enc, fn_ccm_dec) \20fn_set_enc_key(key, keylen * 8, &actx->ccm.ks.ks); \21CRYPTO_ccm128_init(&ctx->ccm_ctx, ctx->m, ctx->l, &actx->ccm.ks.ks, \22(block128_f)fn_blk); \23ctx->str = ctx->enc ? (ccm128_f)fn_ccm_enc : (ccm128_f)fn_ccm_dec; \24ctx->key_set = 1;2526static int ccm_generic_aes_initkey(PROV_CCM_CTX *ctx, const unsigned char *key,27size_t keylen)28{29PROV_AES_CCM_CTX *actx = (PROV_AES_CCM_CTX *)ctx;3031#ifdef HWAES_CAPABLE32if (HWAES_CAPABLE) {33AES_HW_CCM_SET_KEY_FN(HWAES_set_encrypt_key, HWAES_encrypt, NULL, NULL);34} else35#endif /* HWAES_CAPABLE */3637#ifdef VPAES_CAPABLE38if (VPAES_CAPABLE) {39AES_HW_CCM_SET_KEY_FN(vpaes_set_encrypt_key, vpaes_encrypt, NULL, NULL);40} else41#endif42{43AES_HW_CCM_SET_KEY_FN(AES_set_encrypt_key, AES_encrypt, NULL, NULL)44}45return 1;46}4748static const PROV_CCM_HW aes_ccm = {49ccm_generic_aes_initkey,50ossl_ccm_generic_setiv,51ossl_ccm_generic_setaad,52ossl_ccm_generic_auth_encrypt,53ossl_ccm_generic_auth_decrypt,54ossl_ccm_generic_gettag55};5657#if defined(S390X_aes_128_CAPABLE)58# include "cipher_aes_ccm_hw_s390x.inc"59#elif defined(AESNI_CAPABLE)60# include "cipher_aes_ccm_hw_aesni.inc"61#elif defined(SPARC_AES_CAPABLE)62# include "cipher_aes_ccm_hw_t4.inc"63#elif defined(OPENSSL_CPUID_OBJ) && defined(__riscv) && __riscv_xlen == 6464# include "cipher_aes_ccm_hw_rv64i.inc"65#elif defined(OPENSSL_CPUID_OBJ) && defined(__riscv) && __riscv_xlen == 3266# include "cipher_aes_ccm_hw_rv32i.inc"67#else68const PROV_CCM_HW *ossl_prov_aes_hw_ccm(size_t keybits)69{70return &aes_ccm;71}72#endif737475