cryptosoft.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180
  1. /* $OpenBSD: cryptosoft.c,v 1.73 2015/03/14 03:38:46 jsg Exp $ */
  2. /*
  3. * The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu)
  4. *
  5. * This code was written by Angelos D. Keromytis in Athens, Greece, in
  6. * February 2000. Network Security Technologies Inc. (NSTI) kindly
  7. * supported the development of this code.
  8. *
  9. * Copyright (c) 2000, 2001 Angelos D. Keromytis
  10. *
  11. * Permission to use, copy, and modify this software with or without fee
  12. * is hereby granted, provided that this entire notice is included in
  13. * all source code copies of any software which is or includes a copy or
  14. * modification of this software.
  15. *
  16. * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
  17. * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
  18. * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
  19. * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
  20. * PURPOSE.
  21. */
  22. #include <sys/param.h>
  23. #include <sys/systm.h>
  24. #include <sys/malloc.h>
  25. #include <sys/mbuf.h>
  26. #include <sys/errno.h>
  27. #include <dev/rndvar.h>
  28. #include <crypto/md5.h>
  29. #include <crypto/sha1.h>
  30. #include <crypto/rmd160.h>
  31. #include <crypto/cast.h>
  32. #include <crypto/cryptodev.h>
  33. #include <crypto/cryptosoft.h>
  34. #include <crypto/xform.h>
  35. const u_int8_t hmac_ipad_buffer[HMAC_MAX_BLOCK_LEN] = {
  36. 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
  37. 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
  38. 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
  39. 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
  40. 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
  41. 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
  42. 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
  43. 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
  44. 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
  45. 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
  46. 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
  47. 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
  48. 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
  49. 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
  50. 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
  51. 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36
  52. };
  53. const u_int8_t hmac_opad_buffer[HMAC_MAX_BLOCK_LEN] = {
  54. 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
  55. 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
  56. 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
  57. 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
  58. 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
  59. 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
  60. 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
  61. 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
  62. 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
  63. 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
  64. 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
  65. 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
  66. 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
  67. 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
  68. 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
  69. 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C
  70. };
  71. struct swcr_data **swcr_sessions = NULL;
  72. u_int32_t swcr_sesnum = 0;
  73. int32_t swcr_id = -1;
  74. #define COPYBACK(x, a, b, c, d) \
  75. do { \
  76. if ((x) == CRYPTO_BUF_MBUF) \
  77. m_copyback((struct mbuf *)a,b,c,d,M_NOWAIT); \
  78. else \
  79. cuio_copyback((struct uio *)a,b,c,d); \
  80. } while (0)
  81. #define COPYDATA(x, a, b, c, d) \
  82. do { \
  83. if ((x) == CRYPTO_BUF_MBUF) \
  84. m_copydata((struct mbuf *)a,b,c,d); \
  85. else \
  86. cuio_copydata((struct uio *)a,b,c,d); \
  87. } while (0)
  88. /*
  89. * Apply a symmetric encryption/decryption algorithm.
  90. */
  91. int
  92. swcr_encdec(struct cryptodesc *crd, struct swcr_data *sw, caddr_t buf,
  93. int outtype)
  94. {
  95. unsigned char iv[EALG_MAX_BLOCK_LEN], blk[EALG_MAX_BLOCK_LEN], *idat;
  96. unsigned char *ivp, *nivp, iv2[EALG_MAX_BLOCK_LEN];
  97. struct enc_xform *exf;
  98. int i, k, j, blks, ind, count, ivlen;
  99. struct mbuf *m = NULL;
  100. struct uio *uio = NULL;
  101. exf = sw->sw_exf;
  102. blks = exf->blocksize;
  103. ivlen = exf->ivsize;
  104. /* Check for non-padded data */
  105. if (crd->crd_len % blks)
  106. return EINVAL;
  107. if (outtype == CRYPTO_BUF_MBUF)
  108. m = (struct mbuf *) buf;
  109. else
  110. uio = (struct uio *) buf;
  111. /* Initialize the IV */
  112. if (crd->crd_flags & CRD_F_ENCRYPT) {
  113. /* IV explicitly provided ? */
  114. if (crd->crd_flags & CRD_F_IV_EXPLICIT)
  115. bcopy(crd->crd_iv, iv, ivlen);
  116. else
  117. arc4random_buf(iv, ivlen);
  118. /* Do we need to write the IV */
  119. if (!(crd->crd_flags & CRD_F_IV_PRESENT))
  120. COPYBACK(outtype, buf, crd->crd_inject, ivlen, iv);
  121. } else { /* Decryption */
  122. /* IV explicitly provided ? */
  123. if (crd->crd_flags & CRD_F_IV_EXPLICIT)
  124. bcopy(crd->crd_iv, iv, ivlen);
  125. else {
  126. /* Get IV off buf */
  127. COPYDATA(outtype, buf, crd->crd_inject, ivlen, iv);
  128. }
  129. }
  130. ivp = iv;
  131. /*
  132. * xforms that provide a reinit method perform all IV
  133. * handling themselves.
  134. */
  135. if (exf->reinit)
  136. exf->reinit(sw->sw_kschedule, iv);
  137. if (outtype == CRYPTO_BUF_MBUF) {
  138. /* Find beginning of data */
  139. m = m_getptr(m, crd->crd_skip, &k);
  140. if (m == NULL)
  141. return EINVAL;
  142. i = crd->crd_len;
  143. while (i > 0) {
  144. /*
  145. * If there's insufficient data at the end of
  146. * an mbuf, we have to do some copying.
  147. */
  148. if (m->m_len < k + blks && m->m_len != k) {
  149. m_copydata(m, k, blks, blk);
  150. /* Actual encryption/decryption */
  151. if (exf->reinit) {
  152. if (crd->crd_flags & CRD_F_ENCRYPT) {
  153. exf->encrypt(sw->sw_kschedule,
  154. blk);
  155. } else {
  156. exf->decrypt(sw->sw_kschedule,
  157. blk);
  158. }
  159. } else if (crd->crd_flags & CRD_F_ENCRYPT) {
  160. /* XOR with previous block */
  161. for (j = 0; j < blks; j++)
  162. blk[j] ^= ivp[j];
  163. exf->encrypt(sw->sw_kschedule, blk);
  164. /*
  165. * Keep encrypted block for XOR'ing
  166. * with next block
  167. */
  168. bcopy(blk, iv, blks);
  169. ivp = iv;
  170. } else { /* decrypt */
  171. /*
  172. * Keep encrypted block for XOR'ing
  173. * with next block
  174. */
  175. nivp = (ivp == iv) ? iv2 : iv;
  176. bcopy(blk, nivp, blks);
  177. exf->decrypt(sw->sw_kschedule, blk);
  178. /* XOR with previous block */
  179. for (j = 0; j < blks; j++)
  180. blk[j] ^= ivp[j];
  181. ivp = nivp;
  182. }
  183. /* Copy back decrypted block */
  184. m_copyback(m, k, blks, blk, M_NOWAIT);
  185. /* Advance pointer */
  186. m = m_getptr(m, k + blks, &k);
  187. if (m == NULL)
  188. return EINVAL;
  189. i -= blks;
  190. /* Could be done... */
  191. if (i == 0)
  192. break;
  193. }
  194. /* Skip possibly empty mbufs */
  195. if (k == m->m_len) {
  196. for (m = m->m_next; m && m->m_len == 0;
  197. m = m->m_next)
  198. ;
  199. k = 0;
  200. }
  201. /* Sanity check */
  202. if (m == NULL)
  203. return EINVAL;
  204. /*
  205. * Warning: idat may point to garbage here, but
  206. * we only use it in the while() loop, only if
  207. * there are indeed enough data.
  208. */
  209. idat = mtod(m, unsigned char *) + k;
  210. while (m->m_len >= k + blks && i > 0) {
  211. if (exf->reinit) {
  212. if (crd->crd_flags & CRD_F_ENCRYPT) {
  213. exf->encrypt(sw->sw_kschedule,
  214. idat);
  215. } else {
  216. exf->decrypt(sw->sw_kschedule,
  217. idat);
  218. }
  219. } else if (crd->crd_flags & CRD_F_ENCRYPT) {
  220. /* XOR with previous block/IV */
  221. for (j = 0; j < blks; j++)
  222. idat[j] ^= ivp[j];
  223. exf->encrypt(sw->sw_kschedule, idat);
  224. ivp = idat;
  225. } else { /* decrypt */
  226. /*
  227. * Keep encrypted block to be used
  228. * in next block's processing.
  229. */
  230. nivp = (ivp == iv) ? iv2 : iv;
  231. bcopy(idat, nivp, blks);
  232. exf->decrypt(sw->sw_kschedule, idat);
  233. /* XOR with previous block/IV */
  234. for (j = 0; j < blks; j++)
  235. idat[j] ^= ivp[j];
  236. ivp = nivp;
  237. }
  238. idat += blks;
  239. k += blks;
  240. i -= blks;
  241. }
  242. }
  243. } else {
  244. /* Find beginning of data */
  245. count = crd->crd_skip;
  246. ind = cuio_getptr(uio, count, &k);
  247. if (ind == -1)
  248. return EINVAL;
  249. i = crd->crd_len;
  250. while (i > 0) {
  251. /*
  252. * If there's insufficient data at the end,
  253. * we have to do some copying.
  254. */
  255. if (uio->uio_iov[ind].iov_len < k + blks &&
  256. uio->uio_iov[ind].iov_len != k) {
  257. cuio_copydata(uio, count, blks, blk);
  258. /* Actual encryption/decryption */
  259. if (exf->reinit) {
  260. if (crd->crd_flags & CRD_F_ENCRYPT) {
  261. exf->encrypt(sw->sw_kschedule,
  262. blk);
  263. } else {
  264. exf->decrypt(sw->sw_kschedule,
  265. blk);
  266. }
  267. } else if (crd->crd_flags & CRD_F_ENCRYPT) {
  268. /* XOR with previous block */
  269. for (j = 0; j < blks; j++)
  270. blk[j] ^= ivp[j];
  271. exf->encrypt(sw->sw_kschedule, blk);
  272. /*
  273. * Keep encrypted block for XOR'ing
  274. * with next block
  275. */
  276. bcopy(blk, iv, blks);
  277. ivp = iv;
  278. } else { /* decrypt */
  279. /*
  280. * Keep encrypted block for XOR'ing
  281. * with next block
  282. */
  283. nivp = (ivp == iv) ? iv2 : iv;
  284. bcopy(blk, nivp, blks);
  285. exf->decrypt(sw->sw_kschedule, blk);
  286. /* XOR with previous block */
  287. for (j = 0; j < blks; j++)
  288. blk[j] ^= ivp[j];
  289. ivp = nivp;
  290. }
  291. /* Copy back decrypted block */
  292. cuio_copyback(uio, count, blks, blk);
  293. count += blks;
  294. /* Advance pointer */
  295. ind = cuio_getptr(uio, count, &k);
  296. if (ind == -1)
  297. return (EINVAL);
  298. i -= blks;
  299. /* Could be done... */
  300. if (i == 0)
  301. break;
  302. }
  303. /*
  304. * Warning: idat may point to garbage here, but
  305. * we only use it in the while() loop, only if
  306. * there are indeed enough data.
  307. */
  308. idat = (char *)uio->uio_iov[ind].iov_base + k;
  309. while (uio->uio_iov[ind].iov_len >= k + blks &&
  310. i > 0) {
  311. if (exf->reinit) {
  312. if (crd->crd_flags & CRD_F_ENCRYPT) {
  313. exf->encrypt(sw->sw_kschedule,
  314. idat);
  315. } else {
  316. exf->decrypt(sw->sw_kschedule,
  317. idat);
  318. }
  319. } else if (crd->crd_flags & CRD_F_ENCRYPT) {
  320. /* XOR with previous block/IV */
  321. for (j = 0; j < blks; j++)
  322. idat[j] ^= ivp[j];
  323. exf->encrypt(sw->sw_kschedule, idat);
  324. ivp = idat;
  325. } else { /* decrypt */
  326. /*
  327. * Keep encrypted block to be used
  328. * in next block's processing.
  329. */
  330. nivp = (ivp == iv) ? iv2 : iv;
  331. bcopy(idat, nivp, blks);
  332. exf->decrypt(sw->sw_kschedule, idat);
  333. /* XOR with previous block/IV */
  334. for (j = 0; j < blks; j++)
  335. idat[j] ^= ivp[j];
  336. ivp = nivp;
  337. }
  338. idat += blks;
  339. count += blks;
  340. k += blks;
  341. i -= blks;
  342. }
  343. /*
  344. * Advance to the next iov if the end of the current iov
  345. * is aligned with the end of a cipher block.
  346. * Note that the code is equivalent to calling:
  347. * ind = cuio_getptr(uio, count, &k);
  348. */
  349. if (i > 0 && k == uio->uio_iov[ind].iov_len) {
  350. k = 0;
  351. ind++;
  352. if (ind >= uio->uio_iovcnt)
  353. return (EINVAL);
  354. }
  355. }
  356. }
  357. return 0; /* Done with encryption/decryption */
  358. }
  359. /*
  360. * Compute keyed-hash authenticator.
  361. */
  362. int
  363. swcr_authcompute(struct cryptop *crp, struct cryptodesc *crd,
  364. struct swcr_data *sw, caddr_t buf, int outtype)
  365. {
  366. unsigned char aalg[AALG_MAX_RESULT_LEN];
  367. struct auth_hash *axf;
  368. union authctx ctx;
  369. int err;
  370. if (sw->sw_ictx == 0)
  371. return EINVAL;
  372. axf = sw->sw_axf;
  373. bcopy(sw->sw_ictx, &ctx, axf->ctxsize);
  374. if (outtype == CRYPTO_BUF_MBUF)
  375. err = m_apply((struct mbuf *) buf, crd->crd_skip, crd->crd_len,
  376. (int (*)(caddr_t, caddr_t, unsigned int)) axf->Update,
  377. (caddr_t) &ctx);
  378. else
  379. err = cuio_apply((struct uio *) buf, crd->crd_skip,
  380. crd->crd_len,
  381. (int (*)(caddr_t, caddr_t, unsigned int)) axf->Update,
  382. (caddr_t) &ctx);
  383. if (err)
  384. return err;
  385. if (crd->crd_flags & CRD_F_ESN)
  386. axf->Update(&ctx, crd->crd_esn, 4);
  387. switch (sw->sw_alg) {
  388. case CRYPTO_MD5_HMAC:
  389. case CRYPTO_SHA1_HMAC:
  390. case CRYPTO_RIPEMD160_HMAC:
  391. case CRYPTO_SHA2_256_HMAC:
  392. case CRYPTO_SHA2_384_HMAC:
  393. case CRYPTO_SHA2_512_HMAC:
  394. if (sw->sw_octx == NULL)
  395. return EINVAL;
  396. axf->Final(aalg, &ctx);
  397. bcopy(sw->sw_octx, &ctx, axf->ctxsize);
  398. axf->Update(&ctx, aalg, axf->hashsize);
  399. axf->Final(aalg, &ctx);
  400. break;
  401. case CRYPTO_MD5:
  402. case CRYPTO_SHA1:
  403. axf->Final(aalg, &ctx);
  404. break;
  405. }
  406. /* Inject the authentication data */
  407. if (outtype == CRYPTO_BUF_MBUF)
  408. COPYBACK(outtype, buf, crd->crd_inject, axf->authsize, aalg);
  409. else
  410. bcopy(aalg, crp->crp_mac, axf->authsize);
  411. return 0;
  412. }
  413. /*
  414. * Apply a combined encryption-authentication transformation
  415. */
  416. int
  417. swcr_authenc(struct cryptop *crp)
  418. {
  419. uint32_t blkbuf[howmany(EALG_MAX_BLOCK_LEN, sizeof(uint32_t))];
  420. u_char *blk = (u_char *)blkbuf;
  421. u_char aalg[AALG_MAX_RESULT_LEN];
  422. u_char iv[EALG_MAX_BLOCK_LEN];
  423. union authctx ctx;
  424. struct cryptodesc *crd, *crda = NULL, *crde = NULL;
  425. struct swcr_data *sw, *swa, *swe = NULL;
  426. struct auth_hash *axf = NULL;
  427. struct enc_xform *exf = NULL;
  428. struct mbuf *m = NULL;
  429. struct uio *uio = NULL;
  430. caddr_t buf = (caddr_t)crp->crp_buf;
  431. uint32_t *blkp;
  432. int aadlen, blksz, i, ivlen, outtype, len, iskip, oskip;
  433. ivlen = blksz = iskip = oskip = 0;
  434. for (crd = crp->crp_desc; crd; crd = crd->crd_next) {
  435. for (sw = swcr_sessions[crp->crp_sid & 0xffffffff];
  436. sw && sw->sw_alg != crd->crd_alg;
  437. sw = sw->sw_next)
  438. ;
  439. if (sw == NULL)
  440. return (EINVAL);
  441. switch (sw->sw_alg) {
  442. case CRYPTO_AES_GCM_16:
  443. case CRYPTO_AES_GMAC:
  444. swe = sw;
  445. crde = crd;
  446. exf = swe->sw_exf;
  447. ivlen = exf->ivsize;
  448. break;
  449. case CRYPTO_AES_128_GMAC:
  450. case CRYPTO_AES_192_GMAC:
  451. case CRYPTO_AES_256_GMAC:
  452. swa = sw;
  453. crda = crd;
  454. axf = swa->sw_axf;
  455. if (swa->sw_ictx == 0)
  456. return (EINVAL);
  457. bcopy(swa->sw_ictx, &ctx, axf->ctxsize);
  458. blksz = axf->blocksize;
  459. break;
  460. default:
  461. return (EINVAL);
  462. }
  463. }
  464. if (crde == NULL || crda == NULL)
  465. return (EINVAL);
  466. if (crp->crp_flags & CRYPTO_F_IMBUF) {
  467. outtype = CRYPTO_BUF_MBUF;
  468. m = (struct mbuf *)buf;
  469. } else {
  470. outtype = CRYPTO_BUF_IOV;
  471. uio = (struct uio *)buf;
  472. }
  473. /* Initialize the IV */
  474. if (crde->crd_flags & CRD_F_ENCRYPT) {
  475. /* IV explicitly provided ? */
  476. if (crde->crd_flags & CRD_F_IV_EXPLICIT)
  477. bcopy(crde->crd_iv, iv, ivlen);
  478. else
  479. arc4random_buf(iv, ivlen);
  480. /* Do we need to write the IV */
  481. if (!(crde->crd_flags & CRD_F_IV_PRESENT))
  482. COPYBACK(outtype, buf, crde->crd_inject, ivlen, iv);
  483. } else { /* Decryption */
  484. /* IV explicitly provided ? */
  485. if (crde->crd_flags & CRD_F_IV_EXPLICIT)
  486. bcopy(crde->crd_iv, iv, ivlen);
  487. else {
  488. /* Get IV off buf */
  489. COPYDATA(outtype, buf, crde->crd_inject, ivlen, iv);
  490. }
  491. }
  492. /* Supply MAC with IV */
  493. if (axf->Reinit)
  494. axf->Reinit(&ctx, iv, ivlen);
  495. /* Supply MAC with AAD */
  496. aadlen = crda->crd_len;
  497. /*
  498. * Section 5 of RFC 4106 specifies that AAD construction consists of
  499. * {SPI, ESN, SN} whereas the real packet contains only {SPI, SN}.
  500. * Unfortunately it doesn't follow a good example set in the Section
  501. * 3.3.2.1 of RFC 4303 where upper part of the ESN, located in the
  502. * external (to the packet) memory buffer, is processed by the hash
  503. * function in the end thus allowing to retain simple programming
  504. * interfaces and avoid kludges like the one below.
  505. */
  506. if (crda->crd_flags & CRD_F_ESN) {
  507. aadlen += 4;
  508. /* SPI */
  509. COPYDATA(outtype, buf, crda->crd_skip, 4, blk);
  510. iskip = 4; /* loop below will start with an offset of 4 */
  511. /* ESN */
  512. bcopy(crda->crd_esn, blk + 4, 4);
  513. oskip = iskip + 4; /* offset output buffer blk by 8 */
  514. }
  515. for (i = iskip; i < crda->crd_len; i += blksz) {
  516. len = MIN(crda->crd_len - i, blksz - oskip);
  517. COPYDATA(outtype, buf, crda->crd_skip + i, len, blk + oskip);
  518. bzero(blk + len + oskip, blksz - len - oskip);
  519. axf->Update(&ctx, blk, blksz);
  520. oskip = 0; /* reset initial output offset */
  521. }
  522. if (exf->reinit)
  523. exf->reinit(swe->sw_kschedule, iv);
  524. /* Do encryption/decryption with MAC */
  525. for (i = 0; i < crde->crd_len; i += blksz) {
  526. len = MIN(crde->crd_len - i, blksz);
  527. if (len < blksz)
  528. bzero(blk, blksz);
  529. COPYDATA(outtype, buf, crde->crd_skip + i, len, blk);
  530. if (crde->crd_flags & CRD_F_ENCRYPT) {
  531. exf->encrypt(swe->sw_kschedule, blk);
  532. axf->Update(&ctx, blk, len);
  533. } else {
  534. axf->Update(&ctx, blk, len);
  535. exf->decrypt(swe->sw_kschedule, blk);
  536. }
  537. COPYBACK(outtype, buf, crde->crd_skip + i, len, blk);
  538. }
  539. /* Do any required special finalization */
  540. switch (crda->crd_alg) {
  541. case CRYPTO_AES_128_GMAC:
  542. case CRYPTO_AES_192_GMAC:
  543. case CRYPTO_AES_256_GMAC:
  544. /* length block */
  545. bzero(blk, blksz);
  546. blkp = (uint32_t *)blk + 1;
  547. *blkp = htobe32(aadlen * 8);
  548. blkp = (uint32_t *)blk + 3;
  549. *blkp = htobe32(crde->crd_len * 8);
  550. axf->Update(&ctx, blk, blksz);
  551. break;
  552. }
  553. /* Finalize MAC */
  554. axf->Final(aalg, &ctx);
  555. /* Inject the authentication data */
  556. if (outtype == CRYPTO_BUF_MBUF)
  557. COPYBACK(outtype, buf, crda->crd_inject, axf->authsize, aalg);
  558. else
  559. bcopy(aalg, crp->crp_mac, axf->authsize);
  560. return (0);
  561. }
  562. /*
  563. * Apply a compression/decompression algorithm
  564. */
  565. int
  566. swcr_compdec(struct cryptodesc *crd, struct swcr_data *sw,
  567. caddr_t buf, int outtype)
  568. {
  569. u_int8_t *data, *out;
  570. struct comp_algo *cxf;
  571. int adj;
  572. u_int32_t result;
  573. cxf = sw->sw_cxf;
  574. /* We must handle the whole buffer of data in one time
  575. * then if there is not all the data in the mbuf, we must
  576. * copy in a buffer.
  577. */
  578. data = malloc(crd->crd_len, M_CRYPTO_DATA, M_NOWAIT);
  579. if (data == NULL)
  580. return (EINVAL);
  581. COPYDATA(outtype, buf, crd->crd_skip, crd->crd_len, data);
  582. if (crd->crd_flags & CRD_F_COMP)
  583. result = cxf->compress(data, crd->crd_len, &out);
  584. else
  585. result = cxf->decompress(data, crd->crd_len, &out);
  586. free(data, M_CRYPTO_DATA, 0);
  587. if (result == 0)
  588. return EINVAL;
  589. /* Copy back the (de)compressed data. m_copyback is
  590. * extending the mbuf as necessary.
  591. */
  592. sw->sw_size = result;
  593. /* Check the compressed size when doing compression */
  594. if (crd->crd_flags & CRD_F_COMP) {
  595. if (result > crd->crd_len) {
  596. /* Compression was useless, we lost time */
  597. free(out, M_CRYPTO_DATA, 0);
  598. return 0;
  599. }
  600. }
  601. COPYBACK(outtype, buf, crd->crd_skip, result, out);
  602. if (result < crd->crd_len) {
  603. adj = result - crd->crd_len;
  604. if (outtype == CRYPTO_BUF_MBUF) {
  605. adj = result - crd->crd_len;
  606. m_adj((struct mbuf *)buf, adj);
  607. } else {
  608. struct uio *uio = (struct uio *)buf;
  609. int ind;
  610. adj = crd->crd_len - result;
  611. ind = uio->uio_iovcnt - 1;
  612. while (adj > 0 && ind >= 0) {
  613. if (adj < uio->uio_iov[ind].iov_len) {
  614. uio->uio_iov[ind].iov_len -= adj;
  615. break;
  616. }
  617. adj -= uio->uio_iov[ind].iov_len;
  618. uio->uio_iov[ind].iov_len = 0;
  619. ind--;
  620. uio->uio_iovcnt--;
  621. }
  622. }
  623. }
  624. free(out, M_CRYPTO_DATA, 0);
  625. return 0;
  626. }
  627. /*
  628. * Generate a new software session.
  629. */
  630. int
  631. swcr_newsession(u_int32_t *sid, struct cryptoini *cri)
  632. {
  633. struct swcr_data **swd;
  634. struct auth_hash *axf;
  635. struct enc_xform *txf;
  636. struct comp_algo *cxf;
  637. u_int32_t i;
  638. int k;
  639. if (sid == NULL || cri == NULL)
  640. return EINVAL;
  641. if (swcr_sessions) {
  642. for (i = 1; i < swcr_sesnum; i++)
  643. if (swcr_sessions[i] == NULL)
  644. break;
  645. }
  646. if (swcr_sessions == NULL || i == swcr_sesnum) {
  647. if (swcr_sessions == NULL) {
  648. i = 1; /* We leave swcr_sessions[0] empty */
  649. swcr_sesnum = CRYPTO_SW_SESSIONS;
  650. } else
  651. swcr_sesnum *= 2;
  652. swd = mallocarray(swcr_sesnum, sizeof(struct swcr_data *),
  653. M_CRYPTO_DATA, M_NOWAIT | M_ZERO);
  654. if (swd == NULL) {
  655. /* Reset session number */
  656. if (swcr_sesnum == CRYPTO_SW_SESSIONS)
  657. swcr_sesnum = 0;
  658. else
  659. swcr_sesnum /= 2;
  660. return ENOBUFS;
  661. }
  662. /* Copy existing sessions */
  663. if (swcr_sessions) {
  664. bcopy(swcr_sessions, swd,
  665. (swcr_sesnum / 2) * sizeof(struct swcr_data *));
  666. free(swcr_sessions, M_CRYPTO_DATA, 0);
  667. }
  668. swcr_sessions = swd;
  669. }
  670. swd = &swcr_sessions[i];
  671. *sid = i;
  672. while (cri) {
  673. *swd = malloc(sizeof(struct swcr_data), M_CRYPTO_DATA,
  674. M_NOWAIT | M_ZERO);
  675. if (*swd == NULL) {
  676. swcr_freesession(i);
  677. return ENOBUFS;
  678. }
  679. switch (cri->cri_alg) {
  680. case CRYPTO_DES_CBC:
  681. txf = &enc_xform_des;
  682. goto enccommon;
  683. case CRYPTO_3DES_CBC:
  684. txf = &enc_xform_3des;
  685. goto enccommon;
  686. case CRYPTO_BLF_CBC:
  687. txf = &enc_xform_blf;
  688. goto enccommon;
  689. case CRYPTO_CAST_CBC:
  690. txf = &enc_xform_cast5;
  691. goto enccommon;
  692. case CRYPTO_RIJNDAEL128_CBC:
  693. txf = &enc_xform_rijndael128;
  694. goto enccommon;
  695. case CRYPTO_AES_CTR:
  696. txf = &enc_xform_aes_ctr;
  697. goto enccommon;
  698. case CRYPTO_AES_XTS:
  699. txf = &enc_xform_aes_xts;
  700. goto enccommon;
  701. case CRYPTO_AES_GCM_16:
  702. txf = &enc_xform_aes_gcm;
  703. goto enccommon;
  704. case CRYPTO_AES_GMAC:
  705. txf = &enc_xform_aes_gmac;
  706. (*swd)->sw_exf = txf;
  707. break;
  708. case CRYPTO_NULL:
  709. txf = &enc_xform_null;
  710. goto enccommon;
  711. enccommon:
  712. if (txf->ctxsize > 0) {
  713. (*swd)->sw_kschedule = malloc(txf->ctxsize,
  714. M_CRYPTO_DATA, M_NOWAIT | M_ZERO);
  715. if ((*swd)->sw_kschedule == NULL) {
  716. swcr_freesession(i);
  717. return EINVAL;
  718. }
  719. }
  720. if (txf->setkey((*swd)->sw_kschedule, cri->cri_key,
  721. cri->cri_klen / 8) < 0) {
  722. swcr_freesession(i);
  723. return EINVAL;
  724. }
  725. (*swd)->sw_exf = txf;
  726. break;
  727. case CRYPTO_MD5_HMAC:
  728. axf = &auth_hash_hmac_md5_96;
  729. goto authcommon;
  730. case CRYPTO_SHA1_HMAC:
  731. axf = &auth_hash_hmac_sha1_96;
  732. goto authcommon;
  733. case CRYPTO_RIPEMD160_HMAC:
  734. axf = &auth_hash_hmac_ripemd_160_96;
  735. goto authcommon;
  736. case CRYPTO_SHA2_256_HMAC:
  737. axf = &auth_hash_hmac_sha2_256_128;
  738. goto authcommon;
  739. case CRYPTO_SHA2_384_HMAC:
  740. axf = &auth_hash_hmac_sha2_384_192;
  741. goto authcommon;
  742. case CRYPTO_SHA2_512_HMAC:
  743. axf = &auth_hash_hmac_sha2_512_256;
  744. authcommon:
  745. (*swd)->sw_ictx = malloc(axf->ctxsize, M_CRYPTO_DATA,
  746. M_NOWAIT);
  747. if ((*swd)->sw_ictx == NULL) {
  748. swcr_freesession(i);
  749. return ENOBUFS;
  750. }
  751. (*swd)->sw_octx = malloc(axf->ctxsize, M_CRYPTO_DATA,
  752. M_NOWAIT);
  753. if ((*swd)->sw_octx == NULL) {
  754. swcr_freesession(i);
  755. return ENOBUFS;
  756. }
  757. for (k = 0; k < cri->cri_klen / 8; k++)
  758. cri->cri_key[k] ^= HMAC_IPAD_VAL;
  759. axf->Init((*swd)->sw_ictx);
  760. axf->Update((*swd)->sw_ictx, cri->cri_key,
  761. cri->cri_klen / 8);
  762. axf->Update((*swd)->sw_ictx, hmac_ipad_buffer,
  763. axf->blocksize - (cri->cri_klen / 8));
  764. for (k = 0; k < cri->cri_klen / 8; k++)
  765. cri->cri_key[k] ^= (HMAC_IPAD_VAL ^ HMAC_OPAD_VAL);
  766. axf->Init((*swd)->sw_octx);
  767. axf->Update((*swd)->sw_octx, cri->cri_key,
  768. cri->cri_klen / 8);
  769. axf->Update((*swd)->sw_octx, hmac_opad_buffer,
  770. axf->blocksize - (cri->cri_klen / 8));
  771. for (k = 0; k < cri->cri_klen / 8; k++)
  772. cri->cri_key[k] ^= HMAC_OPAD_VAL;
  773. (*swd)->sw_axf = axf;
  774. break;
  775. case CRYPTO_MD5:
  776. axf = &auth_hash_md5;
  777. goto auth3common;
  778. case CRYPTO_SHA1:
  779. axf = &auth_hash_sha1;
  780. auth3common:
  781. (*swd)->sw_ictx = malloc(axf->ctxsize, M_CRYPTO_DATA,
  782. M_NOWAIT);
  783. if ((*swd)->sw_ictx == NULL) {
  784. swcr_freesession(i);
  785. return ENOBUFS;
  786. }
  787. axf->Init((*swd)->sw_ictx);
  788. (*swd)->sw_axf = axf;
  789. break;
  790. case CRYPTO_AES_128_GMAC:
  791. axf = &auth_hash_gmac_aes_128;
  792. goto auth4common;
  793. case CRYPTO_AES_192_GMAC:
  794. axf = &auth_hash_gmac_aes_192;
  795. goto auth4common;
  796. case CRYPTO_AES_256_GMAC:
  797. axf = &auth_hash_gmac_aes_256;
  798. auth4common:
  799. (*swd)->sw_ictx = malloc(axf->ctxsize, M_CRYPTO_DATA,
  800. M_NOWAIT);
  801. if ((*swd)->sw_ictx == NULL) {
  802. swcr_freesession(i);
  803. return ENOBUFS;
  804. }
  805. axf->Init((*swd)->sw_ictx);
  806. axf->Setkey((*swd)->sw_ictx, cri->cri_key,
  807. cri->cri_klen / 8);
  808. (*swd)->sw_axf = axf;
  809. break;
  810. case CRYPTO_DEFLATE_COMP:
  811. cxf = &comp_algo_deflate;
  812. (*swd)->sw_cxf = cxf;
  813. break;
  814. case CRYPTO_ESN:
  815. /* nothing to do */
  816. break;
  817. default:
  818. swcr_freesession(i);
  819. return EINVAL;
  820. }
  821. (*swd)->sw_alg = cri->cri_alg;
  822. cri = cri->cri_next;
  823. swd = &((*swd)->sw_next);
  824. }
  825. return 0;
  826. }
  827. /*
  828. * Free a session.
  829. */
  830. int
  831. swcr_freesession(u_int64_t tid)
  832. {
  833. struct swcr_data *swd;
  834. struct enc_xform *txf;
  835. struct auth_hash *axf;
  836. u_int32_t sid = ((u_int32_t) tid) & 0xffffffff;
  837. if (sid > swcr_sesnum || swcr_sessions == NULL ||
  838. swcr_sessions[sid] == NULL)
  839. return EINVAL;
  840. /* Silently accept and return */
  841. if (sid == 0)
  842. return 0;
  843. while ((swd = swcr_sessions[sid]) != NULL) {
  844. swcr_sessions[sid] = swd->sw_next;
  845. switch (swd->sw_alg) {
  846. case CRYPTO_DES_CBC:
  847. case CRYPTO_3DES_CBC:
  848. case CRYPTO_BLF_CBC:
  849. case CRYPTO_CAST_CBC:
  850. case CRYPTO_RIJNDAEL128_CBC:
  851. case CRYPTO_AES_CTR:
  852. case CRYPTO_AES_XTS:
  853. case CRYPTO_AES_GCM_16:
  854. case CRYPTO_AES_GMAC:
  855. case CRYPTO_NULL:
  856. txf = swd->sw_exf;
  857. if (swd->sw_kschedule) {
  858. explicit_bzero(swd->sw_kschedule, txf->ctxsize);
  859. free(swd->sw_kschedule, M_CRYPTO_DATA, 0);
  860. }
  861. break;
  862. case CRYPTO_MD5_HMAC:
  863. case CRYPTO_SHA1_HMAC:
  864. case CRYPTO_RIPEMD160_HMAC:
  865. case CRYPTO_SHA2_256_HMAC:
  866. case CRYPTO_SHA2_384_HMAC:
  867. case CRYPTO_SHA2_512_HMAC:
  868. axf = swd->sw_axf;
  869. if (swd->sw_ictx) {
  870. explicit_bzero(swd->sw_ictx, axf->ctxsize);
  871. free(swd->sw_ictx, M_CRYPTO_DATA, 0);
  872. }
  873. if (swd->sw_octx) {
  874. explicit_bzero(swd->sw_octx, axf->ctxsize);
  875. free(swd->sw_octx, M_CRYPTO_DATA, 0);
  876. }
  877. break;
  878. case CRYPTO_AES_128_GMAC:
  879. case CRYPTO_AES_192_GMAC:
  880. case CRYPTO_AES_256_GMAC:
  881. case CRYPTO_MD5:
  882. case CRYPTO_SHA1:
  883. axf = swd->sw_axf;
  884. if (swd->sw_ictx) {
  885. explicit_bzero(swd->sw_ictx, axf->ctxsize);
  886. free(swd->sw_ictx, M_CRYPTO_DATA, 0);
  887. }
  888. break;
  889. }
  890. free(swd, M_CRYPTO_DATA, 0);
  891. }
  892. return 0;
  893. }
  894. /*
  895. * Process a software request.
  896. */
  897. int
  898. swcr_process(struct cryptop *crp)
  899. {
  900. struct cryptodesc *crd;
  901. struct swcr_data *sw;
  902. u_int32_t lid;
  903. int type;
  904. /* Sanity check */
  905. if (crp == NULL)
  906. return EINVAL;
  907. if (crp->crp_desc == NULL || crp->crp_buf == NULL) {
  908. crp->crp_etype = EINVAL;
  909. goto done;
  910. }
  911. lid = crp->crp_sid & 0xffffffff;
  912. if (lid >= swcr_sesnum || lid == 0 || swcr_sessions[lid] == NULL) {
  913. crp->crp_etype = ENOENT;
  914. goto done;
  915. }
  916. if (crp->crp_flags & CRYPTO_F_IMBUF)
  917. type = CRYPTO_BUF_MBUF;
  918. else
  919. type = CRYPTO_BUF_IOV;
  920. /* Go through crypto descriptors, processing as we go */
  921. for (crd = crp->crp_desc; crd; crd = crd->crd_next) {
  922. /*
  923. * Find the crypto context.
  924. *
  925. * XXX Note that the logic here prevents us from having
  926. * XXX the same algorithm multiple times in a session
  927. * XXX (or rather, we can but it won't give us the right
  928. * XXX results). To do that, we'd need some way of differentiating
  929. * XXX between the various instances of an algorithm (so we can
  930. * XXX locate the correct crypto context).
  931. */
  932. for (sw = swcr_sessions[lid];
  933. sw && sw->sw_alg != crd->crd_alg;
  934. sw = sw->sw_next)
  935. ;
  936. /* No such context ? */
  937. if (sw == NULL) {
  938. crp->crp_etype = EINVAL;
  939. goto done;
  940. }
  941. switch (sw->sw_alg) {
  942. case CRYPTO_NULL:
  943. break;
  944. case CRYPTO_DES_CBC:
  945. case CRYPTO_3DES_CBC:
  946. case CRYPTO_BLF_CBC:
  947. case CRYPTO_CAST_CBC:
  948. case CRYPTO_RIJNDAEL128_CBC:
  949. case CRYPTO_AES_CTR:
  950. case CRYPTO_AES_XTS:
  951. if ((crp->crp_etype = swcr_encdec(crd, sw,
  952. crp->crp_buf, type)) != 0)
  953. goto done;
  954. break;
  955. case CRYPTO_MD5_HMAC:
  956. case CRYPTO_SHA1_HMAC:
  957. case CRYPTO_RIPEMD160_HMAC:
  958. case CRYPTO_SHA2_256_HMAC:
  959. case CRYPTO_SHA2_384_HMAC:
  960. case CRYPTO_SHA2_512_HMAC:
  961. case CRYPTO_MD5:
  962. case CRYPTO_SHA1:
  963. if ((crp->crp_etype = swcr_authcompute(crp, crd, sw,
  964. crp->crp_buf, type)) != 0)
  965. goto done;
  966. break;
  967. case CRYPTO_AES_GCM_16:
  968. case CRYPTO_AES_GMAC:
  969. case CRYPTO_AES_128_GMAC:
  970. case CRYPTO_AES_192_GMAC:
  971. case CRYPTO_AES_256_GMAC:
  972. crp->crp_etype = swcr_authenc(crp);
  973. goto done;
  974. case CRYPTO_DEFLATE_COMP:
  975. if ((crp->crp_etype = swcr_compdec(crd, sw,
  976. crp->crp_buf, type)) != 0)
  977. goto done;
  978. else
  979. crp->crp_olen = (int)sw->sw_size;
  980. break;
  981. default:
  982. /* Unknown/unsupported algorithm */
  983. crp->crp_etype = EINVAL;
  984. goto done;
  985. }
  986. }
  987. done:
  988. crypto_done(crp);
  989. return 0;
  990. }
  991. /*
  992. * Initialize the driver, called from the kernel main().
  993. */
  994. void
  995. swcr_init(void)
  996. {
  997. int algs[CRYPTO_ALGORITHM_MAX + 1];
  998. int flags = CRYPTOCAP_F_SOFTWARE | CRYPTOCAP_F_ENCRYPT_MAC |
  999. CRYPTOCAP_F_MAC_ENCRYPT;
  1000. swcr_id = crypto_get_driverid(flags);
  1001. if (swcr_id < 0) {
  1002. /* This should never happen */
  1003. panic("Software crypto device cannot initialize!");
  1004. }
  1005. bzero(algs, sizeof(algs));
  1006. algs[CRYPTO_DES_CBC] = CRYPTO_ALG_FLAG_SUPPORTED;
  1007. algs[CRYPTO_3DES_CBC] = CRYPTO_ALG_FLAG_SUPPORTED;
  1008. algs[CRYPTO_BLF_CBC] = CRYPTO_ALG_FLAG_SUPPORTED;
  1009. algs[CRYPTO_CAST_CBC] = CRYPTO_ALG_FLAG_SUPPORTED;
  1010. algs[CRYPTO_MD5_HMAC] = CRYPTO_ALG_FLAG_SUPPORTED;
  1011. algs[CRYPTO_SHA1_HMAC] = CRYPTO_ALG_FLAG_SUPPORTED;
  1012. algs[CRYPTO_RIPEMD160_HMAC] = CRYPTO_ALG_FLAG_SUPPORTED;
  1013. algs[CRYPTO_MD5] = CRYPTO_ALG_FLAG_SUPPORTED;
  1014. algs[CRYPTO_SHA1] = CRYPTO_ALG_FLAG_SUPPORTED;
  1015. algs[CRYPTO_RIJNDAEL128_CBC] = CRYPTO_ALG_FLAG_SUPPORTED;
  1016. algs[CRYPTO_AES_CTR] = CRYPTO_ALG_FLAG_SUPPORTED;
  1017. algs[CRYPTO_AES_XTS] = CRYPTO_ALG_FLAG_SUPPORTED;
  1018. algs[CRYPTO_AES_GCM_16] = CRYPTO_ALG_FLAG_SUPPORTED;
  1019. algs[CRYPTO_AES_GMAC] = CRYPTO_ALG_FLAG_SUPPORTED;
  1020. algs[CRYPTO_DEFLATE_COMP] = CRYPTO_ALG_FLAG_SUPPORTED;
  1021. algs[CRYPTO_NULL] = CRYPTO_ALG_FLAG_SUPPORTED;
  1022. algs[CRYPTO_SHA2_256_HMAC] = CRYPTO_ALG_FLAG_SUPPORTED;
  1023. algs[CRYPTO_SHA2_384_HMAC] = CRYPTO_ALG_FLAG_SUPPORTED;
  1024. algs[CRYPTO_SHA2_512_HMAC] = CRYPTO_ALG_FLAG_SUPPORTED;
  1025. algs[CRYPTO_AES_128_GMAC] = CRYPTO_ALG_FLAG_SUPPORTED;
  1026. algs[CRYPTO_AES_192_GMAC] = CRYPTO_ALG_FLAG_SUPPORTED;
  1027. algs[CRYPTO_AES_256_GMAC] = CRYPTO_ALG_FLAG_SUPPORTED;
  1028. algs[CRYPTO_ESN] = CRYPTO_ALG_FLAG_SUPPORTED;
  1029. crypto_register(swcr_id, algs, swcr_newsession,
  1030. swcr_freesession, swcr_process);
  1031. }