esys-tr-getName-hierarchy.int.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* SPDX-License-Identifier: BSD-2-Clause */
  2. /*******************************************************************************
  3. * Copyright 2017-2018, Fraunhofer SIT sponsored by Infineon Technologies AG
  4. * All rights reserved.
  5. *******************************************************************************/
  6. #ifdef HAVE_CONFIG_H
  7. #include <config.h>
  8. #endif
  9. #include <stdlib.h>
  10. #include "tss2_mu.h"
  11. #include "tss2_esys.h"
  12. #include "esys_iutil.h"
  13. #define LOGMODULE test
  14. #include "util/log.h"
  15. #include "util/aux_util.h"
  16. /** This tests the Esys_TR_FromTPMPublic and Esys_TR_GetName functions by
  17. * creating an NV Index and then attempting to retrieve an ESYS_TR object for
  18. * it.
  19. * Then we call Esys_TR_GetName to see if the correct public name has been
  20. * retrieved.
  21. *
  22. * Tested ESYS commands:
  23. *
  24. * @param[in,out] ectx The ESYS_CONTEXT.
  25. * @retval EXIT_FAILURE
  26. * @retval EXIT_SUCCESS
  27. */
  28. int
  29. test_esys_tr_getName_hierarchy(ESYS_CONTEXT * ectx)
  30. {
  31. TSS2_RC r;
  32. TPM2B_NAME name1, *name2;
  33. size_t offset = 0;
  34. r = Tss2_MU_TPM2_HANDLE_Marshal(TPM2_RH_OWNER, &name1.name[0],
  35. sizeof(name1.name), &offset);
  36. goto_if_error(r, "Marshaling name", error);
  37. name1.size = offset;
  38. r = Esys_TR_GetName(ectx, ESYS_TR_RH_OWNER, &name2);
  39. goto_if_error(r, "TR get name", error);
  40. if (name1.size != name2->size ||
  41. memcmp(&name1.name[0], &name2->name[0], name1.size) != 0)
  42. {
  43. free(name2);
  44. LOG_ERROR("Names mismatch between NV_GetPublic and TR_GetName");
  45. return EXIT_FAILURE;
  46. }
  47. free(name2);
  48. return EXIT_SUCCESS;
  49. error:
  50. return EXIT_FAILURE;
  51. }
  52. int
  53. test_invoke_esys(ESYS_CONTEXT * esys_context) {
  54. return test_esys_tr_getName_hierarchy(esys_context);
  55. }