trusted_tpm.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __TRUSTED_TPM_H
  3. #define __TRUSTED_TPM_H
  4. #include <keys/trusted-type.h>
  5. #include <linux/tpm_command.h>
  6. /* implementation specific TPM constants */
  7. #define TPM_SIZE_OFFSET 2
  8. #define TPM_RETURN_OFFSET 6
  9. #define TPM_DATA_OFFSET 10
  10. #define LOAD32(buffer, offset) (ntohl(*(uint32_t *)&buffer[offset]))
  11. #define LOAD32N(buffer, offset) (*(uint32_t *)&buffer[offset])
  12. #define LOAD16(buffer, offset) (ntohs(*(uint16_t *)&buffer[offset]))
  13. extern struct trusted_key_ops trusted_key_tpm_ops;
  14. struct osapsess {
  15. uint32_t handle;
  16. unsigned char secret[SHA1_DIGEST_SIZE];
  17. unsigned char enonce[TPM_NONCE_SIZE];
  18. };
  19. /* discrete values, but have to store in uint16_t for TPM use */
  20. enum {
  21. SEAL_keytype = 1,
  22. SRK_keytype = 4
  23. };
  24. int TSS_authhmac(unsigned char *digest, const unsigned char *key,
  25. unsigned int keylen, unsigned char *h1,
  26. unsigned char *h2, unsigned int h3, ...);
  27. int TSS_checkhmac1(unsigned char *buffer,
  28. const uint32_t command,
  29. const unsigned char *ononce,
  30. const unsigned char *key,
  31. unsigned int keylen, ...);
  32. int trusted_tpm_send(unsigned char *cmd, size_t buflen);
  33. int oiap(struct tpm_buf *tb, uint32_t *handle, unsigned char *nonce);
  34. int tpm2_seal_trusted(struct tpm_chip *chip,
  35. struct trusted_key_payload *payload,
  36. struct trusted_key_options *options);
  37. int tpm2_unseal_trusted(struct tpm_chip *chip,
  38. struct trusted_key_payload *payload,
  39. struct trusted_key_options *options);
  40. #define TPM_DEBUG 0
  41. #if TPM_DEBUG
  42. static inline void dump_options(struct trusted_key_options *o)
  43. {
  44. pr_info("sealing key type %d\n", o->keytype);
  45. pr_info("sealing key handle %0X\n", o->keyhandle);
  46. pr_info("pcrlock %d\n", o->pcrlock);
  47. pr_info("pcrinfo %d\n", o->pcrinfo_len);
  48. print_hex_dump(KERN_INFO, "pcrinfo ", DUMP_PREFIX_NONE,
  49. 16, 1, o->pcrinfo, o->pcrinfo_len, 0);
  50. }
  51. static inline void dump_sess(struct osapsess *s)
  52. {
  53. print_hex_dump(KERN_INFO, "trusted-key: handle ", DUMP_PREFIX_NONE,
  54. 16, 1, &s->handle, 4, 0);
  55. pr_info("secret:\n");
  56. print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE,
  57. 16, 1, &s->secret, SHA1_DIGEST_SIZE, 0);
  58. pr_info("trusted-key: enonce:\n");
  59. print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE,
  60. 16, 1, &s->enonce, SHA1_DIGEST_SIZE, 0);
  61. }
  62. static inline void dump_tpm_buf(unsigned char *buf)
  63. {
  64. int len;
  65. pr_info("\ntpm buffer\n");
  66. len = LOAD32(buf, TPM_SIZE_OFFSET);
  67. print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 16, 1, buf, len, 0);
  68. }
  69. #else
  70. static inline void dump_options(struct trusted_key_options *o)
  71. {
  72. }
  73. static inline void dump_sess(struct osapsess *s)
  74. {
  75. }
  76. static inline void dump_tpm_buf(unsigned char *buf)
  77. {
  78. }
  79. #endif
  80. #endif