Remove superfluous argument to ecp_write_key

Removed after feedback from PR review.

Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
This commit is contained in:
Steven Cooreman 2020-07-13 10:59:40 +02:00
parent 14f0e526fb
commit 0024df6b37
5 changed files with 12 additions and 18 deletions

View file

@ -1150,7 +1150,6 @@ int mbedtls_ecp_read_key( mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
/** /**
* \brief This function exports an elliptic curve private key. * \brief This function exports an elliptic curve private key.
* *
* \param grp_id The ECP group identifier.
* \param key The private key. * \param key The private key.
* \param buf The output buffer for containing the binary representation * \param buf The output buffer for containing the binary representation
* of the key. (Big endian integer for Weierstrass curves, byte * of the key. (Big endian integer for Weierstrass curves, byte
@ -1164,7 +1163,7 @@ int mbedtls_ecp_read_key( mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
* the group is not implemented. * the group is not implemented.
* \return Another negative error code on different kinds of failure. * \return Another negative error code on different kinds of failure.
*/ */
int mbedtls_ecp_write_key( mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key, int mbedtls_ecp_write_key( mbedtls_ecp_keypair *key,
unsigned char *buf, size_t buflen ); unsigned char *buf, size_t buflen );
/** /**

View file

@ -2999,23 +2999,18 @@ cleanup:
/* /*
* Write a private key. * Write a private key.
*/ */
int mbedtls_ecp_write_key( mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key, int mbedtls_ecp_write_key( mbedtls_ecp_keypair *key,
unsigned char *buf, size_t buflen ) unsigned char *buf, size_t buflen )
{ {
int ret = 0; int ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
ECP_VALIDATE_RET( key != NULL ); ECP_VALIDATE_RET( key != NULL );
ECP_VALIDATE_RET( buf != NULL ); ECP_VALIDATE_RET( buf != NULL );
if( ( ret = mbedtls_ecp_group_load( &key->grp, grp_id ) ) != 0 )
return( ret );
ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
#if defined(ECP_MONTGOMERY) #if defined(ECP_MONTGOMERY)
if( mbedtls_ecp_get_type( &key->grp ) == MBEDTLS_ECP_TYPE_MONTGOMERY ) if( mbedtls_ecp_get_type( &key->grp ) == MBEDTLS_ECP_TYPE_MONTGOMERY )
{ {
if( grp_id == MBEDTLS_ECP_DP_CURVE25519 ) if( key->grp.id == MBEDTLS_ECP_DP_CURVE25519 )
{ {
if( buflen < ECP_CURVE25519_KEY_SIZE ) if( buflen < ECP_CURVE25519_KEY_SIZE )
return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL; return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL;

View file

@ -168,7 +168,7 @@ static int pk_write_ec_private( unsigned char **p, unsigned char *start,
size_t byte_length = ( ec->grp.pbits + 7 ) / 8; size_t byte_length = ( ec->grp.pbits + 7 ) / 8;
unsigned char tmp[MBEDTLS_ECP_MAX_BYTES]; unsigned char tmp[MBEDTLS_ECP_MAX_BYTES];
ret = mbedtls_ecp_write_key( ec->grp.id, ec, tmp, byte_length ); ret = mbedtls_ecp_write_key( ec, tmp, byte_length );
if( ret != 0 ) if( ret != 0 )
goto exit; goto exit;
ret = mbedtls_asn1_write_octet_string( p, start, tmp, byte_length ); ret = mbedtls_asn1_write_octet_string( p, start, tmp, byte_length );

View file

@ -1326,8 +1326,8 @@ static psa_status_t psa_internal_export_key( const psa_key_slot_t *slot,
if( bytes > data_size ) if( bytes > data_size )
return( PSA_ERROR_BUFFER_TOO_SMALL ); return( PSA_ERROR_BUFFER_TOO_SMALL );
status = mbedtls_to_psa_error( status = mbedtls_to_psa_error(
mbedtls_ecp_write_key(slot->data.ecp->grp.id, slot->data.ecp, mbedtls_ecp_write_key( slot->data.ecp,
data, bytes) ); data, bytes ) );
if( status != PSA_SUCCESS ) if( status != PSA_SUCCESS )
return( status ); return( status );
memset( data + bytes, 0, data_size - bytes ); memset( data + bytes, 0, data_size - bytes );

View file

@ -1090,7 +1090,7 @@ void mbedtls_ecp_read_key( int grp_id, data_t* in_key, int expected, int canonic
{ {
unsigned char buf[MBEDTLS_ECP_MAX_BYTES]; unsigned char buf[MBEDTLS_ECP_MAX_BYTES];
ret = mbedtls_ecp_write_key( grp_id, &key, buf, in_key->len ); ret = mbedtls_ecp_write_key( &key, buf, in_key->len );
TEST_ASSERT( ret == 0 ); TEST_ASSERT( ret == 0 );
ASSERT_COMPARE( in_key->x, in_key->len, ASSERT_COMPARE( in_key->x, in_key->len,
@ -1101,13 +1101,13 @@ void mbedtls_ecp_read_key( int grp_id, data_t* in_key, int expected, int canonic
unsigned char export1[MBEDTLS_ECP_MAX_BYTES]; unsigned char export1[MBEDTLS_ECP_MAX_BYTES];
unsigned char export2[MBEDTLS_ECP_MAX_BYTES]; unsigned char export2[MBEDTLS_ECP_MAX_BYTES];
ret = mbedtls_ecp_write_key( grp_id, &key, export1, in_key->len ); ret = mbedtls_ecp_write_key( &key, export1, in_key->len );
TEST_ASSERT( ret == 0 ); TEST_ASSERT( ret == 0 );
ret = mbedtls_ecp_read_key( grp_id, &key2, export1, in_key->len ); ret = mbedtls_ecp_read_key( grp_id, &key2, export1, in_key->len );
TEST_ASSERT( ret == expected ); TEST_ASSERT( ret == expected );
ret = mbedtls_ecp_write_key( grp_id, &key2, export2, in_key->len ); ret = mbedtls_ecp_write_key( &key2, export2, in_key->len );
TEST_ASSERT( ret == 0 ); TEST_ASSERT( ret == 0 );
ASSERT_COMPARE( export1, in_key->len, ASSERT_COMPARE( export1, in_key->len,