Remove curve parameter from public functions

This commit is contained in:
Manuel Pégourié-Gonnard 2019-11-21 12:00:43 +01:00
parent be5f833c9c
commit 1a5337179f
14 changed files with 55 additions and 110 deletions

View file

@ -35,8 +35,7 @@ static int pk_genkey( mbedtls_pk_context *pk )
int ret;
ret = uECC_make_key( mbedtls_pk_uecc( *pk )->public_key,
mbedtls_pk_uecc( *pk )->private_key,
uECC_secp256r1() );
mbedtls_pk_uecc( *pk )->private_key );
if( ret == 0 )
return( -1 );

View file

@ -93,8 +93,7 @@ void pk_parse_public_keyfile_ec( char * key_file, int result )
TEST_ASSERT( mbedtls_ecp_check_pubkey( &eckey->grp, &eckey->Q ) == 0 );
#else
uecckey = mbedtls_pk_uecc( ctx );
TEST_ASSERT( uECC_valid_public_key( uecckey->public_key,
uECC_secp256r1() ) == 0 );
TEST_ASSERT( uECC_valid_public_key( uecckey->public_key ) == 0 );
#endif /* MBEDTLS_USE_TINYCRYPT */
}
@ -136,11 +135,9 @@ void pk_parse_keyfile_ec( char * key_file, char * password, int result )
TEST_ASSERT( mbedtls_ecp_check_privkey( &eckey->grp, &eckey->d ) == 0 );
#else
uecckey = mbedtls_pk_uecc( ctx );
TEST_ASSERT( uECC_valid_public_key( uecckey->public_key,
uECC_secp256r1() ) == 0 );
TEST_ASSERT( uECC_valid_public_key( uecckey->public_key ) == 0 );
TEST_ASSERT( uECC_compute_public_key( uecckey->private_key,
tmp_pubkey,
uECC_secp256r1() ) != 0 );
tmp_pubkey ) != 0 );
TEST_ASSERT( memcmp( tmp_pubkey, uecckey->public_key,
sizeof( tmp_pubkey ) ) == 0 );
#endif /* MBEDTLS_USE_TINYCRYPT */

View file

@ -21,17 +21,15 @@ void test_ecdh()
uint8_t secret1[NUM_ECC_BYTES] = {0};
uint8_t secret2[NUM_ECC_BYTES] = {0};
uECC_Curve curve = uECC_secp256r1();
uECC_set_rng( &uecc_rng_wrapper );
TEST_ASSERT( uECC_make_key( public1, private1, curve ) != 0 );
TEST_ASSERT( uECC_make_key( public1, private1 ) != 0 );
TEST_ASSERT( uECC_make_key( public2, private2, curve ) != 0 );
TEST_ASSERT( uECC_make_key( public2, private2 ) != 0 );
TEST_ASSERT( uECC_shared_secret( public2, private1, secret1, curve ) != 0 );
TEST_ASSERT( uECC_shared_secret( public2, private1, secret1 ) != 0 );
TEST_ASSERT( uECC_shared_secret( public1, private2, secret2, curve ) != 0 );
TEST_ASSERT( uECC_shared_secret( public1, private2, secret2 ) != 0 );
TEST_ASSERT( memcmp( secret1, secret2, sizeof( secret1 ) ) == 0 );
}
@ -45,17 +43,15 @@ void test_ecdsa()
uint8_t hash[NUM_ECC_BYTES] = {0};
uint8_t sig[2*NUM_ECC_BYTES] = {0};
uECC_Curve curve = uECC_secp256r1();
uECC_set_rng( &uecc_rng_wrapper );
TEST_ASSERT( rnd_std_rand( NULL, hash, NUM_ECC_BYTES ) == 0 );
TEST_ASSERT( uECC_make_key( public, private, curve ) != 0 );
TEST_ASSERT( uECC_make_key( public, private ) != 0 );
TEST_ASSERT( uECC_sign( private, hash, sizeof( hash ), sig, curve ) != 0 );
TEST_ASSERT( uECC_sign( private, hash, sizeof( hash ), sig ) != 0 );
TEST_ASSERT( uECC_verify( public, hash, sizeof( hash ), sig, curve ) == UECC_SUCCESS );
TEST_ASSERT( uECC_verify( public, hash, sizeof( hash ), sig ) == UECC_SUCCESS );
}
/* END_CASE */
@ -64,7 +60,6 @@ void ecdh_primitive_testvec( data_t * private1, data_t * xA_str,
data_t * yA_str, data_t * private2,
data_t * xB_str, data_t * yB_str, data_t * z_str )
{
uECC_Curve curve = uECC_secp256r1();
uint8_t public1[2*NUM_ECC_BYTES] = {0};
uint8_t public2[2*NUM_ECC_BYTES] = {0};
uint8_t secret1[NUM_ECC_BYTES] = {0};
@ -76,9 +71,9 @@ void ecdh_primitive_testvec( data_t * private1, data_t * xA_str,
memcpy( public2 + NUM_ECC_BYTES, yB_str->x, yB_str->len );
// Compute shared secrets and compare to test vector secret
TEST_ASSERT( uECC_shared_secret( public2, private1->x, secret1, curve ) != 0 );
TEST_ASSERT( uECC_shared_secret( public2, private1->x, secret1 ) != 0 );
TEST_ASSERT( uECC_shared_secret( public1, private2->x, secret2, curve ) != 0 );
TEST_ASSERT( uECC_shared_secret( public1, private2->x, secret2 ) != 0 );
TEST_ASSERT( memcmp( secret1, secret2, sizeof( secret1 ) ) == 0 );
TEST_ASSERT( memcmp( secret1, z_str->x, sizeof( secret1 ) ) == 0 );
@ -90,7 +85,6 @@ void ecdh_primitive_testvec( data_t * private1, data_t * xA_str,
void ecdsa_primitive_testvec( data_t * xQ_str, data_t * yQ_str,
data_t * hash, data_t * r_str, data_t * s_str )
{
uECC_Curve curve = uECC_secp256r1();
uint8_t pub_bytes[2*NUM_ECC_BYTES] = {0};
uint8_t sig_bytes[2*NUM_ECC_BYTES] = {0};
@ -100,7 +94,7 @@ void ecdsa_primitive_testvec( data_t * xQ_str, data_t * yQ_str,
memcpy( sig_bytes + NUM_ECC_BYTES, s_str->x, r_str->len );
TEST_ASSERT( uECC_verify( pub_bytes, hash->x, hash->len,
sig_bytes, curve ) == UECC_SUCCESS );
sig_bytes ) == UECC_SUCCESS );
// Alter the signature and check the verification fails
for( int i = 0; i < 2*NUM_ECC_BYTES; i++ )
@ -108,7 +102,7 @@ void ecdsa_primitive_testvec( data_t * xQ_str, data_t * yQ_str,
uint8_t temp = sig_bytes[i];
sig_bytes[i] = ( sig_bytes[i] + 1 ) % 256;
TEST_ASSERT( uECC_verify( pub_bytes, hash->x, hash->len,
sig_bytes, curve ) == UECC_FAILURE );
sig_bytes ) == UECC_FAILURE );
sig_bytes[i] = temp;
}