/src/openssl/providers/implementations/ciphers/cipher_sm4_gcm.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /*  | 
2  |  |  * Copyright 2021-2023 The OpenSSL Project Authors. All Rights Reserved.  | 
3  |  |  *  | 
4  |  |  * Licensed under the Apache License 2.0 (the "License").  You may not use  | 
5  |  |  * this file except in compliance with the License.  You can obtain a copy  | 
6  |  |  * in the file LICENSE in the source distribution or at  | 
7  |  |  * https://www.openssl.org/source/license.html  | 
8  |  |  */  | 
9  |  |  | 
10  |  | /* Dispatch functions for SM4 GCM mode */  | 
11  |  |  | 
12  |  | #include "cipher_sm4_gcm.h"  | 
13  |  | #include "prov/implementations.h"  | 
14  |  | #include "prov/providercommon.h"  | 
15  |  |  | 
16  |  | static OSSL_FUNC_cipher_freectx_fn sm4_gcm_freectx;  | 
17  |  |  | 
18  |  | static void *sm4_gcm_newctx(void *provctx, size_t keybits)  | 
19  | 0  | { | 
20  | 0  |     PROV_SM4_GCM_CTX *ctx;  | 
21  |  | 
  | 
22  | 0  |     if (!ossl_prov_is_running())  | 
23  | 0  |         return NULL;  | 
24  |  |  | 
25  | 0  |     ctx = OPENSSL_zalloc(sizeof(*ctx));  | 
26  | 0  |     if (ctx != NULL)  | 
27  | 0  |         ossl_gcm_initctx(provctx, &ctx->base, keybits,  | 
28  | 0  |                          ossl_prov_sm4_hw_gcm(keybits));  | 
29  | 0  |     return ctx;  | 
30  | 0  | }  | 
31  |  |  | 
32  |  | static void *sm4_gcm_dupctx(void *provctx)  | 
33  | 0  | { | 
34  | 0  |     PROV_SM4_GCM_CTX *ctx = provctx;  | 
35  | 0  |     PROV_SM4_GCM_CTX *dctx = NULL;  | 
36  |  | 
  | 
37  | 0  |     if (ctx == NULL)  | 
38  | 0  |         return NULL;  | 
39  |  |  | 
40  | 0  |     dctx = OPENSSL_memdup(ctx, sizeof(*ctx));  | 
41  | 0  |     if (dctx != NULL && dctx->base.gcm.key != NULL)  | 
42  | 0  |         dctx->base.gcm.key = &dctx->ks.ks;  | 
43  |  | 
  | 
44  | 0  |     return dctx;  | 
45  | 0  | }  | 
46  |  |  | 
47  |  | static void sm4_gcm_freectx(void *vctx)  | 
48  | 0  | { | 
49  | 0  |     PROV_SM4_GCM_CTX *ctx = (PROV_SM4_GCM_CTX *)vctx;  | 
50  |  | 
  | 
51  | 0  |     OPENSSL_clear_free(ctx,  sizeof(*ctx));  | 
52  | 0  | }  | 
53  |  |  | 
54  |  | /* ossl_sm4128gcm_functions */  | 
55  |  | IMPLEMENT_aead_cipher(sm4, gcm, GCM, AEAD_FLAGS, 128, 8, 96);  |