Path: blob/main/crypto/openssl/providers/implementations/ciphers/cipher_aes_gcm.c
48383 views
/*1* Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved.2*3* Licensed under the Apache License 2.0 (the "License"). You may not use4* this file except in compliance with the License. You can obtain a copy5* in the file LICENSE in the source distribution or at6* https://www.openssl.org/source/license.html7*/89/*10* AES low level APIs are deprecated for public use, but still ok for internal11* use where we're using them to implement the higher level EVP interface, as is12* the case here.13*/14#include "internal/deprecated.h"1516/* Dispatch functions for AES GCM mode */1718#include "cipher_aes_gcm.h"19#include "prov/implementations.h"20#include "prov/providercommon.h"2122static void *aes_gcm_newctx(void *provctx, size_t keybits)23{24PROV_AES_GCM_CTX *ctx;2526if (!ossl_prov_is_running())27return NULL;2829ctx = OPENSSL_zalloc(sizeof(*ctx));30if (ctx != NULL)31ossl_gcm_initctx(provctx, &ctx->base, keybits,32ossl_prov_aes_hw_gcm(keybits));33return ctx;34}3536static void *aes_gcm_dupctx(void *provctx)37{38PROV_AES_GCM_CTX *ctx = provctx;39PROV_AES_GCM_CTX *dctx = NULL;4041if (!ossl_prov_is_running())42return NULL;4344if (ctx == NULL)45return NULL;4647dctx = OPENSSL_memdup(ctx, sizeof(*ctx));48if (dctx != NULL && dctx->base.gcm.key != NULL)49dctx->base.gcm.key = &dctx->ks.ks;5051return dctx;52}5354static OSSL_FUNC_cipher_freectx_fn aes_gcm_freectx;55static void aes_gcm_freectx(void *vctx)56{57PROV_AES_GCM_CTX *ctx = (PROV_AES_GCM_CTX *)vctx;5859OPENSSL_clear_free(ctx, sizeof(*ctx));60}6162/* ossl_aes128gcm_functions */63IMPLEMENT_aead_cipher(aes, gcm, GCM, AEAD_FLAGS, 128, 8, 96);64/* ossl_aes192gcm_functions */65IMPLEMENT_aead_cipher(aes, gcm, GCM, AEAD_FLAGS, 192, 8, 96);66/* ossl_aes256gcm_functions */67IMPLEMENT_aead_cipher(aes, gcm, GCM, AEAD_FLAGS, 256, 8, 96);686970