mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-08-08 17:42:09 +03:00
Merge pull request #6233 from tom-cosgrove-arm/issue-6226-core-mul
Bignum: extract core_mul from the prototype
This commit is contained in:
@@ -68,7 +68,8 @@ def bound_mpi_limbs(limbs: int, bits_in_limb: int) -> int:
|
||||
|
||||
def limbs_mpi(val: int, bits_in_limb: int) -> int:
|
||||
"""Return the number of limbs required to store value."""
|
||||
return (val.bit_length() + bits_in_limb - 1) // bits_in_limb
|
||||
bit_length = max(val.bit_length(), 1)
|
||||
return (bit_length + bits_in_limb - 1) // bits_in_limb
|
||||
|
||||
def combination_pairs(values: List[T]) -> List[Tuple[T, T]]:
|
||||
"""Return all pair combinations from input values."""
|
||||
|
@@ -230,6 +230,31 @@ class BignumCoreMLA(BignumCoreTarget, bignum_common.OperationCommon):
|
||||
yield cur_op.create_test_case()
|
||||
|
||||
|
||||
class BignumCoreMul(BignumCoreTarget, bignum_common.OperationCommon):
|
||||
"""Test cases for bignum core multiplication."""
|
||||
count = 0
|
||||
input_style = "arch_split"
|
||||
symbol = "*"
|
||||
test_function = "mpi_core_mul"
|
||||
test_name = "mbedtls_mpi_core_mul"
|
||||
arity = 2
|
||||
unique_combinations_only = True
|
||||
|
||||
def format_arg(self, val: str) -> str:
|
||||
return val
|
||||
|
||||
def format_result(self, res: int) -> str:
|
||||
res_str = '{:x}'.format(res)
|
||||
a_limbs = bignum_common.limbs_mpi(self.int_a, self.bits_in_limb)
|
||||
b_limbs = bignum_common.limbs_mpi(self.int_b, self.bits_in_limb)
|
||||
hex_digits = bignum_common.hex_digits_for_limb(a_limbs + b_limbs, self.bits_in_limb)
|
||||
return bignum_common.quote_str(self.format_arg(res_str).zfill(hex_digits))
|
||||
|
||||
def result(self) -> List[str]:
|
||||
result = self.int_a * self.int_b
|
||||
return [self.format_result(result)]
|
||||
|
||||
|
||||
class BignumCoreMontmul(BignumCoreTarget, test_data_generation.BaseTest):
|
||||
"""Test cases for Montgomery multiplication."""
|
||||
count = 0
|
||||
|
Reference in New Issue
Block a user