rotpk_test.c 1.4 KB

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