summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Horman <nhorman@openssl.org>2023-09-01 13:22:03 -0400
committerTomas Mraz <tomas@openssl.org>2024-01-05 17:15:43 +0100
commit1aa0746d71468aaa0b999b3501bb0280a2f5d4f4 (patch)
tree185bc7c28262bdf7594991905a84d8afb4546812
parent51036a43753f565443acdb81f2ed2857c029ee68 (diff)
implement dupctx for chacha20_poly1305
Same as chacha20 in the last commit, just clone the ctx and its underlying tlsmac array if its allocated Fixes #21887 Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23102) (cherry picked from commit e7ef50c3e3b670a476aa0e864da5b5cc874b3528)
-rw-r--r--providers/implementations/ciphers/cipher_chacha20_poly1305.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/providers/implementations/ciphers/cipher_chacha20_poly1305.c b/providers/implementations/ciphers/cipher_chacha20_poly1305.c
index abe670add7..2b271b1d94 100644
--- a/providers/implementations/ciphers/cipher_chacha20_poly1305.c
+++ b/providers/implementations/ciphers/cipher_chacha20_poly1305.c
@@ -23,6 +23,7 @@
static OSSL_FUNC_cipher_newctx_fn chacha20_poly1305_newctx;
static OSSL_FUNC_cipher_freectx_fn chacha20_poly1305_freectx;
+static OSSL_FUNC_cipher_dupctx_fn chacha20_poly1305_dupctx;
static OSSL_FUNC_cipher_encrypt_init_fn chacha20_poly1305_einit;
static OSSL_FUNC_cipher_decrypt_init_fn chacha20_poly1305_dinit;
static OSSL_FUNC_cipher_get_params_fn chacha20_poly1305_get_params;
@@ -58,6 +59,25 @@ static void *chacha20_poly1305_newctx(void *provctx)
return ctx;
}
+static void *chacha20_poly1305_dupctx(void *provctx)
+{
+ PROV_CHACHA20_POLY1305_CTX *ctx = provctx;
+ PROV_CHACHA20_POLY1305_CTX *dctx = NULL;
+
+ if (ctx == NULL)
+ return NULL;
+ dctx = OPENSSL_memdup(ctx, sizeof(*ctx));
+ if (dctx != NULL && dctx->base.tlsmac != NULL && dctx->base.alloced) {
+ dctx->base.tlsmac = OPENSSL_memdup(dctx->base.tlsmac,
+ dctx->base.tlsmacsize);
+ if (dctx->base.tlsmac == NULL) {
+ OPENSSL_free(dctx);
+ dctx = NULL;
+ }
+ }
+ return dctx;
+}
+
static void chacha20_poly1305_freectx(void *vctx)
{
PROV_CHACHA20_POLY1305_CTX *ctx = (PROV_CHACHA20_POLY1305_CTX *)vctx;
@@ -310,6 +330,7 @@ static int chacha20_poly1305_final(void *vctx, unsigned char *out, size_t *outl,
const OSSL_DISPATCH ossl_chacha20_ossl_poly1305_functions[] = {
{ OSSL_FUNC_CIPHER_NEWCTX, (void (*)(void))chacha20_poly1305_newctx },
{ OSSL_FUNC_CIPHER_FREECTX, (void (*)(void))chacha20_poly1305_freectx },
+ { OSSL_FUNC_CIPHER_DUPCTX, (void (*)(void))chacha20_poly1305_dupctx },
{ OSSL_FUNC_CIPHER_ENCRYPT_INIT, (void (*)(void))chacha20_poly1305_einit },
{ OSSL_FUNC_CIPHER_DECRYPT_INIT, (void (*)(void))chacha20_poly1305_dinit },
{ OSSL_FUNC_CIPHER_UPDATE, (void (*)(void))chacha20_poly1305_update },