rse_platform.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (c) 2023, Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #include <psa/client.h>
  8. #include <psa_manifest/sid.h>
  9. #include <rse_crypto_defs.h>
  10. #include <rse_platform_api.h>
  11. psa_status_t
  12. rse_platform_nv_counter_increment(uint32_t counter_id)
  13. {
  14. struct psa_invec in_vec[1];
  15. in_vec[0].base = &counter_id;
  16. in_vec[0].len = sizeof(counter_id);
  17. return psa_call(RSE_PLATFORM_SERVICE_HANDLE,
  18. RSE_PLATFORM_API_ID_NV_INCREMENT,
  19. in_vec, 1, NULL, 0);
  20. }
  21. psa_status_t
  22. rse_platform_nv_counter_read(uint32_t counter_id,
  23. uint32_t size, uint8_t *val)
  24. {
  25. struct psa_invec in_vec[1];
  26. struct psa_outvec out_vec[1];
  27. in_vec[0].base = &counter_id;
  28. in_vec[0].len = sizeof(counter_id);
  29. out_vec[0].base = val;
  30. out_vec[0].len = size;
  31. return psa_call(RSE_PLATFORM_SERVICE_HANDLE,
  32. RSE_PLATFORM_API_ID_NV_READ,
  33. in_vec, 1, out_vec, 1);
  34. }
  35. psa_status_t
  36. rse_platform_key_read(enum rse_key_id_builtin_t key, uint8_t *data,
  37. size_t data_size, size_t *data_length)
  38. {
  39. psa_status_t status;
  40. struct rse_crypto_pack_iovec iov = {
  41. .function_id = RSE_CRYPTO_EXPORT_PUBLIC_KEY_SID,
  42. .key_id = key,
  43. };
  44. psa_invec in_vec[] = {
  45. {.base = &iov, .len = sizeof(struct rse_crypto_pack_iovec)},
  46. };
  47. psa_outvec out_vec[] = {
  48. {.base = data, .len = data_size}
  49. };
  50. status = psa_call(RSE_CRYPTO_HANDLE, PSA_IPC_CALL,
  51. in_vec, IOVEC_LEN(in_vec),
  52. out_vec, IOVEC_LEN(out_vec));
  53. *data_length = out_vec[0].len;
  54. return status;
  55. }