xref: /rk3399_ARM-atf/plat/arm/board/tc/rotpk_test.c (revision b47dddd061e92054c3b2096fc8aa9688bfef68d6)
1 /*
2  * Copyright (c) 2023-2025, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <stdint.h>
8 #include <stdio.h>
9 
10 #include <plat/common/platform.h>
11 #include <rse_platform_api.h>
12 #include <tc_plat.h>
13 #include <tc_rse_comms.h>
14 
15 static void print_hex(const char *key_id_name, size_t key_size, const uint8_t *key_buf)
16 {
17 	printf("%s = ", key_id_name);
18 	for (int i = 0; i < key_size; i++) {
19 		printf("%02x", key_buf[i]);
20 	}
21 	printf("\n\n");
22 }
23 
24 int rotpk_test(void)
25 {
26 	psa_status_t status;
27 	uint8_t key_buf[128];
28 	size_t key_size;
29 
30 	struct key_id_info key_ids[3] = {
31 	       {.key_id = RSE_BUILTIN_KEY_ID_HOST_S_ROTPK,  .key_id_name = "Secure-ROTPK"},
32 	       {.key_id = RSE_BUILTIN_KEY_ID_HOST_NS_ROTPK,  .key_id_name = "NS-ROTPK"},
33 	       {.key_id = RSE_BUILTIN_KEY_ID_HOST_CCA_ROTPK,  .key_id_name = "CCA-ROTPK"}
34 	};
35 
36 	status = plat_rse_comms_init();
37 	if (status != PSA_SUCCESS) {
38 		printf("Failed to initialize RSE communication channel - psa_status = %d\n",
39 		       status);
40 		return -1;
41 	}
42 
43 	for (int i = 0; i < ARRAY_SIZE(key_ids); i++) {
44 		status = rse_platform_key_read(key_ids[i].key_id, key_buf,
45 			       sizeof(key_buf), &key_size);
46 		if (status != PSA_SUCCESS) {
47 			printf("Failed to retrieve %s - psa_status = %d\n", key_ids[i].key_id_name,
48 			       status);
49 			return -1;
50 		}
51 		print_hex(key_ids[i].key_id_name, key_size, key_buf);
52 	}
53 
54 	printf("Passed rotpk_test\n");
55 
56 	return 0;
57 }
58