post-merge: fix ECDSA test vector testing

The way we do negative tests only works if the initial test was positive.

This was not immediately apparent with the set of test data at the time the
code for negative testing was introduced, but it became apparent with the
addition of the "0 private value" / "overlong private value" tests that
happened in development while this branch was developed.
This commit is contained in:
Manuel Pégourié-Gonnard 2018-06-13 09:53:21 +02:00
parent da19f4c79f
commit d0a66ccde3

View file

@ -88,18 +88,18 @@ void ecdsa_prim_test_vectors( int id, char *d_str, char *xQ_str, char *yQ_str,
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &s, &s_check ) == 0 ); TEST_ASSERT( mbedtls_mpi_cmp_mpi( &s, &s_check ) == 0 );
TEST_ASSERT( mbedtls_ecdsa_verify( &grp, hash, hlen, &Q, &r_check, &s_check ) == 0 ); TEST_ASSERT( mbedtls_ecdsa_verify( &grp, hash, hlen, &Q, &r_check, &s_check ) == 0 );
TEST_ASSERT( mbedtls_mpi_sub_int( &r, &r, 1 ) == 0 );
TEST_ASSERT( mbedtls_mpi_add_int( &s, &s, 1 ) == 0 );
TEST_ASSERT( mbedtls_ecdsa_verify( &grp, hash, hlen,
&Q, &r, &s_check ) == MBEDTLS_ERR_ECP_VERIFY_FAILED );
TEST_ASSERT( mbedtls_ecdsa_verify( &grp, hash, hlen,
&Q, &r_check, &s ) == MBEDTLS_ERR_ECP_VERIFY_FAILED );
TEST_ASSERT( mbedtls_ecdsa_verify( &grp, hash, hlen,
&grp.G, &r_check, &s_check ) == MBEDTLS_ERR_ECP_VERIFY_FAILED );
} }
TEST_ASSERT( mbedtls_mpi_sub_int( &r, &r, 1 ) == 0 );
TEST_ASSERT( mbedtls_mpi_add_int( &s, &s, 1 ) == 0 );
TEST_ASSERT( mbedtls_ecdsa_verify( &grp, hash, hlen,
&Q, &r, &s_check ) == MBEDTLS_ERR_ECP_VERIFY_FAILED );
TEST_ASSERT( mbedtls_ecdsa_verify( &grp, hash, hlen,
&Q, &r_check, &s ) == MBEDTLS_ERR_ECP_VERIFY_FAILED );
TEST_ASSERT( mbedtls_ecdsa_verify( &grp, hash, hlen,
&grp.G, &r_check, &s_check ) == MBEDTLS_ERR_ECP_VERIFY_FAILED );
exit: exit:
mbedtls_ecp_group_free( &grp ); mbedtls_ecp_group_free( &grp );
mbedtls_ecp_point_free( &Q ); mbedtls_ecp_point_free( &Q );