xref: /freebsd/crypto/openssl/providers/implementations/ciphers/cipher_aria_gcm.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 GCM mode */
11b077aed3SPierre Pronchery 
12b077aed3SPierre Pronchery #include "cipher_aria_gcm.h"
13b077aed3SPierre Pronchery #include "prov/implementations.h"
14b077aed3SPierre Pronchery #include "prov/providercommon.h"
15b077aed3SPierre Pronchery 
aria_gcm_newctx(void * provctx,size_t keybits)16b077aed3SPierre Pronchery static void *aria_gcm_newctx(void *provctx, size_t keybits)
17b077aed3SPierre Pronchery {
18b077aed3SPierre Pronchery     PROV_ARIA_GCM_CTX *ctx;
19b077aed3SPierre Pronchery 
20b077aed3SPierre Pronchery     if (!ossl_prov_is_running())
21b077aed3SPierre Pronchery         return NULL;
22b077aed3SPierre Pronchery 
23b077aed3SPierre Pronchery     ctx = OPENSSL_zalloc(sizeof(*ctx));
24b077aed3SPierre Pronchery     if (ctx != NULL)
25b077aed3SPierre Pronchery         ossl_gcm_initctx(provctx, &ctx->base, keybits,
26b077aed3SPierre Pronchery                          ossl_prov_aria_hw_gcm(keybits));
27b077aed3SPierre Pronchery     return ctx;
28b077aed3SPierre Pronchery }
29b077aed3SPierre Pronchery 
aria_gcm_dupctx(void * provctx)30*e0c4386eSCy Schubert static void *aria_gcm_dupctx(void *provctx)
31*e0c4386eSCy Schubert {
32*e0c4386eSCy Schubert     PROV_ARIA_GCM_CTX *ctx = provctx;
33*e0c4386eSCy Schubert     PROV_ARIA_GCM_CTX *dctx = NULL;
34*e0c4386eSCy Schubert 
35*e0c4386eSCy Schubert     if (ctx == NULL)
36*e0c4386eSCy Schubert         return NULL;
37*e0c4386eSCy Schubert 
38*e0c4386eSCy Schubert     dctx =  OPENSSL_memdup(ctx, sizeof(*ctx));
39*e0c4386eSCy Schubert     if (dctx != NULL && dctx->base.gcm.key != NULL)
40*e0c4386eSCy Schubert         dctx->base.gcm.key = &dctx->ks.ks;
41*e0c4386eSCy Schubert 
42*e0c4386eSCy Schubert     return dctx;
43*e0c4386eSCy Schubert }
44*e0c4386eSCy Schubert 
45b077aed3SPierre Pronchery static OSSL_FUNC_cipher_freectx_fn aria_gcm_freectx;
aria_gcm_freectx(void * vctx)46b077aed3SPierre Pronchery static void aria_gcm_freectx(void *vctx)
47b077aed3SPierre Pronchery {
48b077aed3SPierre Pronchery     PROV_ARIA_GCM_CTX *ctx = (PROV_ARIA_GCM_CTX *)vctx;
49b077aed3SPierre Pronchery 
50b077aed3SPierre Pronchery     OPENSSL_clear_free(ctx,  sizeof(*ctx));
51b077aed3SPierre Pronchery }
52b077aed3SPierre Pronchery 
53b077aed3SPierre Pronchery /* ossl_aria128gcm_functions */
54b077aed3SPierre Pronchery IMPLEMENT_aead_cipher(aria, gcm, GCM, AEAD_FLAGS, 128, 8, 96);
55b077aed3SPierre Pronchery /* ossl_aria192gcm_functions */
56b077aed3SPierre Pronchery IMPLEMENT_aead_cipher(aria, gcm, GCM, AEAD_FLAGS, 192, 8, 96);
57b077aed3SPierre Pronchery /* ossl_aria256gcm_functions */
58b077aed3SPierre Pronchery IMPLEMENT_aead_cipher(aria, gcm, GCM, AEAD_FLAGS, 256, 8, 96);
59b077aed3SPierre Pronchery 
60