xref: /freebsd-src/crypto/openssl/providers/implementations/ciphers/cipher_aria_ccm.c (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1b077aed3SPierre Pronchery /*
2*e0c4386eSCy Schubert  * Copyright 2019-2024 The OpenSSL Project Authors. All Rights Reserved.
3b077aed3SPierre Pronchery  *
4b077aed3SPierre Pronchery  * Licensed under the Apache License 2.0 (the "License").  You may not use
5b077aed3SPierre Pronchery  * this file except in compliance with the License.  You can obtain a copy
6b077aed3SPierre Pronchery  * in the file LICENSE in the source distribution or at
7b077aed3SPierre Pronchery  * https://www.openssl.org/source/license.html
8b077aed3SPierre Pronchery  */
9b077aed3SPierre Pronchery 
10b077aed3SPierre Pronchery /* Dispatch functions for ARIA CCM mode */
11b077aed3SPierre Pronchery 
12b077aed3SPierre Pronchery #include "cipher_aria_ccm.h"
13b077aed3SPierre Pronchery #include "prov/implementations.h"
14b077aed3SPierre Pronchery #include "prov/providercommon.h"
15b077aed3SPierre Pronchery 
16b077aed3SPierre Pronchery static OSSL_FUNC_cipher_freectx_fn aria_ccm_freectx;
17b077aed3SPierre Pronchery 
aria_ccm_newctx(void * provctx,size_t keybits)18b077aed3SPierre Pronchery static void *aria_ccm_newctx(void *provctx, size_t keybits)
19b077aed3SPierre Pronchery {
20b077aed3SPierre Pronchery     PROV_ARIA_CCM_CTX *ctx;
21b077aed3SPierre Pronchery 
22b077aed3SPierre Pronchery     if (!ossl_prov_is_running())
23b077aed3SPierre Pronchery         return NULL;
24b077aed3SPierre Pronchery 
25b077aed3SPierre Pronchery     ctx = OPENSSL_zalloc(sizeof(*ctx));
26b077aed3SPierre Pronchery     if (ctx != NULL)
27b077aed3SPierre Pronchery         ossl_ccm_initctx(&ctx->base, keybits, ossl_prov_aria_hw_ccm(keybits));
28b077aed3SPierre Pronchery     return ctx;
29b077aed3SPierre Pronchery }
30b077aed3SPierre Pronchery 
aria_ccm_dupctx(void * provctx)31*e0c4386eSCy Schubert static void *aria_ccm_dupctx(void *provctx)
32*e0c4386eSCy Schubert {
33*e0c4386eSCy Schubert     PROV_ARIA_CCM_CTX *ctx = provctx;
34*e0c4386eSCy Schubert     PROV_ARIA_CCM_CTX *dctx = NULL;
35*e0c4386eSCy Schubert 
36*e0c4386eSCy Schubert     if (ctx == NULL)
37*e0c4386eSCy Schubert         return NULL;
38*e0c4386eSCy Schubert 
39*e0c4386eSCy Schubert     dctx = OPENSSL_memdup(ctx, sizeof(*ctx));
40*e0c4386eSCy Schubert     if (dctx != NULL && dctx->base.ccm_ctx.key != NULL)
41*e0c4386eSCy Schubert         dctx->base.ccm_ctx.key = &dctx->ks.ks;
42*e0c4386eSCy Schubert 
43*e0c4386eSCy Schubert     return dctx;
44*e0c4386eSCy Schubert }
45*e0c4386eSCy Schubert 
aria_ccm_freectx(void * vctx)46b077aed3SPierre Pronchery static void aria_ccm_freectx(void *vctx)
47b077aed3SPierre Pronchery {
48b077aed3SPierre Pronchery     PROV_ARIA_CCM_CTX *ctx = (PROV_ARIA_CCM_CTX *)vctx;
49b077aed3SPierre Pronchery 
50b077aed3SPierre Pronchery     OPENSSL_clear_free(ctx,  sizeof(*ctx));
51b077aed3SPierre Pronchery }
52b077aed3SPierre Pronchery 
53b077aed3SPierre Pronchery /* aria128ccm functions */
54b077aed3SPierre Pronchery IMPLEMENT_aead_cipher(aria, ccm, CCM, AEAD_FLAGS, 128, 8, 96);
55b077aed3SPierre Pronchery /* aria192ccm functions */
56b077aed3SPierre Pronchery IMPLEMENT_aead_cipher(aria, ccm, CCM, AEAD_FLAGS, 192, 8, 96);
57b077aed3SPierre Pronchery /* aria256ccm functions */
58b077aed3SPierre Pronchery IMPLEMENT_aead_cipher(aria, ccm, CCM, AEAD_FLAGS, 256, 8, 96);
59b077aed3SPierre Pronchery 
60