fvp_el3_token_sign.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (c) 2024, NVIDIA Corporation. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <errno.h>
  7. #include <string.h>
  8. #include <plat/common/platform.h>
  9. #include <services/rmm_el3_token_sign.h>
  10. static struct el3_token_sign_request el3_req = { 0 };
  11. static bool el3_req_valid;
  12. /*
  13. * According to https://www.secg.org/sec1-v2.pdf 2.3.3
  14. * the size of the ECDSA P384 public key is 97 bytes,
  15. * with the first byte being 0x04.
  16. */
  17. static uint8_t sample_attest_pub_key[] = {
  18. 0x04, 0x76, 0xf9, 0x88, 0x09, 0x1b, 0xe5, 0x85, 0xed, 0x41,
  19. 0x80, 0x1a, 0xec, 0xfa, 0xb8, 0x58, 0x54, 0x8c, 0x63, 0x05,
  20. 0x7e, 0x16, 0xb0, 0xe6, 0x76, 0x12, 0x0b, 0xbd, 0x0d, 0x2f,
  21. 0x9c, 0x29, 0xe0, 0x56, 0xc5, 0xd4, 0x1a, 0x01, 0x30, 0xeb,
  22. 0x9c, 0x21, 0x51, 0x78, 0x99, 0xdc, 0x23, 0x14, 0x6b, 0x28,
  23. 0xe1, 0xb0, 0x62, 0xbd, 0x3e, 0xa4, 0xb3, 0x15, 0xfd, 0x21,
  24. 0x9f, 0x1c, 0xbb, 0x52, 0x8c, 0xb6, 0xe7, 0x4c, 0xa4, 0x9b,
  25. 0xe1, 0x67, 0x73, 0x73, 0x4f, 0x61, 0xa1, 0xca, 0x61, 0x03,
  26. 0x1b, 0x2b, 0xbf, 0x3d, 0x91, 0x8f, 0x2f, 0x94, 0xff, 0xc4,
  27. 0x22, 0x8e, 0x50, 0x91, 0x95, 0x44, 0xae
  28. };
  29. /*
  30. * FVP does not support HES, so provide 0's as keys.
  31. */
  32. int plat_rmmd_el3_token_sign_get_rak_pub(uintptr_t buf, size_t *len,
  33. unsigned int type)
  34. {
  35. (void)type;
  36. if (*len < sizeof(sample_attest_pub_key)) {
  37. return E_RMM_INVAL;
  38. }
  39. if (type != ATTEST_KEY_CURVE_ECC_SECP384R1) {
  40. ERROR("Invalid ECC curve specified\n");
  41. return E_RMM_INVAL;
  42. }
  43. *len = sizeof(sample_attest_pub_key);
  44. (void)memcpy((void *)buf, sample_attest_pub_key,
  45. sizeof(sample_attest_pub_key));
  46. return 0;
  47. }
  48. int plat_rmmd_el3_token_sign_push_req(const struct el3_token_sign_request *req)
  49. {
  50. /*
  51. * TODO: Today this function is called with a lock held on the
  52. * RMM<->EL3 shared buffer. In the future, we may move to a
  53. * different design that may require handling multi-threaded
  54. * calls to this function, for example, if we have a per CPU
  55. * buffer between RMM and EL3.
  56. */
  57. if (el3_req_valid) {
  58. return E_RMM_AGAIN;
  59. }
  60. el3_req = *req;
  61. if ((el3_req.hash_alg_id != EL3_TOKEN_SIGN_HASH_ALG_SHA384) ||
  62. (el3_req.sig_alg_id != ATTEST_KEY_CURVE_ECC_SECP384R1)) {
  63. return E_RMM_INVAL;
  64. }
  65. el3_req_valid = true;
  66. return 0;
  67. }
  68. int plat_rmmd_el3_token_sign_pull_resp(struct el3_token_sign_response *resp)
  69. {
  70. if (!el3_req_valid) {
  71. return E_RMM_AGAIN;
  72. }
  73. resp->rec_granule = el3_req.rec_granule;
  74. resp->req_ticket = el3_req.req_ticket;
  75. resp->sig_len = (uint16_t)sizeof(resp->signature_buf);
  76. /* TODO: Provide real signature */
  77. memset(resp->signature_buf, 0, sizeof(resp->signature_buf));
  78. el3_req_valid = false;
  79. return 0;
  80. }