From 30f073236922fe4e528fdf82eb442babb50516fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Wed, 13 Aug 2025 08:42:45 +0200 Subject: [PATCH] bignum: gcd: improve comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Manuel Pégourié-Gonnard --- library/bignum.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/bignum.c b/library/bignum.c index 358714839c..d03e26c0a7 100644 --- a/library/bignum.c +++ b/library/bignum.c @@ -1849,9 +1849,9 @@ int mbedtls_mpi_gcd(mbedtls_mpi *G, const mbedtls_mpi *A, const mbedtls_mpi *B) goto cleanup; } + /* Make boths inputs odd by putting powers of 2 on the side */ const size_t za = mbedtls_mpi_lsb(&TA); const size_t zb = mbedtls_mpi_lsb(&TB); - MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TA, za)); MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TB, zb)); @@ -1861,6 +1861,7 @@ int mbedtls_mpi_gcd(mbedtls_mpi *G, const mbedtls_mpi *A, const mbedtls_mpi *B) MBEDTLS_MPI_CHK(mbedtls_mpi_gcd_modinv_odd(G, NULL, &TA, &TB)); + /* Re-inject the power of 2 we had previously put aside */ size_t zg = za > zb ? zb : za; // zg = min(za, zb) MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(G, zg));