Merge pull request #6772 from wernerlewis/bignum_refactor_sub

Bignum: Refactor mpi_core_sub tests to use arch_split
This commit is contained in:
Gilles Peskine 2022-12-15 12:32:44 +01:00 committed by GitHub
commit 9fa4897839
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 24 deletions

View file

@ -130,24 +130,20 @@ class BignumCoreAddAndAddIf(BignumCoreTarget, bignum_common.OperationCommon):
class BignumCoreSub(BignumCoreTarget, bignum_common.OperationCommon):
"""Test cases for bignum core sub."""
count = 0
input_style = "arch_split"
symbol = "-"
test_function = "mpi_core_sub"
test_name = "mbedtls_mpi_core_sub"
def result(self) -> List[str]:
if self.int_a >= self.int_b:
result_4 = result_8 = self.int_a - self.int_b
result = self.int_a - self.int_b
carry = 0
else:
bound_val = max(self.int_a, self.int_b)
bound_4 = bignum_common.bound_mpi(bound_val, 32)
result_4 = bound_4 + self.int_a - self.int_b
bound_8 = bignum_common.bound_mpi(bound_val, 64)
result_8 = bound_8 + self.int_a - self.int_b
result = self.limb_boundary + self.int_a - self.int_b
carry = 1
return [
"\"{:x}\"".format(result_4),
"\"{:x}\"".format(result_8),
self.format_result(result),
str(carry)
]