diff --git a/tests/suites/test_suite_ecp.data b/tests/suites/test_suite_ecp.data index 79912ebc3d4..dd466037d9a 100644 --- a/tests/suites/test_suite_ecp.data +++ b/tests/suites/test_suite_ecp.data @@ -796,3 +796,55 @@ fix_negative:"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff": # The first call to fix_negative in the test case of issue #4296. ECP fix_negative: #4296.1 fix_negative:"8A4DD4C8B42C5EAED15FE4F4579F4CE513EC90A94010BF000000000000000000":-1:256 + +ECP check order for SECP192R1 +depends_on:MBEDTLS_ECP_DP_SECP192R1_ENABLED +ecp_check_order:MBEDTLS_ECP_DP_SECP192R1:"FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831" + +ECP check order for SECP224R1 +depends_on:MBEDTLS_ECP_DP_SECP224R1_ENABLED +ecp_check_order:MBEDTLS_ECP_DP_SECP224R1:"FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D" + +ECP check order for SECP256R1 +depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED +ecp_check_order:MBEDTLS_ECP_DP_SECP256R1:"FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551" + +ECP check order for SECP384R1 +depends_on:MBEDTLS_ECP_DP_SECP384R1_ENABLED +ecp_check_order:MBEDTLS_ECP_DP_SECP384R1:"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973" + +ECP check order for SECP521R1 +depends_on:MBEDTLS_ECP_DP_SECP521R1_ENABLED +ecp_check_order:MBEDTLS_ECP_DP_SECP521R1:"01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409" + +ECP check order for BP256R1 +depends_on:MBEDTLS_ECP_DP_BP256R1_ENABLED +ecp_check_order:MBEDTLS_ECP_DP_BP256R1:"A9FB57DBA1EEA9BC3E660A909D838D718C397AA3B561A6F7901E0E82974856A7" + +ECP check order for BP384R1 +depends_on:MBEDTLS_ECP_DP_BP384R1_ENABLED +ecp_check_order:MBEDTLS_ECP_DP_BP384R1:"8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B31F166E6CAC0425A7CF3AB6AF6B7FC3103B883202E9046565" + +ECP check order for BP512R1 +depends_on:MBEDTLS_ECP_DP_BP512R1_ENABLED +ecp_check_order:MBEDTLS_ECP_DP_BP512R1:"AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA70330870553E5C414CA92619418661197FAC10471DB1D381085DDADDB58796829CA90069" + +ECP check order for CURVE25519 +depends_on:MBEDTLS_ECP_DP_CURVE25519_ENABLED +ecp_check_order:MBEDTLS_ECP_DP_CURVE25519:"1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed" + +ECP check order for SECP192K1 +depends_on:MBEDTLS_ECP_DP_SECP192K1_ENABLED +ecp_check_order:MBEDTLS_ECP_DP_SECP192K1:"fffffffffffffffffffffffe26f2fc170f69466a74defd8d" + +ECP check order for SECP224K1 +depends_on:MBEDTLS_ECP_DP_SECP224K1_ENABLED +ecp_check_order:MBEDTLS_ECP_DP_SECP224K1:"10000000000000000000000000001dce8d2ec6184caf0a971769fb1f7" + +ECP check order for SECP256K1 +depends_on:MBEDTLS_ECP_DP_SECP256K1_ENABLED +ecp_check_order:MBEDTLS_ECP_DP_SECP256K1:"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141" + +ECP check order for CURVE448 +depends_on:MBEDTLS_ECP_DP_CURVE448_ENABLED +ecp_check_order:MBEDTLS_ECP_DP_CURVE448:"3fffffffffffffffffffffffffffffffffffffffffffffffffffffff7cca23e9c44edb49aed63690216cc2728dc58f552378c292ab5844f3" diff --git a/tests/suites/test_suite_ecp.function b/tests/suites/test_suite_ecp.function index 538c648c97d..023f5fe6853 100644 --- a/tests/suites/test_suite_ecp.function +++ b/tests/suites/test_suite_ecp.function @@ -1297,3 +1297,27 @@ void ecp_selftest( ) TEST_ASSERT( mbedtls_ecp_self_test( 1 ) == 0 ); } /* END_CASE */ + +/* BEGIN_CASE */ +void ecp_check_order( int id, char * expected_order_hex ) +{ + mbedtls_ecp_group grp; + mbedtls_mpi expected_n; + + mbedtls_ecp_group_init( &grp ); + mbedtls_mpi_init( &expected_n ); + + TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 ); + TEST_ASSERT( mbedtls_test_read_mpi( &expected_n, 16, expected_order_hex ) == 0); + + // check sign bits are well-formed (i.e. 1 or -1) - see #5810 + TEST_ASSERT( grp.N.s == -1 || grp.N.s == 1); + TEST_ASSERT( expected_n.s == -1 || expected_n.s == 1); + + TEST_ASSERT( mbedtls_mpi_cmp_mpi( &grp.N, &expected_n ) == 0 ); + +exit: + mbedtls_ecp_group_free( &grp ); + mbedtls_mpi_free( &expected_n ); +} +/* END_CASE */