plat_tbbr.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <string.h>
  8. #include <drivers/auth/auth_mod.h>
  9. #include <plat/common/platform.h>
  10. #if USE_TBBR_DEFS
  11. #include <tools_share/tbbr_oid.h>
  12. #else
  13. #include <platform_oid.h>
  14. #endif
  15. /*
  16. * Store a new non-volatile counter value. This implementation
  17. * only allows updating of the platform's Trusted NV counter when a
  18. * certificate protected by the Trusted NV counter is signed with
  19. * the ROT key. This avoids a compromised secondary certificate from
  20. * updating the platform's Trusted NV counter, which could lead to the
  21. * platform becoming unusable. The function is suitable for all TBBR
  22. * compliant platforms.
  23. *
  24. * Return: 0 = success, Otherwise = error
  25. */
  26. int plat_set_nv_ctr2(void *cookie, const auth_img_desc_t *img_desc,
  27. unsigned int nv_ctr)
  28. {
  29. int trusted_nv_ctr;
  30. assert(cookie != NULL);
  31. assert(img_desc != NULL);
  32. trusted_nv_ctr = strcmp(cookie, TRUSTED_FW_NVCOUNTER_OID) == 0;
  33. /*
  34. * Only update the Trusted NV Counter if the certificate
  35. * has been signed with the ROT key. Non Trusted NV counter
  36. * updates are unconditional.
  37. */
  38. if (!trusted_nv_ctr || img_desc->parent == NULL)
  39. return plat_set_nv_ctr(cookie, nv_ctr);
  40. /*
  41. * Trusted certificates not signed with the ROT key are not
  42. * allowed to update the Trusted NV Counter.
  43. */
  44. return 1;
  45. }