esys-hash.int.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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_esys.h"
  11. #include "esys_iutil.h"
  12. #define LOGMODULE test
  13. #include "util/log.h"
  14. #include "util/aux_util.h"
  15. /** This test is intended to test the ESYS command Esys_HASH.
  16. *
  17. * The test checks whether the TPM hash function can be used via the ESYS.
  18. *
  19. * Tested ESYS commands:
  20. * - Esys_Hash() (M)
  21. *
  22. * @param[in,out] esys_context The ESYS_CONTEXT.
  23. * @param[in] hierarchy the hierarchy to perform the hash in.
  24. * @retval EXIT_FAILURE
  25. * @retval EXIT_SUCCESS
  26. */
  27. int
  28. test_esys_hash(ESYS_CONTEXT * esys_context, ESYS_TR hierarchy)
  29. {
  30. TSS2_RC r;
  31. TPM2B_MAX_BUFFER data = { .size = 20,
  32. .buffer={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
  33. 1, 2, 3, 4, 5, 6, 7, 8, 9}};
  34. TPMI_ALG_HASH hashAlg = TPM2_ALG_SHA256;
  35. TPM2B_DIGEST *outHash = NULL;
  36. TPMT_TK_HASHCHECK *validation = NULL;
  37. r = Esys_Hash(
  38. esys_context,
  39. ESYS_TR_NONE,
  40. ESYS_TR_NONE,
  41. ESYS_TR_NONE,
  42. &data,
  43. hashAlg,
  44. hierarchy,
  45. &outHash,
  46. &validation);
  47. goto_if_error(r, "Error: Hash", error);
  48. Esys_Free(outHash);
  49. Esys_Free(validation);
  50. return EXIT_SUCCESS;
  51. error:
  52. Esys_Free(outHash);
  53. Esys_Free(validation);
  54. return EXIT_FAILURE;
  55. }
  56. int
  57. test_invoke_esys(ESYS_CONTEXT * esys_context) {
  58. int rc = test_esys_hash(esys_context, ESYS_TR_RH_OWNER);
  59. if (rc)
  60. return rc;
  61. /*
  62. * Test that backwards compat API change is still working, see:
  63. * - https://github.com/tpm2-software/tpm2-tss/issues/1750
  64. */
  65. return test_esys_hash(esys_context, TPM2_RH_OWNER);
  66. }