pkey.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Kernelspace interface to the pkey device driver
  4. *
  5. * Copyright IBM Corp. 2016
  6. *
  7. * Author: Harald Freudenberger <freude@de.ibm.com>
  8. *
  9. */
  10. #ifndef _KAPI_PKEY_H
  11. #define _KAPI_PKEY_H
  12. #include <linux/ioctl.h>
  13. #include <linux/types.h>
  14. #include <uapi/asm/pkey.h>
  15. /*
  16. * Generate (AES) random secure key.
  17. * @param cardnr may be -1 (use default card)
  18. * @param domain may be -1 (use default domain)
  19. * @param keytype one of the PKEY_KEYTYPE values
  20. * @param seckey pointer to buffer receiving the secure key
  21. * @return 0 on success, negative errno value on failure
  22. */
  23. int pkey_genseckey(__u16 cardnr, __u16 domain,
  24. __u32 keytype, struct pkey_seckey *seckey);
  25. /*
  26. * Generate (AES) secure key with given key value.
  27. * @param cardnr may be -1 (use default card)
  28. * @param domain may be -1 (use default domain)
  29. * @param keytype one of the PKEY_KEYTYPE values
  30. * @param clrkey pointer to buffer with clear key data
  31. * @param seckey pointer to buffer receiving the secure key
  32. * @return 0 on success, negative errno value on failure
  33. */
  34. int pkey_clr2seckey(__u16 cardnr, __u16 domain, __u32 keytype,
  35. const struct pkey_clrkey *clrkey,
  36. struct pkey_seckey *seckey);
  37. /*
  38. * Derive (AES) proteced key from the (AES) secure key blob.
  39. * @param cardnr may be -1 (use default card)
  40. * @param domain may be -1 (use default domain)
  41. * @param seckey pointer to buffer with the input secure key
  42. * @param protkey pointer to buffer receiving the protected key and
  43. * additional info (type, length)
  44. * @return 0 on success, negative errno value on failure
  45. */
  46. int pkey_sec2protkey(__u16 cardnr, __u16 domain,
  47. const struct pkey_seckey *seckey,
  48. struct pkey_protkey *protkey);
  49. /*
  50. * Derive (AES) protected key from a given clear key value.
  51. * @param keytype one of the PKEY_KEYTYPE values
  52. * @param clrkey pointer to buffer with clear key data
  53. * @param protkey pointer to buffer receiving the protected key and
  54. * additional info (type, length)
  55. * @return 0 on success, negative errno value on failure
  56. */
  57. int pkey_clr2protkey(__u32 keytype,
  58. const struct pkey_clrkey *clrkey,
  59. struct pkey_protkey *protkey);
  60. /*
  61. * Search for a matching crypto card based on the Master Key
  62. * Verification Pattern provided inside a secure key.
  63. * @param seckey pointer to buffer with the input secure key
  64. * @param cardnr pointer to cardnr, receives the card number on success
  65. * @param domain pointer to domain, receives the domain number on success
  66. * @param verify if set, always verify by fetching verification pattern
  67. * from card
  68. * @return 0 on success, negative errno value on failure. If no card could be
  69. * found, -ENODEV is returned.
  70. */
  71. int pkey_findcard(const struct pkey_seckey *seckey,
  72. __u16 *cardnr, __u16 *domain, int verify);
  73. /*
  74. * Find card and transform secure key to protected key.
  75. * @param seckey pointer to buffer with the input secure key
  76. * @param protkey pointer to buffer receiving the protected key and
  77. * additional info (type, length)
  78. * @return 0 on success, negative errno value on failure
  79. */
  80. int pkey_skey2pkey(const struct pkey_seckey *seckey,
  81. struct pkey_protkey *protkey);
  82. /*
  83. * Verify the given secure key for being able to be useable with
  84. * the pkey module. Check for correct key type and check for having at
  85. * least one crypto card being able to handle this key (master key
  86. * or old master key verification pattern matches).
  87. * Return some info about the key: keysize in bits, keytype (currently
  88. * only AES), flag if key is wrapped with an old MKVP.
  89. * @param seckey pointer to buffer with the input secure key
  90. * @param pcardnr pointer to cardnr, receives the card number on success
  91. * @param pdomain pointer to domain, receives the domain number on success
  92. * @param pkeysize pointer to keysize, receives the bitsize of the key
  93. * @param pattributes pointer to attributes, receives additional info
  94. * PKEY_VERIFY_ATTR_AES if the key is an AES key
  95. * PKEY_VERIFY_ATTR_OLD_MKVP if key has old mkvp stored in
  96. * @return 0 on success, negative errno value on failure. If no card could
  97. * be found which is able to handle this key, -ENODEV is returned.
  98. */
  99. int pkey_verifykey(const struct pkey_seckey *seckey,
  100. u16 *pcardnr, u16 *pdomain,
  101. u16 *pkeysize, u32 *pattributes);
  102. #endif /* _KAPI_PKEY_H */