Private EC key format: change to raw secret value (export)
Change the import/export format of private elliptic curve keys from
RFC 5915 to the raw secret value. This commit updates the export code.
diff --git a/library/psa_crypto.c b/library/psa_crypto.c
index f77df30..eac1eb4 100644
--- a/library/psa_crypto.c
+++ b/library/psa_crypto.c
@@ -869,6 +869,21 @@
*data_length = slot->data.raw.bytes;
return( PSA_SUCCESS );
}
+#if defined(MBEDTLS_ECP_C)
+ if( PSA_KEY_TYPE_IS_ECC_KEYPAIR( slot->type ) && !export_public_key )
+ {
+ size_t bytes = PSA_BITS_TO_BYTES( psa_get_key_bits( slot ) );
+ if( bytes > data_size )
+ return( PSA_ERROR_BUFFER_TOO_SMALL );
+ status = mbedtls_to_psa_error(
+ mbedtls_mpi_write_binary( &slot->data.ecp->d, data, bytes ) );
+ if( status != PSA_SUCCESS )
+ return( status );
+ memset( data + bytes, 0, data_size - bytes );
+ *data_length = bytes;
+ return( PSA_SUCCESS );
+ }
+#endif
else
{
#if defined(MBEDTLS_PK_WRITE_C)