Add invalid key tests for curve SECP224K1

This curve has special arithmetic on 64 bit platforms and an untested
path lead to trying to free a buffer on the stack.

For the sake of completeness, a test case for a point with non-affine
coordinates has been added as well.
This commit is contained in:
Janos Follath 2017-01-27 15:51:14 +00:00 committed by Simon Butcher
parent bfef0ce5e4
commit 0990a8b4c5
2 changed files with 14 additions and 5 deletions

View file

@ -161,11 +161,19 @@ ecp_small_check_pub:10:25:1:POLARSSL_ERR_ECP_INVALID_KEY
ECP check pubkey Montgomery #1 (too big)
depends_on:POLARSSL_ECP_DP_M255_ENABLED
ecp_check_pub_mx:POLARSSL_ECP_DP_M255:"010000000000000000000000000000000000000000000000000000000000000000":POLARSSL_ERR_ECP_INVALID_KEY
ecp_check_pub:POLARSSL_ECP_DP_M255:"010000000000000000000000000000000000000000000000000000000000000000":"0":"1":POLARSSL_ERR_ECP_INVALID_KEY
ECP check pubkey Montgomery #2 (biggest)
depends_on:POLARSSL_ECP_DP_M255_ENABLED
ecp_check_pub_mx:POLARSSL_ECP_DP_M255:"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF":0
ecp_check_pub:POLARSSL_ECP_DP_M255:"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF":"0":"1":0
ECP check pubkey Koblitz #1 (point not on curve)
depends_on:POLARSSL_ECP_DP_SECP224K1_ENABLED
ecp_check_pub:POLARSSL_ECP_DP_SECP224K1:"E2000000000000BB3A13D43B323337383935321F0603551D":"100101FF040830060101FF02010A30220603551D0E041B04636FC0C0":"1":POLARSSL_ERR_ECP_INVALID_KEY
ECP check pubkey Koblitz #2 (coordinate not affine)
depends_on:POLARSSL_ECP_DP_SECP224K1_ENABLED
ecp_check_pub:POLARSSL_ECP_DP_SECP224K1:"E2000000000000BB3A13D43B323337383935321F0603551D":"100101FF040830060101FF02010A30220603551D0E041B04636FC0C0":"101":POLARSSL_ERR_ECP_INVALID_KEY
ECP write binary #0 (zero, bad format)
depends_on:POLARSSL_ECP_DP_SECP192R1_ENABLED

View file

@ -196,7 +196,7 @@ exit:
/* END_CASE */
/* BEGIN_CASE */
void ecp_check_pub_mx( int grp_id, char *key_hex, int ret )
void ecp_check_pub( int grp_id, char *x_hex, char *y_hex, char *z_hex, int ret )
{
ecp_group grp;
ecp_point P;
@ -206,8 +206,9 @@ void ecp_check_pub_mx( int grp_id, char *key_hex, int ret )
TEST_ASSERT( ecp_use_known_dp( &grp, grp_id ) == 0 );
TEST_ASSERT( mpi_read_string( &P.X, 16, key_hex ) == 0 );
TEST_ASSERT( mpi_lset( &P.Z, 1 ) == 0 );
TEST_ASSERT( mpi_read_string( &P.X, 16, x_hex ) == 0 );
TEST_ASSERT( mpi_read_string( &P.Y, 16, y_hex ) == 0 );
TEST_ASSERT( mpi_read_string( &P.Z, 16, z_hex ) == 0 );
TEST_ASSERT( ecp_check_pubkey( &grp, &P ) == ret );