trusted.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249
  1. /*
  2. * Copyright (C) 2010 IBM Corporation
  3. *
  4. * Author:
  5. * David Safford <safford@us.ibm.com>
  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 as published by
  9. * the Free Software Foundation, version 2 of the License.
  10. *
  11. * See Documentation/security/keys-trusted-encrypted.txt
  12. */
  13. #include <crypto/hash_info.h>
  14. #include <linux/uaccess.h>
  15. #include <linux/module.h>
  16. #include <linux/init.h>
  17. #include <linux/slab.h>
  18. #include <linux/parser.h>
  19. #include <linux/string.h>
  20. #include <linux/err.h>
  21. #include <keys/user-type.h>
  22. #include <keys/trusted-type.h>
  23. #include <linux/key-type.h>
  24. #include <linux/rcupdate.h>
  25. #include <linux/crypto.h>
  26. #include <crypto/hash.h>
  27. #include <crypto/sha.h>
  28. #include <linux/capability.h>
  29. #include <linux/tpm.h>
  30. #include <linux/tpm_command.h>
  31. #include "trusted.h"
  32. static const char hmac_alg[] = "hmac(sha1)";
  33. static const char hash_alg[] = "sha1";
  34. struct sdesc {
  35. struct shash_desc shash;
  36. char ctx[];
  37. };
  38. static struct crypto_shash *hashalg;
  39. static struct crypto_shash *hmacalg;
  40. static struct sdesc *init_sdesc(struct crypto_shash *alg)
  41. {
  42. struct sdesc *sdesc;
  43. int size;
  44. size = sizeof(struct shash_desc) + crypto_shash_descsize(alg);
  45. sdesc = kmalloc(size, GFP_KERNEL);
  46. if (!sdesc)
  47. return ERR_PTR(-ENOMEM);
  48. sdesc->shash.tfm = alg;
  49. sdesc->shash.flags = 0x0;
  50. return sdesc;
  51. }
  52. static int TSS_sha1(const unsigned char *data, unsigned int datalen,
  53. unsigned char *digest)
  54. {
  55. struct sdesc *sdesc;
  56. int ret;
  57. sdesc = init_sdesc(hashalg);
  58. if (IS_ERR(sdesc)) {
  59. pr_info("trusted_key: can't alloc %s\n", hash_alg);
  60. return PTR_ERR(sdesc);
  61. }
  62. ret = crypto_shash_digest(&sdesc->shash, data, datalen, digest);
  63. kfree(sdesc);
  64. return ret;
  65. }
  66. static int TSS_rawhmac(unsigned char *digest, const unsigned char *key,
  67. unsigned int keylen, ...)
  68. {
  69. struct sdesc *sdesc;
  70. va_list argp;
  71. unsigned int dlen;
  72. unsigned char *data;
  73. int ret;
  74. sdesc = init_sdesc(hmacalg);
  75. if (IS_ERR(sdesc)) {
  76. pr_info("trusted_key: can't alloc %s\n", hmac_alg);
  77. return PTR_ERR(sdesc);
  78. }
  79. ret = crypto_shash_setkey(hmacalg, key, keylen);
  80. if (ret < 0)
  81. goto out;
  82. ret = crypto_shash_init(&sdesc->shash);
  83. if (ret < 0)
  84. goto out;
  85. va_start(argp, keylen);
  86. for (;;) {
  87. dlen = va_arg(argp, unsigned int);
  88. if (dlen == 0)
  89. break;
  90. data = va_arg(argp, unsigned char *);
  91. if (data == NULL) {
  92. ret = -EINVAL;
  93. break;
  94. }
  95. ret = crypto_shash_update(&sdesc->shash, data, dlen);
  96. if (ret < 0)
  97. break;
  98. }
  99. va_end(argp);
  100. if (!ret)
  101. ret = crypto_shash_final(&sdesc->shash, digest);
  102. out:
  103. kfree(sdesc);
  104. return ret;
  105. }
  106. /*
  107. * calculate authorization info fields to send to TPM
  108. */
  109. static int TSS_authhmac(unsigned char *digest, const unsigned char *key,
  110. unsigned int keylen, unsigned char *h1,
  111. unsigned char *h2, unsigned char h3, ...)
  112. {
  113. unsigned char paramdigest[SHA1_DIGEST_SIZE];
  114. struct sdesc *sdesc;
  115. unsigned int dlen;
  116. unsigned char *data;
  117. unsigned char c;
  118. int ret;
  119. va_list argp;
  120. sdesc = init_sdesc(hashalg);
  121. if (IS_ERR(sdesc)) {
  122. pr_info("trusted_key: can't alloc %s\n", hash_alg);
  123. return PTR_ERR(sdesc);
  124. }
  125. c = h3;
  126. ret = crypto_shash_init(&sdesc->shash);
  127. if (ret < 0)
  128. goto out;
  129. va_start(argp, h3);
  130. for (;;) {
  131. dlen = va_arg(argp, unsigned int);
  132. if (dlen == 0)
  133. break;
  134. data = va_arg(argp, unsigned char *);
  135. if (!data) {
  136. ret = -EINVAL;
  137. break;
  138. }
  139. ret = crypto_shash_update(&sdesc->shash, data, dlen);
  140. if (ret < 0)
  141. break;
  142. }
  143. va_end(argp);
  144. if (!ret)
  145. ret = crypto_shash_final(&sdesc->shash, paramdigest);
  146. if (!ret)
  147. ret = TSS_rawhmac(digest, key, keylen, SHA1_DIGEST_SIZE,
  148. paramdigest, TPM_NONCE_SIZE, h1,
  149. TPM_NONCE_SIZE, h2, 1, &c, 0, 0);
  150. out:
  151. kfree(sdesc);
  152. return ret;
  153. }
  154. /*
  155. * verify the AUTH1_COMMAND (Seal) result from TPM
  156. */
  157. static int TSS_checkhmac1(unsigned char *buffer,
  158. const uint32_t command,
  159. const unsigned char *ononce,
  160. const unsigned char *key,
  161. unsigned int keylen, ...)
  162. {
  163. uint32_t bufsize;
  164. uint16_t tag;
  165. uint32_t ordinal;
  166. uint32_t result;
  167. unsigned char *enonce;
  168. unsigned char *continueflag;
  169. unsigned char *authdata;
  170. unsigned char testhmac[SHA1_DIGEST_SIZE];
  171. unsigned char paramdigest[SHA1_DIGEST_SIZE];
  172. struct sdesc *sdesc;
  173. unsigned int dlen;
  174. unsigned int dpos;
  175. va_list argp;
  176. int ret;
  177. bufsize = LOAD32(buffer, TPM_SIZE_OFFSET);
  178. tag = LOAD16(buffer, 0);
  179. ordinal = command;
  180. result = LOAD32N(buffer, TPM_RETURN_OFFSET);
  181. if (tag == TPM_TAG_RSP_COMMAND)
  182. return 0;
  183. if (tag != TPM_TAG_RSP_AUTH1_COMMAND)
  184. return -EINVAL;
  185. authdata = buffer + bufsize - SHA1_DIGEST_SIZE;
  186. continueflag = authdata - 1;
  187. enonce = continueflag - TPM_NONCE_SIZE;
  188. sdesc = init_sdesc(hashalg);
  189. if (IS_ERR(sdesc)) {
  190. pr_info("trusted_key: can't alloc %s\n", hash_alg);
  191. return PTR_ERR(sdesc);
  192. }
  193. ret = crypto_shash_init(&sdesc->shash);
  194. if (ret < 0)
  195. goto out;
  196. ret = crypto_shash_update(&sdesc->shash, (const u8 *)&result,
  197. sizeof result);
  198. if (ret < 0)
  199. goto out;
  200. ret = crypto_shash_update(&sdesc->shash, (const u8 *)&ordinal,
  201. sizeof ordinal);
  202. if (ret < 0)
  203. goto out;
  204. va_start(argp, keylen);
  205. for (;;) {
  206. dlen = va_arg(argp, unsigned int);
  207. if (dlen == 0)
  208. break;
  209. dpos = va_arg(argp, unsigned int);
  210. ret = crypto_shash_update(&sdesc->shash, buffer + dpos, dlen);
  211. if (ret < 0)
  212. break;
  213. }
  214. va_end(argp);
  215. if (!ret)
  216. ret = crypto_shash_final(&sdesc->shash, paramdigest);
  217. if (ret < 0)
  218. goto out;
  219. ret = TSS_rawhmac(testhmac, key, keylen, SHA1_DIGEST_SIZE, paramdigest,
  220. TPM_NONCE_SIZE, enonce, TPM_NONCE_SIZE, ononce,
  221. 1, continueflag, 0, 0);
  222. if (ret < 0)
  223. goto out;
  224. if (memcmp(testhmac, authdata, SHA1_DIGEST_SIZE))
  225. ret = -EINVAL;
  226. out:
  227. kfree(sdesc);
  228. return ret;
  229. }
  230. /*
  231. * verify the AUTH2_COMMAND (unseal) result from TPM
  232. */
  233. static int TSS_checkhmac2(unsigned char *buffer,
  234. const uint32_t command,
  235. const unsigned char *ononce,
  236. const unsigned char *key1,
  237. unsigned int keylen1,
  238. const unsigned char *key2,
  239. unsigned int keylen2, ...)
  240. {
  241. uint32_t bufsize;
  242. uint16_t tag;
  243. uint32_t ordinal;
  244. uint32_t result;
  245. unsigned char *enonce1;
  246. unsigned char *continueflag1;
  247. unsigned char *authdata1;
  248. unsigned char *enonce2;
  249. unsigned char *continueflag2;
  250. unsigned char *authdata2;
  251. unsigned char testhmac1[SHA1_DIGEST_SIZE];
  252. unsigned char testhmac2[SHA1_DIGEST_SIZE];
  253. unsigned char paramdigest[SHA1_DIGEST_SIZE];
  254. struct sdesc *sdesc;
  255. unsigned int dlen;
  256. unsigned int dpos;
  257. va_list argp;
  258. int ret;
  259. bufsize = LOAD32(buffer, TPM_SIZE_OFFSET);
  260. tag = LOAD16(buffer, 0);
  261. ordinal = command;
  262. result = LOAD32N(buffer, TPM_RETURN_OFFSET);
  263. if (tag == TPM_TAG_RSP_COMMAND)
  264. return 0;
  265. if (tag != TPM_TAG_RSP_AUTH2_COMMAND)
  266. return -EINVAL;
  267. authdata1 = buffer + bufsize - (SHA1_DIGEST_SIZE + 1
  268. + SHA1_DIGEST_SIZE + SHA1_DIGEST_SIZE);
  269. authdata2 = buffer + bufsize - (SHA1_DIGEST_SIZE);
  270. continueflag1 = authdata1 - 1;
  271. continueflag2 = authdata2 - 1;
  272. enonce1 = continueflag1 - TPM_NONCE_SIZE;
  273. enonce2 = continueflag2 - TPM_NONCE_SIZE;
  274. sdesc = init_sdesc(hashalg);
  275. if (IS_ERR(sdesc)) {
  276. pr_info("trusted_key: can't alloc %s\n", hash_alg);
  277. return PTR_ERR(sdesc);
  278. }
  279. ret = crypto_shash_init(&sdesc->shash);
  280. if (ret < 0)
  281. goto out;
  282. ret = crypto_shash_update(&sdesc->shash, (const u8 *)&result,
  283. sizeof result);
  284. if (ret < 0)
  285. goto out;
  286. ret = crypto_shash_update(&sdesc->shash, (const u8 *)&ordinal,
  287. sizeof ordinal);
  288. if (ret < 0)
  289. goto out;
  290. va_start(argp, keylen2);
  291. for (;;) {
  292. dlen = va_arg(argp, unsigned int);
  293. if (dlen == 0)
  294. break;
  295. dpos = va_arg(argp, unsigned int);
  296. ret = crypto_shash_update(&sdesc->shash, buffer + dpos, dlen);
  297. if (ret < 0)
  298. break;
  299. }
  300. va_end(argp);
  301. if (!ret)
  302. ret = crypto_shash_final(&sdesc->shash, paramdigest);
  303. if (ret < 0)
  304. goto out;
  305. ret = TSS_rawhmac(testhmac1, key1, keylen1, SHA1_DIGEST_SIZE,
  306. paramdigest, TPM_NONCE_SIZE, enonce1,
  307. TPM_NONCE_SIZE, ononce, 1, continueflag1, 0, 0);
  308. if (ret < 0)
  309. goto out;
  310. if (memcmp(testhmac1, authdata1, SHA1_DIGEST_SIZE)) {
  311. ret = -EINVAL;
  312. goto out;
  313. }
  314. ret = TSS_rawhmac(testhmac2, key2, keylen2, SHA1_DIGEST_SIZE,
  315. paramdigest, TPM_NONCE_SIZE, enonce2,
  316. TPM_NONCE_SIZE, ononce, 1, continueflag2, 0, 0);
  317. if (ret < 0)
  318. goto out;
  319. if (memcmp(testhmac2, authdata2, SHA1_DIGEST_SIZE))
  320. ret = -EINVAL;
  321. out:
  322. kfree(sdesc);
  323. return ret;
  324. }
  325. /*
  326. * For key specific tpm requests, we will generate and send our
  327. * own TPM command packets using the drivers send function.
  328. */
  329. static int trusted_tpm_send(const u32 chip_num, unsigned char *cmd,
  330. size_t buflen)
  331. {
  332. int rc;
  333. dump_tpm_buf(cmd);
  334. rc = tpm_send(chip_num, cmd, buflen);
  335. dump_tpm_buf(cmd);
  336. if (rc > 0)
  337. /* Can't return positive return codes values to keyctl */
  338. rc = -EPERM;
  339. return rc;
  340. }
  341. /*
  342. * Lock a trusted key, by extending a selected PCR.
  343. *
  344. * Prevents a trusted key that is sealed to PCRs from being accessed.
  345. * This uses the tpm driver's extend function.
  346. */
  347. static int pcrlock(const int pcrnum)
  348. {
  349. unsigned char hash[SHA1_DIGEST_SIZE];
  350. int ret;
  351. if (!capable(CAP_SYS_ADMIN))
  352. return -EPERM;
  353. ret = tpm_get_random(TPM_ANY_NUM, hash, SHA1_DIGEST_SIZE);
  354. if (ret != SHA1_DIGEST_SIZE)
  355. return ret;
  356. return tpm_pcr_extend(TPM_ANY_NUM, pcrnum, hash) ? -EINVAL : 0;
  357. }
  358. /*
  359. * Create an object specific authorisation protocol (OSAP) session
  360. */
  361. static int osap(struct tpm_buf *tb, struct osapsess *s,
  362. const unsigned char *key, uint16_t type, uint32_t handle)
  363. {
  364. unsigned char enonce[TPM_NONCE_SIZE];
  365. unsigned char ononce[TPM_NONCE_SIZE];
  366. int ret;
  367. ret = tpm_get_random(TPM_ANY_NUM, ononce, TPM_NONCE_SIZE);
  368. if (ret != TPM_NONCE_SIZE)
  369. return ret;
  370. INIT_BUF(tb);
  371. store16(tb, TPM_TAG_RQU_COMMAND);
  372. store32(tb, TPM_OSAP_SIZE);
  373. store32(tb, TPM_ORD_OSAP);
  374. store16(tb, type);
  375. store32(tb, handle);
  376. storebytes(tb, ononce, TPM_NONCE_SIZE);
  377. ret = trusted_tpm_send(TPM_ANY_NUM, tb->data, MAX_BUF_SIZE);
  378. if (ret < 0)
  379. return ret;
  380. s->handle = LOAD32(tb->data, TPM_DATA_OFFSET);
  381. memcpy(s->enonce, &(tb->data[TPM_DATA_OFFSET + sizeof(uint32_t)]),
  382. TPM_NONCE_SIZE);
  383. memcpy(enonce, &(tb->data[TPM_DATA_OFFSET + sizeof(uint32_t) +
  384. TPM_NONCE_SIZE]), TPM_NONCE_SIZE);
  385. return TSS_rawhmac(s->secret, key, SHA1_DIGEST_SIZE, TPM_NONCE_SIZE,
  386. enonce, TPM_NONCE_SIZE, ononce, 0, 0);
  387. }
  388. /*
  389. * Create an object independent authorisation protocol (oiap) session
  390. */
  391. static int oiap(struct tpm_buf *tb, uint32_t *handle, unsigned char *nonce)
  392. {
  393. int ret;
  394. INIT_BUF(tb);
  395. store16(tb, TPM_TAG_RQU_COMMAND);
  396. store32(tb, TPM_OIAP_SIZE);
  397. store32(tb, TPM_ORD_OIAP);
  398. ret = trusted_tpm_send(TPM_ANY_NUM, tb->data, MAX_BUF_SIZE);
  399. if (ret < 0)
  400. return ret;
  401. *handle = LOAD32(tb->data, TPM_DATA_OFFSET);
  402. memcpy(nonce, &tb->data[TPM_DATA_OFFSET + sizeof(uint32_t)],
  403. TPM_NONCE_SIZE);
  404. return 0;
  405. }
  406. struct tpm_digests {
  407. unsigned char encauth[SHA1_DIGEST_SIZE];
  408. unsigned char pubauth[SHA1_DIGEST_SIZE];
  409. unsigned char xorwork[SHA1_DIGEST_SIZE * 2];
  410. unsigned char xorhash[SHA1_DIGEST_SIZE];
  411. unsigned char nonceodd[TPM_NONCE_SIZE];
  412. };
  413. /*
  414. * Have the TPM seal(encrypt) the trusted key, possibly based on
  415. * Platform Configuration Registers (PCRs). AUTH1 for sealing key.
  416. */
  417. static int tpm_seal(struct tpm_buf *tb, uint16_t keytype,
  418. uint32_t keyhandle, const unsigned char *keyauth,
  419. const unsigned char *data, uint32_t datalen,
  420. unsigned char *blob, uint32_t *bloblen,
  421. const unsigned char *blobauth,
  422. const unsigned char *pcrinfo, uint32_t pcrinfosize)
  423. {
  424. struct osapsess sess;
  425. struct tpm_digests *td;
  426. unsigned char cont;
  427. uint32_t ordinal;
  428. uint32_t pcrsize;
  429. uint32_t datsize;
  430. int sealinfosize;
  431. int encdatasize;
  432. int storedsize;
  433. int ret;
  434. int i;
  435. /* alloc some work space for all the hashes */
  436. td = kmalloc(sizeof *td, GFP_KERNEL);
  437. if (!td)
  438. return -ENOMEM;
  439. /* get session for sealing key */
  440. ret = osap(tb, &sess, keyauth, keytype, keyhandle);
  441. if (ret < 0)
  442. goto out;
  443. dump_sess(&sess);
  444. /* calculate encrypted authorization value */
  445. memcpy(td->xorwork, sess.secret, SHA1_DIGEST_SIZE);
  446. memcpy(td->xorwork + SHA1_DIGEST_SIZE, sess.enonce, SHA1_DIGEST_SIZE);
  447. ret = TSS_sha1(td->xorwork, SHA1_DIGEST_SIZE * 2, td->xorhash);
  448. if (ret < 0)
  449. goto out;
  450. ret = tpm_get_random(TPM_ANY_NUM, td->nonceodd, TPM_NONCE_SIZE);
  451. if (ret != TPM_NONCE_SIZE)
  452. goto out;
  453. ordinal = htonl(TPM_ORD_SEAL);
  454. datsize = htonl(datalen);
  455. pcrsize = htonl(pcrinfosize);
  456. cont = 0;
  457. /* encrypt data authorization key */
  458. for (i = 0; i < SHA1_DIGEST_SIZE; ++i)
  459. td->encauth[i] = td->xorhash[i] ^ blobauth[i];
  460. /* calculate authorization HMAC value */
  461. if (pcrinfosize == 0) {
  462. /* no pcr info specified */
  463. ret = TSS_authhmac(td->pubauth, sess.secret, SHA1_DIGEST_SIZE,
  464. sess.enonce, td->nonceodd, cont,
  465. sizeof(uint32_t), &ordinal, SHA1_DIGEST_SIZE,
  466. td->encauth, sizeof(uint32_t), &pcrsize,
  467. sizeof(uint32_t), &datsize, datalen, data, 0,
  468. 0);
  469. } else {
  470. /* pcr info specified */
  471. ret = TSS_authhmac(td->pubauth, sess.secret, SHA1_DIGEST_SIZE,
  472. sess.enonce, td->nonceodd, cont,
  473. sizeof(uint32_t), &ordinal, SHA1_DIGEST_SIZE,
  474. td->encauth, sizeof(uint32_t), &pcrsize,
  475. pcrinfosize, pcrinfo, sizeof(uint32_t),
  476. &datsize, datalen, data, 0, 0);
  477. }
  478. if (ret < 0)
  479. goto out;
  480. /* build and send the TPM request packet */
  481. INIT_BUF(tb);
  482. store16(tb, TPM_TAG_RQU_AUTH1_COMMAND);
  483. store32(tb, TPM_SEAL_SIZE + pcrinfosize + datalen);
  484. store32(tb, TPM_ORD_SEAL);
  485. store32(tb, keyhandle);
  486. storebytes(tb, td->encauth, SHA1_DIGEST_SIZE);
  487. store32(tb, pcrinfosize);
  488. storebytes(tb, pcrinfo, pcrinfosize);
  489. store32(tb, datalen);
  490. storebytes(tb, data, datalen);
  491. store32(tb, sess.handle);
  492. storebytes(tb, td->nonceodd, TPM_NONCE_SIZE);
  493. store8(tb, cont);
  494. storebytes(tb, td->pubauth, SHA1_DIGEST_SIZE);
  495. ret = trusted_tpm_send(TPM_ANY_NUM, tb->data, MAX_BUF_SIZE);
  496. if (ret < 0)
  497. goto out;
  498. /* calculate the size of the returned Blob */
  499. sealinfosize = LOAD32(tb->data, TPM_DATA_OFFSET + sizeof(uint32_t));
  500. encdatasize = LOAD32(tb->data, TPM_DATA_OFFSET + sizeof(uint32_t) +
  501. sizeof(uint32_t) + sealinfosize);
  502. storedsize = sizeof(uint32_t) + sizeof(uint32_t) + sealinfosize +
  503. sizeof(uint32_t) + encdatasize;
  504. /* check the HMAC in the response */
  505. ret = TSS_checkhmac1(tb->data, ordinal, td->nonceodd, sess.secret,
  506. SHA1_DIGEST_SIZE, storedsize, TPM_DATA_OFFSET, 0,
  507. 0);
  508. /* copy the returned blob to caller */
  509. if (!ret) {
  510. memcpy(blob, tb->data + TPM_DATA_OFFSET, storedsize);
  511. *bloblen = storedsize;
  512. }
  513. out:
  514. kfree(td);
  515. return ret;
  516. }
  517. /*
  518. * use the AUTH2_COMMAND form of unseal, to authorize both key and blob
  519. */
  520. static int tpm_unseal(struct tpm_buf *tb,
  521. uint32_t keyhandle, const unsigned char *keyauth,
  522. const unsigned char *blob, int bloblen,
  523. const unsigned char *blobauth,
  524. unsigned char *data, unsigned int *datalen)
  525. {
  526. unsigned char nonceodd[TPM_NONCE_SIZE];
  527. unsigned char enonce1[TPM_NONCE_SIZE];
  528. unsigned char enonce2[TPM_NONCE_SIZE];
  529. unsigned char authdata1[SHA1_DIGEST_SIZE];
  530. unsigned char authdata2[SHA1_DIGEST_SIZE];
  531. uint32_t authhandle1 = 0;
  532. uint32_t authhandle2 = 0;
  533. unsigned char cont = 0;
  534. uint32_t ordinal;
  535. uint32_t keyhndl;
  536. int ret;
  537. /* sessions for unsealing key and data */
  538. ret = oiap(tb, &authhandle1, enonce1);
  539. if (ret < 0) {
  540. pr_info("trusted_key: oiap failed (%d)\n", ret);
  541. return ret;
  542. }
  543. ret = oiap(tb, &authhandle2, enonce2);
  544. if (ret < 0) {
  545. pr_info("trusted_key: oiap failed (%d)\n", ret);
  546. return ret;
  547. }
  548. ordinal = htonl(TPM_ORD_UNSEAL);
  549. keyhndl = htonl(SRKHANDLE);
  550. ret = tpm_get_random(TPM_ANY_NUM, nonceodd, TPM_NONCE_SIZE);
  551. if (ret != TPM_NONCE_SIZE) {
  552. pr_info("trusted_key: tpm_get_random failed (%d)\n", ret);
  553. return ret;
  554. }
  555. ret = TSS_authhmac(authdata1, keyauth, TPM_NONCE_SIZE,
  556. enonce1, nonceodd, cont, sizeof(uint32_t),
  557. &ordinal, bloblen, blob, 0, 0);
  558. if (ret < 0)
  559. return ret;
  560. ret = TSS_authhmac(authdata2, blobauth, TPM_NONCE_SIZE,
  561. enonce2, nonceodd, cont, sizeof(uint32_t),
  562. &ordinal, bloblen, blob, 0, 0);
  563. if (ret < 0)
  564. return ret;
  565. /* build and send TPM request packet */
  566. INIT_BUF(tb);
  567. store16(tb, TPM_TAG_RQU_AUTH2_COMMAND);
  568. store32(tb, TPM_UNSEAL_SIZE + bloblen);
  569. store32(tb, TPM_ORD_UNSEAL);
  570. store32(tb, keyhandle);
  571. storebytes(tb, blob, bloblen);
  572. store32(tb, authhandle1);
  573. storebytes(tb, nonceodd, TPM_NONCE_SIZE);
  574. store8(tb, cont);
  575. storebytes(tb, authdata1, SHA1_DIGEST_SIZE);
  576. store32(tb, authhandle2);
  577. storebytes(tb, nonceodd, TPM_NONCE_SIZE);
  578. store8(tb, cont);
  579. storebytes(tb, authdata2, SHA1_DIGEST_SIZE);
  580. ret = trusted_tpm_send(TPM_ANY_NUM, tb->data, MAX_BUF_SIZE);
  581. if (ret < 0) {
  582. pr_info("trusted_key: authhmac failed (%d)\n", ret);
  583. return ret;
  584. }
  585. *datalen = LOAD32(tb->data, TPM_DATA_OFFSET);
  586. ret = TSS_checkhmac2(tb->data, ordinal, nonceodd,
  587. keyauth, SHA1_DIGEST_SIZE,
  588. blobauth, SHA1_DIGEST_SIZE,
  589. sizeof(uint32_t), TPM_DATA_OFFSET,
  590. *datalen, TPM_DATA_OFFSET + sizeof(uint32_t), 0,
  591. 0);
  592. if (ret < 0) {
  593. pr_info("trusted_key: TSS_checkhmac2 failed (%d)\n", ret);
  594. return ret;
  595. }
  596. memcpy(data, tb->data + TPM_DATA_OFFSET + sizeof(uint32_t), *datalen);
  597. return 0;
  598. }
  599. /*
  600. * Have the TPM seal(encrypt) the symmetric key
  601. */
  602. static int key_seal(struct trusted_key_payload *p,
  603. struct trusted_key_options *o)
  604. {
  605. struct tpm_buf *tb;
  606. int ret;
  607. tb = kzalloc(sizeof *tb, GFP_KERNEL);
  608. if (!tb)
  609. return -ENOMEM;
  610. /* include migratable flag at end of sealed key */
  611. p->key[p->key_len] = p->migratable;
  612. ret = tpm_seal(tb, o->keytype, o->keyhandle, o->keyauth,
  613. p->key, p->key_len + 1, p->blob, &p->blob_len,
  614. o->blobauth, o->pcrinfo, o->pcrinfo_len);
  615. if (ret < 0)
  616. pr_info("trusted_key: srkseal failed (%d)\n", ret);
  617. kfree(tb);
  618. return ret;
  619. }
  620. /*
  621. * Have the TPM unseal(decrypt) the symmetric key
  622. */
  623. static int key_unseal(struct trusted_key_payload *p,
  624. struct trusted_key_options *o)
  625. {
  626. struct tpm_buf *tb;
  627. int ret;
  628. tb = kzalloc(sizeof *tb, GFP_KERNEL);
  629. if (!tb)
  630. return -ENOMEM;
  631. ret = tpm_unseal(tb, o->keyhandle, o->keyauth, p->blob, p->blob_len,
  632. o->blobauth, p->key, &p->key_len);
  633. if (ret < 0)
  634. pr_info("trusted_key: srkunseal failed (%d)\n", ret);
  635. else
  636. /* pull migratable flag out of sealed key */
  637. p->migratable = p->key[--p->key_len];
  638. kfree(tb);
  639. return ret;
  640. }
  641. enum {
  642. Opt_err = -1,
  643. Opt_new, Opt_load, Opt_update,
  644. Opt_keyhandle, Opt_keyauth, Opt_blobauth,
  645. Opt_pcrinfo, Opt_pcrlock, Opt_migratable,
  646. Opt_hash,
  647. Opt_policydigest,
  648. Opt_policyhandle,
  649. };
  650. static const match_table_t key_tokens = {
  651. {Opt_new, "new"},
  652. {Opt_load, "load"},
  653. {Opt_update, "update"},
  654. {Opt_keyhandle, "keyhandle=%s"},
  655. {Opt_keyauth, "keyauth=%s"},
  656. {Opt_blobauth, "blobauth=%s"},
  657. {Opt_pcrinfo, "pcrinfo=%s"},
  658. {Opt_pcrlock, "pcrlock=%s"},
  659. {Opt_migratable, "migratable=%s"},
  660. {Opt_hash, "hash=%s"},
  661. {Opt_policydigest, "policydigest=%s"},
  662. {Opt_policyhandle, "policyhandle=%s"},
  663. {Opt_err, NULL}
  664. };
  665. /* can have zero or more token= options */
  666. static int getoptions(char *c, struct trusted_key_payload *pay,
  667. struct trusted_key_options *opt)
  668. {
  669. substring_t args[MAX_OPT_ARGS];
  670. char *p = c;
  671. int token;
  672. int res;
  673. unsigned long handle;
  674. unsigned long lock;
  675. unsigned long token_mask = 0;
  676. int i;
  677. int tpm2;
  678. tpm2 = tpm_is_tpm2(TPM_ANY_NUM);
  679. if (tpm2 < 0)
  680. return tpm2;
  681. opt->hash = tpm2 ? HASH_ALGO_SHA256 : HASH_ALGO_SHA1;
  682. opt->digest_len = hash_digest_size[opt->hash];
  683. while ((p = strsep(&c, " \t"))) {
  684. if (*p == '\0' || *p == ' ' || *p == '\t')
  685. continue;
  686. token = match_token(p, key_tokens, args);
  687. if (test_and_set_bit(token, &token_mask))
  688. return -EINVAL;
  689. switch (token) {
  690. case Opt_pcrinfo:
  691. opt->pcrinfo_len = strlen(args[0].from) / 2;
  692. if (opt->pcrinfo_len > MAX_PCRINFO_SIZE)
  693. return -EINVAL;
  694. res = hex2bin(opt->pcrinfo, args[0].from,
  695. opt->pcrinfo_len);
  696. if (res < 0)
  697. return -EINVAL;
  698. break;
  699. case Opt_keyhandle:
  700. res = kstrtoul(args[0].from, 16, &handle);
  701. if (res < 0)
  702. return -EINVAL;
  703. opt->keytype = SEAL_keytype;
  704. opt->keyhandle = handle;
  705. break;
  706. case Opt_keyauth:
  707. if (strlen(args[0].from) != 2 * SHA1_DIGEST_SIZE)
  708. return -EINVAL;
  709. res = hex2bin(opt->keyauth, args[0].from,
  710. SHA1_DIGEST_SIZE);
  711. if (res < 0)
  712. return -EINVAL;
  713. break;
  714. case Opt_blobauth:
  715. if (strlen(args[0].from) != 2 * SHA1_DIGEST_SIZE)
  716. return -EINVAL;
  717. res = hex2bin(opt->blobauth, args[0].from,
  718. SHA1_DIGEST_SIZE);
  719. if (res < 0)
  720. return -EINVAL;
  721. break;
  722. case Opt_migratable:
  723. if (*args[0].from == '0')
  724. pay->migratable = 0;
  725. else
  726. return -EINVAL;
  727. break;
  728. case Opt_pcrlock:
  729. res = kstrtoul(args[0].from, 10, &lock);
  730. if (res < 0)
  731. return -EINVAL;
  732. opt->pcrlock = lock;
  733. break;
  734. case Opt_hash:
  735. if (test_bit(Opt_policydigest, &token_mask))
  736. return -EINVAL;
  737. for (i = 0; i < HASH_ALGO__LAST; i++) {
  738. if (!strcmp(args[0].from, hash_algo_name[i])) {
  739. opt->hash = i;
  740. opt->digest_len =
  741. hash_digest_size[opt->hash];
  742. break;
  743. }
  744. }
  745. if (i == HASH_ALGO__LAST)
  746. return -EINVAL;
  747. if (!tpm2 && i != HASH_ALGO_SHA1) {
  748. pr_info("trusted_key: TPM 1.x only supports SHA-1.\n");
  749. return -EINVAL;
  750. }
  751. break;
  752. case Opt_policydigest:
  753. if (!tpm2 ||
  754. strlen(args[0].from) != (2 * opt->digest_len))
  755. return -EINVAL;
  756. res = hex2bin(opt->policydigest, args[0].from,
  757. opt->digest_len);
  758. if (res < 0)
  759. return -EINVAL;
  760. break;
  761. case Opt_policyhandle:
  762. if (!tpm2)
  763. return -EINVAL;
  764. res = kstrtoul(args[0].from, 16, &handle);
  765. if (res < 0)
  766. return -EINVAL;
  767. opt->policyhandle = handle;
  768. break;
  769. default:
  770. return -EINVAL;
  771. }
  772. }
  773. return 0;
  774. }
  775. /*
  776. * datablob_parse - parse the keyctl data and fill in the
  777. * payload and options structures
  778. *
  779. * On success returns 0, otherwise -EINVAL.
  780. */
  781. static int datablob_parse(char *datablob, struct trusted_key_payload *p,
  782. struct trusted_key_options *o)
  783. {
  784. substring_t args[MAX_OPT_ARGS];
  785. long keylen;
  786. int ret = -EINVAL;
  787. int key_cmd;
  788. char *c;
  789. /* main command */
  790. c = strsep(&datablob, " \t");
  791. if (!c)
  792. return -EINVAL;
  793. key_cmd = match_token(c, key_tokens, args);
  794. switch (key_cmd) {
  795. case Opt_new:
  796. /* first argument is key size */
  797. c = strsep(&datablob, " \t");
  798. if (!c)
  799. return -EINVAL;
  800. ret = kstrtol(c, 10, &keylen);
  801. if (ret < 0 || keylen < MIN_KEY_SIZE || keylen > MAX_KEY_SIZE)
  802. return -EINVAL;
  803. p->key_len = keylen;
  804. ret = getoptions(datablob, p, o);
  805. if (ret < 0)
  806. return ret;
  807. ret = Opt_new;
  808. break;
  809. case Opt_load:
  810. /* first argument is sealed blob */
  811. c = strsep(&datablob, " \t");
  812. if (!c)
  813. return -EINVAL;
  814. p->blob_len = strlen(c) / 2;
  815. if (p->blob_len > MAX_BLOB_SIZE)
  816. return -EINVAL;
  817. ret = hex2bin(p->blob, c, p->blob_len);
  818. if (ret < 0)
  819. return -EINVAL;
  820. ret = getoptions(datablob, p, o);
  821. if (ret < 0)
  822. return ret;
  823. ret = Opt_load;
  824. break;
  825. case Opt_update:
  826. /* all arguments are options */
  827. ret = getoptions(datablob, p, o);
  828. if (ret < 0)
  829. return ret;
  830. ret = Opt_update;
  831. break;
  832. case Opt_err:
  833. return -EINVAL;
  834. break;
  835. }
  836. return ret;
  837. }
  838. static struct trusted_key_options *trusted_options_alloc(void)
  839. {
  840. struct trusted_key_options *options;
  841. int tpm2;
  842. tpm2 = tpm_is_tpm2(TPM_ANY_NUM);
  843. if (tpm2 < 0)
  844. return NULL;
  845. options = kzalloc(sizeof *options, GFP_KERNEL);
  846. if (options) {
  847. /* set any non-zero defaults */
  848. options->keytype = SRK_keytype;
  849. if (!tpm2)
  850. options->keyhandle = SRKHANDLE;
  851. }
  852. return options;
  853. }
  854. static struct trusted_key_payload *trusted_payload_alloc(struct key *key)
  855. {
  856. struct trusted_key_payload *p = NULL;
  857. int ret;
  858. ret = key_payload_reserve(key, sizeof *p);
  859. if (ret < 0)
  860. return p;
  861. p = kzalloc(sizeof *p, GFP_KERNEL);
  862. if (p)
  863. p->migratable = 1; /* migratable by default */
  864. return p;
  865. }
  866. /*
  867. * trusted_instantiate - create a new trusted key
  868. *
  869. * Unseal an existing trusted blob or, for a new key, get a
  870. * random key, then seal and create a trusted key-type key,
  871. * adding it to the specified keyring.
  872. *
  873. * On success, return 0. Otherwise return errno.
  874. */
  875. static int trusted_instantiate(struct key *key,
  876. struct key_preparsed_payload *prep)
  877. {
  878. struct trusted_key_payload *payload = NULL;
  879. struct trusted_key_options *options = NULL;
  880. size_t datalen = prep->datalen;
  881. char *datablob;
  882. int ret = 0;
  883. int key_cmd;
  884. size_t key_len;
  885. int tpm2;
  886. tpm2 = tpm_is_tpm2(TPM_ANY_NUM);
  887. if (tpm2 < 0)
  888. return tpm2;
  889. if (datalen <= 0 || datalen > 32767 || !prep->data)
  890. return -EINVAL;
  891. datablob = kmalloc(datalen + 1, GFP_KERNEL);
  892. if (!datablob)
  893. return -ENOMEM;
  894. memcpy(datablob, prep->data, datalen);
  895. datablob[datalen] = '\0';
  896. options = trusted_options_alloc();
  897. if (!options) {
  898. ret = -ENOMEM;
  899. goto out;
  900. }
  901. payload = trusted_payload_alloc(key);
  902. if (!payload) {
  903. ret = -ENOMEM;
  904. goto out;
  905. }
  906. key_cmd = datablob_parse(datablob, payload, options);
  907. if (key_cmd < 0) {
  908. ret = key_cmd;
  909. goto out;
  910. }
  911. if (!options->keyhandle) {
  912. ret = -EINVAL;
  913. goto out;
  914. }
  915. dump_payload(payload);
  916. dump_options(options);
  917. switch (key_cmd) {
  918. case Opt_load:
  919. if (tpm2)
  920. ret = tpm_unseal_trusted(TPM_ANY_NUM, payload, options);
  921. else
  922. ret = key_unseal(payload, options);
  923. dump_payload(payload);
  924. dump_options(options);
  925. if (ret < 0)
  926. pr_info("trusted_key: key_unseal failed (%d)\n", ret);
  927. break;
  928. case Opt_new:
  929. key_len = payload->key_len;
  930. ret = tpm_get_random(TPM_ANY_NUM, payload->key, key_len);
  931. if (ret != key_len) {
  932. pr_info("trusted_key: key_create failed (%d)\n", ret);
  933. goto out;
  934. }
  935. if (tpm2)
  936. ret = tpm_seal_trusted(TPM_ANY_NUM, payload, options);
  937. else
  938. ret = key_seal(payload, options);
  939. if (ret < 0)
  940. pr_info("trusted_key: key_seal failed (%d)\n", ret);
  941. break;
  942. default:
  943. ret = -EINVAL;
  944. goto out;
  945. }
  946. if (!ret && options->pcrlock)
  947. ret = pcrlock(options->pcrlock);
  948. out:
  949. kfree(datablob);
  950. kfree(options);
  951. if (!ret)
  952. rcu_assign_keypointer(key, payload);
  953. else
  954. kfree(payload);
  955. return ret;
  956. }
  957. static void trusted_rcu_free(struct rcu_head *rcu)
  958. {
  959. struct trusted_key_payload *p;
  960. p = container_of(rcu, struct trusted_key_payload, rcu);
  961. memset(p->key, 0, p->key_len);
  962. kfree(p);
  963. }
  964. /*
  965. * trusted_update - reseal an existing key with new PCR values
  966. */
  967. static int trusted_update(struct key *key, struct key_preparsed_payload *prep)
  968. {
  969. struct trusted_key_payload *p;
  970. struct trusted_key_payload *new_p;
  971. struct trusted_key_options *new_o;
  972. size_t datalen = prep->datalen;
  973. char *datablob;
  974. int ret = 0;
  975. if (test_bit(KEY_FLAG_NEGATIVE, &key->flags))
  976. return -ENOKEY;
  977. p = key->payload.data[0];
  978. if (!p->migratable)
  979. return -EPERM;
  980. if (datalen <= 0 || datalen > 32767 || !prep->data)
  981. return -EINVAL;
  982. datablob = kmalloc(datalen + 1, GFP_KERNEL);
  983. if (!datablob)
  984. return -ENOMEM;
  985. new_o = trusted_options_alloc();
  986. if (!new_o) {
  987. ret = -ENOMEM;
  988. goto out;
  989. }
  990. new_p = trusted_payload_alloc(key);
  991. if (!new_p) {
  992. ret = -ENOMEM;
  993. goto out;
  994. }
  995. memcpy(datablob, prep->data, datalen);
  996. datablob[datalen] = '\0';
  997. ret = datablob_parse(datablob, new_p, new_o);
  998. if (ret != Opt_update) {
  999. ret = -EINVAL;
  1000. kfree(new_p);
  1001. goto out;
  1002. }
  1003. if (!new_o->keyhandle) {
  1004. ret = -EINVAL;
  1005. kfree(new_p);
  1006. goto out;
  1007. }
  1008. /* copy old key values, and reseal with new pcrs */
  1009. new_p->migratable = p->migratable;
  1010. new_p->key_len = p->key_len;
  1011. memcpy(new_p->key, p->key, p->key_len);
  1012. dump_payload(p);
  1013. dump_payload(new_p);
  1014. ret = key_seal(new_p, new_o);
  1015. if (ret < 0) {
  1016. pr_info("trusted_key: key_seal failed (%d)\n", ret);
  1017. kfree(new_p);
  1018. goto out;
  1019. }
  1020. if (new_o->pcrlock) {
  1021. ret = pcrlock(new_o->pcrlock);
  1022. if (ret < 0) {
  1023. pr_info("trusted_key: pcrlock failed (%d)\n", ret);
  1024. kfree(new_p);
  1025. goto out;
  1026. }
  1027. }
  1028. rcu_assign_keypointer(key, new_p);
  1029. call_rcu(&p->rcu, trusted_rcu_free);
  1030. out:
  1031. kfree(datablob);
  1032. kfree(new_o);
  1033. return ret;
  1034. }
  1035. /*
  1036. * trusted_read - copy the sealed blob data to userspace in hex.
  1037. * On success, return to userspace the trusted key datablob size.
  1038. */
  1039. static long trusted_read(const struct key *key, char __user *buffer,
  1040. size_t buflen)
  1041. {
  1042. struct trusted_key_payload *p;
  1043. char *ascii_buf;
  1044. char *bufp;
  1045. int i;
  1046. p = rcu_dereference_key(key);
  1047. if (!p)
  1048. return -EINVAL;
  1049. if (!buffer || buflen <= 0)
  1050. return 2 * p->blob_len;
  1051. ascii_buf = kmalloc(2 * p->blob_len, GFP_KERNEL);
  1052. if (!ascii_buf)
  1053. return -ENOMEM;
  1054. bufp = ascii_buf;
  1055. for (i = 0; i < p->blob_len; i++)
  1056. bufp = hex_byte_pack(bufp, p->blob[i]);
  1057. if ((copy_to_user(buffer, ascii_buf, 2 * p->blob_len)) != 0) {
  1058. kfree(ascii_buf);
  1059. return -EFAULT;
  1060. }
  1061. kfree(ascii_buf);
  1062. return 2 * p->blob_len;
  1063. }
  1064. /*
  1065. * trusted_destroy - before freeing the key, clear the decrypted data
  1066. */
  1067. static void trusted_destroy(struct key *key)
  1068. {
  1069. struct trusted_key_payload *p = key->payload.data[0];
  1070. if (!p)
  1071. return;
  1072. memset(p->key, 0, p->key_len);
  1073. kfree(key->payload.data[0]);
  1074. }
  1075. struct key_type key_type_trusted = {
  1076. .name = "trusted",
  1077. .instantiate = trusted_instantiate,
  1078. .update = trusted_update,
  1079. .destroy = trusted_destroy,
  1080. .describe = user_describe,
  1081. .read = trusted_read,
  1082. };
  1083. EXPORT_SYMBOL_GPL(key_type_trusted);
  1084. static void trusted_shash_release(void)
  1085. {
  1086. if (hashalg)
  1087. crypto_free_shash(hashalg);
  1088. if (hmacalg)
  1089. crypto_free_shash(hmacalg);
  1090. }
  1091. static int __init trusted_shash_alloc(void)
  1092. {
  1093. int ret;
  1094. hmacalg = crypto_alloc_shash(hmac_alg, 0, CRYPTO_ALG_ASYNC);
  1095. if (IS_ERR(hmacalg)) {
  1096. pr_info("trusted_key: could not allocate crypto %s\n",
  1097. hmac_alg);
  1098. return PTR_ERR(hmacalg);
  1099. }
  1100. hashalg = crypto_alloc_shash(hash_alg, 0, CRYPTO_ALG_ASYNC);
  1101. if (IS_ERR(hashalg)) {
  1102. pr_info("trusted_key: could not allocate crypto %s\n",
  1103. hash_alg);
  1104. ret = PTR_ERR(hashalg);
  1105. goto hashalg_fail;
  1106. }
  1107. return 0;
  1108. hashalg_fail:
  1109. crypto_free_shash(hmacalg);
  1110. return ret;
  1111. }
  1112. static int __init init_trusted(void)
  1113. {
  1114. int ret;
  1115. ret = trusted_shash_alloc();
  1116. if (ret < 0)
  1117. return ret;
  1118. ret = register_key_type(&key_type_trusted);
  1119. if (ret < 0)
  1120. trusted_shash_release();
  1121. return ret;
  1122. }
  1123. static void __exit cleanup_trusted(void)
  1124. {
  1125. trusted_shash_release();
  1126. unregister_key_type(&key_type_trusted);
  1127. }
  1128. late_initcall(init_trusted);
  1129. module_exit(cleanup_trusted);
  1130. MODULE_LICENSE("GPL");