1e1051a39Sopenharmony_ci/*
2e1051a39Sopenharmony_ci * Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
3e1051a39Sopenharmony_ci *
4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License").  You may not use
5e1051a39Sopenharmony_ci * this file except in compliance with the License.  You can obtain a copy
6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at
7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html
8e1051a39Sopenharmony_ci */
9e1051a39Sopenharmony_ci
10e1051a39Sopenharmony_ci/* Dispatch functions for SM4 GCM mode */
11e1051a39Sopenharmony_ci
12e1051a39Sopenharmony_ci#include "cipher_sm4_gcm.h"
13e1051a39Sopenharmony_ci#include "prov/implementations.h"
14e1051a39Sopenharmony_ci#include "prov/providercommon.h"
15e1051a39Sopenharmony_ci
16e1051a39Sopenharmony_cistatic OSSL_FUNC_cipher_freectx_fn sm4_gcm_freectx;
17e1051a39Sopenharmony_ci
18e1051a39Sopenharmony_cistatic void *sm4_gcm_newctx(void *provctx, size_t keybits)
19e1051a39Sopenharmony_ci{
20e1051a39Sopenharmony_ci    PROV_SM4_GCM_CTX *ctx;
21e1051a39Sopenharmony_ci
22e1051a39Sopenharmony_ci    if (!ossl_prov_is_running())
23e1051a39Sopenharmony_ci        return NULL;
24e1051a39Sopenharmony_ci
25e1051a39Sopenharmony_ci    ctx = OPENSSL_zalloc(sizeof(*ctx));
26e1051a39Sopenharmony_ci    if (ctx != NULL)
27e1051a39Sopenharmony_ci        ossl_gcm_initctx(provctx, &ctx->base, keybits,
28e1051a39Sopenharmony_ci                         ossl_prov_sm4_hw_gcm(keybits));
29e1051a39Sopenharmony_ci    return ctx;
30e1051a39Sopenharmony_ci}
31e1051a39Sopenharmony_ci
32e1051a39Sopenharmony_cistatic void sm4_gcm_freectx(void *vctx)
33e1051a39Sopenharmony_ci{
34e1051a39Sopenharmony_ci    PROV_SM4_GCM_CTX *ctx = (PROV_SM4_GCM_CTX *)vctx;
35e1051a39Sopenharmony_ci
36e1051a39Sopenharmony_ci    OPENSSL_clear_free(ctx,  sizeof(*ctx));
37e1051a39Sopenharmony_ci}
38e1051a39Sopenharmony_ci
39e1051a39Sopenharmony_ci/* ossl_sm4128gcm_functions */
40e1051a39Sopenharmony_ciIMPLEMENT_aead_cipher(sm4, gcm, GCM, AEAD_FLAGS, 128, 8, 96);
41