mirror of https://github.com/ARMmbed/mbed-os.git
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
parent
1f4f6dd0b6
commit
0dd43976b8
|
@ -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
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue