Crypto: Align to PSA Crypto headers 0.1.0a

This patch updates the PSA Crypto API headers to version
0.1.0a. The Crypto service implementation is updated when
needed to make sure the service is buildable and functional.

Change-Id: I63709db0d87f449012d0c8355658f1af1583b3ab
Signed-off-by: Antonio de Angelis <antonio.deangelis@arm.com>
diff --git a/interface/include/tfm_crypto_defs.h b/interface/include/tfm_crypto_defs.h
index 1332a00..e9bb955 100644
--- a/interface/include/tfm_crypto_defs.h
+++ b/interface/include/tfm_crypto_defs.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -28,17 +28,23 @@
 #define TFM_CRYPTO_MAX_KEY_LENGTH (16)
 
 /**
-  * \brief Define miscellaneous literal constants that are used in the module
-  *
-  */
+ * \brief Define miscellaneous literal constants that are used in the module
+ *
+ */
 enum {
     TFM_CRYPTO_NOT_IN_USE = 0,
     TFM_CRYPTO_IN_USE = 1
 };
 
+/**
+ * \brief Possible return values from the TFM Crypto service. They must
+ *        provide corresponding return values for psa_status_t possible
+ *        values as specified in psa_crypto.h
+ */
 enum tfm_crypto_err_t {
     TFM_CRYPTO_ERR_PSA_SUCCESS = 0,
-    TFM_CRYPTO_ERR_PSA_ERROR_NOT_SUPPORTED = TFM_CRYPTO_ERR_PSA_ERROR_OFFSET,
+    TFM_CRYPTO_ERR_PSA_ERROR_UNKNOWN_ERROR = TFM_CRYPTO_ERR_PSA_ERROR_OFFSET,
+    TFM_CRYPTO_ERR_PSA_ERROR_NOT_SUPPORTED,
     TFM_CRYPTO_ERR_PSA_ERROR_NOT_PERMITTED,
     TFM_CRYPTO_ERR_PSA_ERROR_BUFFER_TOO_SMALL,
     TFM_CRYPTO_ERR_PSA_ERROR_OCCUPIED_SLOT,
@@ -54,21 +60,23 @@
     TFM_CRYPTO_ERR_PSA_ERROR_INSUFFICIENT_ENTROPY,
     TFM_CRYPTO_ERR_PSA_ERROR_INVALID_SIGNATURE,
     TFM_CRYPTO_ERR_PSA_ERROR_INVALID_PADDING,
-    TFM_CRYPTO_ERR_PSA_ERROR_UNKNOWN_ERROR,
 
     /* Add an invalid return code which forces the size of the type as well */
     TFM_CRYPTO_ERR_INVALID = INT_MAX
 };
 
 /**
- * \brief A macro to translate PSA API return values including the offset
- *        needed by TFM, to the corresponding PSA value
+ * \brief A macro to translate TFM Crypto service return values to the
+ *        corresponding PSA return value. The user of this macro needs
+ *        to cast the produced value to psa_status_t explicitly if needed
+ *
+ * \return Values specified by \ref psa_status_t
  */
 #define TFM_CRYPTO_PSA_RETURN(val) \
-                        ( (val == TFM_CRYPTO_ERR_PSA_SUCCESS) ? val : \
-                         ((val >= TFM_CRYPTO_ERR_PSA_ERROR_NOT_SUPPORTED) ? \
-                          (val - (TFM_CRYPTO_ERR_PSA_ERROR_NOT_SUPPORTED-1)) : \
-                           TFM_CRYPTO_ERR_INVALID) )
+      ( (val == TFM_CRYPTO_ERR_PSA_SUCCESS) ? val : \
+        ((val >= (enum tfm_crypto_err_t)TFM_CRYPTO_ERR_PSA_ERROR_OFFSET) ? \
+         (val - ((enum tfm_crypto_err_t)TFM_CRYPTO_ERR_PSA_ERROR_OFFSET-1)) : \
+          TFM_CRYPTO_ERR_INVALID) )
 
 #ifdef __cplusplus
 }