tpm2_identity_util.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* SPDX-License-Identifier: BSD-3-Clause */
  2. #ifndef LIB_TPM2_IDENTITY_UTIL_H_
  3. #define LIB_TPM2_IDENTITY_UTIL_H_
  4. #include <tss2/tss2_sys.h>
  5. #include <openssl/err.h>
  6. #include <openssl/hmac.h>
  7. #include <openssl/rsa.h>
  8. /**
  9. * Generates HMAC integrity and symmetric encryption keys for TPM2 identies.
  10. *
  11. * @param parent_pub
  12. * The public key used for seed generation and protection.
  13. * @param pubname
  14. * The Name object associated with the parent_pub credential.
  15. * @param protection_seed
  16. * The symmetric seed value used to generate protection keys.
  17. * @param protection_hmac_key
  18. * The HMAC integrity key to populate.
  19. * @param protection_enc_key
  20. * The symmetric encryption key to populate.
  21. * @return
  22. * True on success, false on failure.
  23. */
  24. bool tpm2_identity_util_calc_outer_integrity_hmac_key_and_dupsensitive_enc_key(
  25. TPM2B_PUBLIC *parent_pub, TPM2B_NAME *pubname,
  26. TPM2B_DIGEST *protection_seed, TPM2B_MAX_BUFFER *protection_hmac_key,
  27. TPM2B_MAX_BUFFER *protection_enc_key);
  28. /**
  29. * Encrypts a randomly generated seed with parent public key for TPM2
  30. * credential protection process.
  31. *
  32. * @param protection_seed
  33. * The identity structure protection seed to generate and populate.
  34. * @param parent_pub
  35. * The public key used for encryption.
  36. * @param label
  37. * Indicates label for the seed, such as "IDENTITY" or "DUPLICATE".
  38. * @param label_len
  39. * Length of label.
  40. * @param encrypted_protection_seed
  41. * The encrypted protection seed to populate.
  42. * @return
  43. * True on success, false on failure.
  44. */
  45. bool tpm2_identity_util_share_secret_with_public_key(
  46. TPM2B_DIGEST *protection_seed, TPM2B_PUBLIC *parent_pub,
  47. const unsigned char *label, int label_len,
  48. TPM2B_ENCRYPTED_SECRET *encrypted_protection_seed);
  49. /**
  50. * Marshalls Credential Value and encrypts it with the symmetric encryption key.
  51. *
  52. * @param name_alg
  53. * Hash algorithm used to compute Name of the public key.
  54. * @param sensitive
  55. * The Credential Value to be marshalled and encrypted with symmetric key.
  56. * @param pubname
  57. * The Name object corresponding to the public key.
  58. * @param enc_sensitive_key
  59. * The symmetric encryption key.
  60. * @param sym_alg
  61. * The algorithm used for the symmetric encryption key.
  62. * @param encrypted_inner_integrity
  63. * The encrypted, marshalled Credential Value to populate.
  64. * @return
  65. * True on success, false on failure.
  66. */
  67. bool tpm2_identity_util_calculate_inner_integrity(TPMI_ALG_HASH name_alg,
  68. TPM2B_SENSITIVE *sensitive, TPM2B_NAME *pubname,
  69. TPM2B_DATA *enc_sensitive_key, TPMT_SYM_DEF_OBJECT *sym_alg,
  70. TPM2B_MAX_BUFFER *encrypted_inner_integrity);
  71. /**
  72. * Encrypts Credential Value with enc key and calculates HMAC with hmac key.
  73. *
  74. * @param parent_name_alg
  75. * Hash algorithm used to compute Name of the public key.
  76. * @param pubname
  77. * The Name object corresponding to the public key.
  78. * @param marshalled_sensitive
  79. * Marshalled Credential Value to be encrypted with symmetric encryption key.
  80. * @param protection_hmac_key
  81. * The HMAC integrity key.
  82. * @param protection_enc_key
  83. * The symmetric encryption key.
  84. * @param sym_alg
  85. * The algorithm used for the symmetric encryption key.
  86. * @param encrypted_duplicate_sensitive
  87. * The encrypted Credential Value to populate.
  88. * @param outer_hmac
  89. * The outer HMAC structure to populate.
  90. */
  91. void tpm2_identity_util_calculate_outer_integrity(TPMI_ALG_HASH parent_name_alg,
  92. TPM2B_NAME *pubname, TPM2B_MAX_BUFFER *marshalled_sensitive,
  93. TPM2B_MAX_BUFFER *protection_hmac_key,
  94. TPM2B_MAX_BUFFER *protection_enc_key, TPMT_SYM_DEF_OBJECT *sym_alg,
  95. TPM2B_MAX_BUFFER *encrypted_duplicate_sensitive,
  96. TPM2B_DIGEST *outer_hmac);
  97. /**
  98. * Computes the name of a TPM key.
  99. *
  100. * @param public
  101. * Public key structure
  102. * @param pubname
  103. * The name structure to populate.
  104. */
  105. bool tpm2_identity_create_name(TPM2B_PUBLIC *public, TPM2B_NAME *pubname);
  106. #endif /* LIB_TPM2_IDENTITY_UTIL_H_ */