libmbedtls: fix cipher_wrap.c for chacha20 and chachapoly

For chacha20 and chachapoly, the *_ctx_clone() function is missing
and therefore the wrong function pointers are assigned to
.ctx_clone_func and .ctx_free_func when MBEDTLS_CHACHA20_C
or MBEDTLS_CHACHAPOLY_C is enabled.

Signed-off-by: Simon Ott <simon.ott@aisec.fraunhofer.de>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
[jw: rebased onto mbedtls-3.4.0]
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
[tve: rebased onto mbedtls-3.6.0]
Signed-off-by: Tom Van Eyck <tom.vaneyck@kuleuven.be>
diff --git a/lib/libmbedtls/mbedtls/library/cipher_wrap.c b/lib/libmbedtls/mbedtls/library/cipher_wrap.c
index 05f4aa8..ee0b802 100644
--- a/lib/libmbedtls/mbedtls/library/cipher_wrap.c
+++ b/lib/libmbedtls/mbedtls/library/cipher_wrap.c
@@ -1966,6 +1966,11 @@
     return ctx;
 }
 
+static void chacha20_ctx_clone(void *dst, const void *src)
+{
+    memcpy(dst, src, sizeof(mbedtls_chacha20_context));
+}
+
 static void chacha20_ctx_free(void *ctx)
 {
     mbedtls_chacha20_free((mbedtls_chacha20_context *) ctx);
@@ -1998,6 +2003,7 @@
     chacha20_setkey_wrap,
 #endif
     chacha20_ctx_alloc,
+    chacha20_ctx_clone,
     chacha20_ctx_free
 };
 static const mbedtls_cipher_info_t chacha20_info = {
@@ -2043,6 +2049,11 @@
     return ctx;
 }
 
+static void chachapoly_ctx_clone(void *dst, const void *src)
+{
+    memcpy(dst, src, sizeof(mbedtls_chachapoly_context));
+}
+
 static void chachapoly_ctx_free(void *ctx)
 {
     mbedtls_chachapoly_free((mbedtls_chachapoly_context *) ctx);
@@ -2075,6 +2086,7 @@
     chachapoly_setkey_wrap,
 #endif
     chachapoly_ctx_alloc,
+    chachapoly_ctx_clone,
     chachapoly_ctx_free
 };
 static const mbedtls_cipher_info_t chachapoly_info = {