Fix representation conversion with 32-bit limbs
The Montgomery representation depends on the limb size. So the representation conversion test cases need separate 64-bit and 32-bit cases when the representation is Montgomery. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
4c950d5ff1
commit
ad335b55ff
1 changed files with 20 additions and 6 deletions
|
@ -14,7 +14,7 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from typing import Dict, Iterator, List
|
from typing import Iterator, List, Optional, Union
|
||||||
|
|
||||||
from . import test_case
|
from . import test_case
|
||||||
from . import test_data_generation
|
from . import test_data_generation
|
||||||
|
@ -115,9 +115,13 @@ class BignumModRawConvertRep(bignum_common.ModOperationCommon,
|
||||||
"""Test cases for representation conversion."""
|
"""Test cases for representation conversion."""
|
||||||
arity = 1
|
arity = 1
|
||||||
|
|
||||||
def __init__(self, val_n: str, val_a: str,
|
def __init__(self, val_n: str, val_a: str, bits_in_limb: Optional[int],
|
||||||
rep: bignum_common.ModulusRepresentation) -> None:
|
rep: bignum_common.ModulusRepresentation) -> None:
|
||||||
super().__init__(val_n=val_n, val_a=val_a)
|
if bits_in_limb is None:
|
||||||
|
super().__init__(val_n=val_n, val_a=val_a)
|
||||||
|
else:
|
||||||
|
self.input_style = "arch_split"
|
||||||
|
super().__init__(val_n=val_n, val_a=val_a, bits_in_limb=bits_in_limb)
|
||||||
self.rep = rep
|
self.rep = rep
|
||||||
|
|
||||||
def arguments(self) -> List[str]:
|
def arguments(self) -> List[str]:
|
||||||
|
@ -125,16 +129,26 @@ class BignumModRawConvertRep(bignum_common.ModOperationCommon,
|
||||||
bignum_common.quote_str(self.arg_a)] +
|
bignum_common.quote_str(self.arg_a)] +
|
||||||
self.result())
|
self.result())
|
||||||
|
|
||||||
|
def description(self) -> str:
|
||||||
|
base = super().description()
|
||||||
|
mod_with_rep = 'mod({})'.format(self.rep.name)
|
||||||
|
return base.replace('mod', mod_with_rep, 1)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def generate_function_tests(cls) -> Iterator[test_case.TestCase]:
|
def generate_function_tests(cls) -> Iterator[test_case.TestCase]:
|
||||||
representations = \
|
representations = \
|
||||||
bignum_common.ModulusRepresentation.supported_representations()
|
bignum_common.ModulusRepresentation.supported_representations()
|
||||||
for rep in representations:
|
for rep in representations:
|
||||||
|
if rep is bignum_common.ModulusRepresentation.MONTGOMERY:
|
||||||
|
limb_sizes = cls.limb_sizes #type: Union[List[int], List[None]]
|
||||||
|
else:
|
||||||
|
limb_sizes = [None] # no dependency on limb size
|
||||||
for n in cls.moduli:
|
for n in cls.moduli:
|
||||||
for a in cls.input_values:
|
for a in cls.input_values:
|
||||||
test_object = cls(n, a, rep)
|
for bil in limb_sizes:
|
||||||
if test_object.is_valid:
|
test_object = cls(n, a, bil, rep)
|
||||||
yield test_object.create_test_case()
|
if test_object.is_valid:
|
||||||
|
yield test_object.create_test_case()
|
||||||
|
|
||||||
class BignumModRawCanonicalToModulusRep(BignumModRawConvertRep):
|
class BignumModRawCanonicalToModulusRep(BignumModRawConvertRep):
|
||||||
"""Test cases for mpi_mod_raw_canonical_to_modulus_rep."""
|
"""Test cases for mpi_mod_raw_canonical_to_modulus_rep."""
|
||||||
|
|
Loading…
Reference in a new issue