From 5972096114127759abce1c8450b29129cba97814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Thu, 17 Jul 2025 09:39:55 +0200 Subject: [PATCH] Forbid uninteresting edge cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A == N (as pointers) will not happen in pratice: in our context, it would mean we know at compile time that A == N (as values), and we wouldn't be calling this function if we knew that already. N == 1 when I != NULL is also not going to happen: we don't care about operations mod 1. Signed-off-by: Manuel Pégourié-Gonnard --- library/bignum_core.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/bignum_core.h b/library/bignum_core.h index 1589c34640..b8e0807170 100644 --- a/library/bignum_core.h +++ b/library/bignum_core.h @@ -825,7 +825,9 @@ void mbedtls_mpi_core_from_mont_rep(mbedtls_mpi_uint *X, /** Compute GCD(A, N) and optionally the inverse of A mod N if it exists. * * Requires N to be odd, and 0 <= A <= N. + * When I != NULL, N (the modulus) must not be 1. * + * A and N may not alias each other. * When I == NULL (computing only the GCD), G may alias A or N. * When I != NULL (computing the modular inverse), G or I may alias A * but none of them may alias N (the modulus).