summaryrefslogtreecommitdiffstats
path: root/providers
diff options
context:
space:
mode:
authorNeil Horman <nhorman@openssl.org>2023-08-28 18:07:16 +0200
committerPauli <pauli@openssl.org>2023-09-04 02:15:58 +0200
commit61cfc22b60e33bc77b1e1944759af48c8e58f0d2 (patch)
tree28532ea7f227fe8f7c5ab6f989678f837e39f061 /providers
parentMove ALIGN32 and ALIGN64 into common.h, and fix for clang-cl.exe (diff)
downloadopenssl-61cfc22b60e33bc77b1e1944759af48c8e58f0d2.tar.xz
openssl-61cfc22b60e33bc77b1e1944759af48c8e58f0d2.zip
Implement dupctx for chacha20 cipher
Implement the dupctx method for the chacha20 cipher, so that EVP_PKEY_CTX_copy works Its pretty straightforward, its basically just a memdup. Checking the pointers that might need fixing up: in PROV_CHACHA20_CTX all members are statically declared, so memduping should be fine in PROV_CHACHA20_CTX->base (PROV_CIPHER_CTX): Non statically declared members: *tlsmac needs to get memduped to avoid double free conditions, but only if base.alloced is set *hw pointer is always assigned to the chacha20_hw global variable, so can be left alone *libctx can be left alone as provctx is always NULL in chacha20_newctx *ks appears unused by chacha20, so can be ignored Fixes #20978 Reviewed-by: Richard Levitte <levitte@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Shane Lontis <shane.lontis@oracle.com> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/21878)
Diffstat (limited to 'providers')
-rw-r--r--providers/implementations/ciphers/cipher_chacha20.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/providers/implementations/ciphers/cipher_chacha20.c b/providers/implementations/ciphers/cipher_chacha20.c
index 41aa056c2d..49e36ba1a9 100644
--- a/providers/implementations/ciphers/cipher_chacha20.c
+++ b/providers/implementations/ciphers/cipher_chacha20.c
@@ -21,6 +21,7 @@
static OSSL_FUNC_cipher_newctx_fn chacha20_newctx;
static OSSL_FUNC_cipher_freectx_fn chacha20_freectx;
+static OSSL_FUNC_cipher_dupctx_fn chacha20_dupctx;
static OSSL_FUNC_cipher_get_params_fn chacha20_get_params;
static OSSL_FUNC_cipher_get_ctx_params_fn chacha20_get_ctx_params;
static OSSL_FUNC_cipher_set_ctx_params_fn chacha20_set_ctx_params;
@@ -64,6 +65,25 @@ static void chacha20_freectx(void *vctx)
}
}
+static void *chacha20_dupctx(void *vctx)
+{
+ PROV_CHACHA20_CTX *ctx = (PROV_CHACHA20_CTX *)vctx;
+ PROV_CHACHA20_CTX *dupctx = NULL;
+
+ if (ctx != NULL) {
+ dupctx = OPENSSL_memdup(ctx, sizeof(*dupctx));
+ if (dupctx != NULL && dupctx->base.tlsmac != NULL && dupctx->base.alloced) {
+ dupctx->base.tlsmac = OPENSSL_memdup(dupctx->base.tlsmac,
+ dupctx->base.tlsmacsize);
+ if (dupctx->base.tlsmac == NULL) {
+ OPENSSL_free(dupctx);
+ dupctx = NULL;
+ }
+ }
+ }
+ return dupctx;
+}
+
static int chacha20_get_params(OSSL_PARAM params[])
{
return ossl_cipher_generic_get_params(params, 0, CHACHA20_FLAGS,
@@ -187,6 +207,7 @@ int ossl_chacha20_dinit(void *vctx, const unsigned char *key, size_t keylen,
const OSSL_DISPATCH ossl_chacha20_functions[] = {
{ OSSL_FUNC_CIPHER_NEWCTX, (void (*)(void))chacha20_newctx },
{ OSSL_FUNC_CIPHER_FREECTX, (void (*)(void))chacha20_freectx },
+ { OSSL_FUNC_CIPHER_DUPCTX, (void (*)(void))chacha20_dupctx },
{ OSSL_FUNC_CIPHER_ENCRYPT_INIT, (void (*)(void))ossl_chacha20_einit },
{ OSSL_FUNC_CIPHER_DECRYPT_INIT, (void (*)(void))ossl_chacha20_dinit },
{ OSSL_FUNC_CIPHER_UPDATE, (void (*)(void))chacha20_update },