pkey.h 4.2 KB

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