pkey_sysfs.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * pkey module sysfs related functions
  4. *
  5. * Copyright IBM Corp. 2024
  6. */
  7. #define KMSG_COMPONENT "pkey"
  8. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  9. #include <linux/sysfs.h>
  10. #include "zcrypt_api.h"
  11. #include "zcrypt_ccamisc.h"
  12. #include "zcrypt_ep11misc.h"
  13. #include "pkey_base.h"
  14. /*
  15. * Wrapper around pkey_handler_gen_key() which deals with the
  16. * ENODEV return code and then tries to enforce a pkey handler
  17. * module load.
  18. */
  19. static int sys_pkey_handler_gen_key(u32 keytype, u32 keysubtype,
  20. u32 keybitsize, u32 flags,
  21. u8 *keybuf, u32 *keybuflen, u32 *keyinfo)
  22. {
  23. int rc;
  24. rc = pkey_handler_gen_key(NULL, 0,
  25. keytype, keysubtype,
  26. keybitsize, flags,
  27. keybuf, keybuflen, keyinfo);
  28. if (rc == -ENODEV) {
  29. pkey_handler_request_modules();
  30. rc = pkey_handler_gen_key(NULL, 0,
  31. keytype, keysubtype,
  32. keybitsize, flags,
  33. keybuf, keybuflen, keyinfo);
  34. }
  35. return rc;
  36. }
  37. /*
  38. * Sysfs attribute read function for all protected key binary attributes.
  39. * The implementation can not deal with partial reads, because a new random
  40. * protected key blob is generated with each read. In case of partial reads
  41. * (i.e. off != 0 or count < key blob size) -EINVAL is returned.
  42. */
  43. static ssize_t pkey_protkey_aes_attr_read(u32 keytype, bool is_xts, char *buf,
  44. loff_t off, size_t count)
  45. {
  46. struct protaeskeytoken protkeytoken;
  47. struct pkey_protkey protkey;
  48. int rc;
  49. if (off != 0 || count < sizeof(protkeytoken))
  50. return -EINVAL;
  51. if (is_xts)
  52. if (count < 2 * sizeof(protkeytoken))
  53. return -EINVAL;
  54. memset(&protkeytoken, 0, sizeof(protkeytoken));
  55. protkeytoken.type = TOKTYPE_NON_CCA;
  56. protkeytoken.version = TOKVER_PROTECTED_KEY;
  57. protkeytoken.keytype = keytype;
  58. protkey.len = sizeof(protkey.protkey);
  59. rc = sys_pkey_handler_gen_key(keytype, PKEY_TYPE_PROTKEY, 0, 0,
  60. protkey.protkey, &protkey.len,
  61. &protkey.type);
  62. if (rc)
  63. return rc;
  64. protkeytoken.len = protkey.len;
  65. memcpy(&protkeytoken.protkey, &protkey.protkey, protkey.len);
  66. memcpy(buf, &protkeytoken, sizeof(protkeytoken));
  67. if (is_xts) {
  68. /* xts needs a second protected key, reuse protkey struct */
  69. protkey.len = sizeof(protkey.protkey);
  70. rc = sys_pkey_handler_gen_key(keytype, PKEY_TYPE_PROTKEY, 0, 0,
  71. protkey.protkey, &protkey.len,
  72. &protkey.type);
  73. if (rc)
  74. return rc;
  75. protkeytoken.len = protkey.len;
  76. memcpy(&protkeytoken.protkey, &protkey.protkey, protkey.len);
  77. memcpy(buf + sizeof(protkeytoken), &protkeytoken,
  78. sizeof(protkeytoken));
  79. return 2 * sizeof(protkeytoken);
  80. }
  81. return sizeof(protkeytoken);
  82. }
  83. /*
  84. * Sysfs attribute read function for the AES XTS prot key binary attributes.
  85. * The implementation can not deal with partial reads, because a new random
  86. * protected key blob is generated with each read. In case of partial reads
  87. * (i.e. off != 0 or count < key blob size) -EINVAL is returned.
  88. */
  89. static ssize_t pkey_protkey_aes_xts_attr_read(u32 keytype, char *buf,
  90. loff_t off, size_t count)
  91. {
  92. struct protkeytoken *t = (struct protkeytoken *)buf;
  93. u32 protlen, prottype;
  94. int rc;
  95. switch (keytype) {
  96. case PKEY_KEYTYPE_AES_XTS_128:
  97. protlen = 64;
  98. break;
  99. case PKEY_KEYTYPE_AES_XTS_256:
  100. protlen = 96;
  101. break;
  102. default:
  103. return -EINVAL;
  104. }
  105. if (off != 0 || count < sizeof(*t) + protlen)
  106. return -EINVAL;
  107. memset(t, 0, sizeof(*t) + protlen);
  108. t->type = TOKTYPE_NON_CCA;
  109. t->version = TOKVER_PROTECTED_KEY;
  110. t->keytype = keytype;
  111. rc = sys_pkey_handler_gen_key(keytype, PKEY_TYPE_PROTKEY, 0, 0,
  112. t->protkey, &protlen, &prottype);
  113. if (rc)
  114. return rc;
  115. t->len = protlen;
  116. return sizeof(*t) + protlen;
  117. }
  118. /*
  119. * Sysfs attribute read function for the HMAC prot key binary attributes.
  120. * The implementation can not deal with partial reads, because a new random
  121. * protected key blob is generated with each read. In case of partial reads
  122. * (i.e. off != 0 or count < key blob size) -EINVAL is returned.
  123. */
  124. static ssize_t pkey_protkey_hmac_attr_read(u32 keytype, char *buf,
  125. loff_t off, size_t count)
  126. {
  127. struct protkeytoken *t = (struct protkeytoken *)buf;
  128. u32 protlen, prottype;
  129. int rc;
  130. switch (keytype) {
  131. case PKEY_KEYTYPE_HMAC_512:
  132. protlen = 96;
  133. break;
  134. case PKEY_KEYTYPE_HMAC_1024:
  135. protlen = 160;
  136. break;
  137. default:
  138. return -EINVAL;
  139. }
  140. if (off != 0 || count < sizeof(*t) + protlen)
  141. return -EINVAL;
  142. memset(t, 0, sizeof(*t) + protlen);
  143. t->type = TOKTYPE_NON_CCA;
  144. t->version = TOKVER_PROTECTED_KEY;
  145. t->keytype = keytype;
  146. rc = sys_pkey_handler_gen_key(keytype, PKEY_TYPE_PROTKEY, 0, 0,
  147. t->protkey, &protlen, &prottype);
  148. if (rc)
  149. return rc;
  150. t->len = protlen;
  151. return sizeof(*t) + protlen;
  152. }
  153. static ssize_t protkey_aes_128_read(struct file *filp,
  154. struct kobject *kobj,
  155. struct bin_attribute *attr,
  156. char *buf, loff_t off,
  157. size_t count)
  158. {
  159. return pkey_protkey_aes_attr_read(PKEY_KEYTYPE_AES_128, false, buf,
  160. off, count);
  161. }
  162. static ssize_t protkey_aes_192_read(struct file *filp,
  163. struct kobject *kobj,
  164. struct bin_attribute *attr,
  165. char *buf, loff_t off,
  166. size_t count)
  167. {
  168. return pkey_protkey_aes_attr_read(PKEY_KEYTYPE_AES_192, false, buf,
  169. off, count);
  170. }
  171. static ssize_t protkey_aes_256_read(struct file *filp,
  172. struct kobject *kobj,
  173. struct bin_attribute *attr,
  174. char *buf, loff_t off,
  175. size_t count)
  176. {
  177. return pkey_protkey_aes_attr_read(PKEY_KEYTYPE_AES_256, false, buf,
  178. off, count);
  179. }
  180. static ssize_t protkey_aes_128_xts_read(struct file *filp,
  181. struct kobject *kobj,
  182. struct bin_attribute *attr,
  183. char *buf, loff_t off,
  184. size_t count)
  185. {
  186. return pkey_protkey_aes_attr_read(PKEY_KEYTYPE_AES_128, true, buf,
  187. off, count);
  188. }
  189. static ssize_t protkey_aes_256_xts_read(struct file *filp,
  190. struct kobject *kobj,
  191. struct bin_attribute *attr,
  192. char *buf, loff_t off,
  193. size_t count)
  194. {
  195. return pkey_protkey_aes_attr_read(PKEY_KEYTYPE_AES_256, true, buf,
  196. off, count);
  197. }
  198. static ssize_t protkey_aes_xts_128_read(struct file *filp,
  199. struct kobject *kobj,
  200. struct bin_attribute *attr,
  201. char *buf, loff_t off,
  202. size_t count)
  203. {
  204. return pkey_protkey_aes_xts_attr_read(PKEY_KEYTYPE_AES_XTS_128,
  205. buf, off, count);
  206. }
  207. static ssize_t protkey_aes_xts_256_read(struct file *filp,
  208. struct kobject *kobj,
  209. struct bin_attribute *attr,
  210. char *buf, loff_t off,
  211. size_t count)
  212. {
  213. return pkey_protkey_aes_xts_attr_read(PKEY_KEYTYPE_AES_XTS_256,
  214. buf, off, count);
  215. }
  216. static ssize_t protkey_hmac_512_read(struct file *filp,
  217. struct kobject *kobj,
  218. struct bin_attribute *attr,
  219. char *buf, loff_t off,
  220. size_t count)
  221. {
  222. return pkey_protkey_hmac_attr_read(PKEY_KEYTYPE_HMAC_512,
  223. buf, off, count);
  224. }
  225. static ssize_t protkey_hmac_1024_read(struct file *filp,
  226. struct kobject *kobj,
  227. struct bin_attribute *attr,
  228. char *buf, loff_t off,
  229. size_t count)
  230. {
  231. return pkey_protkey_hmac_attr_read(PKEY_KEYTYPE_HMAC_1024,
  232. buf, off, count);
  233. }
  234. static BIN_ATTR_RO(protkey_aes_128, sizeof(struct protaeskeytoken));
  235. static BIN_ATTR_RO(protkey_aes_192, sizeof(struct protaeskeytoken));
  236. static BIN_ATTR_RO(protkey_aes_256, sizeof(struct protaeskeytoken));
  237. static BIN_ATTR_RO(protkey_aes_128_xts, 2 * sizeof(struct protaeskeytoken));
  238. static BIN_ATTR_RO(protkey_aes_256_xts, 2 * sizeof(struct protaeskeytoken));
  239. static BIN_ATTR_RO(protkey_aes_xts_128, sizeof(struct protkeytoken) + 64);
  240. static BIN_ATTR_RO(protkey_aes_xts_256, sizeof(struct protkeytoken) + 96);
  241. static BIN_ATTR_RO(protkey_hmac_512, sizeof(struct protkeytoken) + 96);
  242. static BIN_ATTR_RO(protkey_hmac_1024, sizeof(struct protkeytoken) + 160);
  243. static struct bin_attribute *protkey_attrs[] = {
  244. &bin_attr_protkey_aes_128,
  245. &bin_attr_protkey_aes_192,
  246. &bin_attr_protkey_aes_256,
  247. &bin_attr_protkey_aes_128_xts,
  248. &bin_attr_protkey_aes_256_xts,
  249. &bin_attr_protkey_aes_xts_128,
  250. &bin_attr_protkey_aes_xts_256,
  251. &bin_attr_protkey_hmac_512,
  252. &bin_attr_protkey_hmac_1024,
  253. NULL
  254. };
  255. static struct attribute_group protkey_attr_group = {
  256. .name = "protkey",
  257. .bin_attrs = protkey_attrs,
  258. };
  259. /*
  260. * Sysfs attribute read function for all secure key ccadata binary attributes.
  261. * The implementation can not deal with partial reads, because a new random
  262. * protected key blob is generated with each read. In case of partial reads
  263. * (i.e. off != 0 or count < key blob size) -EINVAL is returned.
  264. */
  265. static ssize_t pkey_ccadata_aes_attr_read(u32 keytype, bool is_xts, char *buf,
  266. loff_t off, size_t count)
  267. {
  268. struct pkey_seckey *seckey = (struct pkey_seckey *)buf;
  269. u32 buflen;
  270. int rc;
  271. if (off != 0 || count < sizeof(struct secaeskeytoken))
  272. return -EINVAL;
  273. if (is_xts)
  274. if (count < 2 * sizeof(struct secaeskeytoken))
  275. return -EINVAL;
  276. buflen = sizeof(seckey->seckey);
  277. rc = sys_pkey_handler_gen_key(keytype, PKEY_TYPE_CCA_DATA, 0, 0,
  278. seckey->seckey, &buflen, NULL);
  279. if (rc)
  280. return rc;
  281. if (is_xts) {
  282. seckey++;
  283. buflen = sizeof(seckey->seckey);
  284. rc = sys_pkey_handler_gen_key(keytype, PKEY_TYPE_CCA_DATA, 0, 0,
  285. seckey->seckey, &buflen, NULL);
  286. if (rc)
  287. return rc;
  288. return 2 * sizeof(struct secaeskeytoken);
  289. }
  290. return sizeof(struct secaeskeytoken);
  291. }
  292. static ssize_t ccadata_aes_128_read(struct file *filp,
  293. struct kobject *kobj,
  294. struct bin_attribute *attr,
  295. char *buf, loff_t off,
  296. size_t count)
  297. {
  298. return pkey_ccadata_aes_attr_read(PKEY_KEYTYPE_AES_128, false, buf,
  299. off, count);
  300. }
  301. static ssize_t ccadata_aes_192_read(struct file *filp,
  302. struct kobject *kobj,
  303. struct bin_attribute *attr,
  304. char *buf, loff_t off,
  305. size_t count)
  306. {
  307. return pkey_ccadata_aes_attr_read(PKEY_KEYTYPE_AES_192, false, buf,
  308. off, count);
  309. }
  310. static ssize_t ccadata_aes_256_read(struct file *filp,
  311. struct kobject *kobj,
  312. struct bin_attribute *attr,
  313. char *buf, loff_t off,
  314. size_t count)
  315. {
  316. return pkey_ccadata_aes_attr_read(PKEY_KEYTYPE_AES_256, false, buf,
  317. off, count);
  318. }
  319. static ssize_t ccadata_aes_128_xts_read(struct file *filp,
  320. struct kobject *kobj,
  321. struct bin_attribute *attr,
  322. char *buf, loff_t off,
  323. size_t count)
  324. {
  325. return pkey_ccadata_aes_attr_read(PKEY_KEYTYPE_AES_128, true, buf,
  326. off, count);
  327. }
  328. static ssize_t ccadata_aes_256_xts_read(struct file *filp,
  329. struct kobject *kobj,
  330. struct bin_attribute *attr,
  331. char *buf, loff_t off,
  332. size_t count)
  333. {
  334. return pkey_ccadata_aes_attr_read(PKEY_KEYTYPE_AES_256, true, buf,
  335. off, count);
  336. }
  337. static BIN_ATTR_RO(ccadata_aes_128, sizeof(struct secaeskeytoken));
  338. static BIN_ATTR_RO(ccadata_aes_192, sizeof(struct secaeskeytoken));
  339. static BIN_ATTR_RO(ccadata_aes_256, sizeof(struct secaeskeytoken));
  340. static BIN_ATTR_RO(ccadata_aes_128_xts, 2 * sizeof(struct secaeskeytoken));
  341. static BIN_ATTR_RO(ccadata_aes_256_xts, 2 * sizeof(struct secaeskeytoken));
  342. static struct bin_attribute *ccadata_attrs[] = {
  343. &bin_attr_ccadata_aes_128,
  344. &bin_attr_ccadata_aes_192,
  345. &bin_attr_ccadata_aes_256,
  346. &bin_attr_ccadata_aes_128_xts,
  347. &bin_attr_ccadata_aes_256_xts,
  348. NULL
  349. };
  350. static struct attribute_group ccadata_attr_group = {
  351. .name = "ccadata",
  352. .bin_attrs = ccadata_attrs,
  353. };
  354. #define CCACIPHERTOKENSIZE (sizeof(struct cipherkeytoken) + 80)
  355. /*
  356. * Sysfs attribute read function for all secure key ccacipher binary attributes.
  357. * The implementation can not deal with partial reads, because a new random
  358. * secure key blob is generated with each read. In case of partial reads
  359. * (i.e. off != 0 or count < key blob size) -EINVAL is returned.
  360. */
  361. static ssize_t pkey_ccacipher_aes_attr_read(enum pkey_key_size keybits,
  362. bool is_xts, char *buf, loff_t off,
  363. size_t count)
  364. {
  365. u32 keysize = CCACIPHERTOKENSIZE;
  366. int rc;
  367. if (off != 0 || count < CCACIPHERTOKENSIZE)
  368. return -EINVAL;
  369. if (is_xts)
  370. if (count < 2 * CCACIPHERTOKENSIZE)
  371. return -EINVAL;
  372. memset(buf, 0, is_xts ? 2 * keysize : keysize);
  373. rc = sys_pkey_handler_gen_key(pkey_aes_bitsize_to_keytype(keybits),
  374. PKEY_TYPE_CCA_CIPHER, keybits, 0,
  375. buf, &keysize, NULL);
  376. if (rc)
  377. return rc;
  378. if (is_xts) {
  379. keysize = CCACIPHERTOKENSIZE;
  380. buf += CCACIPHERTOKENSIZE;
  381. rc = sys_pkey_handler_gen_key(
  382. pkey_aes_bitsize_to_keytype(keybits),
  383. PKEY_TYPE_CCA_CIPHER, keybits, 0,
  384. buf, &keysize, NULL);
  385. if (rc)
  386. return rc;
  387. return 2 * CCACIPHERTOKENSIZE;
  388. }
  389. return CCACIPHERTOKENSIZE;
  390. }
  391. static ssize_t ccacipher_aes_128_read(struct file *filp,
  392. struct kobject *kobj,
  393. struct bin_attribute *attr,
  394. char *buf, loff_t off,
  395. size_t count)
  396. {
  397. return pkey_ccacipher_aes_attr_read(PKEY_SIZE_AES_128, false, buf,
  398. off, count);
  399. }
  400. static ssize_t ccacipher_aes_192_read(struct file *filp,
  401. struct kobject *kobj,
  402. struct bin_attribute *attr,
  403. char *buf, loff_t off,
  404. size_t count)
  405. {
  406. return pkey_ccacipher_aes_attr_read(PKEY_SIZE_AES_192, false, buf,
  407. off, count);
  408. }
  409. static ssize_t ccacipher_aes_256_read(struct file *filp,
  410. struct kobject *kobj,
  411. struct bin_attribute *attr,
  412. char *buf, loff_t off,
  413. size_t count)
  414. {
  415. return pkey_ccacipher_aes_attr_read(PKEY_SIZE_AES_256, false, buf,
  416. off, count);
  417. }
  418. static ssize_t ccacipher_aes_128_xts_read(struct file *filp,
  419. struct kobject *kobj,
  420. struct bin_attribute *attr,
  421. char *buf, loff_t off,
  422. size_t count)
  423. {
  424. return pkey_ccacipher_aes_attr_read(PKEY_SIZE_AES_128, true, buf,
  425. off, count);
  426. }
  427. static ssize_t ccacipher_aes_256_xts_read(struct file *filp,
  428. struct kobject *kobj,
  429. struct bin_attribute *attr,
  430. char *buf, loff_t off,
  431. size_t count)
  432. {
  433. return pkey_ccacipher_aes_attr_read(PKEY_SIZE_AES_256, true, buf,
  434. off, count);
  435. }
  436. static BIN_ATTR_RO(ccacipher_aes_128, CCACIPHERTOKENSIZE);
  437. static BIN_ATTR_RO(ccacipher_aes_192, CCACIPHERTOKENSIZE);
  438. static BIN_ATTR_RO(ccacipher_aes_256, CCACIPHERTOKENSIZE);
  439. static BIN_ATTR_RO(ccacipher_aes_128_xts, 2 * CCACIPHERTOKENSIZE);
  440. static BIN_ATTR_RO(ccacipher_aes_256_xts, 2 * CCACIPHERTOKENSIZE);
  441. static struct bin_attribute *ccacipher_attrs[] = {
  442. &bin_attr_ccacipher_aes_128,
  443. &bin_attr_ccacipher_aes_192,
  444. &bin_attr_ccacipher_aes_256,
  445. &bin_attr_ccacipher_aes_128_xts,
  446. &bin_attr_ccacipher_aes_256_xts,
  447. NULL
  448. };
  449. static struct attribute_group ccacipher_attr_group = {
  450. .name = "ccacipher",
  451. .bin_attrs = ccacipher_attrs,
  452. };
  453. /*
  454. * Sysfs attribute read function for all ep11 aes key binary attributes.
  455. * The implementation can not deal with partial reads, because a new random
  456. * secure key blob is generated with each read. In case of partial reads
  457. * (i.e. off != 0 or count < key blob size) -EINVAL is returned.
  458. * This function and the sysfs attributes using it provide EP11 key blobs
  459. * padded to the upper limit of MAXEP11AESKEYBLOBSIZE which is currently
  460. * 336 bytes.
  461. */
  462. static ssize_t pkey_ep11_aes_attr_read(enum pkey_key_size keybits,
  463. bool is_xts, char *buf, loff_t off,
  464. size_t count)
  465. {
  466. u32 keysize = MAXEP11AESKEYBLOBSIZE;
  467. int rc;
  468. if (off != 0 || count < MAXEP11AESKEYBLOBSIZE)
  469. return -EINVAL;
  470. if (is_xts)
  471. if (count < 2 * MAXEP11AESKEYBLOBSIZE)
  472. return -EINVAL;
  473. memset(buf, 0, is_xts ? 2 * keysize : keysize);
  474. rc = sys_pkey_handler_gen_key(pkey_aes_bitsize_to_keytype(keybits),
  475. PKEY_TYPE_EP11_AES, keybits, 0,
  476. buf, &keysize, NULL);
  477. if (rc)
  478. return rc;
  479. if (is_xts) {
  480. keysize = MAXEP11AESKEYBLOBSIZE;
  481. buf += MAXEP11AESKEYBLOBSIZE;
  482. rc = sys_pkey_handler_gen_key(
  483. pkey_aes_bitsize_to_keytype(keybits),
  484. PKEY_TYPE_EP11_AES, keybits, 0,
  485. buf, &keysize, NULL);
  486. if (rc)
  487. return rc;
  488. return 2 * MAXEP11AESKEYBLOBSIZE;
  489. }
  490. return MAXEP11AESKEYBLOBSIZE;
  491. }
  492. static ssize_t ep11_aes_128_read(struct file *filp,
  493. struct kobject *kobj,
  494. struct bin_attribute *attr,
  495. char *buf, loff_t off,
  496. size_t count)
  497. {
  498. return pkey_ep11_aes_attr_read(PKEY_SIZE_AES_128, false, buf,
  499. off, count);
  500. }
  501. static ssize_t ep11_aes_192_read(struct file *filp,
  502. struct kobject *kobj,
  503. struct bin_attribute *attr,
  504. char *buf, loff_t off,
  505. size_t count)
  506. {
  507. return pkey_ep11_aes_attr_read(PKEY_SIZE_AES_192, false, buf,
  508. off, count);
  509. }
  510. static ssize_t ep11_aes_256_read(struct file *filp,
  511. struct kobject *kobj,
  512. struct bin_attribute *attr,
  513. char *buf, loff_t off,
  514. size_t count)
  515. {
  516. return pkey_ep11_aes_attr_read(PKEY_SIZE_AES_256, false, buf,
  517. off, count);
  518. }
  519. static ssize_t ep11_aes_128_xts_read(struct file *filp,
  520. struct kobject *kobj,
  521. struct bin_attribute *attr,
  522. char *buf, loff_t off,
  523. size_t count)
  524. {
  525. return pkey_ep11_aes_attr_read(PKEY_SIZE_AES_128, true, buf,
  526. off, count);
  527. }
  528. static ssize_t ep11_aes_256_xts_read(struct file *filp,
  529. struct kobject *kobj,
  530. struct bin_attribute *attr,
  531. char *buf, loff_t off,
  532. size_t count)
  533. {
  534. return pkey_ep11_aes_attr_read(PKEY_SIZE_AES_256, true, buf,
  535. off, count);
  536. }
  537. static BIN_ATTR_RO(ep11_aes_128, MAXEP11AESKEYBLOBSIZE);
  538. static BIN_ATTR_RO(ep11_aes_192, MAXEP11AESKEYBLOBSIZE);
  539. static BIN_ATTR_RO(ep11_aes_256, MAXEP11AESKEYBLOBSIZE);
  540. static BIN_ATTR_RO(ep11_aes_128_xts, 2 * MAXEP11AESKEYBLOBSIZE);
  541. static BIN_ATTR_RO(ep11_aes_256_xts, 2 * MAXEP11AESKEYBLOBSIZE);
  542. static struct bin_attribute *ep11_attrs[] = {
  543. &bin_attr_ep11_aes_128,
  544. &bin_attr_ep11_aes_192,
  545. &bin_attr_ep11_aes_256,
  546. &bin_attr_ep11_aes_128_xts,
  547. &bin_attr_ep11_aes_256_xts,
  548. NULL
  549. };
  550. static struct attribute_group ep11_attr_group = {
  551. .name = "ep11",
  552. .bin_attrs = ep11_attrs,
  553. };
  554. const struct attribute_group *pkey_attr_groups[] = {
  555. &protkey_attr_group,
  556. &ccadata_attr_group,
  557. &ccacipher_attr_group,
  558. &ep11_attr_group,
  559. NULL,
  560. };