From af84b28c9ec8299863452ba5ecd0ee550621e18f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Mon, 28 Jul 2025 23:42:15 +0200 Subject: [PATCH] GCD-modinv tests: centralize things in __init__() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit That way generate_function_tests() only needs to filter test data. Signed-off-by: Manuel Pégourié-Gonnard --- scripts/mbedtls_framework/bignum_core.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/scripts/mbedtls_framework/bignum_core.py b/scripts/mbedtls_framework/bignum_core.py index 4254427a5..0481d7579 100644 --- a/scripts/mbedtls_framework/bignum_core.py +++ b/scripts/mbedtls_framework/bignum_core.py @@ -942,19 +942,19 @@ class BignumCoreGcdModinvOdd(BignumCoreTarget, test_data_generation.BaseTest): ("rand1024[4.5] * 3", int(bignum_data.RANDOM_1024_BIT_SEED_4_NO5, 16) * 3), ) - def __init__(self, a: int, a_desc: str, n: int, n_desc: str, g: int, i: int) -> None: + def __init__(self, a: int, a_desc: str, n: int, n_desc: str) -> None: self.a_val = a self.a_desc = a_desc self.n_val = n self.n_desc = n_desc - self.g_val = g - self.i_val = i + self.g_val = g = math.gcd(a, n) + self.i_val = bignum_common.invmod_positive(a, n) if g == 1 else None def arguments(self) -> List[str]: a_str = f"{self.a_val:x}" n_str = f"{self.n_val:x}" g_str = f"{self.g_val:x}" - i_str = f"{self.i_val:x}" if self.i_val != 0 else "" + i_str = f"{self.i_val:x}" if self.i_val is not None else "" return [bignum_common.quote_str(s) for s in (a_str, n_str, g_str, i_str)] def description(self) -> str: @@ -968,9 +968,4 @@ class BignumCoreGcdModinvOdd(BignumCoreTarget, test_data_generation.BaseTest): for a_desc, a in cls.DATA: if a > n: continue - g = math.gcd(a, n) - if g == 1: - i = bignum_common.invmod_positive(a, n) - else: - i = 0 - yield cls(a, a_desc, n, n_desc, g, i).create_test_case() + yield cls(a, a_desc, n, n_desc).create_test_case()