pkey.h 4.3 KB

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