/src/openssl/providers/implementations/ciphers/cipher_aes_gcm.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /*  | 
2  |  |  * Copyright 2019-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  |  | /*  | 
11  |  |  * AES low level APIs are deprecated for public use, but still ok for internal  | 
12  |  |  * use where we're using them to implement the higher level EVP interface, as is  | 
13  |  |  * the case here.  | 
14  |  |  */  | 
15  |  | #include "internal/deprecated.h"  | 
16  |  |  | 
17  |  | /* Dispatch functions for AES GCM mode */  | 
18  |  |  | 
19  |  | #include "cipher_aes_gcm.h"  | 
20  |  | #include "prov/implementations.h"  | 
21  |  | #include "prov/providercommon.h"  | 
22  |  |  | 
23  |  | static void *aes_gcm_newctx(void *provctx, size_t keybits)  | 
24  | 0  | { | 
25  | 0  |     PROV_AES_GCM_CTX *ctx;  | 
26  |  | 
  | 
27  | 0  |     if (!ossl_prov_is_running())  | 
28  | 0  |         return NULL;  | 
29  |  |  | 
30  | 0  |     ctx = OPENSSL_zalloc(sizeof(*ctx));  | 
31  | 0  |     if (ctx != NULL)  | 
32  | 0  |         ossl_gcm_initctx(provctx, &ctx->base, keybits,  | 
33  | 0  |                          ossl_prov_aes_hw_gcm(keybits));  | 
34  | 0  |     return ctx;  | 
35  | 0  | }  | 
36  |  |  | 
37  |  | static void *aes_gcm_dupctx(void *provctx)  | 
38  | 0  | { | 
39  | 0  |     PROV_AES_GCM_CTX *ctx = provctx;  | 
40  | 0  |     PROV_AES_GCM_CTX *dctx = NULL;  | 
41  |  | 
  | 
42  | 0  |     if (!ossl_prov_is_running())  | 
43  | 0  |         return NULL;  | 
44  |  |  | 
45  | 0  |     if (ctx == NULL)  | 
46  | 0  |         return NULL;  | 
47  |  |  | 
48  | 0  |     dctx = OPENSSL_memdup(ctx, sizeof(*ctx));  | 
49  | 0  |     if (dctx != NULL && dctx->base.gcm.key != NULL)  | 
50  | 0  |         dctx->base.gcm.key = &dctx->ks.ks;  | 
51  |  | 
  | 
52  | 0  |     return dctx;  | 
53  | 0  | }  | 
54  |  |  | 
55  |  | static OSSL_FUNC_cipher_freectx_fn aes_gcm_freectx;  | 
56  |  | static void aes_gcm_freectx(void *vctx)  | 
57  | 0  | { | 
58  | 0  |     PROV_AES_GCM_CTX *ctx = (PROV_AES_GCM_CTX *)vctx;  | 
59  |  | 
  | 
60  | 0  |     OPENSSL_clear_free(ctx,  sizeof(*ctx));  | 
61  | 0  | }  | 
62  |  |  | 
63  |  | /* ossl_aes128gcm_functions */  | 
64  |  | IMPLEMENT_aead_cipher(aes, gcm, GCM, AEAD_FLAGS, 128, 8, 96);  | 
65  |  | /* ossl_aes192gcm_functions */  | 
66  |  | IMPLEMENT_aead_cipher(aes, gcm, GCM, AEAD_FLAGS, 192, 8, 96);  | 
67  |  | /* ossl_aes256gcm_functions */  | 
68  |  | IMPLEMENT_aead_cipher(aes, gcm, GCM, AEAD_FLAGS, 256, 8, 96);  |