Remove mbedtls_psa_tls_psa_ec_to_ecpoint()
Initially this function was doing something because the output format of psa_export_public() didn't match the ECPoint format that TLS wants. Then it became a no-op then the output format of psa_export_public() changed, but it made sense to still keep the function in case the format changed again. Now that the PSA Crypto API has reached 1.0 status, this is unlikely to happen, so the no-op function is no longer useful. Removing it de-clutters the code a bit; while at it we can remove a temporary stack buffer (that was up to 133 bytes). It's OK to remove this function even if it was declared in a public header, as there's a warning at the top of the file saying it's not part of the public API. Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
This commit is contained in:
parent
59753768f0
commit
58d2383ef4
2 changed files with 11 additions and 41 deletions
|
@ -277,26 +277,6 @@ static inline psa_key_type_t mbedtls_psa_parse_tls_ecc_group(
|
|||
}
|
||||
#endif /* MBEDTLS_ECP_C */
|
||||
|
||||
/* This function takes a buffer holding an EC public key
|
||||
* exported through psa_export_public_key(), and converts
|
||||
* it into an ECPoint structure to be put into a ClientKeyExchange
|
||||
* message in an ECDHE exchange.
|
||||
*
|
||||
* Both the present and the foreseeable future format of EC public keys
|
||||
* used by PSA have the ECPoint structure contained in the exported key
|
||||
* as a subbuffer, and the function merely selects this subbuffer instead
|
||||
* of making a copy.
|
||||
*/
|
||||
static inline int mbedtls_psa_tls_psa_ec_to_ecpoint( unsigned char *src,
|
||||
size_t srclen,
|
||||
unsigned char **dst,
|
||||
size_t *dstlen )
|
||||
{
|
||||
*dst = src;
|
||||
*dstlen = srclen;
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/* This function takes a buffer holding an ECPoint structure
|
||||
* (as contained in a TLS ServerKeyExchange message for ECDHE
|
||||
* exchanges) and converts it into a format that the PSA key
|
||||
|
|
|
@ -3379,11 +3379,6 @@ static int ssl_write_client_key_exchange( mbedtls_ssl_context *ssl )
|
|||
|
||||
mbedtls_ssl_handshake_params *handshake = ssl->handshake;
|
||||
|
||||
unsigned char own_pubkey[MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH];
|
||||
size_t own_pubkey_len;
|
||||
unsigned char *own_pubkey_ecpoint;
|
||||
size_t own_pubkey_ecpoint_len;
|
||||
|
||||
header_len = 4;
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "Perform PSA-based ECDH computation." ) );
|
||||
|
@ -3411,27 +3406,22 @@ static int ssl_write_client_key_exchange( mbedtls_ssl_context *ssl )
|
|||
if( status != PSA_SUCCESS )
|
||||
return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED );
|
||||
|
||||
/* Export the public part of the ECDH private key from PSA
|
||||
* and convert it to ECPoint format used in ClientKeyExchange. */
|
||||
/* Export the public part of the ECDH private key from PSA.
|
||||
* The export format is an ECPoint structre as expected by TLS,
|
||||
* but we just need to add a length byte before that. */
|
||||
unsigned char *own_pubkey = ssl->out_msg + header_len + 1;
|
||||
unsigned char *end = ssl->out_msg + MBEDTLS_SSL_OUT_CONTENT_LEN;
|
||||
size_t own_pubkey_max_len = (size_t)( end - own_pubkey );
|
||||
size_t own_pubkey_len;
|
||||
|
||||
status = psa_export_public_key( handshake->ecdh_psa_privkey,
|
||||
own_pubkey, sizeof( own_pubkey ),
|
||||
own_pubkey, own_pubkey_max_len,
|
||||
&own_pubkey_len );
|
||||
if( status != PSA_SUCCESS )
|
||||
return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED );
|
||||
|
||||
if( mbedtls_psa_tls_psa_ec_to_ecpoint( own_pubkey,
|
||||
own_pubkey_len,
|
||||
&own_pubkey_ecpoint,
|
||||
&own_pubkey_ecpoint_len ) != 0 )
|
||||
{
|
||||
return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED );
|
||||
}
|
||||
|
||||
/* Copy ECPoint structure to outgoing message buffer. */
|
||||
ssl->out_msg[header_len] = (unsigned char) own_pubkey_ecpoint_len;
|
||||
memcpy( ssl->out_msg + header_len + 1,
|
||||
own_pubkey_ecpoint, own_pubkey_ecpoint_len );
|
||||
content_len = own_pubkey_ecpoint_len + 1;
|
||||
ssl->out_msg[header_len] = (unsigned char) own_pubkey_len;
|
||||
content_len = own_pubkey_len + 1;
|
||||
|
||||
/* The ECDH secret is the premaster secret used for key derivation. */
|
||||
|
||||
|
|
Loading…
Reference in a new issue