100b7e0bfSlaurenw-arm /* 200b7e0bfSlaurenw-arm * Copyright (c) 2023, Arm Limited. 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 10*7f8589cdSTamas Ban #include <drivers/arm/rse_comms.h> 1100b7e0bfSlaurenw-arm #include <plat/common/platform.h> 12*7f8589cdSTamas Ban #include <rse_platform_api.h> 1300b7e0bfSlaurenw-arm #include <tc_plat.h> 1400b7e0bfSlaurenw-arm 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 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] = { 31*7f8589cdSTamas Ban {.key_id = RSE_BUILTIN_KEY_ID_HOST_S_ROTPK, .key_id_name = "Secure-ROTPK"}, 32*7f8589cdSTamas Ban {.key_id = RSE_BUILTIN_KEY_ID_HOST_NS_ROTPK, .key_id_name = "NS-ROTPK"}, 33*7f8589cdSTamas Ban {.key_id = RSE_BUILTIN_KEY_ID_HOST_CCA_ROTPK, .key_id_name = "CCA-ROTPK"} 3400b7e0bfSlaurenw-arm }; 3500b7e0bfSlaurenw-arm 36*7f8589cdSTamas Ban status = rse_comms_init(PLAT_RSE_AP_SND_MHU_BASE, PLAT_RSE_AP_RCV_MHU_BASE); 3700b7e0bfSlaurenw-arm if (status != PSA_SUCCESS) { 38*7f8589cdSTamas Ban printf("Failed to initialize RSE communication channel - psa_status = %d\n", status); 3900b7e0bfSlaurenw-arm return -1; 4000b7e0bfSlaurenw-arm } 4100b7e0bfSlaurenw-arm 4200b7e0bfSlaurenw-arm for (int i = 0; i < ARRAY_SIZE(key_ids); i++) { 43*7f8589cdSTamas Ban status = rse_platform_key_read(key_ids[i].key_id, key_buf, 4400b7e0bfSlaurenw-arm sizeof(key_buf), &key_size); 4500b7e0bfSlaurenw-arm if (status != PSA_SUCCESS) { 46cb6b7505Slaurenw-arm printf("Failed to retrieve %s - psa_status = %d\n", key_ids[i].key_id_name, status); 4700b7e0bfSlaurenw-arm return -1; 4800b7e0bfSlaurenw-arm } 4900b7e0bfSlaurenw-arm print_hex(key_ids[i].key_id_name, key_size, key_buf); 5000b7e0bfSlaurenw-arm } 5100b7e0bfSlaurenw-arm 5200b7e0bfSlaurenw-arm printf("Passed rotpk_test\n"); 5300b7e0bfSlaurenw-arm 5400b7e0bfSlaurenw-arm return 0; 5500b7e0bfSlaurenw-arm } 56