Import mbedtls_ecp_write_key for Cypress Mbed TLS driver

Mbed TLS 2.24.0 has added a new function mbedtls_ecp_write_key()
which is the reverse of the existing mbedtls_ecp_read_key(). This
function should be platform agnostic, but needs to be copied into
Cypress's hardware-accelerated ECP driver as part of the updated
API.
pull/14333/head
Lingkai Dong 2021-01-25 10:06:57 +00:00
parent 1f4f6dd0b6
commit 0dd43976b8
1 changed files with 38 additions and 0 deletions

View File

@ -2619,6 +2619,44 @@ cleanup:
return( ret ); return( ret );
} }
/*
* Write a private key.
*/
int mbedtls_ecp_write_key( mbedtls_ecp_keypair *key,
unsigned char *buf, size_t buflen )
{
int ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
ECP_VALIDATE_RET( key != NULL );
ECP_VALIDATE_RET( buf != NULL );
#if defined(ECP_MONTGOMERY)
if( mbedtls_ecp_get_type( &key->grp ) == MBEDTLS_ECP_TYPE_MONTGOMERY )
{
if( key->grp.id == MBEDTLS_ECP_DP_CURVE25519 )
{
if( buflen < ECP_CURVE25519_KEY_SIZE )
return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL;
MBEDTLS_MPI_CHK( mbedtls_mpi_write_binary_le( &key->d, buf, buflen ) );
}
else
ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
}
#endif
#if defined(ECP_SHORTWEIERSTRASS)
if( mbedtls_ecp_get_type( &key->grp ) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS )
{
MBEDTLS_MPI_CHK( mbedtls_mpi_write_binary( &key->d, buf, buflen ) );
}
#endif
cleanup:
return( ret );
}
/* /*
* Check a public-private key pair * Check a public-private key pair
*/ */