Fix code style (indentation) in ssl_tls13_generate_and_write_ecdh_key_exchange()

Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
This commit is contained in:
Przemek Stekiel 2022-03-02 08:45:56 +01:00
parent 0f5ecefbe9
commit e894c5c4a5

View File

@ -148,60 +148,60 @@ static int ssl_tls13_generate_and_write_ecdh_key_exchange(
unsigned char *end, unsigned char *end,
size_t *out_len ) size_t *out_len )
{ {
psa_status_t status = PSA_ERROR_GENERIC_ERROR; psa_status_t status = PSA_ERROR_GENERIC_ERROR;
int ret = MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE; int ret = MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE;
psa_key_attributes_t key_attributes; psa_key_attributes_t key_attributes;
size_t own_pubkey_len; size_t own_pubkey_len;
mbedtls_ssl_handshake_params *handshake = ssl->handshake; mbedtls_ssl_handshake_params *handshake = ssl->handshake;
size_t ecdh_bits = 0; size_t ecdh_bits = 0;
MBEDTLS_SSL_DEBUG_MSG( 1, ( "Perform PSA-based ECDH computation." ) ); MBEDTLS_SSL_DEBUG_MSG( 1, ( "Perform PSA-based ECDH computation." ) );
/* Convert EC group to PSA key type. */ /* Convert EC group to PSA key type. */
if( ( handshake->ecdh_psa_type = if( ( handshake->ecdh_psa_type =
mbedtls_psa_parse_tls_ecc_group( named_group, &ecdh_bits ) ) == 0 ) mbedtls_psa_parse_tls_ecc_group( named_group, &ecdh_bits ) ) == 0 )
return( MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE ); return( MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE );
if( ecdh_bits > 0xffff ) if( ecdh_bits > 0xffff )
return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER ); return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER );
ssl->handshake->ecdh_bits = (uint16_t) ecdh_bits; ssl->handshake->ecdh_bits = (uint16_t) ecdh_bits;
key_attributes = psa_key_attributes_init(); key_attributes = psa_key_attributes_init();
psa_set_key_usage_flags( &key_attributes, PSA_KEY_USAGE_DERIVE ); psa_set_key_usage_flags( &key_attributes, PSA_KEY_USAGE_DERIVE );
psa_set_key_algorithm( &key_attributes, PSA_ALG_ECDH ); psa_set_key_algorithm( &key_attributes, PSA_ALG_ECDH );
psa_set_key_type( &key_attributes, handshake->ecdh_psa_type ); psa_set_key_type( &key_attributes, handshake->ecdh_psa_type );
psa_set_key_bits( &key_attributes, handshake->ecdh_bits ); psa_set_key_bits( &key_attributes, handshake->ecdh_bits );
/* Generate ECDH private key. */ /* Generate ECDH private key. */
status = psa_generate_key( &key_attributes, status = psa_generate_key( &key_attributes,
&handshake->ecdh_psa_privkey ); &handshake->ecdh_psa_privkey );
if( status != PSA_SUCCESS ) if( status != PSA_SUCCESS )
{ {
ret = psa_ssl_status_to_mbedtls( status ); ret = psa_ssl_status_to_mbedtls( status );
MBEDTLS_SSL_DEBUG_RET( 1, "psa_generate_key", ret ); MBEDTLS_SSL_DEBUG_RET( 1, "psa_generate_key", ret );
return( ret ); return( ret );
} }
/* Export the public part of the ECDH private key from PSA. */ /* Export the public part of the ECDH private key from PSA. */
status = psa_export_public_key( handshake->ecdh_psa_privkey, status = psa_export_public_key( handshake->ecdh_psa_privkey,
buf, (size_t)( end - buf ), buf, (size_t)( end - buf ),
&own_pubkey_len ); &own_pubkey_len );
if( status != PSA_SUCCESS ) if( status != PSA_SUCCESS )
{ {
ret = psa_ssl_status_to_mbedtls( status ); ret = psa_ssl_status_to_mbedtls( status );
MBEDTLS_SSL_DEBUG_RET( 1, "psa_export_public_key", ret ); MBEDTLS_SSL_DEBUG_RET( 1, "psa_export_public_key", ret );
return( ret ); return( ret );
} }
if( own_pubkey_len > (size_t)( end - buf ) ) if( own_pubkey_len > (size_t)( end - buf ) )
{ {
MBEDTLS_SSL_DEBUG_MSG( 1, ( "No space in the buffer for ECDH public key." ) ); MBEDTLS_SSL_DEBUG_MSG( 1, ( "No space in the buffer for ECDH public key." ) );
return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ); return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL );
} }
*out_len = own_pubkey_len; *out_len = own_pubkey_len;
return( 0 ); return( 0 );
} }