Unify PSA to Mbed TLS error translation

Move all error translation utilities to psa_util.c.
Introduce macros and functions to avoid having
a local copy of the error translating function in
each place.
Identify overlapping errors and introduce a
generic function.
Provide a single macro for all error translations
(unless one file needs a couple of different ones).
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
diff --git a/library/lmots.c b/library/lmots.c
index c6b45ed..4061edd 100644
--- a/library/lmots.c
+++ b/library/lmots.c
@@ -41,9 +41,14 @@
 #include "mbedtls/lms.h"
 #include "mbedtls/platform_util.h"
 #include "mbedtls/error.h"
+#include "mbedtls/psa_util.h"
 
 #include "psa/crypto.h"
 
+#define PSA_TO_MBEDTLS_ERR(status) PSA_TO_MBEDTLS_ERR_LIST(status,   \
+                                                           psa_to_lms_errors,             \
+                                                           psa_generic_status_to_mbedtls)
+
 #define PUBLIC_KEY_TYPE_OFFSET     (0)
 #define PUBLIC_KEY_I_KEY_ID_OFFSET (PUBLIC_KEY_TYPE_OFFSET + \
                                     MBEDTLS_LMOTS_TYPE_LEN)
@@ -198,7 +203,7 @@
 exit:
     psa_hash_abort(&op);
 
-    return mbedtls_lms_error_from_psa(status);
+    return PSA_TO_MBEDTLS_ERR(status);
 }
 
 /* Hash each element of the string of digits (+ checksum), producing a hash
@@ -321,7 +326,7 @@
     psa_hash_abort(&op);
     mbedtls_platform_zeroize(tmp_hash, sizeof(tmp_hash));
 
-    return mbedtls_lms_error_from_psa(status);
+    return PSA_TO_MBEDTLS_ERR(status);
 }
 
 /* Combine the hashes of the digit array into a public key. This is used in
@@ -386,9 +391,10 @@
         psa_hash_abort(&op);
     }
 
-    return mbedtls_lms_error_from_psa(status);
+    return PSA_TO_MBEDTLS_ERR(status);
 }
 
+#if !defined(MBEDTLS_DEPRECATED_REMOVED)
 int mbedtls_lms_error_from_psa(psa_status_t status)
 {
     switch (status) {
@@ -406,6 +412,7 @@
             return MBEDTLS_ERR_ERROR_GENERIC_ERROR;
     }
 }
+#endif /* !MBEDTLS_DEPRECATED_REMOVED */
 
 void mbedtls_lmots_public_init(mbedtls_lmots_public_t *ctx)
 {
@@ -682,7 +689,7 @@
 exit:
     psa_hash_abort(&op);
 
-    return mbedtls_lms_error_from_psa(status);
+    return PSA_TO_MBEDTLS_ERR(status);
 }
 
 int mbedtls_lmots_calculate_public_key(mbedtls_lmots_public_t *ctx,