From 54052559280563002eab746eb2f2eb2bb77216e1 Mon Sep 17 00:00:00 2001 From: Alexey Skalozub Date: Sat, 28 Oct 2017 03:47:00 +0300 Subject: [PATCH] Fix losing sign when multiplying by -1 --- components/mbedtls/port/esp_bignum.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/components/mbedtls/port/esp_bignum.c b/components/mbedtls/port/esp_bignum.c index a9faa2670f..f18652c7bb 100644 --- a/components/mbedtls/port/esp_bignum.c +++ b/components/mbedtls/port/esp_bignum.c @@ -497,10 +497,14 @@ int mbedtls_mpi_mul_mpi( mbedtls_mpi *Z, const mbedtls_mpi *X, const mbedtls_mpi return 0; } if (bits_x == 1) { - return mbedtls_mpi_copy(Z, Y); + ret = mbedtls_mpi_copy(Z, Y); + Z->s *= X->s; + return ret; } if (bits_y == 1) { - return mbedtls_mpi_copy(Z, X); + ret = mbedtls_mpi_copy(Z, X); + Z->s *= Y->s; + return ret; } words_mult = (words_x > words_y ? words_x : words_y); -- 2.40.0