From 576087d8366f05e5ceb91e7185049cc5355871fd Mon Sep 17 00:00:00 2001 From: Janos Follath Date: Mon, 19 Feb 2024 11:05:01 +0000 Subject: [PATCH] Exp mod: use assignment instead memcpy memcpy() has the advantage of making the reader stop and arguably signal that the shallow copy here is intentional. But that hinges on having the right amount of & and the right size. An assignment is clearer and less risky. Signed-off-by: Janos Follath --- library/bignum.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/bignum.c b/library/bignum.c index 674aab7d29..42b735f1a3 100644 --- a/library/bignum.c +++ b/library/bignum.c @@ -1630,10 +1630,10 @@ int mbedtls_mpi_exp_mod(mbedtls_mpi *X, const mbedtls_mpi *A, MBEDTLS_MPI_CHK(mbedtls_mpi_core_get_mont_r2_unsafe(&RR, N)); if (prec_RR != NULL) { - memcpy(prec_RR, &RR, sizeof(mbedtls_mpi)); + *prec_RR = RR; } } else { - memcpy(&RR, prec_RR, sizeof(mbedtls_mpi)); + RR = *prec_RR; } /* @@ -1642,7 +1642,7 @@ int mbedtls_mpi_exp_mod(mbedtls_mpi *X, const mbedtls_mpi *A, if (E->n == 0) { mbedtls_mpi_lset(&E_core, 0); } else { - memcpy(&E_core, E, sizeof(mbedtls_mpi)); + E_core = *E; } /*