sys-entity-util.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* SPDX-License-Identifier: BSD-2-Clause */
  2. /***********************************************************************
  3. * Copyright (c) 2017-2018, Intel Corporation
  4. *
  5. * All rights reserved.
  6. ***********************************************************************/
  7. #ifdef HAVE_CONFIG_H
  8. #include <config.h>
  9. #endif
  10. #include "tss2_tpm2_types.h"
  11. #include "sys-util.h"
  12. #include "session-util.h"
  13. static ENTITY *entities = NULL;
  14. int
  15. AddEntity(TPM2_HANDLE handle, TPM2B_AUTH *auth)
  16. {
  17. ENTITY *e;
  18. HASH_FIND_INT(entities, &handle, e);
  19. if (!e) {
  20. e = calloc(1, sizeof(*e));
  21. if (!e)
  22. return -1;
  23. e->entityHandle = handle;
  24. HASH_ADD_INT(entities, entityHandle, e);
  25. }
  26. CopySizedByteBuffer((TPM2B *)&e->entityAuth, (TPM2B *)auth);
  27. return 0;
  28. }
  29. void
  30. DeleteEntity(TPM2_HANDLE handle)
  31. {
  32. ENTITY *e;
  33. HASH_FIND_INT(entities, &handle, e);
  34. if (!e)
  35. return;
  36. HASH_DEL(entities, e);
  37. free(e);
  38. }
  39. int
  40. GetEntityAuth(TPM2_HANDLE handle, TPM2B_AUTH *auth)
  41. {
  42. ENTITY *e;
  43. HASH_FIND_INT(entities, &handle, e);
  44. if (!e)
  45. return -1;
  46. CopySizedByteBuffer((TPM2B *)auth, (TPM2B *)&e->entityAuth);
  47. return 0;
  48. }
  49. ENTITY *
  50. GetEntity(TPM2_HANDLE handle)
  51. {
  52. ENTITY *e;
  53. HASH_FIND_INT(entities, &handle, e);
  54. return e;
  55. }