1 /*
2 * Copyright (c) 2023, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #include <stdint.h>
8 #include <stdio.h>
9
10 #include <drivers/arm/rss_comms.h>
11 #include <plat/common/platform.h>
12 #include <rss_platform_api.h>
13 #include <tc_plat.h>
14
print_hex(const char * key_id_name,size_t key_size,const uint8_t * key_buf)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
rotpk_test(void)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 = RSS_BUILTIN_KEY_ID_HOST_S_ROTPK, .key_id_name = "Secure-ROTPK"},
32 {.key_id = RSS_BUILTIN_KEY_ID_HOST_NS_ROTPK, .key_id_name = "NS-ROTPK"},
33 {.key_id = RSS_BUILTIN_KEY_ID_HOST_CCA_ROTPK, .key_id_name = "CCA-ROTPK"}
34 };
35
36 status = rss_comms_init(PLAT_RSS_AP_SND_MHU_BASE, PLAT_RSS_AP_RCV_MHU_BASE);
37 if (status != PSA_SUCCESS) {
38 printf("Failed to initialize RSS communication channel - psa_status = %d\n", status);
39 return -1;
40 }
41
42 for (int i = 0; i < ARRAY_SIZE(key_ids); i++) {
43 status = rss_platform_key_read(key_ids[i].key_id, key_buf,
44 sizeof(key_buf), &key_size);
45 if (status != PSA_SUCCESS) {
46 printf("Failed to retrieve %s - psa_status = %d\n", key_ids[i].key_id_name, status);
47 return -1;
48 }
49 print_hex(key_ids[i].key_id_name, key_size, key_buf);
50 }
51
52 printf("Passed rotpk_test\n");
53
54 return 0;
55 }
56