Bignum Tests: Move ModOperation to common
The class BignumModRawOperation implements functionality that are needed
in other modules, therefore we move it to common.
No intended changes to test cases. The order of add_and_add_if and sub tests
have been switched.
Signed-off-by: Janos Follath <janos.follath@arm.com>
diff --git a/scripts/mbedtls_dev/bignum_common.py b/scripts/mbedtls_dev/bignum_common.py
index 7ab788b..28e27b0 100644
--- a/scripts/mbedtls_dev/bignum_common.py
+++ b/scripts/mbedtls_dev/bignum_common.py
@@ -142,6 +142,58 @@
yield cls(a_value, b_value).create_test_case()
+class ModOperationCommon(OperationCommon):
+ #pylint: disable=abstract-method
+ """Target for bignum mod_raw test case generation."""
+
+ def __init__(self, val_n: str, val_a: str, val_b: str = "0", bits_in_limb: int = 64) -> None:
+ super().__init__(val_a=val_a, val_b=val_b)
+ self.val_n = val_n
+ self.bits_in_limb = bits_in_limb
+
+ @property
+ def int_n(self) -> int:
+ return hex_to_int(self.val_n)
+
+ @property
+ def boundary(self) -> int:
+ data_in = [self.int_a, self.int_b, self.int_n]
+ return max([n for n in data_in if n is not None])
+
+ @property
+ def limbs(self) -> int:
+ return limbs_mpi(self.boundary, self.bits_in_limb)
+
+ @property
+ def hex_digits(self) -> int:
+ return 2 * (self.limbs * self.bits_in_limb // 8)
+
+ @property
+ def hex_n(self) -> str:
+ return "{:x}".format(self.int_n).zfill(self.hex_digits)
+
+ @property
+ def hex_a(self) -> str:
+ return "{:x}".format(self.int_a).zfill(self.hex_digits)
+
+ @property
+ def hex_b(self) -> str:
+ return "{:x}".format(self.int_b).zfill(self.hex_digits)
+
+ @property
+ def r(self) -> int: # pylint: disable=invalid-name
+ l = limbs_mpi(self.int_n, self.bits_in_limb)
+ return bound_mpi_limbs(l, self.bits_in_limb)
+
+ @property
+ def r_inv(self) -> int:
+ return invmod(self.r, self.int_n)
+
+ @property
+ def r2(self) -> int: # pylint: disable=invalid-name
+ return pow(self.r, 2)
+
+
class OperationCommonArchSplit(OperationCommon):
#pylint: disable=abstract-method
"""Common features for operations where the result depends on