From be69c7d5594255ea9e9c34721987666561a7bf86 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 20 Dec 2022 19:51:22 +0100 Subject: [PATCH] Generate test cases for mpi_mod_raw_modulus_to_canonical_rep as well Signed-off-by: Gilles Peskine --- scripts/mbedtls_dev/bignum_mod_raw.py | 39 +++++++++++++++++++-------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/scripts/mbedtls_dev/bignum_mod_raw.py b/scripts/mbedtls_dev/bignum_mod_raw.py index c504581493..800bcb13e1 100644 --- a/scripts/mbedtls_dev/bignum_mod_raw.py +++ b/scripts/mbedtls_dev/bignum_mod_raw.py @@ -108,23 +108,18 @@ class BignumModRawAdd(bignum_common.ModOperationCommon, # BEGIN MERGE SLOT 6 -class BignumModRawCanonicalToModulusRep(bignum_common.ModOperationCommon, - BignumModRawTarget): - """Test cases for mpi_mod_raw_canonical_to_modulus_rep.""" - test_function = "mpi_mod_raw_canonical_to_modulus_rep" - test_name = "Rep canon->mod" +class BignumModRawConvertRep(bignum_common.ModOperationCommon, + BignumModRawTarget): + # This is an abstract class, it's ok to have unimplemented methods. + #pylint: disable=abstract-method + """Test cases for representation conversion.""" arity = 1 - def __init__(self, - val_n: str, val_a: str, + def __init__(self, val_n: str, val_a: str, rep: bignum_common.ModulusRepresentation) -> None: super().__init__(val_n=val_n, val_a=val_a) self.rep = rep - def result(self) -> List[str]: - result = self.convert_from_canonical(self.int_a, self.rep) - return [self.format_result(result)] - def arguments(self) -> List[str]: return ([bignum_common.quote_str(self.arg_n), self.rep.symbol(), bignum_common.quote_str(self.arg_a)] + @@ -141,6 +136,28 @@ class BignumModRawCanonicalToModulusRep(bignum_common.ModOperationCommon, if test_object.is_valid: yield test_object.create_test_case() +class BignumModRawCanonicalToModulusRep(BignumModRawConvertRep): + """Test cases for mpi_mod_raw_canonical_to_modulus_rep.""" + test_function = "mpi_mod_raw_canonical_to_modulus_rep" + test_name = "Rep canon->mod" + + def result(self) -> List[str]: + result = self.convert_from_canonical(self.int_a, self.rep) + return [self.format_result(result)] + +class BignumModRawModulusToCanonicalRep(BignumModRawConvertRep): + """Test cases for mpi_mod_raw_modulus_to_canonical_rep.""" + test_function = "mpi_mod_raw_modulus_to_canonical_rep" + test_name = "Rep mod->canon" + + @property + def arg_a(self) -> str: + converted_a = self.convert_from_canonical(self.int_a, self.rep) + return self.format_arg(hex(converted_a)[2:]) + + def result(self) -> List[str]: + return [self.format_result(self.int_a)] + # END MERGE SLOT 6 # BEGIN MERGE SLOT 7