psa arch test v1.2 release commits
diff --git a/secure-debug/tests/adac/suite.cmake b/secure-debug/tests/adac/suite.cmake
new file mode 100644
index 0000000..167d305
--- /dev/null
+++ b/secure-debug/tests/adac/suite.cmake
@@ -0,0 +1,41 @@
+#/** @file
+# * Copyright (c) 2021 Arm Limited or its affiliates. All rights reserved.
+# * SPDX-License-Identifier : Apache-2.0
+# *
+# * Licensed under the Apache License, Version 2.0 (the "License");
+# * you may not use this file except in compliance with the License.
+# * You may obtain a copy of the License at
+# *
+# *  http://www.apache.org/licenses/LICENSE-2.0
+# *
+# * Unless required by applicable law or agreed to in writing, software
+# * distributed under the License is distributed on an "AS IS" BASIS,
+# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# * See the License for the specific language governing permissions and
+# * limitations under the License.
+#**/
+
+foreach(test ${PSA_TEST_LIST})
+	include(${PSA_SUITE_DIR}/${test}/test.cmake)
+	foreach(source_file ${CC_SOURCE})
+		list(APPEND SUITE_CC_SOURCE
+			${PSA_SUITE_DIR}/${test}/${source_file}
+		)
+	endforeach()
+	unset(CC_SOURCE)
+endforeach()
+
+add_definitions(${CC_OPTIONS})
+add_library(${TEST_COMBINE_LIB} STATIC ${SUITE_CC_SOURCE})
+
+# Test related Include directories
+foreach(test ${PSA_TEST_LIST})
+	target_include_directories(${TEST_COMBINE_LIB} PRIVATE ${PSA_SUITE_DIR}/${test})
+endforeach()
+
+target_include_directories(${TEST_COMBINE_LIB} PRIVATE
+	${CMAKE_BINARY_DIR}
+	${PSA_ROOT_DIR}/val/include
+	${PSA_ROOT_DIR}/platform/${TARGET}/include
+)
+target_link_libraries(${TEST_COMBINE_LIB} mbedcrypto)
diff --git a/secure-debug/tests/adac/test_a001/test.cmake b/secure-debug/tests/adac/test_a001/test.cmake
new file mode 100644
index 0000000..c38649e
--- /dev/null
+++ b/secure-debug/tests/adac/test_a001/test.cmake
@@ -0,0 +1,21 @@
+#/** @file
+# * Copyright (c) 2021, Arm Limited or its affiliates. All rights reserved.
+# * SPDX-License-Identifier : Apache-2.0
+# *
+# * Licensed under the Apache License, Version 2.0 (the "License");
+# * you may not use this file except in compliance with the License.
+# * You may obtain a copy of the License at
+# *
+# *  http://www.apache.org/licenses/LICENSE-2.0
+# *
+# * Unless required by applicable law or agreed to in writing, software
+# * distributed under the License is distributed on an "AS IS" BASIS,
+# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# * See the License for the specific language governing permissions and
+# * limitations under the License.
+#**/
+
+list(APPEND CC_SOURCE
+	test_a001.c
+)
+list(APPEND CC_OPTIONS )
diff --git a/secure-debug/tests/adac/test_a001/test_a001.c b/secure-debug/tests/adac/test_a001/test_a001.c
new file mode 100644
index 0000000..66f878e
--- /dev/null
+++ b/secure-debug/tests/adac/test_a001/test_a001.c
@@ -0,0 +1,86 @@
+/** @file
+ * Copyright (c) 2021, Arm Limited or its affiliates. All rights reserved.
+ * SPDX-License-Identifier : Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+**/
+
+#include <psa_adac.h>
+#include <val_adac.h>
+#include "val_interfaces.h"
+
+#include "test_a001.h"
+
+#define TEST_NUM  VAL_CREATE_TEST_ID(VAL_SECURE_DEBUG_BASE, 1)
+#define TEST_DESC "Testing ADAC Protocol Host API| UT: psa_challenge\n"
+TEST_PUBLISH(TEST_NUM, test_entry);
+
+void test_entry(val_api_t *val_api)
+{
+    int32_t   status = VAL_STATUS_SUCCESS;
+    val_api_t *val = NULL;
+
+    val = val_api;
+
+    /* test init */
+    val->test_init(TEST_NUM, TEST_DESC);
+    val_adac_host_init();
+
+    uint8_t challenge1[CHALLENGE_SIZE], challenge2[CHALLENGE_SIZE], i;
+
+    request_packet_t *request;
+    response_packet_t *response;
+
+    if (PSA_SUCCESS != val_issue_command(SDP_AUTH_START_CMD, request, NULL, 0))
+        goto test_fail_exit;
+
+    response = val_await_response();
+    if (PSA_SUCCESS != val_parse_response(SDP_AUTH_START_CMD, response))
+        goto test_fail_exit;
+
+    psa_auth_challenge_t *challenge = (psa_auth_challenge_t *) response->data;
+
+    *challenge1 = (uint8_t)(challenge->challenge_vector);
+    response_packet_release(response);
+
+    if (PSA_SUCCESS != val_issue_command(SDP_AUTH_START_CMD, request, NULL, 0))
+        goto test_fail_exit;
+
+    response = val_await_response();
+    if (PSA_SUCCESS != val_parse_response(SDP_AUTH_START_CMD, response))
+        goto test_fail_exit;
+
+    challenge = (psa_auth_challenge_t *) response->data;
+
+    *challenge2 = (uint8_t)(challenge->challenge_vector);
+    response_packet_release(response);
+
+    for (i = 0; i < CHALLENGE_SIZE; i++) {
+        if (challenge1[i] != challenge2[i])
+            break;
+    }
+
+    if (i == CHALLENGE_SIZE) {
+	    val->print(PRINT_ERROR, "Challenge response obtained is not unique\n", 0);
+        goto test_fail_exit;
+    } else {
+	    val->print(PRINT_INFO, "Challenge response obtained is unique\n", 0);
+        goto test_end;
+    }
+
+test_fail_exit:
+	val_set_status(RESULT_FAIL(VAL_STATUS_TEST_FAILED));
+test_end:
+    val->test_exit();
+}
+
diff --git a/secure-debug/tests/adac/test_a001/test_a001.h b/secure-debug/tests/adac/test_a001/test_a001.h
new file mode 100644
index 0000000..5212fed
--- /dev/null
+++ b/secure-debug/tests/adac/test_a001/test_a001.h
@@ -0,0 +1,26 @@
+/** @file
+ * Copyright (c) 2021, Arm Limited or its affiliates. All rights reserved.
+ * SPDX-License-Identifier : Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+**/
+#ifndef _TEST_A001_TESTS_H_
+#define _TEST_A001_TESTS_H_
+
+#define test_entry CONCAT(test_entry_, a001)
+
+extern val_api_t *val;
+extern char *key_file;
+extern char *chain_file;
+
+#endif /* _TEST_A001_TESTS_H_ */
diff --git a/secure-debug/tests/adac/test_a002/test.cmake b/secure-debug/tests/adac/test_a002/test.cmake
new file mode 100644
index 0000000..c6318e9
--- /dev/null
+++ b/secure-debug/tests/adac/test_a002/test.cmake
@@ -0,0 +1,21 @@
+#/** @file
+# * Copyright (c) 2021, Arm Limited or its affiliates. All rights reserved.
+# * SPDX-License-Identifier : Apache-2.0
+# *
+# * Licensed under the Apache License, Version 2.0 (the "License");
+# * you may not use this file except in compliance with the License.
+# * You may obtain a copy of the License at
+# *
+# *  http://www.apache.org/licenses/LICENSE-2.0
+# *
+# * Unless required by applicable law or agreed to in writing, software
+# * distributed under the License is distributed on an "AS IS" BASIS,
+# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# * See the License for the specific language governing permissions and
+# * limitations under the License.
+#**/
+
+list(APPEND CC_SOURCE
+	test_a002.c
+)
+list(APPEND CC_OPTIONS )
diff --git a/secure-debug/tests/adac/test_a002/test_a002.c b/secure-debug/tests/adac/test_a002/test_a002.c
new file mode 100644
index 0000000..dabbc34
--- /dev/null
+++ b/secure-debug/tests/adac/test_a002/test_a002.c
@@ -0,0 +1,124 @@
+/** @file
+ * Copyright (c) 2021, Arm Limited or its affiliates. All rights reserved.
+ * SPDX-License-Identifier : Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+**/
+
+#include <psa_adac.h>
+#include <val_adac.h>
+#include "val_interfaces.h"
+
+#include "test_a002.h"
+
+#define TEST_NUM  VAL_CREATE_TEST_ID(VAL_SECURE_DEBUG_BASE, 2)
+#define TEST_DESC "Testing ADAC Protocol Host API| UT: psa_connect\n"
+TEST_PUBLISH(TEST_NUM, test_entry);
+
+void test_entry(val_api_t *val_api)
+{
+    int32_t   status = VAL_STATUS_SUCCESS;
+    val_api_t *val = NULL;
+
+    val = val_api;
+
+    /* test init */
+    val->test_init(TEST_NUM, TEST_DESC);
+    val_adac_host_init();
+
+    uint8_t *chain = NULL;
+    size_t chain_size = 0;
+
+    if (PSA_SUCCESS != val_load_certificate_chain(chain_file, &chain, &chain_size))
+        goto test_fail_exit;
+
+    psa_tlv_t *exts[MAX_EXTENSIONS];
+    size_t exts_count = 0;
+    uint8_t key_type;
+
+    if (PSA_SUCCESS != val_infer_cryptosystem((uint32_t *) chain, chain_size, exts,
+                                                           &exts_count, &key_type)) {
+        goto test_fail_exit;
+    }
+
+    request_packet_t *request;
+
+    if (PSA_SUCCESS != val_issue_command(SDP_DISCOVERY_CMD, request, NULL, 0))
+        goto test_fail_exit;
+
+    response_packet_t *response;
+
+    response = val_await_response();
+    if (PSA_SUCCESS != val_parse_response(SDP_DISCOVERY_CMD, response))
+        goto test_fail_exit;
+
+    if (!val_check_cryptosystem_support(response, key_type))
+        goto test_fail_exit;
+
+    response_packet_release(response);
+
+    psa_key_handle_t handle;
+    uint8_t *key = NULL;
+    size_t key_size = 0;
+
+    if (PSA_SUCCESS != val_get_private_key(key_file, &key_type, &handle, &key, &key_size))
+        goto test_fail_exit;
+
+    if (PSA_SUCCESS != val_issue_command(SDP_AUTH_START_CMD, request, NULL, 0))
+        goto test_fail_exit;
+
+    response = val_await_response();
+    if (PSA_SUCCESS != val_parse_response(SDP_AUTH_START_CMD, response))
+        goto test_fail_exit;
+
+    psa_auth_challenge_t *challenge = (psa_auth_challenge_t *) response->data;
+
+    uint8_t *token = NULL;
+    size_t token_size = 0;
+
+    if (PSA_SUCCESS != val_sign_token(challenge->challenge_vector,
+                                      sizeof(challenge->challenge_vector),
+                                      key_type, NULL, 0, &token, &token_size,
+                                      handle, key, key_size)) {
+        goto test_fail_exit;
+    }
+    response_packet_release(response);
+
+    if (PSA_SUCCESS != val_send_certificate(exts, exts_count))
+        goto test_fail_exit;
+
+	val->print(PRINT_INFO, "Sending token\n", 0);
+    if (PSA_SUCCESS != val_issue_command(SDP_AUTH_RESPONSE_CMD, request,
+                                        (uint8_t *)token, token_size)) {
+        goto test_fail_exit;
+    }
+
+	val->print(PRINT_INFO, "Receiving token_authentication response\n", 0);
+    response = val_await_response();
+    if (PSA_SUCCESS != val_parse_response(SDP_AUTH_RESPONSE_CMD, response))
+        goto test_fail_exit;
+
+    if (response->status == SDP_SUCCESS)
+	    val->print(PRINT_INFO, "Target unlocked successfully\n", 0);
+    else
+        goto test_fail_exit;
+
+    response_packet_release(response);
+    goto test_end;
+
+test_fail_exit:
+	val_set_status(RESULT_FAIL(VAL_STATUS_TEST_FAILED));
+test_end:
+    val->test_exit();
+}
+
diff --git a/secure-debug/tests/adac/test_a002/test_a002.h b/secure-debug/tests/adac/test_a002/test_a002.h
new file mode 100644
index 0000000..da5f094
--- /dev/null
+++ b/secure-debug/tests/adac/test_a002/test_a002.h
@@ -0,0 +1,26 @@
+/** @file
+ * Copyright (c) 2021, Arm Limited or its affiliates. All rights reserved.
+ * SPDX-License-Identifier : Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+**/
+#ifndef _TEST_A002_TESTS_H_
+#define _TEST_A002_TESTS_H_
+
+#define test_entry CONCAT(test_entry_, a002)
+
+extern val_api_t *val;
+extern char *key_file;
+extern char *chain_file;
+
+#endif /* _TEST_A002_TESTS_H_ */
diff --git a/secure-debug/tests/adac/testsuite.db b/secure-debug/tests/adac/testsuite.db
new file mode 100644
index 0000000..9695860
--- /dev/null
+++ b/secure-debug/tests/adac/testsuite.db
@@ -0,0 +1,26 @@
+#/** @file
+# * Copyright (c) 2021 Arm Limited or its affiliates. All rights reserved.
+# * SPDX-License-Identifier : Apache-2.0
+# *
+# * Licensed under the Apache License, Version 2.0 (the "License");
+# * you may not use this file except in compliance with the License.
+# * You may obtain a copy of the License at
+# *
+# *  http://www.apache.org/licenses/LICENSE-2.0
+# *
+# * Unless required by applicable law or agreed to in writing, software
+# * distributed under the License is distributed on an "AS IS" BASIS,
+# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# * See the License for the specific language governing permissions and
+# * limitations under the License.
+#**/
+
+
+#List of tests to be compiled and run as part of initial_attestation suite
+
+(START)
+
+test_a001
+test_a002
+
+(END)