Merge pull request #5811 from polhenarejos/bug_x448

Fix order value for curve x448
This commit is contained in:
Dave Rodgman 2022-06-27 13:47:24 +01:00 committed by GitHub
commit f5b7082f6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 81 additions and 0 deletions

View file

@ -0,0 +1,2 @@
Bugfix
* Fix order value of curve x448.

View file

@ -4737,6 +4737,8 @@ int mbedtls_ecp_group_load( mbedtls_ecp_group *grp, mbedtls_ecp_group_id id )
ECP_VALIDATE_RET( grp != NULL );
mbedtls_ecp_group_free( grp );
mbedtls_ecp_group_init( grp );
grp->id = id;
switch( id )

View file

@ -890,3 +890,56 @@ ecp_export:MBEDTLS_ECP_DP_SECP256R1:"37cc56d976091e5a723ec7592dff206eee7cf906917
ECP export key parameters #2 (invalid group)
depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED
ecp_export:MBEDTLS_ECP_DP_SECP256R1:"37cc56d976091e5a723ec7592dff206eee7cf9069174d0ad14b5f76822596292":"4ee500d82311ffea2fd2345d5d16bd8a88c26b770d55cd8a2a0efa01c8b4edff":"00f12a1320760270a83cbffd53f6031ef76a5d86c8a204f2c30ca9ebf51f0f0ea7":MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE:1
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"

View file

@ -1063,3 +1063,27 @@ exit:
mbedtls_ecp_point_free( &export_Q );
}
/* 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 */