100b7e0bfSlaurenw-arm /*
2*5b46aaccSYann Gautier * Copyright (c) 2023-2025, Arm Limited and Contributors. All rights reserved.
300b7e0bfSlaurenw-arm *
400b7e0bfSlaurenw-arm * SPDX-License-Identifier: BSD-3-Clause
500b7e0bfSlaurenw-arm */
600b7e0bfSlaurenw-arm
700b7e0bfSlaurenw-arm #include <stdint.h>
800b7e0bfSlaurenw-arm #include <stdio.h>
900b7e0bfSlaurenw-arm
1000b7e0bfSlaurenw-arm #include <plat/common/platform.h>
117f8589cdSTamas Ban #include <rse_platform_api.h>
1200b7e0bfSlaurenw-arm #include <tc_plat.h>
13*5b46aaccSYann Gautier #include <tc_rse_comms.h>
1400b7e0bfSlaurenw-arm
print_hex(const char * key_id_name,size_t key_size,const uint8_t * key_buf)1500b7e0bfSlaurenw-arm static void print_hex(const char *key_id_name, size_t key_size, const uint8_t *key_buf)
1600b7e0bfSlaurenw-arm {
1700b7e0bfSlaurenw-arm printf("%s = ", key_id_name);
1800b7e0bfSlaurenw-arm for (int i = 0; i < key_size; i++) {
1900b7e0bfSlaurenw-arm printf("%02x", key_buf[i]);
2000b7e0bfSlaurenw-arm }
2100b7e0bfSlaurenw-arm printf("\n\n");
2200b7e0bfSlaurenw-arm }
2300b7e0bfSlaurenw-arm
rotpk_test(void)2400b7e0bfSlaurenw-arm int rotpk_test(void)
2500b7e0bfSlaurenw-arm {
2600b7e0bfSlaurenw-arm psa_status_t status;
2700b7e0bfSlaurenw-arm uint8_t key_buf[128];
2800b7e0bfSlaurenw-arm size_t key_size;
2900b7e0bfSlaurenw-arm
3000b7e0bfSlaurenw-arm struct key_id_info key_ids[3] = {
317f8589cdSTamas Ban {.key_id = RSE_BUILTIN_KEY_ID_HOST_S_ROTPK, .key_id_name = "Secure-ROTPK"},
327f8589cdSTamas Ban {.key_id = RSE_BUILTIN_KEY_ID_HOST_NS_ROTPK, .key_id_name = "NS-ROTPK"},
337f8589cdSTamas Ban {.key_id = RSE_BUILTIN_KEY_ID_HOST_CCA_ROTPK, .key_id_name = "CCA-ROTPK"}
3400b7e0bfSlaurenw-arm };
3500b7e0bfSlaurenw-arm
36*5b46aaccSYann Gautier status = plat_rse_comms_init();
3700b7e0bfSlaurenw-arm if (status != PSA_SUCCESS) {
38*5b46aaccSYann Gautier printf("Failed to initialize RSE communication channel - psa_status = %d\n",
39*5b46aaccSYann Gautier status);
4000b7e0bfSlaurenw-arm return -1;
4100b7e0bfSlaurenw-arm }
4200b7e0bfSlaurenw-arm
4300b7e0bfSlaurenw-arm for (int i = 0; i < ARRAY_SIZE(key_ids); i++) {
447f8589cdSTamas Ban status = rse_platform_key_read(key_ids[i].key_id, key_buf,
4500b7e0bfSlaurenw-arm sizeof(key_buf), &key_size);
4600b7e0bfSlaurenw-arm if (status != PSA_SUCCESS) {
47*5b46aaccSYann Gautier printf("Failed to retrieve %s - psa_status = %d\n", key_ids[i].key_id_name,
48*5b46aaccSYann Gautier status);
4900b7e0bfSlaurenw-arm return -1;
5000b7e0bfSlaurenw-arm }
5100b7e0bfSlaurenw-arm print_hex(key_ids[i].key_id_name, key_size, key_buf);
5200b7e0bfSlaurenw-arm }
5300b7e0bfSlaurenw-arm
5400b7e0bfSlaurenw-arm printf("Passed rotpk_test\n");
5500b7e0bfSlaurenw-arm
5600b7e0bfSlaurenw-arm return 0;
5700b7e0bfSlaurenw-arm }
58