ecp_curves: Minor rework for p384

This patch adjusts formatting, documentation and testing.

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
This commit is contained in:
Minos Galanakis 2023-03-09 11:15:15 +00:00
parent f359c91f9b
commit 37f4cb6d0e
4 changed files with 45 additions and 35 deletions

View file

@ -144,12 +144,13 @@ class EcpP224R1Raw(bignum_common.ModOperationCommon,
def is_valid(self) -> bool:
return True
class EcpPp384R1Raw(bignum_common.ModOperationCommon,
EcpTarget):
class EcpP384R1Raw(bignum_common.ModOperationCommon,
EcpTarget):
"""Test cases for ecp quasi_reduction modulo p384."""
test_function = "ecp_mod_p384_raw"
test_name = "ecp_mod_p384_raw"
input_style = "arch_split"
input_style = "fixed"
arity = 1
moduli = [("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
@ -164,7 +165,7 @@ class EcpPp384R1Raw(bignum_common.ModOperationCommon,
"fffffff0000000000000000fffffffe"),
# Maximum canonical P384 multiplication result
("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
"fdfffffffe0000000000000001fffffffc0000000000000000000000000000000"
"10000000200000000fffffffe000000020000000400000000fffffffc00000004"),
@ -178,6 +179,16 @@ class EcpPp384R1Raw(bignum_common.ModOperationCommon,
"b68abef41dbd35183a0614fb7222606ffffffff84396eee542f18a9189d94396c"
"784059c17a9f18f807214ef32f2f10ffffffff8a77fac20000000000000000"),
# Testing with overflow in A(23) + A(20) + A(19) - A(22);
("783753f8a5afba6c1862eead1deb2fcdd907272be3ffd18542b24a71ee8b26ca"
"b0aa33513610ff973042bbe1637cc9fc99ad36c7f703514572cf4f5c3044469a"
"8f5be6312c19e5d3f8fc1ac6ffffffffffffffff8c86252400000000ffffffff"),
# Testing with underflow in A(23) + A(20) + A(19) - A(22);
("65e1d2362fce922663b7fd517586e88842a9b4bd092e93e6251c9c69f278cbf8"
"285d99ae3b53da5ba36e56701e2b17c225f1239556c5f00117fa140218b46ebd8"
"e34f50d0018701fa8a0a5cc00000000000000004410bcb4ffffffff00000000"),
# First 8 number generated by random.getrandbits(768) - seed(2,2)
("ffed9235288bc781ae66267594c9c9500925e4749b575bd13653f8dd9b1f282e"
"4067c3584ee207f8da94e3e8ab73738fcf1822ffbc6887782b491044d5e34124"
@ -213,9 +224,7 @@ class EcpPp384R1Raw(bignum_common.ModOperationCommon,
@property
def arg_a(self) -> str:
hex_digits = bignum_common.hex_digits_for_limb((766 // self.bits_in_limb) + 1,
self.bits_in_limb)
return super().format_arg('{:x}'.format(self.int_a)).zfill(hex_digits)
return super().format_arg('{:x}'.format(self.int_a)).zfill(2 * self.hex_digits)
def result(self) -> List[str]:
result = self.int_a % self.int_n