1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-06-12 08:21:54 +03:00

Bignum: Implement mbedtls_mpi_mod_raw_inv_prime() and tests

Fixes #6023.

Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
This commit is contained in:
Tom Cosgrove
2022-12-08 09:44:10 +00:00
parent a7f0d7b029
commit 6129268fee
6 changed files with 187 additions and 4 deletions

View File

@ -18,6 +18,7 @@ from typing import Dict, List
from . import test_data_generation
from . import bignum_common
from .bignum_data import ONLY_PRIME_MODULI
class BignumModRawTarget(test_data_generation.BaseTarget):
#pylint: disable=abstract-method, too-few-public-methods
@ -53,6 +54,36 @@ class BignumModRawSub(bignum_common.ModOperationCommon,
# BEGIN MERGE SLOT 3
class BignumModRawInvPrime(bignum_common.ModOperationCommon,
BignumModRawTarget):
"""Test cases for bignum mpi_mod_raw_inv_prime()."""
moduli = ONLY_PRIME_MODULI
symbol = "^ -1"
test_function = "mpi_mod_raw_inv_prime"
test_name = "mbedtls_mpi_mod_raw_inv_prime (Montgomery form only)"
input_style = "fixed"
arity = 1
suffix = True
@property
def is_valid(self) -> bool:
return self.int_a > 0 and self.int_a < self.int_n
def arguments(self) -> List[str]:
# Input has to be given in Montgomery form
mont_a = self.to_montgomery(self.int_a)
arg_mont_a = self.format_arg('{:x}'.format(mont_a))
return [bignum_common.quote_str(n) for n in [self.arg_n,
arg_mont_a]
] + self.result()
def result(self) -> List[str]:
result = bignum_common.invmod(self.int_a, self.int_n)
if result < 0:
result += self.int_n
mont_result = self.to_montgomery(result)
return [self.format_result(mont_result)]
# END MERGE SLOT 3
# BEGIN MERGE SLOT 4