ADAC: Authenticated Debug Access Control

The commit adds the impelementation of ADAC protocol towards the
target side.

Following components are part of the commit:-
    Core   : ADAC protocol core
    SDA    : Secure Debug Agent

The commit also demonstrates the porting of a platform from
trusted-firmware-m. Corstone1000 platform is used for the purpose.

Change-Id: I50b93f9e48789cf5927736b4d1cb35b9a47c38db
Signed-off-by: Satish Kumar <satish.kumar01@arm.com>
diff --git a/template_hal_files/psa_adac_crypto_api_impl.c b/template_hal_files/psa_adac_crypto_api_impl.c
new file mode 100644
index 0000000..edd602c
--- /dev/null
+++ b/template_hal_files/psa_adac_crypto_api_impl.c
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2020 Arm Limited. All rights reserved.
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <psa/crypto.h>
+#include "psa_adac_config.h"
+#include "psa_adac_debug.h"
+#include "psa_adac.h"
+
+/** \addtogroup adac-crypto-api
+ * @{
+ */
+
+/** \brief ADAC cryptographic back-end initialization
+ *
+ * This function will be called by ADAC library.
+ */
+psa_status_t psa_adac_crypto_init()
+{
+    // Code me
+}
+
+/** \brief Generate challenge
+ *
+ * \param[out] output       Output buffer for the challenge.
+ * \param output_size       Number of bytes to generate and output.
+ */
+psa_status_t psa_adac_generate_challenge(uint8_t *output, size_t output_size);
+{
+    // Code me
+}
+
+/** \brief Compute the hash of a message
+ *
+ * \param alg               The hash algorithm to compute.
+ * \param[in] input         Buffer containing the message to hash.
+ * \param input_size        Size of the \p input buffer in bytes.
+ * \param[out] hash         Buffer where the hash is to be written.
+ * \param hash_size         Size of the \p hash buffer in bytes.
+ * \param[out] hash_length  On success, the length of the hash in bytes.
+ *
+ * \retval PSA_SUCCESS
+ *         Success.
+ * \retval PSA_ERROR_NOT_SUPPORTED
+ *         \p alg is not supported (or unknown hash algorithm).
+ * \retval PSA_ERROR_INVALID_ARGUMENT
+ * \retval PSA_ERROR_HARDWARE_FAILURE
+ */
+psa_status_t psa_adac_hash(psa_algorithm_t alg, const uint8_t *input, size_t input_size,
+                           uint8_t *hash, size_t hash_size, size_t *hash_length)
+{
+    // Code me
+}
+
+/** \brief Compute the hash of a message composed of multiple parts
+ *
+ * \param alg               The hash algorithm to compute.
+ * \param[in] inputs        Array of buffers containing the message to hash.
+ * \param[in] input_sizes   Array of size of the \p inputs buffers in bytes.
+ * \param input_count       Number of entries in \p inputs and \p input_sizes.
+ * \param[out] hash         Buffer where the hash is to be written.
+ * \param hash_size         Size of the \p hash buffer in bytes.
+ * \param[out] hash_length  On success, the length of the hash in bytes.
+ *
+ * \retval PSA_SUCCESS
+ *         Success.
+ * \retval PSA_ERROR_NOT_SUPPORTED
+ *         \p alg is not supported (or unknown hash algorithm).
+ * \retval PSA_ERROR_INVALID_ARGUMENT
+ * \retval PSA_ERROR_HARDWARE_FAILURE
+ */
+psa_status_t psa_adac_hash_multiple(psa_algorithm_t alg,
+                                    const uint8_t *inputs[], size_t input_sizes[], size_t input_count,
+                                    uint8_t hash[], size_t hash_size, size_t *hash_length)
+{
+    // Code me
+}
+
+/** \brief Compute the hash of a message and compare it with an expected value.
+ *
+ * \param alg               The hash algorithm to compute.
+ * \param[in] input         Buffer containing the message to hash.
+ * \param input_size        Size of the \p input buffer in bytes.
+ * \param[out] hash         Buffer containing the expected hash value.
+ * \param hash_size         Size of the \p hash buffer in bytes.
+ *
+ * \retval PSA_SUCCESS
+ *         The expected hash is identical to the actual hash of the input.
+ * \retval PSA_ERROR_INVALID_SIGNATURE
+ *         The hash of the message was calculated successfully, but it
+ *         differs from the expected hash.
+ * \retval PSA_ERROR_NOT_SUPPORTED
+ *         \p alg is not supported (or unknown hash algorithm).
+ * \retval PSA_ERROR_INVALID_ARGUMENT
+ * \retval PSA_ERROR_HARDWARE_FAILURE
+ */
+psa_status_t psa_adac_hash_verify(psa_algorithm_t alg, const uint8_t input[], size_t input_size,
+                                  uint8_t hash[], size_t hash_size)
+{
+    // Code me
+}
+
+/** \brief Compute the hash of a message and compare it with a list of expected values
+ *
+ */
+psa_status_t psa_adac_hash_verify_multiple(psa_algorithm_t alg, const uint8_t input[], size_t input_length,
+                                           uint8_t *hash[], size_t hash_size[], size_t hash_count)
+{
+    // Code me
+}
+
+/** \brief Verify a signature
+ *
+ */
+psa_status_t psa_adac_verify_signature(uint8_t key_type, uint8_t *key, size_t key_size, psa_algorithm_t hash_algo,
+                                       const uint8_t *inputs[], size_t input_sizes[], size_t input_count,
+                                       psa_algorithm_t sig_algo, uint8_t *sig, size_t sig_size)
+{
+    // Code me
+}
+
+/** \brief Verify a message authentication code
+ *
+ */
+psa_status_t psa_adac_mac_verify(psa_algorithm_t alg, const uint8_t *inputs[], size_t input_sizes[], size_t input_count,
+                                 const uint8_t key[], size_t key_size, uint8_t mac[], size_t mac_size)
+{
+    // Code me
+}
+
+/** \brief Derive key
+ *
+ */
+psa_status_t psa_adac_derive_key(uint8_t *crt, size_t crt_size, uint8_t key_type, uint8_t *key, size_t key_size)
+{
+    // Code me
+}
+
+/**@}*/
+
+#endif //PSA_ADAC_PSA_CRYPTO_API_H
diff --git a/template_hal_files/target_name.c b/template_hal_files/target_name.c
new file mode 100644
index 0000000..0bc2ebc
--- /dev/null
+++ b/template_hal_files/target_name.c
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2020 Arm Limited. All rights reserved.
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <psa_adac_config.h>
+#include <psa_adac_debug.h>
+#include <psa_adac_sda.h>
+#include <platform/platform.h>
+#include <platform/msg_interface.h>
+
+void psa_adac_platform_init()
+{
+    // TODO: Code me
+}
+
+size_t psa_adac_platform_discovery(uint8_t *reply, size_t reply_size)
+{
+    // TODO: Code me
+}
+
+void psa_adac_platform_lock()
+{
+    // TODO: Code me
+}
+
+int psa_adac_platform_check_token(uint8_t *token, size_t token_size)
+{
+    // TODO: Code me
+}
+
+int psa_adac_platform_check_certificate(uint8_t *crt, size_t crt_size)
+{
+    // TODO: Code me
+}
+
+int psa_adac_apply_permissions(uint8_t permissions_mask[16])
+{
+    // TODO: Code me
+}
+
+void platform_init()
+{
+    // TODO: Code me
+}
diff --git a/template_hal_files/trasport_layer.c b/template_hal_files/trasport_layer.c
new file mode 100644
index 0000000..d5540b2
--- /dev/null
+++ b/template_hal_files/trasport_layer.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2020 Arm Limited. All rights reserved.
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <psa_adac_debug.h>
+#include <platform/msg_interface.h>
+
+#include <platform/platform.h>
+
+int psa_adac_detect_debug_request()
+{
+    // Code me
+}
+
+void psa_adac_acknowledge_debug_request()
+{
+    // Code me
+}
+
+int msg_interface_init(void *ctx, uint8_t buffer[], size_t buffer_size)
+{
+    // Code me
+}
+
+int msg_interface_free(void *ctx)
+{
+    // Code me
+}
+
+int request_packet_send()
+{
+    // Code me
+}
+
+request_packet_t *request_packet_receive(void *ctx)
+{
+    // Code me
+}
+
+int response_packet_send(response_packet_t *p)
+{
+    // Code me
+}
+
+response_packet_t *response_packet_receive()
+{
+    // Code me
+}