1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-07 06:42:56 +03:00

make ret_from_status() global function and move it to has_info.[ch]

Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
This commit is contained in:
Przemek Stekiel
2022-07-29 11:20:07 +02:00
parent 712bb9c5af
commit 2aae040615
3 changed files with 29 additions and 22 deletions

View File

@@ -22,6 +22,7 @@
#include "hash_info.h" #include "hash_info.h"
#include "legacy_or_psa.h" #include "legacy_or_psa.h"
#include "error.h"
typedef struct typedef struct
{ {
@@ -107,3 +108,20 @@ mbedtls_md_type_t mbedtls_hash_info_md_from_psa( psa_algorithm_t psa_alg )
return entry->md_type; return entry->md_type;
} }
int mbedtls_md_error_from_psa( psa_status_t status )
{
switch( status )
{
case PSA_SUCCESS:
return( 0 );
case PSA_ERROR_NOT_SUPPORTED:
return( MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE );
case PSA_ERROR_INVALID_ARGUMENT:
return( MBEDTLS_ERR_MD_BAD_INPUT_DATA );
case PSA_ERROR_INSUFFICIENT_MEMORY:
return( MBEDTLS_ERR_MD_ALLOC_FAILED );
default:
return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
}
}

View File

@@ -74,4 +74,12 @@ psa_algorithm_t mbedtls_hash_info_psa_from_md( mbedtls_md_type_t md_type );
*/ */
mbedtls_md_type_t mbedtls_hash_info_md_from_psa( psa_algorithm_t psa_alg ); mbedtls_md_type_t mbedtls_hash_info_md_from_psa( psa_algorithm_t psa_alg );
/** Convert PSA status to MD error code.
*
* \param status PSA status.
*
* \return The corresponding MD error code,
*/
int mbedtls_md_error_from_psa( psa_status_t status );
#endif /* MBEDTLS_HASH_INFO_H */ #endif /* MBEDTLS_HASH_INFO_H */

View File

@@ -1098,25 +1098,6 @@ cleanup:
} }
#if defined(MBEDTLS_PKCS1_V21) #if defined(MBEDTLS_PKCS1_V21)
#if !defined(MBEDTLS_MD_C)
static int ret_from_status( psa_status_t status )
{
switch( status )
{
case PSA_SUCCESS:
return( 0 );
case PSA_ERROR_NOT_SUPPORTED:
return( MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE );
case PSA_ERROR_INVALID_ARGUMENT:
return( MBEDTLS_ERR_MD_BAD_INPUT_DATA );
case PSA_ERROR_INSUFFICIENT_MEMORY:
return( MBEDTLS_ERR_MD_ALLOC_FAILED );
default:
return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
}
}
#endif /* !MBEDTLS_MD_C */
/** /**
* Generate and apply the MGF1 operation (from PKCS#1 v2.1) to a buffer. * Generate and apply the MGF1 operation (from PKCS#1 v2.1) to a buffer.
* *
@@ -1208,7 +1189,7 @@ exit:
#else #else
psa_hash_abort( &op ); psa_hash_abort( &op );
return( ret_from_status( status ) ); return( mbedtls_md_error_from_psa( status ) );
#endif #endif
} }
@@ -1276,7 +1257,7 @@ exit:
exit: exit:
psa_hash_abort( &op ); psa_hash_abort( &op );
return( ret_from_status( status ) ); return( mbedtls_md_error_from_psa( status ) );
#endif /* !MBEDTLS_MD_C */ #endif /* !MBEDTLS_MD_C */
} }
@@ -1308,7 +1289,7 @@ static int compute_hash( mbedtls_md_type_t md_alg,
status = psa_hash_compute( alg, input, ilen, output, out_size, &out_len ); status = psa_hash_compute( alg, input, ilen, output, out_size, &out_len );
return( ret_from_status( status ) ); return( mbedtls_md_error_from_psa( status ) );
#endif /* !MBEDTLS_MD_C */ #endif /* !MBEDTLS_MD_C */
} }
#endif /* MBEDTLS_PKCS1_V21 */ #endif /* MBEDTLS_PKCS1_V21 */