pkey.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Userspace interface to the pkey device driver
  3. *
  4. * Copyright IBM Corp. 2017
  5. *
  6. * Author: Harald Freudenberger <freude@de.ibm.com>
  7. *
  8. */
  9. #ifndef _UAPI_PKEY_H
  10. #define _UAPI_PKEY_H
  11. #include <linux/ioctl.h>
  12. #include <linux/types.h>
  13. /*
  14. * Ioctl calls supported by the pkey device driver
  15. */
  16. #define PKEY_IOCTL_MAGIC 'p'
  17. #define SECKEYBLOBSIZE 64 /* secure key blob size is always 64 bytes */
  18. #define MAXPROTKEYSIZE 64 /* a protected key blob may be up to 64 bytes */
  19. #define MAXCLRKEYSIZE 32 /* a clear key value may be up to 32 bytes */
  20. /* defines for the type field within the pkey_protkey struct */
  21. #define PKEY_KEYTYPE_AES_128 1
  22. #define PKEY_KEYTYPE_AES_192 2
  23. #define PKEY_KEYTYPE_AES_256 3
  24. /* Struct to hold a secure key blob */
  25. struct pkey_seckey {
  26. __u8 seckey[SECKEYBLOBSIZE]; /* the secure key blob */
  27. };
  28. /* Struct to hold protected key and length info */
  29. struct pkey_protkey {
  30. __u32 type; /* key type, one of the PKEY_KEYTYPE values */
  31. __u32 len; /* bytes actually stored in protkey[] */
  32. __u8 protkey[MAXPROTKEYSIZE]; /* the protected key blob */
  33. };
  34. /* Struct to hold a clear key value */
  35. struct pkey_clrkey {
  36. __u8 clrkey[MAXCLRKEYSIZE]; /* 16, 24, or 32 byte clear key value */
  37. };
  38. /*
  39. * Generate secure key
  40. */
  41. struct pkey_genseck {
  42. __u16 cardnr; /* in: card to use or FFFF for any */
  43. __u16 domain; /* in: domain or FFFF for any */
  44. __u32 keytype; /* in: key type to generate */
  45. struct pkey_seckey seckey; /* out: the secure key blob */
  46. };
  47. #define PKEY_GENSECK _IOWR(PKEY_IOCTL_MAGIC, 0x01, struct pkey_genseck)
  48. /*
  49. * Construct secure key from clear key value
  50. */
  51. struct pkey_clr2seck {
  52. __u16 cardnr; /* in: card to use or FFFF for any */
  53. __u16 domain; /* in: domain or FFFF for any */
  54. __u32 keytype; /* in: key type to generate */
  55. struct pkey_clrkey clrkey; /* in: the clear key value */
  56. struct pkey_seckey seckey; /* out: the secure key blob */
  57. };
  58. #define PKEY_CLR2SECK _IOWR(PKEY_IOCTL_MAGIC, 0x02, struct pkey_clr2seck)
  59. /*
  60. * Fabricate protected key from a secure key
  61. */
  62. struct pkey_sec2protk {
  63. __u16 cardnr; /* in: card to use or FFFF for any */
  64. __u16 domain; /* in: domain or FFFF for any */
  65. struct pkey_seckey seckey; /* in: the secure key blob */
  66. struct pkey_protkey protkey; /* out: the protected key */
  67. };
  68. #define PKEY_SEC2PROTK _IOWR(PKEY_IOCTL_MAGIC, 0x03, struct pkey_sec2protk)
  69. /*
  70. * Fabricate protected key from an clear key value
  71. */
  72. struct pkey_clr2protk {
  73. __u32 keytype; /* in: key type to generate */
  74. struct pkey_clrkey clrkey; /* in: the clear key value */
  75. struct pkey_protkey protkey; /* out: the protected key */
  76. };
  77. #define PKEY_CLR2PROTK _IOWR(PKEY_IOCTL_MAGIC, 0x04, struct pkey_clr2protk)
  78. /*
  79. * Search for matching crypto card based on the Master Key
  80. * Verification Pattern provided inside a secure key.
  81. */
  82. struct pkey_findcard {
  83. struct pkey_seckey seckey; /* in: the secure key blob */
  84. __u16 cardnr; /* out: card number */
  85. __u16 domain; /* out: domain number */
  86. };
  87. #define PKEY_FINDCARD _IOWR(PKEY_IOCTL_MAGIC, 0x05, struct pkey_findcard)
  88. /*
  89. * Combined together: findcard + sec2prot
  90. */
  91. struct pkey_skey2pkey {
  92. struct pkey_seckey seckey; /* in: the secure key blob */
  93. struct pkey_protkey protkey; /* out: the protected key */
  94. };
  95. #define PKEY_SKEY2PKEY _IOWR(PKEY_IOCTL_MAGIC, 0x06, struct pkey_skey2pkey)
  96. /*
  97. * Verify the given secure key for being able to be useable with
  98. * the pkey module. Check for correct key type and check for having at
  99. * least one crypto card being able to handle this key (master key
  100. * or old master key verification pattern matches).
  101. * Return some info about the key: keysize in bits, keytype (currently
  102. * only AES), flag if key is wrapped with an old MKVP.
  103. */
  104. struct pkey_verifykey {
  105. struct pkey_seckey seckey; /* in: the secure key blob */
  106. __u16 cardnr; /* out: card number */
  107. __u16 domain; /* out: domain number */
  108. __u16 keysize; /* out: key size in bits */
  109. __u32 attributes; /* out: attribute bits */
  110. };
  111. #define PKEY_VERIFYKEY _IOWR(PKEY_IOCTL_MAGIC, 0x07, struct pkey_verifykey)
  112. #define PKEY_VERIFY_ATTR_AES 0x00000001 /* key is an AES key */
  113. #define PKEY_VERIFY_ATTR_OLD_MKVP 0x00000100 /* key has old MKVP value */
  114. #endif /* _UAPI_PKEY_H */