aboutsummaryrefslogtreecommitdiff
path: root/crypto/openssl/providers/implementations/ciphers/cipher_chacha20.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/openssl/providers/implementations/ciphers/cipher_chacha20.c')
-rw-r--r--crypto/openssl/providers/implementations/ciphers/cipher_chacha20.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/crypto/openssl/providers/implementations/ciphers/cipher_chacha20.c b/crypto/openssl/providers/implementations/ciphers/cipher_chacha20.c
index 386c865d832e..ef80a515d756 100644
--- a/crypto/openssl/providers/implementations/ciphers/cipher_chacha20.c
+++ b/crypto/openssl/providers/implementations/ciphers/cipher_chacha20.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
@@ -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 },