pkey_api.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225
  1. /*
  2. * pkey device driver
  3. *
  4. * Copyright IBM Corp. 2017
  5. * Author(s): Harald Freudenberger
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License (version 2 only)
  9. * as published by the Free Software Foundation.
  10. *
  11. */
  12. #define KMSG_COMPONENT "pkey"
  13. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  14. #include <linux/fs.h>
  15. #include <linux/init.h>
  16. #include <linux/miscdevice.h>
  17. #include <linux/module.h>
  18. #include <linux/slab.h>
  19. #include <linux/kallsyms.h>
  20. #include <linux/debugfs.h>
  21. #include <asm/zcrypt.h>
  22. #include <asm/cpacf.h>
  23. #include <asm/pkey.h>
  24. #include "zcrypt_api.h"
  25. MODULE_LICENSE("GPL");
  26. MODULE_AUTHOR("IBM Corporation");
  27. MODULE_DESCRIPTION("s390 protected key interface");
  28. /* Size of parameter block used for all cca requests/replies */
  29. #define PARMBSIZE 512
  30. /* Size of vardata block used for some of the cca requests/replies */
  31. #define VARDATASIZE 4096
  32. /*
  33. * debug feature data and functions
  34. */
  35. static debug_info_t *debug_info;
  36. #define DEBUG_DBG(...) debug_sprintf_event(debug_info, 6, ##__VA_ARGS__)
  37. #define DEBUG_INFO(...) debug_sprintf_event(debug_info, 5, ##__VA_ARGS__)
  38. #define DEBUG_WARN(...) debug_sprintf_event(debug_info, 4, ##__VA_ARGS__)
  39. #define DEBUG_ERR(...) debug_sprintf_event(debug_info, 3, ##__VA_ARGS__)
  40. static void __init pkey_debug_init(void)
  41. {
  42. debug_info = debug_register("pkey", 1, 1, 4 * sizeof(long));
  43. debug_register_view(debug_info, &debug_sprintf_view);
  44. debug_set_level(debug_info, 3);
  45. }
  46. static void __exit pkey_debug_exit(void)
  47. {
  48. debug_unregister(debug_info);
  49. }
  50. /* inside view of a secure key token (only type 0x01 version 0x04) */
  51. struct secaeskeytoken {
  52. u8 type; /* 0x01 for internal key token */
  53. u8 res0[3];
  54. u8 version; /* should be 0x04 */
  55. u8 res1[1];
  56. u8 flag; /* key flags */
  57. u8 res2[1];
  58. u64 mkvp; /* master key verification pattern */
  59. u8 key[32]; /* key value (encrypted) */
  60. u8 cv[8]; /* control vector */
  61. u16 bitsize; /* key bit size */
  62. u16 keysize; /* key byte size */
  63. u8 tvv[4]; /* token validation value */
  64. } __packed;
  65. /*
  66. * Simple check if the token is a valid CCA secure AES key
  67. * token. If keybitsize is given, the bitsize of the key is
  68. * also checked. Returns 0 on success or errno value on failure.
  69. */
  70. static int check_secaeskeytoken(const u8 *token, int keybitsize)
  71. {
  72. struct secaeskeytoken *t = (struct secaeskeytoken *) token;
  73. if (t->type != 0x01) {
  74. DEBUG_ERR(
  75. "check_secaeskeytoken secure token check failed, type mismatch 0x%02x != 0x01\n",
  76. (int) t->type);
  77. return -EINVAL;
  78. }
  79. if (t->version != 0x04) {
  80. DEBUG_ERR(
  81. "check_secaeskeytoken secure token check failed, version mismatch 0x%02x != 0x04\n",
  82. (int) t->version);
  83. return -EINVAL;
  84. }
  85. if (keybitsize > 0 && t->bitsize != keybitsize) {
  86. DEBUG_ERR(
  87. "check_secaeskeytoken secure token check failed, bitsize mismatch %d != %d\n",
  88. (int) t->bitsize, keybitsize);
  89. return -EINVAL;
  90. }
  91. return 0;
  92. }
  93. /*
  94. * Allocate consecutive memory for request CPRB, request param
  95. * block, reply CPRB and reply param block and fill in values
  96. * for the common fields. Returns 0 on success or errno value
  97. * on failure.
  98. */
  99. static int alloc_and_prep_cprbmem(size_t paramblen,
  100. u8 **pcprbmem,
  101. struct CPRBX **preqCPRB,
  102. struct CPRBX **prepCPRB)
  103. {
  104. u8 *cprbmem;
  105. size_t cprbplusparamblen = sizeof(struct CPRBX) + paramblen;
  106. struct CPRBX *preqcblk, *prepcblk;
  107. /*
  108. * allocate consecutive memory for request CPRB, request param
  109. * block, reply CPRB and reply param block
  110. */
  111. cprbmem = kmalloc(2 * cprbplusparamblen, GFP_KERNEL);
  112. if (!cprbmem)
  113. return -ENOMEM;
  114. memset(cprbmem, 0, 2 * cprbplusparamblen);
  115. preqcblk = (struct CPRBX *) cprbmem;
  116. prepcblk = (struct CPRBX *) (cprbmem + cprbplusparamblen);
  117. /* fill request cprb struct */
  118. preqcblk->cprb_len = sizeof(struct CPRBX);
  119. preqcblk->cprb_ver_id = 0x02;
  120. memcpy(preqcblk->func_id, "T2", 2);
  121. preqcblk->rpl_msgbl = cprbplusparamblen;
  122. if (paramblen) {
  123. preqcblk->req_parmb =
  124. ((u8 *) preqcblk) + sizeof(struct CPRBX);
  125. preqcblk->rpl_parmb =
  126. ((u8 *) prepcblk) + sizeof(struct CPRBX);
  127. }
  128. *pcprbmem = cprbmem;
  129. *preqCPRB = preqcblk;
  130. *prepCPRB = prepcblk;
  131. return 0;
  132. }
  133. /*
  134. * Free the cprb memory allocated with the function above.
  135. * If the scrub value is not zero, the memory is filled
  136. * with zeros before freeing (useful if there was some
  137. * clear key material in there).
  138. */
  139. static void free_cprbmem(void *mem, size_t paramblen, int scrub)
  140. {
  141. if (scrub)
  142. memzero_explicit(mem, 2 * (sizeof(struct CPRBX) + paramblen));
  143. kfree(mem);
  144. }
  145. /*
  146. * Helper function to prepare the xcrb struct
  147. */
  148. static inline void prep_xcrb(struct ica_xcRB *pxcrb,
  149. u16 cardnr,
  150. struct CPRBX *preqcblk,
  151. struct CPRBX *prepcblk)
  152. {
  153. memset(pxcrb, 0, sizeof(*pxcrb));
  154. pxcrb->agent_ID = 0x4341; /* 'CA' */
  155. pxcrb->user_defined = (cardnr == 0xFFFF ? AUTOSELECT : cardnr);
  156. pxcrb->request_control_blk_length =
  157. preqcblk->cprb_len + preqcblk->req_parml;
  158. pxcrb->request_control_blk_addr = (void __user *) preqcblk;
  159. pxcrb->reply_control_blk_length = preqcblk->rpl_msgbl;
  160. pxcrb->reply_control_blk_addr = (void __user *) prepcblk;
  161. }
  162. /*
  163. * Helper function which calls zcrypt_send_cprb with
  164. * memory management segment adjusted to kernel space
  165. * so that the copy_from_user called within this
  166. * function do in fact copy from kernel space.
  167. */
  168. static inline int _zcrypt_send_cprb(struct ica_xcRB *xcrb)
  169. {
  170. int rc;
  171. mm_segment_t old_fs = get_fs();
  172. set_fs(KERNEL_DS);
  173. rc = zcrypt_send_cprb(xcrb);
  174. set_fs(old_fs);
  175. return rc;
  176. }
  177. /*
  178. * Generate (random) AES secure key.
  179. */
  180. int pkey_genseckey(u16 cardnr, u16 domain,
  181. u32 keytype, struct pkey_seckey *seckey)
  182. {
  183. int i, rc, keysize;
  184. int seckeysize;
  185. u8 *mem;
  186. struct CPRBX *preqcblk, *prepcblk;
  187. struct ica_xcRB xcrb;
  188. struct kgreqparm {
  189. u8 subfunc_code[2];
  190. u16 rule_array_len;
  191. struct lv1 {
  192. u16 len;
  193. char key_form[8];
  194. char key_length[8];
  195. char key_type1[8];
  196. char key_type2[8];
  197. } lv1;
  198. struct lv2 {
  199. u16 len;
  200. struct keyid {
  201. u16 len;
  202. u16 attr;
  203. u8 data[SECKEYBLOBSIZE];
  204. } keyid[6];
  205. } lv2;
  206. } *preqparm;
  207. struct kgrepparm {
  208. u8 subfunc_code[2];
  209. u16 rule_array_len;
  210. struct lv3 {
  211. u16 len;
  212. u16 keyblocklen;
  213. struct {
  214. u16 toklen;
  215. u16 tokattr;
  216. u8 tok[0];
  217. /* ... some more data ... */
  218. } keyblock;
  219. } lv3;
  220. } *prepparm;
  221. /* get already prepared memory for 2 cprbs with param block each */
  222. rc = alloc_and_prep_cprbmem(PARMBSIZE, &mem, &preqcblk, &prepcblk);
  223. if (rc)
  224. return rc;
  225. /* fill request cprb struct */
  226. preqcblk->domain = domain;
  227. /* fill request cprb param block with KG request */
  228. preqparm = (struct kgreqparm *) preqcblk->req_parmb;
  229. memcpy(preqparm->subfunc_code, "KG", 2);
  230. preqparm->rule_array_len = sizeof(preqparm->rule_array_len);
  231. preqparm->lv1.len = sizeof(struct lv1);
  232. memcpy(preqparm->lv1.key_form, "OP ", 8);
  233. switch (keytype) {
  234. case PKEY_KEYTYPE_AES_128:
  235. keysize = 16;
  236. memcpy(preqparm->lv1.key_length, "KEYLN16 ", 8);
  237. break;
  238. case PKEY_KEYTYPE_AES_192:
  239. keysize = 24;
  240. memcpy(preqparm->lv1.key_length, "KEYLN24 ", 8);
  241. break;
  242. case PKEY_KEYTYPE_AES_256:
  243. keysize = 32;
  244. memcpy(preqparm->lv1.key_length, "KEYLN32 ", 8);
  245. break;
  246. default:
  247. DEBUG_ERR(
  248. "pkey_genseckey unknown/unsupported keytype %d\n",
  249. keytype);
  250. rc = -EINVAL;
  251. goto out;
  252. }
  253. memcpy(preqparm->lv1.key_type1, "AESDATA ", 8);
  254. preqparm->lv2.len = sizeof(struct lv2);
  255. for (i = 0; i < 6; i++) {
  256. preqparm->lv2.keyid[i].len = sizeof(struct keyid);
  257. preqparm->lv2.keyid[i].attr = (i == 2 ? 0x30 : 0x10);
  258. }
  259. preqcblk->req_parml = sizeof(struct kgreqparm);
  260. /* fill xcrb struct */
  261. prep_xcrb(&xcrb, cardnr, preqcblk, prepcblk);
  262. /* forward xcrb with request CPRB and reply CPRB to zcrypt dd */
  263. rc = _zcrypt_send_cprb(&xcrb);
  264. if (rc) {
  265. DEBUG_ERR(
  266. "pkey_genseckey zcrypt_send_cprb (cardnr=%d domain=%d) failed with errno %d\n",
  267. (int) cardnr, (int) domain, rc);
  268. goto out;
  269. }
  270. /* check response returncode and reasoncode */
  271. if (prepcblk->ccp_rtcode != 0) {
  272. DEBUG_ERR(
  273. "pkey_genseckey secure key generate failure, card response %d/%d\n",
  274. (int) prepcblk->ccp_rtcode,
  275. (int) prepcblk->ccp_rscode);
  276. rc = -EIO;
  277. goto out;
  278. }
  279. /* process response cprb param block */
  280. prepcblk->rpl_parmb = ((u8 *) prepcblk) + sizeof(struct CPRBX);
  281. prepparm = (struct kgrepparm *) prepcblk->rpl_parmb;
  282. /* check length of the returned secure key token */
  283. seckeysize = prepparm->lv3.keyblock.toklen
  284. - sizeof(prepparm->lv3.keyblock.toklen)
  285. - sizeof(prepparm->lv3.keyblock.tokattr);
  286. if (seckeysize != SECKEYBLOBSIZE) {
  287. DEBUG_ERR(
  288. "pkey_genseckey secure token size mismatch %d != %d bytes\n",
  289. seckeysize, SECKEYBLOBSIZE);
  290. rc = -EIO;
  291. goto out;
  292. }
  293. /* check secure key token */
  294. rc = check_secaeskeytoken(prepparm->lv3.keyblock.tok, 8*keysize);
  295. if (rc) {
  296. rc = -EIO;
  297. goto out;
  298. }
  299. /* copy the generated secure key token */
  300. memcpy(seckey->seckey, prepparm->lv3.keyblock.tok, SECKEYBLOBSIZE);
  301. out:
  302. free_cprbmem(mem, PARMBSIZE, 0);
  303. return rc;
  304. }
  305. EXPORT_SYMBOL(pkey_genseckey);
  306. /*
  307. * Generate an AES secure key with given key value.
  308. */
  309. int pkey_clr2seckey(u16 cardnr, u16 domain, u32 keytype,
  310. const struct pkey_clrkey *clrkey,
  311. struct pkey_seckey *seckey)
  312. {
  313. int rc, keysize, seckeysize;
  314. u8 *mem;
  315. struct CPRBX *preqcblk, *prepcblk;
  316. struct ica_xcRB xcrb;
  317. struct cmreqparm {
  318. u8 subfunc_code[2];
  319. u16 rule_array_len;
  320. char rule_array[8];
  321. struct lv1 {
  322. u16 len;
  323. u8 clrkey[0];
  324. } lv1;
  325. struct lv2 {
  326. u16 len;
  327. struct keyid {
  328. u16 len;
  329. u16 attr;
  330. u8 data[SECKEYBLOBSIZE];
  331. } keyid;
  332. } lv2;
  333. } *preqparm;
  334. struct lv2 *plv2;
  335. struct cmrepparm {
  336. u8 subfunc_code[2];
  337. u16 rule_array_len;
  338. struct lv3 {
  339. u16 len;
  340. u16 keyblocklen;
  341. struct {
  342. u16 toklen;
  343. u16 tokattr;
  344. u8 tok[0];
  345. /* ... some more data ... */
  346. } keyblock;
  347. } lv3;
  348. } *prepparm;
  349. /* get already prepared memory for 2 cprbs with param block each */
  350. rc = alloc_and_prep_cprbmem(PARMBSIZE, &mem, &preqcblk, &prepcblk);
  351. if (rc)
  352. return rc;
  353. /* fill request cprb struct */
  354. preqcblk->domain = domain;
  355. /* fill request cprb param block with CM request */
  356. preqparm = (struct cmreqparm *) preqcblk->req_parmb;
  357. memcpy(preqparm->subfunc_code, "CM", 2);
  358. memcpy(preqparm->rule_array, "AES ", 8);
  359. preqparm->rule_array_len =
  360. sizeof(preqparm->rule_array_len) + sizeof(preqparm->rule_array);
  361. switch (keytype) {
  362. case PKEY_KEYTYPE_AES_128:
  363. keysize = 16;
  364. break;
  365. case PKEY_KEYTYPE_AES_192:
  366. keysize = 24;
  367. break;
  368. case PKEY_KEYTYPE_AES_256:
  369. keysize = 32;
  370. break;
  371. default:
  372. DEBUG_ERR(
  373. "pkey_clr2seckey unknown/unsupported keytype %d\n",
  374. keytype);
  375. rc = -EINVAL;
  376. goto out;
  377. }
  378. preqparm->lv1.len = sizeof(struct lv1) + keysize;
  379. memcpy(preqparm->lv1.clrkey, clrkey->clrkey, keysize);
  380. plv2 = (struct lv2 *) (((u8 *) &preqparm->lv2) + keysize);
  381. plv2->len = sizeof(struct lv2);
  382. plv2->keyid.len = sizeof(struct keyid);
  383. plv2->keyid.attr = 0x30;
  384. preqcblk->req_parml = sizeof(struct cmreqparm) + keysize;
  385. /* fill xcrb struct */
  386. prep_xcrb(&xcrb, cardnr, preqcblk, prepcblk);
  387. /* forward xcrb with request CPRB and reply CPRB to zcrypt dd */
  388. rc = _zcrypt_send_cprb(&xcrb);
  389. if (rc) {
  390. DEBUG_ERR(
  391. "pkey_clr2seckey zcrypt_send_cprb (cardnr=%d domain=%d) failed with errno %d\n",
  392. (int) cardnr, (int) domain, rc);
  393. goto out;
  394. }
  395. /* check response returncode and reasoncode */
  396. if (prepcblk->ccp_rtcode != 0) {
  397. DEBUG_ERR(
  398. "pkey_clr2seckey clear key import failure, card response %d/%d\n",
  399. (int) prepcblk->ccp_rtcode,
  400. (int) prepcblk->ccp_rscode);
  401. rc = -EIO;
  402. goto out;
  403. }
  404. /* process response cprb param block */
  405. prepcblk->rpl_parmb = ((u8 *) prepcblk) + sizeof(struct CPRBX);
  406. prepparm = (struct cmrepparm *) prepcblk->rpl_parmb;
  407. /* check length of the returned secure key token */
  408. seckeysize = prepparm->lv3.keyblock.toklen
  409. - sizeof(prepparm->lv3.keyblock.toklen)
  410. - sizeof(prepparm->lv3.keyblock.tokattr);
  411. if (seckeysize != SECKEYBLOBSIZE) {
  412. DEBUG_ERR(
  413. "pkey_clr2seckey secure token size mismatch %d != %d bytes\n",
  414. seckeysize, SECKEYBLOBSIZE);
  415. rc = -EIO;
  416. goto out;
  417. }
  418. /* check secure key token */
  419. rc = check_secaeskeytoken(prepparm->lv3.keyblock.tok, 8*keysize);
  420. if (rc) {
  421. rc = -EIO;
  422. goto out;
  423. }
  424. /* copy the generated secure key token */
  425. memcpy(seckey->seckey, prepparm->lv3.keyblock.tok, SECKEYBLOBSIZE);
  426. out:
  427. free_cprbmem(mem, PARMBSIZE, 1);
  428. return rc;
  429. }
  430. EXPORT_SYMBOL(pkey_clr2seckey);
  431. /*
  432. * Derive a proteced key from the secure key blob.
  433. */
  434. int pkey_sec2protkey(u16 cardnr, u16 domain,
  435. const struct pkey_seckey *seckey,
  436. struct pkey_protkey *protkey)
  437. {
  438. int rc;
  439. u8 *mem;
  440. struct CPRBX *preqcblk, *prepcblk;
  441. struct ica_xcRB xcrb;
  442. struct uskreqparm {
  443. u8 subfunc_code[2];
  444. u16 rule_array_len;
  445. struct lv1 {
  446. u16 len;
  447. u16 attr_len;
  448. u16 attr_flags;
  449. } lv1;
  450. struct lv2 {
  451. u16 len;
  452. u16 attr_len;
  453. u16 attr_flags;
  454. u8 token[0]; /* cca secure key token */
  455. } lv2 __packed;
  456. } *preqparm;
  457. struct uskrepparm {
  458. u8 subfunc_code[2];
  459. u16 rule_array_len;
  460. struct lv3 {
  461. u16 len;
  462. u16 attr_len;
  463. u16 attr_flags;
  464. struct cpacfkeyblock {
  465. u8 version; /* version of this struct */
  466. u8 flags[2];
  467. u8 algo;
  468. u8 form;
  469. u8 pad1[3];
  470. u16 keylen;
  471. u8 key[64]; /* the key (keylen bytes) */
  472. u16 keyattrlen;
  473. u8 keyattr[32];
  474. u8 pad2[1];
  475. u8 vptype;
  476. u8 vp[32]; /* verification pattern */
  477. } keyblock;
  478. } lv3 __packed;
  479. } *prepparm;
  480. /* get already prepared memory for 2 cprbs with param block each */
  481. rc = alloc_and_prep_cprbmem(PARMBSIZE, &mem, &preqcblk, &prepcblk);
  482. if (rc)
  483. return rc;
  484. /* fill request cprb struct */
  485. preqcblk->domain = domain;
  486. /* fill request cprb param block with USK request */
  487. preqparm = (struct uskreqparm *) preqcblk->req_parmb;
  488. memcpy(preqparm->subfunc_code, "US", 2);
  489. preqparm->rule_array_len = sizeof(preqparm->rule_array_len);
  490. preqparm->lv1.len = sizeof(struct lv1);
  491. preqparm->lv1.attr_len = sizeof(struct lv1) - sizeof(preqparm->lv1.len);
  492. preqparm->lv1.attr_flags = 0x0001;
  493. preqparm->lv2.len = sizeof(struct lv2) + SECKEYBLOBSIZE;
  494. preqparm->lv2.attr_len = sizeof(struct lv2)
  495. - sizeof(preqparm->lv2.len) + SECKEYBLOBSIZE;
  496. preqparm->lv2.attr_flags = 0x0000;
  497. memcpy(preqparm->lv2.token, seckey->seckey, SECKEYBLOBSIZE);
  498. preqcblk->req_parml = sizeof(struct uskreqparm) + SECKEYBLOBSIZE;
  499. /* fill xcrb struct */
  500. prep_xcrb(&xcrb, cardnr, preqcblk, prepcblk);
  501. /* forward xcrb with request CPRB and reply CPRB to zcrypt dd */
  502. rc = _zcrypt_send_cprb(&xcrb);
  503. if (rc) {
  504. DEBUG_ERR(
  505. "pkey_sec2protkey zcrypt_send_cprb (cardnr=%d domain=%d) failed with errno %d\n",
  506. (int) cardnr, (int) domain, rc);
  507. goto out;
  508. }
  509. /* check response returncode and reasoncode */
  510. if (prepcblk->ccp_rtcode != 0) {
  511. DEBUG_ERR(
  512. "pkey_sec2protkey unwrap secure key failure, card response %d/%d\n",
  513. (int) prepcblk->ccp_rtcode,
  514. (int) prepcblk->ccp_rscode);
  515. rc = -EIO;
  516. goto out;
  517. }
  518. if (prepcblk->ccp_rscode != 0) {
  519. DEBUG_WARN(
  520. "pkey_sec2protkey unwrap secure key warning, card response %d/%d\n",
  521. (int) prepcblk->ccp_rtcode,
  522. (int) prepcblk->ccp_rscode);
  523. }
  524. /* process response cprb param block */
  525. prepcblk->rpl_parmb = ((u8 *) prepcblk) + sizeof(struct CPRBX);
  526. prepparm = (struct uskrepparm *) prepcblk->rpl_parmb;
  527. /* check the returned keyblock */
  528. if (prepparm->lv3.keyblock.version != 0x01) {
  529. DEBUG_ERR(
  530. "pkey_sec2protkey reply param keyblock version mismatch 0x%02x != 0x01\n",
  531. (int) prepparm->lv3.keyblock.version);
  532. rc = -EIO;
  533. goto out;
  534. }
  535. /* copy the tanslated protected key */
  536. switch (prepparm->lv3.keyblock.keylen) {
  537. case 16+32:
  538. protkey->type = PKEY_KEYTYPE_AES_128;
  539. break;
  540. case 24+32:
  541. protkey->type = PKEY_KEYTYPE_AES_192;
  542. break;
  543. case 32+32:
  544. protkey->type = PKEY_KEYTYPE_AES_256;
  545. break;
  546. default:
  547. DEBUG_ERR("pkey_sec2protkey unknown/unsupported keytype %d\n",
  548. prepparm->lv3.keyblock.keylen);
  549. rc = -EIO;
  550. goto out;
  551. }
  552. protkey->len = prepparm->lv3.keyblock.keylen;
  553. memcpy(protkey->protkey, prepparm->lv3.keyblock.key, protkey->len);
  554. out:
  555. free_cprbmem(mem, PARMBSIZE, 0);
  556. return rc;
  557. }
  558. EXPORT_SYMBOL(pkey_sec2protkey);
  559. /*
  560. * Create a protected key from a clear key value.
  561. */
  562. int pkey_clr2protkey(u32 keytype,
  563. const struct pkey_clrkey *clrkey,
  564. struct pkey_protkey *protkey)
  565. {
  566. long fc;
  567. int keysize;
  568. u8 paramblock[64];
  569. switch (keytype) {
  570. case PKEY_KEYTYPE_AES_128:
  571. keysize = 16;
  572. fc = CPACF_PCKMO_ENC_AES_128_KEY;
  573. break;
  574. case PKEY_KEYTYPE_AES_192:
  575. keysize = 24;
  576. fc = CPACF_PCKMO_ENC_AES_192_KEY;
  577. break;
  578. case PKEY_KEYTYPE_AES_256:
  579. keysize = 32;
  580. fc = CPACF_PCKMO_ENC_AES_256_KEY;
  581. break;
  582. default:
  583. DEBUG_ERR("pkey_clr2protkey unknown/unsupported keytype %d\n",
  584. keytype);
  585. return -EINVAL;
  586. }
  587. /* prepare param block */
  588. memset(paramblock, 0, sizeof(paramblock));
  589. memcpy(paramblock, clrkey->clrkey, keysize);
  590. /* call the pckmo instruction */
  591. cpacf_pckmo(fc, paramblock);
  592. /* copy created protected key */
  593. protkey->type = keytype;
  594. protkey->len = keysize + 32;
  595. memcpy(protkey->protkey, paramblock, keysize + 32);
  596. return 0;
  597. }
  598. EXPORT_SYMBOL(pkey_clr2protkey);
  599. /*
  600. * query cryptographic facility from adapter
  601. */
  602. static int query_crypto_facility(u16 cardnr, u16 domain,
  603. const char *keyword,
  604. u8 *rarray, size_t *rarraylen,
  605. u8 *varray, size_t *varraylen)
  606. {
  607. int rc;
  608. u16 len;
  609. u8 *mem, *ptr;
  610. struct CPRBX *preqcblk, *prepcblk;
  611. struct ica_xcRB xcrb;
  612. struct fqreqparm {
  613. u8 subfunc_code[2];
  614. u16 rule_array_len;
  615. char rule_array[8];
  616. struct lv1 {
  617. u16 len;
  618. u8 data[VARDATASIZE];
  619. } lv1;
  620. u16 dummylen;
  621. } *preqparm;
  622. size_t parmbsize = sizeof(struct fqreqparm);
  623. struct fqrepparm {
  624. u8 subfunc_code[2];
  625. u8 lvdata[0];
  626. } *prepparm;
  627. /* get already prepared memory for 2 cprbs with param block each */
  628. rc = alloc_and_prep_cprbmem(parmbsize, &mem, &preqcblk, &prepcblk);
  629. if (rc)
  630. return rc;
  631. /* fill request cprb struct */
  632. preqcblk->domain = domain;
  633. /* fill request cprb param block with FQ request */
  634. preqparm = (struct fqreqparm *) preqcblk->req_parmb;
  635. memcpy(preqparm->subfunc_code, "FQ", 2);
  636. strncpy(preqparm->rule_array, keyword, sizeof(preqparm->rule_array));
  637. preqparm->rule_array_len =
  638. sizeof(preqparm->rule_array_len) + sizeof(preqparm->rule_array);
  639. preqparm->lv1.len = sizeof(preqparm->lv1);
  640. preqparm->dummylen = sizeof(preqparm->dummylen);
  641. preqcblk->req_parml = parmbsize;
  642. /* fill xcrb struct */
  643. prep_xcrb(&xcrb, cardnr, preqcblk, prepcblk);
  644. /* forward xcrb with request CPRB and reply CPRB to zcrypt dd */
  645. rc = _zcrypt_send_cprb(&xcrb);
  646. if (rc) {
  647. DEBUG_ERR(
  648. "query_crypto_facility zcrypt_send_cprb (cardnr=%d domain=%d) failed with errno %d\n",
  649. (int) cardnr, (int) domain, rc);
  650. goto out;
  651. }
  652. /* check response returncode and reasoncode */
  653. if (prepcblk->ccp_rtcode != 0) {
  654. DEBUG_ERR(
  655. "query_crypto_facility unwrap secure key failure, card response %d/%d\n",
  656. (int) prepcblk->ccp_rtcode,
  657. (int) prepcblk->ccp_rscode);
  658. rc = -EIO;
  659. goto out;
  660. }
  661. /* process response cprb param block */
  662. prepcblk->rpl_parmb = ((u8 *) prepcblk) + sizeof(struct CPRBX);
  663. prepparm = (struct fqrepparm *) prepcblk->rpl_parmb;
  664. ptr = prepparm->lvdata;
  665. /* check and possibly copy reply rule array */
  666. len = *((u16 *) ptr);
  667. if (len > sizeof(u16)) {
  668. ptr += sizeof(u16);
  669. len -= sizeof(u16);
  670. if (rarray && rarraylen && *rarraylen > 0) {
  671. *rarraylen = (len > *rarraylen ? *rarraylen : len);
  672. memcpy(rarray, ptr, *rarraylen);
  673. }
  674. ptr += len;
  675. }
  676. /* check and possible copy reply var array */
  677. len = *((u16 *) ptr);
  678. if (len > sizeof(u16)) {
  679. ptr += sizeof(u16);
  680. len -= sizeof(u16);
  681. if (varray && varraylen && *varraylen > 0) {
  682. *varraylen = (len > *varraylen ? *varraylen : len);
  683. memcpy(varray, ptr, *varraylen);
  684. }
  685. ptr += len;
  686. }
  687. out:
  688. free_cprbmem(mem, parmbsize, 0);
  689. return rc;
  690. }
  691. /*
  692. * Fetch the current and old mkvp values via
  693. * query_crypto_facility from adapter.
  694. */
  695. static int fetch_mkvp(u16 cardnr, u16 domain, u64 mkvp[2])
  696. {
  697. int rc, found = 0;
  698. size_t rlen, vlen;
  699. u8 *rarray, *varray, *pg;
  700. pg = (u8 *) __get_free_page(GFP_KERNEL);
  701. if (!pg)
  702. return -ENOMEM;
  703. rarray = pg;
  704. varray = pg + PAGE_SIZE/2;
  705. rlen = vlen = PAGE_SIZE/2;
  706. rc = query_crypto_facility(cardnr, domain, "STATICSA",
  707. rarray, &rlen, varray, &vlen);
  708. if (rc == 0 && rlen > 8*8 && vlen > 184+8) {
  709. if (rarray[8*8] == '2') {
  710. /* current master key state is valid */
  711. mkvp[0] = *((u64 *)(varray + 184));
  712. mkvp[1] = *((u64 *)(varray + 172));
  713. found = 1;
  714. }
  715. }
  716. free_page((unsigned long) pg);
  717. return found ? 0 : -ENOENT;
  718. }
  719. /* struct to hold cached mkvp info for each card/domain */
  720. struct mkvp_info {
  721. struct list_head list;
  722. u16 cardnr;
  723. u16 domain;
  724. u64 mkvp[2];
  725. };
  726. /* a list with mkvp_info entries */
  727. static LIST_HEAD(mkvp_list);
  728. static DEFINE_SPINLOCK(mkvp_list_lock);
  729. static int mkvp_cache_fetch(u16 cardnr, u16 domain, u64 mkvp[2])
  730. {
  731. int rc = -ENOENT;
  732. struct mkvp_info *ptr;
  733. spin_lock_bh(&mkvp_list_lock);
  734. list_for_each_entry(ptr, &mkvp_list, list) {
  735. if (ptr->cardnr == cardnr &&
  736. ptr->domain == domain) {
  737. memcpy(mkvp, ptr->mkvp, 2 * sizeof(u64));
  738. rc = 0;
  739. break;
  740. }
  741. }
  742. spin_unlock_bh(&mkvp_list_lock);
  743. return rc;
  744. }
  745. static void mkvp_cache_update(u16 cardnr, u16 domain, u64 mkvp[2])
  746. {
  747. int found = 0;
  748. struct mkvp_info *ptr;
  749. spin_lock_bh(&mkvp_list_lock);
  750. list_for_each_entry(ptr, &mkvp_list, list) {
  751. if (ptr->cardnr == cardnr &&
  752. ptr->domain == domain) {
  753. memcpy(ptr->mkvp, mkvp, 2 * sizeof(u64));
  754. found = 1;
  755. break;
  756. }
  757. }
  758. if (!found) {
  759. ptr = kmalloc(sizeof(*ptr), GFP_ATOMIC);
  760. if (!ptr) {
  761. spin_unlock_bh(&mkvp_list_lock);
  762. return;
  763. }
  764. ptr->cardnr = cardnr;
  765. ptr->domain = domain;
  766. memcpy(ptr->mkvp, mkvp, 2 * sizeof(u64));
  767. list_add(&ptr->list, &mkvp_list);
  768. }
  769. spin_unlock_bh(&mkvp_list_lock);
  770. }
  771. static void mkvp_cache_scrub(u16 cardnr, u16 domain)
  772. {
  773. struct mkvp_info *ptr;
  774. spin_lock_bh(&mkvp_list_lock);
  775. list_for_each_entry(ptr, &mkvp_list, list) {
  776. if (ptr->cardnr == cardnr &&
  777. ptr->domain == domain) {
  778. list_del(&ptr->list);
  779. kfree(ptr);
  780. break;
  781. }
  782. }
  783. spin_unlock_bh(&mkvp_list_lock);
  784. }
  785. static void __exit mkvp_cache_free(void)
  786. {
  787. struct mkvp_info *ptr, *pnext;
  788. spin_lock_bh(&mkvp_list_lock);
  789. list_for_each_entry_safe(ptr, pnext, &mkvp_list, list) {
  790. list_del(&ptr->list);
  791. kfree(ptr);
  792. }
  793. spin_unlock_bh(&mkvp_list_lock);
  794. }
  795. /*
  796. * Search for a matching crypto card based on the Master Key
  797. * Verification Pattern provided inside a secure key.
  798. */
  799. int pkey_findcard(const struct pkey_seckey *seckey,
  800. u16 *pcardnr, u16 *pdomain, int verify)
  801. {
  802. struct secaeskeytoken *t = (struct secaeskeytoken *) seckey;
  803. struct zcrypt_device_matrix *device_matrix;
  804. u16 card, dom;
  805. u64 mkvp[2];
  806. int i, rc, oi = -1;
  807. /* mkvp must not be zero */
  808. if (t->mkvp == 0)
  809. return -EINVAL;
  810. /* fetch status of all crypto cards */
  811. device_matrix = kmalloc(sizeof(struct zcrypt_device_matrix),
  812. GFP_KERNEL);
  813. if (!device_matrix)
  814. return -ENOMEM;
  815. zcrypt_device_status_mask(device_matrix);
  816. /* walk through all crypto cards */
  817. for (i = 0; i < MAX_ZDEV_ENTRIES; i++) {
  818. card = AP_QID_CARD(device_matrix->device[i].qid);
  819. dom = AP_QID_QUEUE(device_matrix->device[i].qid);
  820. if (device_matrix->device[i].online &&
  821. device_matrix->device[i].functions & 0x04) {
  822. /* an enabled CCA Coprocessor card */
  823. /* try cached mkvp */
  824. if (mkvp_cache_fetch(card, dom, mkvp) == 0 &&
  825. t->mkvp == mkvp[0]) {
  826. if (!verify)
  827. break;
  828. /* verify: fetch mkvp from adapter */
  829. if (fetch_mkvp(card, dom, mkvp) == 0) {
  830. mkvp_cache_update(card, dom, mkvp);
  831. if (t->mkvp == mkvp[0])
  832. break;
  833. }
  834. }
  835. } else {
  836. /* Card is offline and/or not a CCA card. */
  837. /* del mkvp entry from cache if it exists */
  838. mkvp_cache_scrub(card, dom);
  839. }
  840. }
  841. if (i >= MAX_ZDEV_ENTRIES) {
  842. /* nothing found, so this time without cache */
  843. for (i = 0; i < MAX_ZDEV_ENTRIES; i++) {
  844. if (!(device_matrix->device[i].online &&
  845. device_matrix->device[i].functions & 0x04))
  846. continue;
  847. card = AP_QID_CARD(device_matrix->device[i].qid);
  848. dom = AP_QID_QUEUE(device_matrix->device[i].qid);
  849. /* fresh fetch mkvp from adapter */
  850. if (fetch_mkvp(card, dom, mkvp) == 0) {
  851. mkvp_cache_update(card, dom, mkvp);
  852. if (t->mkvp == mkvp[0])
  853. break;
  854. if (t->mkvp == mkvp[1] && oi < 0)
  855. oi = i;
  856. }
  857. }
  858. if (i >= MAX_ZDEV_ENTRIES && oi >= 0) {
  859. /* old mkvp matched, use this card then */
  860. card = AP_QID_CARD(device_matrix->device[oi].qid);
  861. dom = AP_QID_QUEUE(device_matrix->device[oi].qid);
  862. }
  863. }
  864. if (i < MAX_ZDEV_ENTRIES || oi >= 0) {
  865. if (pcardnr)
  866. *pcardnr = card;
  867. if (pdomain)
  868. *pdomain = dom;
  869. rc = 0;
  870. } else
  871. rc = -ENODEV;
  872. kfree(device_matrix);
  873. return rc;
  874. }
  875. EXPORT_SYMBOL(pkey_findcard);
  876. /*
  877. * Find card and transform secure key into protected key.
  878. */
  879. int pkey_skey2pkey(const struct pkey_seckey *seckey,
  880. struct pkey_protkey *protkey)
  881. {
  882. u16 cardnr, domain;
  883. int rc, verify;
  884. /*
  885. * The pkey_sec2protkey call may fail when a card has been
  886. * addressed where the master key was changed after last fetch
  887. * of the mkvp into the cache. So first try without verify then
  888. * with verify enabled (thus refreshing the mkvp for each card).
  889. */
  890. for (verify = 0; verify < 2; verify++) {
  891. rc = pkey_findcard(seckey, &cardnr, &domain, verify);
  892. if (rc)
  893. continue;
  894. rc = pkey_sec2protkey(cardnr, domain, seckey, protkey);
  895. if (rc == 0)
  896. break;
  897. }
  898. if (rc)
  899. DEBUG_DBG("pkey_skey2pkey failed rc=%d\n", rc);
  900. return rc;
  901. }
  902. EXPORT_SYMBOL(pkey_skey2pkey);
  903. /*
  904. * Verify key and give back some info about the key.
  905. */
  906. int pkey_verifykey(const struct pkey_seckey *seckey,
  907. u16 *pcardnr, u16 *pdomain,
  908. u16 *pkeysize, u32 *pattributes)
  909. {
  910. struct secaeskeytoken *t = (struct secaeskeytoken *) seckey;
  911. u16 cardnr, domain;
  912. u64 mkvp[2];
  913. int rc;
  914. /* check the secure key for valid AES secure key */
  915. rc = check_secaeskeytoken((u8 *) seckey, 0);
  916. if (rc)
  917. goto out;
  918. if (pattributes)
  919. *pattributes = PKEY_VERIFY_ATTR_AES;
  920. if (pkeysize)
  921. *pkeysize = t->bitsize;
  922. /* try to find a card which can handle this key */
  923. rc = pkey_findcard(seckey, &cardnr, &domain, 1);
  924. if (rc)
  925. goto out;
  926. /* check mkvp for old mkvp match */
  927. rc = mkvp_cache_fetch(cardnr, domain, mkvp);
  928. if (rc)
  929. goto out;
  930. if (t->mkvp == mkvp[1]) {
  931. DEBUG_DBG("pkey_verifykey secure key has old mkvp\n");
  932. if (pattributes)
  933. *pattributes |= PKEY_VERIFY_ATTR_OLD_MKVP;
  934. }
  935. if (pcardnr)
  936. *pcardnr = cardnr;
  937. if (pdomain)
  938. *pdomain = domain;
  939. out:
  940. DEBUG_DBG("pkey_verifykey rc=%d\n", rc);
  941. return rc;
  942. }
  943. EXPORT_SYMBOL(pkey_verifykey);
  944. /*
  945. * File io functions
  946. */
  947. static long pkey_unlocked_ioctl(struct file *filp, unsigned int cmd,
  948. unsigned long arg)
  949. {
  950. int rc;
  951. switch (cmd) {
  952. case PKEY_GENSECK: {
  953. struct pkey_genseck __user *ugs = (void __user *) arg;
  954. struct pkey_genseck kgs;
  955. if (copy_from_user(&kgs, ugs, sizeof(kgs)))
  956. return -EFAULT;
  957. rc = pkey_genseckey(kgs.cardnr, kgs.domain,
  958. kgs.keytype, &kgs.seckey);
  959. DEBUG_DBG("pkey_ioctl pkey_genseckey()=%d\n", rc);
  960. if (rc)
  961. break;
  962. if (copy_to_user(ugs, &kgs, sizeof(kgs)))
  963. return -EFAULT;
  964. break;
  965. }
  966. case PKEY_CLR2SECK: {
  967. struct pkey_clr2seck __user *ucs = (void __user *) arg;
  968. struct pkey_clr2seck kcs;
  969. if (copy_from_user(&kcs, ucs, sizeof(kcs)))
  970. return -EFAULT;
  971. rc = pkey_clr2seckey(kcs.cardnr, kcs.domain, kcs.keytype,
  972. &kcs.clrkey, &kcs.seckey);
  973. DEBUG_DBG("pkey_ioctl pkey_clr2seckey()=%d\n", rc);
  974. if (rc)
  975. break;
  976. if (copy_to_user(ucs, &kcs, sizeof(kcs)))
  977. return -EFAULT;
  978. memzero_explicit(&kcs, sizeof(kcs));
  979. break;
  980. }
  981. case PKEY_SEC2PROTK: {
  982. struct pkey_sec2protk __user *usp = (void __user *) arg;
  983. struct pkey_sec2protk ksp;
  984. if (copy_from_user(&ksp, usp, sizeof(ksp)))
  985. return -EFAULT;
  986. rc = pkey_sec2protkey(ksp.cardnr, ksp.domain,
  987. &ksp.seckey, &ksp.protkey);
  988. DEBUG_DBG("pkey_ioctl pkey_sec2protkey()=%d\n", rc);
  989. if (rc)
  990. break;
  991. if (copy_to_user(usp, &ksp, sizeof(ksp)))
  992. return -EFAULT;
  993. break;
  994. }
  995. case PKEY_CLR2PROTK: {
  996. struct pkey_clr2protk __user *ucp = (void __user *) arg;
  997. struct pkey_clr2protk kcp;
  998. if (copy_from_user(&kcp, ucp, sizeof(kcp)))
  999. return -EFAULT;
  1000. rc = pkey_clr2protkey(kcp.keytype,
  1001. &kcp.clrkey, &kcp.protkey);
  1002. DEBUG_DBG("pkey_ioctl pkey_clr2protkey()=%d\n", rc);
  1003. if (rc)
  1004. break;
  1005. if (copy_to_user(ucp, &kcp, sizeof(kcp)))
  1006. return -EFAULT;
  1007. memzero_explicit(&kcp, sizeof(kcp));
  1008. break;
  1009. }
  1010. case PKEY_FINDCARD: {
  1011. struct pkey_findcard __user *ufc = (void __user *) arg;
  1012. struct pkey_findcard kfc;
  1013. if (copy_from_user(&kfc, ufc, sizeof(kfc)))
  1014. return -EFAULT;
  1015. rc = pkey_findcard(&kfc.seckey,
  1016. &kfc.cardnr, &kfc.domain, 1);
  1017. DEBUG_DBG("pkey_ioctl pkey_findcard()=%d\n", rc);
  1018. if (rc)
  1019. break;
  1020. if (copy_to_user(ufc, &kfc, sizeof(kfc)))
  1021. return -EFAULT;
  1022. break;
  1023. }
  1024. case PKEY_SKEY2PKEY: {
  1025. struct pkey_skey2pkey __user *usp = (void __user *) arg;
  1026. struct pkey_skey2pkey ksp;
  1027. if (copy_from_user(&ksp, usp, sizeof(ksp)))
  1028. return -EFAULT;
  1029. rc = pkey_skey2pkey(&ksp.seckey, &ksp.protkey);
  1030. DEBUG_DBG("pkey_ioctl pkey_skey2pkey()=%d\n", rc);
  1031. if (rc)
  1032. break;
  1033. if (copy_to_user(usp, &ksp, sizeof(ksp)))
  1034. return -EFAULT;
  1035. break;
  1036. }
  1037. case PKEY_VERIFYKEY: {
  1038. struct pkey_verifykey __user *uvk = (void __user *) arg;
  1039. struct pkey_verifykey kvk;
  1040. if (copy_from_user(&kvk, uvk, sizeof(kvk)))
  1041. return -EFAULT;
  1042. rc = pkey_verifykey(&kvk.seckey, &kvk.cardnr, &kvk.domain,
  1043. &kvk.keysize, &kvk.attributes);
  1044. DEBUG_DBG("pkey_ioctl pkey_verifykey()=%d\n", rc);
  1045. if (rc)
  1046. break;
  1047. if (copy_to_user(uvk, &kvk, sizeof(kvk)))
  1048. return -EFAULT;
  1049. break;
  1050. }
  1051. default:
  1052. /* unknown/unsupported ioctl cmd */
  1053. return -ENOTTY;
  1054. }
  1055. return rc;
  1056. }
  1057. /*
  1058. * Sysfs and file io operations
  1059. */
  1060. static const struct file_operations pkey_fops = {
  1061. .owner = THIS_MODULE,
  1062. .open = nonseekable_open,
  1063. .llseek = no_llseek,
  1064. .unlocked_ioctl = pkey_unlocked_ioctl,
  1065. };
  1066. static struct miscdevice pkey_dev = {
  1067. .name = "pkey",
  1068. .minor = MISC_DYNAMIC_MINOR,
  1069. .mode = 0666,
  1070. .fops = &pkey_fops,
  1071. };
  1072. /*
  1073. * Module init
  1074. */
  1075. static int __init pkey_init(void)
  1076. {
  1077. cpacf_mask_t pckmo_functions;
  1078. /* check for pckmo instructions available */
  1079. if (!cpacf_query(CPACF_PCKMO, &pckmo_functions))
  1080. return -EOPNOTSUPP;
  1081. if (!cpacf_test_func(&pckmo_functions, CPACF_PCKMO_ENC_AES_128_KEY) ||
  1082. !cpacf_test_func(&pckmo_functions, CPACF_PCKMO_ENC_AES_192_KEY) ||
  1083. !cpacf_test_func(&pckmo_functions, CPACF_PCKMO_ENC_AES_256_KEY))
  1084. return -EOPNOTSUPP;
  1085. pkey_debug_init();
  1086. return misc_register(&pkey_dev);
  1087. }
  1088. /*
  1089. * Module exit
  1090. */
  1091. static void __exit pkey_exit(void)
  1092. {
  1093. misc_deregister(&pkey_dev);
  1094. mkvp_cache_free();
  1095. pkey_debug_exit();
  1096. }
  1097. module_init(pkey_init);
  1098. module_exit(pkey_exit);