From 76960a7217e47cc18d225dbd2d00d47016a601db Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Mon, 21 Feb 2022 13:42:09 +0100 Subject: [PATCH] mbedtls_mpi_read_binary() document that function guarantees to return an MPI with exactly the necessary number of limbs and remove redundant call to mbedtls_mpi_grow() Signed-off-by: Przemyslaw Stekiel --- library/bignum.c | 6 ++++++ library/psa_crypto.c | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/library/bignum.c b/library/bignum.c index a7e3fa3de..288f85932 100644 --- a/library/bignum.c +++ b/library/bignum.c @@ -785,6 +785,9 @@ static void mpi_bigendian_to_host( mbedtls_mpi_uint * const p, size_t limbs ) /* * Import X from unsigned binary data, little endian + * + * This function is guaranteed to return an MPI with exactly the necessary + * number of limbs (in particular, it does not skip 0s in the input). */ int mbedtls_mpi_read_binary_le( mbedtls_mpi *X, const unsigned char *buf, size_t buflen ) @@ -811,6 +814,9 @@ cleanup: /* * Import X from unsigned binary data, big endian + * + * This function is guaranteed to return an MPI with exactly the necessary + * number of limbs (in particular, it does not skip 0s in the input). */ int mbedtls_mpi_read_binary( mbedtls_mpi *X, const unsigned char *buf, size_t buflen ) { diff --git a/library/psa_crypto.c b/library/psa_crypto.c index f8a2ae4e3..36a1b0c90 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -4934,7 +4934,6 @@ static psa_status_t psa_generate_derived_ecc_key_weierstrass_helper( * Result of comparison is returned. When it indicates error * then this fuction is called again. */ - MBEDTLS_MPI_CHK( mbedtls_mpi_grow( &k, diff_N_2.n ) ); MBEDTLS_MPI_CHK( mbedtls_mpi_lt_mpi_ct( &diff_N_2, &k, &key_out_of_range ) ); }