Convert psa status to mbedtls
Signed-off-by: Przemyslaw Stekiel <przemyslaw.stekiel@mobica.com>
diff --git a/library/ssl_tls.c b/library/ssl_tls.c
index 0be6ec6..1bd9854 100644
--- a/library/ssl_tls.c
+++ b/library/ssl_tls.c
@@ -669,6 +669,21 @@
const unsigned char *, size_t,
unsigned char *, size_t);
+static int psa_status_to_mbedtls( psa_status_t status )
+{
+ switch( status )
+ {
+ case PSA_SUCCESS:
+ return( 0 );
+ case PSA_ERROR_INSUFFICIENT_MEMORY:
+ return( MBEDTLS_ERR_CIPHER_ALLOC_FAILED );
+ case PSA_ERROR_NOT_SUPPORTED:
+ return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
+ default:
+ return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
+ }
+}
+
/*
* Populate a transform structure with session keys and all the other
* necessary information.
@@ -1092,7 +1107,8 @@
&key_type,
&key_bits ) ) != PSA_SUCCESS )
{
- MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_cipher_to_psa", status );
+ MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_cipher_to_psa", psa_status_to_mbedtls( status ) );
+ ret = psa_status_to_mbedtls( status );
goto end;
}
@@ -1106,7 +1122,8 @@
PSA_BITS_TO_BYTES( key_bits ),
&transform->psa_key_enc ) ) != PSA_SUCCESS )
{
- MBEDTLS_SSL_DEBUG_RET( 1, "psa_import_key", status );
+ MBEDTLS_SSL_DEBUG_RET( 1, "psa_import_key", psa_status_to_mbedtls( status ) );
+ ret = psa_status_to_mbedtls( status );
goto end;
}
if( ( status = psa_import_key( &attributes,
@@ -1114,7 +1131,8 @@
PSA_BITS_TO_BYTES( key_bits ),
&transform->psa_key_dec ) ) != PSA_SUCCESS )
{
- MBEDTLS_SSL_DEBUG_RET( 1, "psa_import_key", status );
+ MBEDTLS_SSL_DEBUG_RET( 1, "psa_import_key", psa_status_to_mbedtls( status ) );
+ ret = psa_status_to_mbedtls( status );
goto end;
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */
diff --git a/library/ssl_tls13_keys.c b/library/ssl_tls13_keys.c
index 58ff010..99d0860 100644
--- a/library/ssl_tls13_keys.c
+++ b/library/ssl_tls13_keys.c
@@ -922,7 +922,7 @@
&key_type,
&key_bits ) ) != PSA_SUCCESS )
{
- MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_cipher_to_psa", status );
+ MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_cipher_to_psa", psa_status_to_mbedtls( status ) );
return( psa_status_to_mbedtls( status ) );
}
@@ -936,7 +936,7 @@
PSA_BITS_TO_BYTES( key_bits ),
&transform->psa_key_enc ) ) != PSA_SUCCESS )
{
- MBEDTLS_SSL_DEBUG_RET( 1, "psa_import_key", status );
+ MBEDTLS_SSL_DEBUG_RET( 1, "psa_import_key", psa_status_to_mbedtls( status ) );
return( psa_status_to_mbedtls( status ) );
}
if( ( status = psa_import_key( &attributes,
@@ -944,7 +944,7 @@
PSA_BITS_TO_BYTES( key_bits ),
&transform->psa_key_dec ) ) != PSA_SUCCESS )
{
- MBEDTLS_SSL_DEBUG_RET( 1, "psa_import_key", status );
+ MBEDTLS_SSL_DEBUG_RET( 1, "psa_import_key", psa_status_to_mbedtls( status ) );
return( psa_status_to_mbedtls( status ) );
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */