From 514806bbe9f8ac8a01947e9317df80762fb57ab9 Mon Sep 17 00:00:00 2001 From: Gabor Mezei Date: Tue, 28 Mar 2023 15:03:20 +0200 Subject: [PATCH 1/9] Add a second round of carry reduction for P192 fast reduction The first round of carry reduction can generate a carry so a second round is needed. Signed-off-by: Gabor Mezei --- library/ecp_curves.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/library/ecp_curves.c b/library/ecp_curves.c index 6ee3d6c53..14c390cbb 100644 --- a/library/ecp_curves.c +++ b/library/ecp_curves.c @@ -4897,7 +4897,7 @@ static inline void carry64(mbedtls_mpi_uint *dst, mbedtls_mpi_uint *carry) #define A(i) Np + (i) * WIDTH #define ADD(i) add64(p, A(i), &c) #define NEXT p += WIDTH; carry64(p, &c) -#define LAST p += WIDTH; *p = c; while (++p < end) *p = 0 +#define LAST p += WIDTH; do *p = 0; while (++p < end) #define RESET last_carry[0] = c; c = 0; p = Np #define ADD_LAST add64(p, last_carry, &c) @@ -4934,13 +4934,23 @@ int mbedtls_ecp_mod_p192_raw(mbedtls_mpi_uint *Np, size_t Nn) RESET; + /* Use the reduction for the carry as well: + * 2^192 * last_carry = 2^64 * last_carry + last_carry mod P192 + * It can generate a carry. */ + ADD_LAST; NEXT; // A0 += last_carry + ADD_LAST; NEXT; // A1 += last_carry + // A2 += carry + + RESET; + /* Use the reduction for the carry as well: * 2^192 * last_carry = 2^64 * last_carry + last_carry mod P192 */ ADD_LAST; NEXT; // A0 += last_carry ADD_LAST; NEXT; // A1 += last_carry + // A2 += carry - LAST; // A2 += carry + LAST; return 0; } From 62adc726d00712cf31b88d7a63d444c52ec5436f Mon Sep 17 00:00:00 2001 From: Gabor Mezei Date: Tue, 28 Mar 2023 15:04:48 +0200 Subject: [PATCH 2/9] Add test cases for P192 fast reduction testing Signed-off-by: Gabor Mezei --- scripts/mbedtls_dev/ecp.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/scripts/mbedtls_dev/ecp.py b/scripts/mbedtls_dev/ecp.py index aee871831..c5ad3c8f1 100644 --- a/scripts/mbedtls_dev/ecp.py +++ b/scripts/mbedtls_dev/ecp.py @@ -43,6 +43,24 @@ class EcpP192R1Raw(bignum_common.ModOperationCommon, # Modulus - 1 "fffffffffffffffffffffffffffffffefffffffffffffffe", + # Modulus + 1 + "ffffffffffffffffffffffffffffffff0000000000000000", + + # 2^192 - 1 + "ffffffffffffffffffffffffffffffffffffffffffffffff", + + # Maximum canonical P192 multiplication result + ("fffffffffffffffffffffffffffffffdfffffffffffffffc" + "000000000000000100000000000000040000000000000004"), + + # Generate an overflow during reduction + ("00000000000000000000000000000001ffffffffffffffff" + "ffffffffffffffffffffffffffffffff0000000000000000"), + + # Generate an overflow during carry reduction + ("ffffffffffffffff00000000000000010000000000000000" + "fffffffffffffffeffffffffffffffff0000000000000000"), + # First 8 number generated by random.getrandbits(384) - seed(2,2) ("cf1822ffbc6887782b491044d5e341245c6e433715ba2bdd" "177219d30e7a269fd95bafc8f2a4d27bdcf4bb99f4bea973"), From 64a229f6ac2eb096f78c37b94c79162888c0ebf6 Mon Sep 17 00:00:00 2001 From: Gabor Mezei Date: Tue, 28 Mar 2023 15:05:57 +0200 Subject: [PATCH 3/9] Add test cases for P224 fast reduction testing Signed-off-by: Gabor Mezei --- scripts/mbedtls_dev/ecp.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/mbedtls_dev/ecp.py b/scripts/mbedtls_dev/ecp.py index c5ad3c8f1..daa669db0 100644 --- a/scripts/mbedtls_dev/ecp.py +++ b/scripts/mbedtls_dev/ecp.py @@ -114,6 +114,12 @@ class EcpP224R1Raw(bignum_common.ModOperationCommon, # Modulus - 1 "ffffffffffffffffffffffffffffffff000000000000000000000000", + # Modulus + 1 + "ffffffffffffffffffffffffffffffff000000000000000000000002", + + # 2^224 - 1 + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + # Maximum canonical P224 multiplication result ("fffffffffffffffffffffffffffffffe000000000000000000000000" "00000001000000000000000000000000000000000000000000000000"), From a9a68728b38005cf2fae90242d842d95bf683dad Mon Sep 17 00:00:00 2001 From: Gabor Mezei Date: Tue, 28 Mar 2023 15:06:51 +0200 Subject: [PATCH 4/9] Add test cases for P521 fast reduction testing Signed-off-by: Gabor Mezei --- scripts/mbedtls_dev/ecp.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/mbedtls_dev/ecp.py b/scripts/mbedtls_dev/ecp.py index daa669db0..8f714c908 100644 --- a/scripts/mbedtls_dev/ecp.py +++ b/scripts/mbedtls_dev/ecp.py @@ -351,7 +351,15 @@ class EcpP521R1Raw(bignum_common.ModOperationCommon, input_values = [ "0", "1", - # Corner case: maximum canonical P521 multiplication result + # Modulus - 1 + ("01ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"), + + # Modulus + 1 + ("020000000000000000000000000000000000000000000000000000000000000000" + "000000000000000000000000000000000000000000000000000000000000000000"), + + # Maximum canonical P521 multiplication result ("0003ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" "fffff800" From fede27639270552a2a3043a4aff625c916924ce2 Mon Sep 17 00:00:00 2001 From: Gabor Mezei Date: Tue, 28 Mar 2023 15:29:40 +0200 Subject: [PATCH 5/9] Typo: reformat numbers Signed-off-by: Gabor Mezei --- scripts/mbedtls_dev/ecp.py | 114 +++++++++++++++++++++---------------- 1 file changed, 64 insertions(+), 50 deletions(-) diff --git a/scripts/mbedtls_dev/ecp.py b/scripts/mbedtls_dev/ecp.py index 8f714c908..8b602c6e7 100644 --- a/scripts/mbedtls_dev/ecp.py +++ b/scripts/mbedtls_dev/ecp.py @@ -177,78 +177,92 @@ class EcpP384R1Raw(bignum_common.ModOperationCommon, input_style = "fixed" arity = 1 - moduli = [("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - "fffffeffffffff0000000000000000ffffffff") + moduli = [("ffffffffffffffffffffffffffffffffffffffffffffffff" + "fffffffffffffffeffffffff0000000000000000ffffffff") ] # type: List[str] input_values = [ "0", "1", # Modulus - 1 - ("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffef" - "fffffff0000000000000000fffffffe"), + ("ffffffffffffffffffffffffffffffffffffffffffffffff" + "fffffffffffffffeffffffff0000000000000000fffffffe"), # Maximum canonical P384 multiplication result - ("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - "fdfffffffe0000000000000001fffffffc0000000000000000000000000000000" - "10000000200000000fffffffe000000020000000400000000fffffffc00000004"), + ("ffffffffffffffffffffffffffffffffffffffffffffffff" + "fffffffffffffffdfffffffe0000000000000001fffffffc" + "000000000000000000000000000000010000000200000000" + "fffffffe000000020000000400000000fffffffc00000004"), # Testing with overflow in A(12) + A(21) + A(20); - ("497811378624857a2c2af60d70583376545484cfae5c812fe2999fc1abb51d18b" - "559e8ca3b50aaf263fdf8f24bdfb98fffffffff20e65bf9099e4e73a5e8b517cf" - "4fbeb8fd1750fdae6d43f2e53f82d5ffffffffffffffffcc6f1e06111c62e0"), + ("497811378624857a2c2af60d70583376545484cfae5c812f" + "e2999fc1abb51d18b559e8ca3b50aaf263fdf8f24bdfb98f" + "ffffffff20e65bf9099e4e73a5e8b517cf4fbeb8fd1750fd" + "ae6d43f2e53f82d5ffffffffffffffffcc6f1e06111c62e0"), # Testing with underflow in A(13) + A(22) + A(23) - A(12) - A(20); - ("dfdd25e96777406b3c04b8c7b406f5fcf287e1e576003a092852a6fbe517f2712" - "b68abef41dbd35183a0614fb7222606ffffffff84396eee542f18a9189d94396c" - "784059c17a9f18f807214ef32f2f10ffffffff8a77fac20000000000000000"), + ("dfdd25e96777406b3c04b8c7b406f5fcf287e1e576003a09" + "2852a6fbe517f2712b68abef41dbd35183a0614fb7222606" + "ffffffff84396eee542f18a9189d94396c784059c17a9f18" + "f807214ef32f2f10ffffffff8a77fac20000000000000000"), # Testing with overflow in A(23) + A(20) + A(19) - A(22); - ("783753f8a5afba6c1862eead1deb2fcdd907272be3ffd18542b24a71ee8b26ca" - "b0aa33513610ff973042bbe1637cc9fc99ad36c7f703514572cf4f5c3044469a" - "8f5be6312c19e5d3f8fc1ac6ffffffffffffffff8c86252400000000ffffffff"), + ("783753f8a5afba6c1862eead1deb2fcdd907272be3ffd185" + "42b24a71ee8b26cab0aa33513610ff973042bbe1637cc9fc" + "99ad36c7f703514572cf4f5c3044469a8f5be6312c19e5d3" + "f8fc1ac6ffffffffffffffff8c86252400000000ffffffff"), # Testing with underflow in A(23) + A(20) + A(19) - A(22); - ("65e1d2362fce922663b7fd517586e88842a9b4bd092e93e6251c9c69f278cbf8" - "285d99ae3b53da5ba36e56701e2b17c225f1239556c5f00117fa140218b46ebd8" - "e34f50d0018701fa8a0a5cc00000000000000004410bcb4ffffffff00000000"), + ("65e1d2362fce922663b7fd517586e88842a9b4bd092e93e6" + "251c9c69f278cbf8285d99ae3b53da5ba36e56701e2b17c2" + "25f1239556c5f00117fa140218b46ebd8e34f50d0018701f" + "a8a0a5cc00000000000000004410bcb4ffffffff00000000"), # Testing the second round of carry reduction - ("000000000000000000000000ffffffffffffffffffffffffffffffffffffffff" - "ffffffffffffffff00000000000000000000000000000000ffffffff00000000" - "000000000000000100000000000000000000000000000000ffffffff00000001"), + ("000000000000000000000000ffffffffffffffffffffffff" + "ffffffffffffffffffffffffffffffff0000000000000000" + "0000000000000000ffffffff000000000000000000000001" + "00000000000000000000000000000000ffffffff00000001"), # First 8 number generated by random.getrandbits(768) - seed(2,2) - ("ffed9235288bc781ae66267594c9c9500925e4749b575bd13653f8dd9b1f282e" - "4067c3584ee207f8da94e3e8ab73738fcf1822ffbc6887782b491044d5e34124" - "5c6e433715ba2bdd177219d30e7a269fd95bafc8f2a4d27bdcf4bb99f4bea973"), - ("e8624fab5186ee32ee8d7ee9770348a05d300cb90706a045defc044a09325626" - "e6b58de744ab6cce80877b6f71e1f6d2ef8acd128b4f2fc15f3f57ebf30b94fa" - "82523e86feac7eb7dc38f519b91751dacdbd47d364be8049a372db8f6e405d93"), - ("fec3f6b32e8d4b8a8f54f8ceacaab39e83844b40ffa9b9f15c14bc4a829e07b0" - "829a48d422fe99a22c70501e533c91352d3d854e061b90303b08c6e33c729578" - "2d6c797f8f7d9b782a1be9cd8697bbd0e2520e33e44c50556c71c4a66148a86f"), - ("bd143fa9b714210c665d7435c1066932f4767f26294365b2721dea3bf63f23d0" - "dbe53fcafb2147df5ca495fa5a91c89b97eeab64ca2ce6bc5d3fd983c34c769f" - "e89204e2e8168561867e5e15bc01bfce6a27e0dfcbf8754472154e76e4c11ab2"), - ("8ebdbfe3eb9ac688b9d39cca91551e8259cc60b17604e4b4e73695c3e652c71a" - "74667bffe202849da9643a295a9ac6decbd4d3e2d4dec9ef83f0be4e80371eb9" - "7f81375eecc1cb6347733e847d718d733ff98ff387c56473a7a83ee0761ebfd2"), - ("d4c0dca8b4c9e755cc9c3adcf515a8234da4daeb4f3f87777ad1f45ae9500ec9" - "c5e2486c44a4a8f69dc8db48e86ec9c6e06f291b2a838af8d5c44a4eb3172062" - "d08f1bb2531d6460f0caeef038c89b38a8acb5137c9260dc74e088a9b9492f25"), - ("227eeb7b9d7d01f5769da05d205bbfcc8c69069134bccd3e1cf4f589f8e4ce0a" - "f29d115ef24bd625dd961e6830b54fa7d28f93435339774bb1e386c4fd5079e6" - "81b8f5896838b769da59b74a6c3181c81e220df848b1df78feb994a81167346"), - ("d322a7353ead4efe440e2b4fda9c025a22f1a83185b98f5fc11e60de1b343f52" - "ea748db9e020307aaeb6db2c3a038a709779ac1f45e9dd320c855fdfa7251af0" - "930cdbd30f0ad2a81b2d19a2beaa14a7ff3fe32a30ffc4eed0a7bd04e85bfcdd"), + ("ffed9235288bc781ae66267594c9c9500925e4749b575bd1" + "3653f8dd9b1f282e4067c3584ee207f8da94e3e8ab73738f" + "cf1822ffbc6887782b491044d5e341245c6e433715ba2bdd" + "177219d30e7a269fd95bafc8f2a4d27bdcf4bb99f4bea973"), + ("e8624fab5186ee32ee8d7ee9770348a05d300cb90706a045" + "defc044a09325626e6b58de744ab6cce80877b6f71e1f6d2" + "ef8acd128b4f2fc15f3f57ebf30b94fa82523e86feac7eb7" + "dc38f519b91751dacdbd47d364be8049a372db8f6e405d93"), + ("fec3f6b32e8d4b8a8f54f8ceacaab39e83844b40ffa9b9f1" + "5c14bc4a829e07b0829a48d422fe99a22c70501e533c9135" + "2d3d854e061b90303b08c6e33c7295782d6c797f8f7d9b78" + "2a1be9cd8697bbd0e2520e33e44c50556c71c4a66148a86f"), + ("bd143fa9b714210c665d7435c1066932f4767f26294365b2" + "721dea3bf63f23d0dbe53fcafb2147df5ca495fa5a91c89b" + "97eeab64ca2ce6bc5d3fd983c34c769fe89204e2e8168561" + "867e5e15bc01bfce6a27e0dfcbf8754472154e76e4c11ab2"), + ("8ebdbfe3eb9ac688b9d39cca91551e8259cc60b17604e4b4" + "e73695c3e652c71a74667bffe202849da9643a295a9ac6de" + "cbd4d3e2d4dec9ef83f0be4e80371eb97f81375eecc1cb63" + "47733e847d718d733ff98ff387c56473a7a83ee0761ebfd2"), + ("d4c0dca8b4c9e755cc9c3adcf515a8234da4daeb4f3f8777" + "7ad1f45ae9500ec9c5e2486c44a4a8f69dc8db48e86ec9c6" + "e06f291b2a838af8d5c44a4eb3172062d08f1bb2531d6460" + "f0caeef038c89b38a8acb5137c9260dc74e088a9b9492f25"), + ("0227eeb7b9d7d01f5769da05d205bbfcc8c69069134bccd3" + "e1cf4f589f8e4ce0af29d115ef24bd625dd961e6830b54fa" + "7d28f93435339774bb1e386c4fd5079e681b8f5896838b76" + "9da59b74a6c3181c81e220df848b1df78feb994a81167346"), + ("d322a7353ead4efe440e2b4fda9c025a22f1a83185b98f5f" + "c11e60de1b343f52ea748db9e020307aaeb6db2c3a038a70" + "9779ac1f45e9dd320c855fdfa7251af0930cdbd30f0ad2a8" + "1b2d19a2beaa14a7ff3fe32a30ffc4eed0a7bd04e85bfcdd"), # Next 2 number generated by random.getrandbits(384) - ("5c3747465cc36c270e8a35b10828d569c268a20eb78ac332e5e138e26c4454b9" - "0f756132e16dce72f18e859835e1f291"), - ("eb2b5693babb7fbb0a76c196067cfdcb11457d9cf45e2fa01d7f427515392480" - "0600571fac3a5b263fdf57cd2c006497") + ("5c3747465cc36c270e8a35b10828d569c268a20eb78ac332" + "e5e138e26c4454b90f756132e16dce72f18e859835e1f291"), + ("eb2b5693babb7fbb0a76c196067cfdcb11457d9cf45e2fa0" + "1d7f4275153924800600571fac3a5b263fdf57cd2c006497") ] @property From 54ad647e8d67b22fa3143e6d083125f37047de4a Mon Sep 17 00:00:00 2001 From: Gabor Mezei Date: Tue, 28 Mar 2023 15:30:32 +0200 Subject: [PATCH 6/9] Add test cases for P384 fast reduction testing Signed-off-by: Gabor Mezei --- scripts/mbedtls_dev/ecp.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/mbedtls_dev/ecp.py b/scripts/mbedtls_dev/ecp.py index 8b602c6e7..88112c561 100644 --- a/scripts/mbedtls_dev/ecp.py +++ b/scripts/mbedtls_dev/ecp.py @@ -188,6 +188,14 @@ class EcpP384R1Raw(bignum_common.ModOperationCommon, ("ffffffffffffffffffffffffffffffffffffffffffffffff" "fffffffffffffffeffffffff0000000000000000fffffffe"), + # Modulus + 1 + ("ffffffffffffffffffffffffffffffffffffffffffffffff" + "fffffffffffffffeffffffff000000000000000100000000"), + + # 2^384 - 1 + ("ffffffffffffffffffffffffffffffffffffffffffffffff" + "ffffffffffffffffffffffffffffffffffffffffffffffff"), + # Maximum canonical P384 multiplication result ("ffffffffffffffffffffffffffffffffffffffffffffffff" "fffffffffffffffdfffffffe0000000000000001fffffffc" From a8d0da3880b7db36c52ea2f28cf154919a1ce6e0 Mon Sep 17 00:00:00 2001 From: Gabor Mezei Date: Tue, 28 Mar 2023 15:31:05 +0200 Subject: [PATCH 7/9] Add test cases for P256 fast reduction testing Signed-off-by: Gabor Mezei --- scripts/mbedtls_dev/ecp.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/mbedtls_dev/ecp.py b/scripts/mbedtls_dev/ecp.py index 88112c561..d661002c8 100644 --- a/scripts/mbedtls_dev/ecp.py +++ b/scripts/mbedtls_dev/ecp.py @@ -302,6 +302,12 @@ class EcpP256R1Raw(bignum_common.ModOperationCommon, # Modulus - 1 "ffffffff00000001000000000000000000000000fffffffffffffffffffffffe", + # Modulus + 1 + "ffffffff00000001000000000000000000000001000000000000000000000000", + + # 2^256 - 1 + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + # Maximum canonical P256 multiplication result ("fffffffe00000002fffffffe0000000100000001fffffffe00000001fffffffc" "00000003fffffffcfffffffffffffffffffffffc000000000000000000000004"), From c33a36b5df752be155faa346e7525a24c64eb667 Mon Sep 17 00:00:00 2001 From: Gabor Mezei Date: Tue, 28 Mar 2023 15:32:47 +0200 Subject: [PATCH 8/9] Typo: reorder testing classes Signed-off-by: Gabor Mezei --- scripts/mbedtls_dev/ecp.py | 158 ++++++++++++++++++------------------- 1 file changed, 79 insertions(+), 79 deletions(-) diff --git a/scripts/mbedtls_dev/ecp.py b/scripts/mbedtls_dev/ecp.py index d661002c8..0afeca6a2 100644 --- a/scripts/mbedtls_dev/ecp.py +++ b/scripts/mbedtls_dev/ecp.py @@ -169,6 +169,85 @@ class EcpP224R1Raw(bignum_common.ModOperationCommon, return True +class EcpP256R1Raw(bignum_common.ModOperationCommon, + EcpTarget): + """Test cases for ECP P256 fast reduction.""" + symbol = "-" + test_function = "ecp_mod_p256_raw" + test_name = "ecp_mod_p256_raw" + input_style = "fixed" + arity = 1 + + moduli = ["ffffffff00000001000000000000000000000000ffffffffffffffffffffffff"] # type: List[str] + + input_values = [ + "0", "1", + + # Modulus - 1 + "ffffffff00000001000000000000000000000000fffffffffffffffffffffffe", + + # Modulus + 1 + "ffffffff00000001000000000000000000000001000000000000000000000000", + + # 2^256 - 1 + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + + # Maximum canonical P256 multiplication result + ("fffffffe00000002fffffffe0000000100000001fffffffe00000001fffffffc" + "00000003fffffffcfffffffffffffffffffffffc000000000000000000000004"), + + # Generate an overflow during reduction + ("0000000000000000000000010000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000000ffffffff"), + + # Generate an underflow during reduction + ("0000000000000000000000000000000000000000000000000000000000000010" + "ffffffff00000000000000000000000000000000000000000000000000000000"), + + # Generate an overflow during carry reduction + ("aaaaaaaa00000000000000000000000000000000000000000000000000000000" + "00000000000000000000000000000000aaaaaaacaaaaaaaaaaaaaaaa00000000"), + + # Generate an underflow during carry reduction + ("000000000000000000000001ffffffff00000000000000000000000000000000" + "0000000000000000000000000000000000000002000000020000000100000002"), + + # First 8 number generated by random.getrandbits(512) - seed(2,2) + ("4067c3584ee207f8da94e3e8ab73738fcf1822ffbc6887782b491044d5e34124" + "5c6e433715ba2bdd177219d30e7a269fd95bafc8f2a4d27bdcf4bb99f4bea973"), + ("82523e86feac7eb7dc38f519b91751dacdbd47d364be8049a372db8f6e405d93" + "ffed9235288bc781ae66267594c9c9500925e4749b575bd13653f8dd9b1f282e"), + ("e8624fab5186ee32ee8d7ee9770348a05d300cb90706a045defc044a09325626" + "e6b58de744ab6cce80877b6f71e1f6d2ef8acd128b4f2fc15f3f57ebf30b94fa"), + ("829a48d422fe99a22c70501e533c91352d3d854e061b90303b08c6e33c729578" + "2d6c797f8f7d9b782a1be9cd8697bbd0e2520e33e44c50556c71c4a66148a86f"), + ("e89204e2e8168561867e5e15bc01bfce6a27e0dfcbf8754472154e76e4c11ab2" + "fec3f6b32e8d4b8a8f54f8ceacaab39e83844b40ffa9b9f15c14bc4a829e07b0"), + ("bd143fa9b714210c665d7435c1066932f4767f26294365b2721dea3bf63f23d0" + "dbe53fcafb2147df5ca495fa5a91c89b97eeab64ca2ce6bc5d3fd983c34c769f"), + ("74667bffe202849da9643a295a9ac6decbd4d3e2d4dec9ef83f0be4e80371eb9" + "7f81375eecc1cb6347733e847d718d733ff98ff387c56473a7a83ee0761ebfd2"), + ("d08f1bb2531d6460f0caeef038c89b38a8acb5137c9260dc74e088a9b9492f25" + "8ebdbfe3eb9ac688b9d39cca91551e8259cc60b17604e4b4e73695c3e652c71a"), + + # Next 2 number generated by random.getrandbits(256) + "c5e2486c44a4a8f69dc8db48e86ec9c6e06f291b2a838af8d5c44a4eb3172062", + "d4c0dca8b4c9e755cc9c3adcf515a8234da4daeb4f3f87777ad1f45ae9500ec9" + ] + + @property + def arg_a(self) -> str: + 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 + return [self.format_result(result)] + + @property + def is_valid(self) -> bool: + return True + + class EcpP384R1Raw(bignum_common.ModOperationCommon, EcpTarget): """Test cases for ecp quasi_reduction modulo p384.""" @@ -285,85 +364,6 @@ class EcpP384R1Raw(bignum_common.ModOperationCommon, def is_valid(self) -> bool: return True -class EcpP256R1Raw(bignum_common.ModOperationCommon, - EcpTarget): - """Test cases for ECP P256 fast reduction.""" - symbol = "-" - test_function = "ecp_mod_p256_raw" - test_name = "ecp_mod_p256_raw" - input_style = "fixed" - arity = 1 - - moduli = ["ffffffff00000001000000000000000000000000ffffffffffffffffffffffff"] # type: List[str] - - input_values = [ - "0", "1", - - # Modulus - 1 - "ffffffff00000001000000000000000000000000fffffffffffffffffffffffe", - - # Modulus + 1 - "ffffffff00000001000000000000000000000001000000000000000000000000", - - # 2^256 - 1 - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - - # Maximum canonical P256 multiplication result - ("fffffffe00000002fffffffe0000000100000001fffffffe00000001fffffffc" - "00000003fffffffcfffffffffffffffffffffffc000000000000000000000004"), - - # Generate an overflow during reduction - ("0000000000000000000000010000000000000000000000000000000000000000" - "00000000000000000000000000000000000000000000000000000000ffffffff"), - - # Generate an underflow during reduction - ("0000000000000000000000000000000000000000000000000000000000000010" - "ffffffff00000000000000000000000000000000000000000000000000000000"), - - # Generate an overflow during carry reduction - ("aaaaaaaa00000000000000000000000000000000000000000000000000000000" - "00000000000000000000000000000000aaaaaaacaaaaaaaaaaaaaaaa00000000"), - - # Generate an underflow during carry reduction - ("000000000000000000000001ffffffff00000000000000000000000000000000" - "0000000000000000000000000000000000000002000000020000000100000002"), - - # First 8 number generated by random.getrandbits(512) - seed(2,2) - ("4067c3584ee207f8da94e3e8ab73738fcf1822ffbc6887782b491044d5e34124" - "5c6e433715ba2bdd177219d30e7a269fd95bafc8f2a4d27bdcf4bb99f4bea973"), - ("82523e86feac7eb7dc38f519b91751dacdbd47d364be8049a372db8f6e405d93" - "ffed9235288bc781ae66267594c9c9500925e4749b575bd13653f8dd9b1f282e"), - ("e8624fab5186ee32ee8d7ee9770348a05d300cb90706a045defc044a09325626" - "e6b58de744ab6cce80877b6f71e1f6d2ef8acd128b4f2fc15f3f57ebf30b94fa"), - ("829a48d422fe99a22c70501e533c91352d3d854e061b90303b08c6e33c729578" - "2d6c797f8f7d9b782a1be9cd8697bbd0e2520e33e44c50556c71c4a66148a86f"), - ("e89204e2e8168561867e5e15bc01bfce6a27e0dfcbf8754472154e76e4c11ab2" - "fec3f6b32e8d4b8a8f54f8ceacaab39e83844b40ffa9b9f15c14bc4a829e07b0"), - ("bd143fa9b714210c665d7435c1066932f4767f26294365b2721dea3bf63f23d0" - "dbe53fcafb2147df5ca495fa5a91c89b97eeab64ca2ce6bc5d3fd983c34c769f"), - ("74667bffe202849da9643a295a9ac6decbd4d3e2d4dec9ef83f0be4e80371eb9" - "7f81375eecc1cb6347733e847d718d733ff98ff387c56473a7a83ee0761ebfd2"), - ("d08f1bb2531d6460f0caeef038c89b38a8acb5137c9260dc74e088a9b9492f25" - "8ebdbfe3eb9ac688b9d39cca91551e8259cc60b17604e4b4e73695c3e652c71a"), - - # Next 2 number generated by random.getrandbits(256) - "c5e2486c44a4a8f69dc8db48e86ec9c6e06f291b2a838af8d5c44a4eb3172062", - "d4c0dca8b4c9e755cc9c3adcf515a8234da4daeb4f3f87777ad1f45ae9500ec9" - ] - - @property - def arg_a(self) -> str: - 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 - return [self.format_result(result)] - - @property - def is_valid(self) -> bool: - return True - - class EcpP521R1Raw(bignum_common.ModOperationCommon, EcpTarget): """Test cases for ecp quasi_reduction().""" From d8c0e1aa8d686e2ddbe98abe987e9e5ee4247fb9 Mon Sep 17 00:00:00 2001 From: Gabor Mezei Date: Tue, 28 Mar 2023 15:34:49 +0200 Subject: [PATCH 9/9] Fix comments Signed-off-by: Gabor Mezei --- scripts/mbedtls_dev/ecp.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/mbedtls_dev/ecp.py b/scripts/mbedtls_dev/ecp.py index 0afeca6a2..1c03205c1 100644 --- a/scripts/mbedtls_dev/ecp.py +++ b/scripts/mbedtls_dev/ecp.py @@ -28,7 +28,7 @@ class EcpTarget(test_data_generation.BaseTarget): class EcpP192R1Raw(bignum_common.ModOperationCommon, EcpTarget): - """Test cases for ecp quasi_reduction().""" + """Test cases for ECP P192 fast reduction.""" symbol = "-" test_function = "ecp_mod_p192_raw" test_name = "ecp_mod_p192_raw" @@ -99,7 +99,7 @@ class EcpP192R1Raw(bignum_common.ModOperationCommon, class EcpP224R1Raw(bignum_common.ModOperationCommon, EcpTarget): - """Test cases for ecp quasi_reduction().""" + """Test cases for ECP P224 fast reduction.""" symbol = "-" test_function = "ecp_mod_p224_raw" test_name = "ecp_mod_p224_raw" @@ -250,7 +250,7 @@ class EcpP256R1Raw(bignum_common.ModOperationCommon, class EcpP384R1Raw(bignum_common.ModOperationCommon, EcpTarget): - """Test cases for ecp quasi_reduction modulo p384.""" + """Test cases for ECP P384 fast reduction.""" test_function = "ecp_mod_p384_raw" test_name = "ecp_mod_p384_raw" input_style = "fixed" @@ -366,7 +366,7 @@ class EcpP384R1Raw(bignum_common.ModOperationCommon, class EcpP521R1Raw(bignum_common.ModOperationCommon, EcpTarget): - """Test cases for ecp quasi_reduction().""" + """Test cases for ECP P521 fast reduction.""" test_function = "ecp_mod_p521_raw" test_name = "ecp_mod_p521_raw" input_style = "arch_split"