Crypto: Add support for Hash functionalities
This patch introduces support for the Hash functionalities
exposed by the PSA Crypto API, and adds a set of tests to
the Regression test suite to validate the API functions.
Change-Id: I4169b7a1a7a04140d557edef4e9d86a9c6ae0f50
Signed-off-by: Antonio de Angelis <antonio.deangelis@arm.com>
diff --git a/interface/include/tfm_crypto_veneers.h b/interface/include/tfm_crypto_veneers.h
index b158f51..cce9432 100644
--- a/interface/include/tfm_crypto_veneers.h
+++ b/interface/include/tfm_crypto_veneers.h
@@ -149,10 +149,76 @@
* \return Return values as described in \ref tfm_crypto_err_t
*/
enum tfm_crypto_err_t tfm_crypto_veneer_cipher_finish(
- psa_cipher_operation_t *operation,
- uint8_t *output,
- size_t output_size,
- size_t *output_length);
+ psa_cipher_operation_t *operation,
+ uint8_t *output,
+ size_t output_size,
+ size_t *output_length);
+/**
+ * \brief Starts a hash operation with the provided algorithm (veneer function)
+ *
+ * \param[in] operation Hash operation context
+ * \param[in] alg Algorithm chosen as hash
+ *
+ * \return Returns values as described in \ref tfm_crypto_err_t
+ */
+enum tfm_crypto_err_t tfm_crypto_veneer_hash_start(
+ psa_hash_operation_t *operation,
+ psa_algorithm_t alg);
+/**
+ * \brief Adds a new input chunk to the data for which the final hash value
+ * will be computed (veneer function)
+ *
+ * \param[in] operation Hash operation context
+ * \param[in] input Buffer containing the input data
+ * \param[in] input_length Size of the provided input data
+ *
+ * \return Returns values as described in \ref tfm_crypto_err_t
+ */
+enum tfm_crypto_err_t tfm_crypto_veneer_hash_update(
+ psa_hash_operation_t *operation,
+ const uint8_t *input,
+ size_t input_length);
+/**
+ * \brief Finalises a hash context operation producing the final hash value
+ * (veneer function)
+ *
+ * \param[in] operation Hash operation context
+ * \param[out] hash Buffer containing hash data
+ * \param[in] hash_size Size of the hash buffer
+ * \param[out] hash_length Size of the produced hash
+ *
+ * \return Returns values as described in \ref tfm_crypto_err_t
+ */
+enum tfm_crypto_err_t tfm_crypto_veneer_hash_finish(
+ psa_hash_operation_t *operation,
+ uint8_t *hash,
+ size_t hash_size,
+ size_t *hash_length);
+/**
+ * \brief Finalises a hash context operation, verifying that the final hash
+ * value matches the one provided as input (veneer function)
+ *
+ * \param[in] operation Hash operation context
+ * \param[in] hash Buffer containing the provided hash value
+ * \param[in] hash_length Size of the provided hash value
+ *
+ * \return Returns values as described in \ref tfm_crypto_err_t
+ */
+enum tfm_crypto_err_t tfm_crypto_veneer_hash_verify(
+ psa_hash_operation_t *operation,
+ const uint8_t *hash,
+ size_t hash_length);
+/**
+ * \brief Aborts a hash operation, clears the operation context provided
+ * (veneer function)
+ *
+ * \param[in] operation Hash operation context
+ *
+ * \return Returns values as described in \ref tfm_crypto_err_t
+ */
+enum tfm_crypto_err_t tfm_crypto_veneer_hash_abort(
+ psa_hash_operation_t *operation);
+
#ifdef __cplusplus
}
#endif
diff --git a/interface/src/tfm_crypto_api.c b/interface/src/tfm_crypto_api.c
index d98f85f..dbeb6a8 100644
--- a/interface/src/tfm_crypto_api.c
+++ b/interface/src/tfm_crypto_api.c
@@ -188,3 +188,76 @@
return TFM_CRYPTO_PSA_RETURN(err);
}
+
+psa_status_t psa_hash_start(psa_hash_operation_t *operation,
+ psa_algorithm_t alg)
+{
+ enum tfm_crypto_err_t err;
+
+ err = tfm_ns_lock_dispatch((veneer_fn)tfm_crypto_veneer_hash_start,
+ (uint32_t)operation,
+ (uint32_t)alg,
+ 0,
+ 0);
+
+ return TFM_CRYPTO_PSA_RETURN(err);
+}
+
+psa_status_t psa_hash_update(psa_hash_operation_t *operation,
+ const uint8_t *input,
+ size_t input_length)
+{
+ enum tfm_crypto_err_t err;
+
+ err = tfm_ns_lock_dispatch((veneer_fn)tfm_crypto_veneer_hash_update,
+ (uint32_t)operation,
+ (uint32_t)input,
+ (uint32_t)input_length,
+ 0);
+
+ return TFM_CRYPTO_PSA_RETURN(err);
+}
+
+psa_status_t psa_hash_finish(psa_hash_operation_t *operation,
+ uint8_t *hash,
+ size_t hash_size,
+ size_t *hash_length)
+{
+ enum tfm_crypto_err_t err;
+
+ err = tfm_ns_lock_dispatch((veneer_fn)tfm_crypto_veneer_hash_finish,
+ (uint32_t)operation,
+ (uint32_t)hash,
+ (uint32_t)hash_size,
+ (uint32_t)hash_length);
+
+ return TFM_CRYPTO_PSA_RETURN(err);
+}
+
+psa_status_t psa_hash_verify(psa_hash_operation_t *operation,
+ const uint8_t *hash,
+ size_t hash_length)
+{
+ enum tfm_crypto_err_t err;
+
+ err = tfm_ns_lock_dispatch((veneer_fn)tfm_crypto_veneer_hash_verify,
+ (uint32_t)operation,
+ (uint32_t)hash,
+ (uint32_t)hash_length,
+ 0);
+
+ return TFM_CRYPTO_PSA_RETURN(err);
+}
+
+psa_status_t psa_hash_abort(psa_hash_operation_t *operation)
+{
+ enum tfm_crypto_err_t err;
+
+ err = tfm_ns_lock_dispatch((veneer_fn)tfm_crypto_veneer_hash_abort,
+ (uint32_t)operation,
+ 0,
+ 0,
+ 0);
+
+ return TFM_CRYPTO_PSA_RETURN(err);
+}