sys-create-keyedhash-sha1-hmac.int.c 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 <stdlib.h>
  11. #include "tss2_tpm2_types.h"
  12. #include "inttypes.h"
  13. #define LOGMODULE test
  14. #include "util/log.h"
  15. #include "sys-util.h"
  16. #include "test.h"
  17. int
  18. test_invoke (TSS2_SYS_CONTEXT *sys_context)
  19. {
  20. TSS2_RC rc = TPM2_RC_SUCCESS;
  21. TPM2_HANDLE parent_handle = 0;
  22. TPM2B_SENSITIVE_CREATE inSensitive = { 0 };
  23. TPM2B_DATA outsideInfo = { 0 };
  24. TPML_PCR_SELECTION creationPCR = { 0 };
  25. TPM2B_PRIVATE outPrivate = TPM2B_PRIVATE_INIT;
  26. TPM2B_PUBLIC inPublic = { 0 };
  27. TPM2B_PUBLIC outPublic = { 0 };
  28. TPM2B_CREATION_DATA creationData = { 0 };
  29. TPM2B_DIGEST creationHash = TPM2B_DIGEST_INIT;
  30. TPMT_TK_CREATION creationTicket = { 0 };
  31. /* session parameters */
  32. /* command session info */
  33. TSS2L_SYS_AUTH_COMMAND sessions_cmd = {
  34. .auths = {{ .sessionHandle = TPM2_RH_PW }},
  35. .count = 1
  36. };
  37. /* response session info */
  38. TSS2L_SYS_AUTH_RESPONSE sessions_rsp = {
  39. .auths = { 0 },
  40. .count = 0
  41. };
  42. rc = create_primary_rsa_2048_aes_128_cfb (sys_context, &parent_handle);
  43. if (rc == TSS2_RC_SUCCESS) {
  44. LOG_INFO("primary created successfully: 0x%" PRIx32, parent_handle);
  45. } else {
  46. LOG_ERROR("CreatePrimary failed with 0x%" PRIx32, rc);
  47. return 99; /* fatal error */
  48. }
  49. inPublic.publicArea.nameAlg = TPM2_ALG_SHA1;
  50. inPublic.publicArea.type = TPM2_ALG_KEYEDHASH;
  51. inPublic.publicArea.objectAttributes |= TPMA_OBJECT_SIGN_ENCRYPT;
  52. inPublic.publicArea.objectAttributes |= TPMA_OBJECT_SENSITIVEDATAORIGIN;
  53. inPublic.publicArea.parameters.keyedHashDetail.scheme.scheme = TPM2_ALG_HMAC;
  54. inPublic.publicArea.parameters.keyedHashDetail.scheme.details.hmac.hashAlg = TPM2_ALG_SHA1;
  55. LOG_INFO("Create keyedhash SHA1 HMAC");
  56. rc = TSS2_RETRY_EXP (Tss2_Sys_Create (sys_context,
  57. parent_handle,
  58. &sessions_cmd,
  59. &inSensitive,
  60. &inPublic,
  61. &outsideInfo,
  62. &creationPCR,
  63. &outPrivate,
  64. &outPublic,
  65. &creationData,
  66. &creationHash,
  67. &creationTicket,
  68. &sessions_rsp));
  69. if (rc == TPM2_RC_SUCCESS) {
  70. LOG_INFO("success");
  71. } else {
  72. LOG_ERROR("Create FAILED! Response Code : 0x%x", rc);
  73. return 1;
  74. }
  75. rc = Tss2_Sys_FlushContext(sys_context, parent_handle);
  76. if (rc != TSS2_RC_SUCCESS) {
  77. LOG_ERROR("Tss2_Sys_FlushContext failed with 0x%"PRIx32, rc);
  78. return 99; /* fatal error */
  79. }
  80. return 0;
  81. }