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

Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
diff --git a/library/hash_info.c b/library/hash_info.c
index c3a81cf..19afae8 100644
--- a/library/hash_info.c
+++ b/library/hash_info.c
@@ -22,6 +22,7 @@
 
 #include "hash_info.h"
 #include "legacy_or_psa.h"
+#include "error.h"
 
 typedef struct
 {
@@ -107,3 +108,20 @@
 
     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 );
+    }
+}
diff --git a/library/hash_info.h b/library/hash_info.h
index 67983f7..54f5f7c 100644
--- a/library/hash_info.h
+++ b/library/hash_info.h
@@ -74,4 +74,12 @@
  */
 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 */
diff --git a/library/rsa.c b/library/rsa.c
index e461f6e..3ff6fdc 100644
--- a/library/rsa.c
+++ b/library/rsa.c
@@ -1098,25 +1098,6 @@
 }
 
 #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.
  *
@@ -1208,7 +1189,7 @@
 #else
     psa_hash_abort( &op );
 
-    return( ret_from_status( status ) );
+    return( mbedtls_md_error_from_psa( status ) );
 #endif
 }
 
@@ -1276,7 +1257,7 @@
 exit:
     psa_hash_abort( &op );
 
-    return( ret_from_status( status ) );
+    return( mbedtls_md_error_from_psa( status ) );
 #endif /* !MBEDTLS_MD_C */
 }
 
@@ -1308,7 +1289,7 @@
 
     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_PKCS1_V21 */