ssl_tls1X_populate_transform(): import psa keys only if alg is not MBEDTLS_SSL_NULL_CIPHER
Signed-off-by: Przemyslaw Stekiel <przemyslaw.stekiel@mobica.com>
This commit is contained in:
parent
77aec8d181
commit
f9cd60853f
2 changed files with 47 additions and 40 deletions
|
@ -1020,17 +1020,20 @@ static int ssl_tls12_populate_transform( mbedtls_ssl_transform *transform,
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
transform->psa_alg = alg;
|
||||||
|
|
||||||
|
if ( alg != MBEDTLS_SSL_NULL_CIPHER )
|
||||||
|
{
|
||||||
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
|
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
|
||||||
psa_set_key_algorithm( &attributes, alg );
|
psa_set_key_algorithm( &attributes, alg );
|
||||||
psa_set_key_type( &attributes, key_type );
|
psa_set_key_type( &attributes, key_type );
|
||||||
|
|
||||||
transform->psa_alg = alg;
|
|
||||||
|
|
||||||
if( ( status = psa_import_key( &attributes,
|
if( ( status = psa_import_key( &attributes,
|
||||||
key1,
|
key1,
|
||||||
PSA_BITS_TO_BYTES( key_bits ),
|
PSA_BITS_TO_BYTES( key_bits ),
|
||||||
&transform->psa_key_enc ) ) != PSA_SUCCESS )
|
&transform->psa_key_enc ) ) != PSA_SUCCESS )
|
||||||
{
|
{
|
||||||
|
MBEDTLS_SSL_DEBUG_RET( 3, "psa_import_key", (int)status );
|
||||||
ret = psa_ssl_status_to_mbedtls( status );
|
ret = psa_ssl_status_to_mbedtls( status );
|
||||||
MBEDTLS_SSL_DEBUG_RET( 1, "psa_import_key", ret );
|
MBEDTLS_SSL_DEBUG_RET( 1, "psa_import_key", ret );
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -1047,6 +1050,7 @@ static int ssl_tls12_populate_transform( mbedtls_ssl_transform *transform,
|
||||||
MBEDTLS_SSL_DEBUG_RET( 1, "psa_import_key", ret );
|
MBEDTLS_SSL_DEBUG_RET( 1, "psa_import_key", ret );
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
if( ( ret = mbedtls_cipher_setup( &transform->cipher_ctx_enc,
|
if( ( ret = mbedtls_cipher_setup( &transform->cipher_ctx_enc,
|
||||||
cipher_info ) ) != 0 )
|
cipher_info ) ) != 0 )
|
||||||
|
|
|
@ -940,12 +940,14 @@ int mbedtls_ssl_tls13_populate_transform( mbedtls_ssl_transform *transform,
|
||||||
return( psa_ssl_status_to_mbedtls( status ) );
|
return( psa_ssl_status_to_mbedtls( status ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
transform->psa_alg = alg;
|
||||||
|
|
||||||
|
if ( alg != MBEDTLS_SSL_NULL_CIPHER )
|
||||||
|
{
|
||||||
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
|
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
|
||||||
psa_set_key_algorithm( &attributes, alg );
|
psa_set_key_algorithm( &attributes, alg );
|
||||||
psa_set_key_type( &attributes, key_type );
|
psa_set_key_type( &attributes, key_type );
|
||||||
|
|
||||||
transform->psa_alg = alg;
|
|
||||||
|
|
||||||
if( ( status = psa_import_key( &attributes,
|
if( ( status = psa_import_key( &attributes,
|
||||||
key_enc,
|
key_enc,
|
||||||
PSA_BITS_TO_BYTES( key_bits ),
|
PSA_BITS_TO_BYTES( key_bits ),
|
||||||
|
@ -965,6 +967,7 @@ int mbedtls_ssl_tls13_populate_transform( mbedtls_ssl_transform *transform,
|
||||||
MBEDTLS_SSL_DEBUG_RET( 1, "psa_import_key", psa_ssl_status_to_mbedtls( status ) );
|
MBEDTLS_SSL_DEBUG_RET( 1, "psa_import_key", psa_ssl_status_to_mbedtls( status ) );
|
||||||
return( psa_ssl_status_to_mbedtls( status ) );
|
return( psa_ssl_status_to_mbedtls( status ) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue