Crypto: Add Crypto service
This change introduces the implementation of the Crypto
service based on the interface psa_crypto.h
This patch introduces changes for:
-- Secure Service, including manifest
-- Platform
-- Non-Secure interface
Change-Id: I3b68266ca80f4cd2bda2a1cd2b28b51c654b4c59
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
new file mode 100644
index 0000000..1332a00
--- /dev/null
+++ b/interface/include/tfm_crypto_defs.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2018, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef __TFM_CRYPTO_DEFS_H__
+#define __TFM_CRYPTO_DEFS_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+#include <limits.h>
+#include "tfm_api.h"
+
+/* The return value is shared with the TFM service status value. The Crypto
+ * return codes shouldn't overlap with predefined TFM status values.
+ */
+#define TFM_CRYPTO_ERR_PSA_ERROR_OFFSET (TFM_PARTITION_SPECIFIC_ERROR_MIN)
+
+/**
+ * \brief This defines the maximum supported key length in bytes
+ *
+ */
+#define TFM_CRYPTO_MAX_KEY_LENGTH (16)
+
+/**
+ * \brief Define miscellaneous literal constants that are used in the module
+ *
+ */
+enum {
+ TFM_CRYPTO_NOT_IN_USE = 0,
+ TFM_CRYPTO_IN_USE = 1
+};
+
+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_NOT_PERMITTED,
+ TFM_CRYPTO_ERR_PSA_ERROR_BUFFER_TOO_SMALL,
+ TFM_CRYPTO_ERR_PSA_ERROR_OCCUPIED_SLOT,
+ TFM_CRYPTO_ERR_PSA_ERROR_EMPTY_SLOT,
+ TFM_CRYPTO_ERR_PSA_ERROR_BAD_STATE,
+ TFM_CRYPTO_ERR_PSA_ERROR_INVALID_ARGUMENT,
+ TFM_CRYPTO_ERR_PSA_ERROR_INSUFFICIENT_MEMORY,
+ TFM_CRYPTO_ERR_PSA_ERROR_INSUFFICIENT_STORAGE,
+ TFM_CRYPTO_ERR_PSA_ERROR_COMMUNICATION_FAILURE,
+ TFM_CRYPTO_ERR_PSA_ERROR_STORAGE_FAILURE,
+ TFM_CRYPTO_ERR_PSA_ERROR_HARDWARE_FAILURE,
+ TFM_CRYPTO_ERR_PSA_ERROR_TAMPERING_DETECTED,
+ 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
+ */
+#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) )
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TFM_CRYPTO_DEFS_H__ */