Path: blob/main/crypto/openssl/providers/implementations/ciphers/cipher_aes_ccm.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/*10* AES low level APIs are deprecated for public use, but still ok for internal11* use where we're using them to implement the higher level EVP interface, as is12* the case here.13*/14#include "internal/deprecated.h"1516/* Dispatch functions for AES CCM mode */1718#include "cipher_aes_ccm.h"19#include "prov/implementations.h"20#include "prov/providercommon.h"2122static void *aes_ccm_newctx(void *provctx, size_t keybits)23{24PROV_AES_CCM_CTX *ctx;2526if (!ossl_prov_is_running())27return NULL;2829ctx = OPENSSL_zalloc(sizeof(*ctx));30if (ctx != NULL)31ossl_ccm_initctx(&ctx->base, keybits, ossl_prov_aes_hw_ccm(keybits));32return ctx;33}3435static void *aes_ccm_dupctx(void *provctx)36{37PROV_AES_CCM_CTX *ctx = provctx;38PROV_AES_CCM_CTX *dupctx = NULL;3940if (!ossl_prov_is_running())41return NULL;4243if (ctx == NULL)44return NULL;45dupctx = OPENSSL_memdup(provctx, sizeof(*ctx));46if (dupctx == NULL)47return NULL;48/*49* ossl_cm_initctx, via the ossl_prov_aes_hw_ccm functions assign a50* provctx->ccm.ks.ks to the ccm context key so we need to point it to51* the memduped copy52*/53dupctx->base.ccm_ctx.key = &dupctx->ccm.ks.ks;5455return dupctx;56}5758static OSSL_FUNC_cipher_freectx_fn aes_ccm_freectx;59static void aes_ccm_freectx(void *vctx)60{61PROV_AES_CCM_CTX *ctx = (PROV_AES_CCM_CTX *)vctx;6263OPENSSL_clear_free(ctx, sizeof(*ctx));64}6566/* ossl_aes128ccm_functions */67IMPLEMENT_aead_cipher(aes, ccm, CCM, AEAD_FLAGS, 128, 8, 96);68/* ossl_aes192ccm_functions */69IMPLEMENT_aead_cipher(aes, ccm, CCM, AEAD_FLAGS, 192, 8, 96);70/* ossl_aes256ccm_functions */71IMPLEMENT_aead_cipher(aes, ccm, CCM, AEAD_FLAGS, 256, 8, 96);727374