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