Skip to content

Commit

Permalink
libmbedtls: fix cipher_wrap.c for chacha20 and chachapoly
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
smo4201 authored and jenswi-linaro committed Oct 6, 2023
1 parent 7300f4d commit ad67ef0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/libmbedtls/mbedtls/library/cipher_wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1852,6 +1852,11 @@ static void *chacha20_ctx_alloc(void)
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);
Expand Down Expand Up @@ -1882,6 +1887,7 @@ static const mbedtls_cipher_base_t chacha20_base_info = {
chacha20_setkey_wrap,
chacha20_setkey_wrap,
chacha20_ctx_alloc,
chacha20_ctx_clone,
chacha20_ctx_free
};
static const mbedtls_cipher_info_t chacha20_info = {
Expand Down Expand Up @@ -1927,6 +1933,11 @@ static void *chachapoly_ctx_alloc(void)
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);
Expand Down Expand Up @@ -1957,6 +1968,7 @@ static const mbedtls_cipher_base_t chachapoly_base_info = {
chachapoly_setkey_wrap,
chachapoly_setkey_wrap,
chachapoly_ctx_alloc,
chachapoly_ctx_clone,
chachapoly_ctx_free
};
static const mbedtls_cipher_info_t chachapoly_info = {
Expand Down

0 comments on commit ad67ef0

Please sign in to comment.