xfrm_algo.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  1. /*
  2. * xfrm algorithm interface
  3. *
  4. * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the Free
  8. * Software Foundation; either version 2 of the License, or (at your option)
  9. * any later version.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/kernel.h>
  13. #include <linux/pfkeyv2.h>
  14. #include <linux/crypto.h>
  15. #include <linux/scatterlist.h>
  16. #include <net/xfrm.h>
  17. #if defined(CONFIG_INET_ESP) || defined(CONFIG_INET_ESP_MODULE) || defined(CONFIG_INET6_ESP) || defined(CONFIG_INET6_ESP_MODULE)
  18. #include <net/esp.h>
  19. #endif
  20. /*
  21. * Algorithms supported by IPsec. These entries contain properties which
  22. * are used in key negotiation and xfrm processing, and are used to verify
  23. * that instantiated crypto transforms have correct parameters for IPsec
  24. * purposes.
  25. */
  26. static struct xfrm_algo_desc aead_list[] = {
  27. {
  28. .name = "rfc4106(gcm(aes))",
  29. .uinfo = {
  30. .aead = {
  31. .geniv = "seqiv",
  32. .icv_truncbits = 64,
  33. }
  34. },
  35. .pfkey_supported = 1,
  36. .desc = {
  37. .sadb_alg_id = SADB_X_EALG_AES_GCM_ICV8,
  38. .sadb_alg_ivlen = 8,
  39. .sadb_alg_minbits = 128,
  40. .sadb_alg_maxbits = 256
  41. }
  42. },
  43. {
  44. .name = "rfc4106(gcm(aes))",
  45. .uinfo = {
  46. .aead = {
  47. .geniv = "seqiv",
  48. .icv_truncbits = 96,
  49. }
  50. },
  51. .pfkey_supported = 1,
  52. .desc = {
  53. .sadb_alg_id = SADB_X_EALG_AES_GCM_ICV12,
  54. .sadb_alg_ivlen = 8,
  55. .sadb_alg_minbits = 128,
  56. .sadb_alg_maxbits = 256
  57. }
  58. },
  59. {
  60. .name = "rfc4106(gcm(aes))",
  61. .uinfo = {
  62. .aead = {
  63. .geniv = "seqiv",
  64. .icv_truncbits = 128,
  65. }
  66. },
  67. .pfkey_supported = 1,
  68. .desc = {
  69. .sadb_alg_id = SADB_X_EALG_AES_GCM_ICV16,
  70. .sadb_alg_ivlen = 8,
  71. .sadb_alg_minbits = 128,
  72. .sadb_alg_maxbits = 256
  73. }
  74. },
  75. {
  76. .name = "rfc4309(ccm(aes))",
  77. .uinfo = {
  78. .aead = {
  79. .geniv = "seqiv",
  80. .icv_truncbits = 64,
  81. }
  82. },
  83. .pfkey_supported = 1,
  84. .desc = {
  85. .sadb_alg_id = SADB_X_EALG_AES_CCM_ICV8,
  86. .sadb_alg_ivlen = 8,
  87. .sadb_alg_minbits = 128,
  88. .sadb_alg_maxbits = 256
  89. }
  90. },
  91. {
  92. .name = "rfc4309(ccm(aes))",
  93. .uinfo = {
  94. .aead = {
  95. .geniv = "seqiv",
  96. .icv_truncbits = 96,
  97. }
  98. },
  99. .pfkey_supported = 1,
  100. .desc = {
  101. .sadb_alg_id = SADB_X_EALG_AES_CCM_ICV12,
  102. .sadb_alg_ivlen = 8,
  103. .sadb_alg_minbits = 128,
  104. .sadb_alg_maxbits = 256
  105. }
  106. },
  107. {
  108. .name = "rfc4309(ccm(aes))",
  109. .uinfo = {
  110. .aead = {
  111. .geniv = "seqiv",
  112. .icv_truncbits = 128,
  113. }
  114. },
  115. .pfkey_supported = 1,
  116. .desc = {
  117. .sadb_alg_id = SADB_X_EALG_AES_CCM_ICV16,
  118. .sadb_alg_ivlen = 8,
  119. .sadb_alg_minbits = 128,
  120. .sadb_alg_maxbits = 256
  121. }
  122. },
  123. {
  124. .name = "rfc4543(gcm(aes))",
  125. .uinfo = {
  126. .aead = {
  127. .geniv = "seqiv",
  128. .icv_truncbits = 128,
  129. }
  130. },
  131. .pfkey_supported = 1,
  132. .desc = {
  133. .sadb_alg_id = SADB_X_EALG_NULL_AES_GMAC,
  134. .sadb_alg_ivlen = 8,
  135. .sadb_alg_minbits = 128,
  136. .sadb_alg_maxbits = 256
  137. }
  138. },
  139. {
  140. .name = "rfc7539esp(chacha20,poly1305)",
  141. .uinfo = {
  142. .aead = {
  143. .geniv = "seqiv",
  144. .icv_truncbits = 128,
  145. }
  146. },
  147. .pfkey_supported = 0,
  148. },
  149. };
  150. static struct xfrm_algo_desc aalg_list[] = {
  151. {
  152. .name = "digest_null",
  153. .uinfo = {
  154. .auth = {
  155. .icv_truncbits = 0,
  156. .icv_fullbits = 0,
  157. }
  158. },
  159. .pfkey_supported = 1,
  160. .desc = {
  161. .sadb_alg_id = SADB_X_AALG_NULL,
  162. .sadb_alg_ivlen = 0,
  163. .sadb_alg_minbits = 0,
  164. .sadb_alg_maxbits = 0
  165. }
  166. },
  167. {
  168. .name = "hmac(md5)",
  169. .compat = "md5",
  170. .uinfo = {
  171. .auth = {
  172. .icv_truncbits = 96,
  173. .icv_fullbits = 128,
  174. }
  175. },
  176. .pfkey_supported = 1,
  177. .desc = {
  178. .sadb_alg_id = SADB_AALG_MD5HMAC,
  179. .sadb_alg_ivlen = 0,
  180. .sadb_alg_minbits = 128,
  181. .sadb_alg_maxbits = 128
  182. }
  183. },
  184. {
  185. .name = "hmac(sha1)",
  186. .compat = "sha1",
  187. .uinfo = {
  188. .auth = {
  189. .icv_truncbits = 96,
  190. .icv_fullbits = 160,
  191. }
  192. },
  193. .pfkey_supported = 1,
  194. .desc = {
  195. .sadb_alg_id = SADB_AALG_SHA1HMAC,
  196. .sadb_alg_ivlen = 0,
  197. .sadb_alg_minbits = 160,
  198. .sadb_alg_maxbits = 160
  199. }
  200. },
  201. {
  202. .name = "hmac(sha256)",
  203. .compat = "sha256",
  204. .uinfo = {
  205. .auth = {
  206. .icv_truncbits = 96,
  207. .icv_fullbits = 256,
  208. }
  209. },
  210. .pfkey_supported = 1,
  211. .desc = {
  212. .sadb_alg_id = SADB_X_AALG_SHA2_256HMAC,
  213. .sadb_alg_ivlen = 0,
  214. .sadb_alg_minbits = 256,
  215. .sadb_alg_maxbits = 256
  216. }
  217. },
  218. {
  219. .name = "hmac(sha384)",
  220. .uinfo = {
  221. .auth = {
  222. .icv_truncbits = 192,
  223. .icv_fullbits = 384,
  224. }
  225. },
  226. .pfkey_supported = 1,
  227. .desc = {
  228. .sadb_alg_id = SADB_X_AALG_SHA2_384HMAC,
  229. .sadb_alg_ivlen = 0,
  230. .sadb_alg_minbits = 384,
  231. .sadb_alg_maxbits = 384
  232. }
  233. },
  234. {
  235. .name = "hmac(sha512)",
  236. .uinfo = {
  237. .auth = {
  238. .icv_truncbits = 256,
  239. .icv_fullbits = 512,
  240. }
  241. },
  242. .pfkey_supported = 1,
  243. .desc = {
  244. .sadb_alg_id = SADB_X_AALG_SHA2_512HMAC,
  245. .sadb_alg_ivlen = 0,
  246. .sadb_alg_minbits = 512,
  247. .sadb_alg_maxbits = 512
  248. }
  249. },
  250. {
  251. .name = "hmac(rmd160)",
  252. .compat = "rmd160",
  253. .uinfo = {
  254. .auth = {
  255. .icv_truncbits = 96,
  256. .icv_fullbits = 160,
  257. }
  258. },
  259. .pfkey_supported = 1,
  260. .desc = {
  261. .sadb_alg_id = SADB_X_AALG_RIPEMD160HMAC,
  262. .sadb_alg_ivlen = 0,
  263. .sadb_alg_minbits = 160,
  264. .sadb_alg_maxbits = 160
  265. }
  266. },
  267. {
  268. .name = "xcbc(aes)",
  269. .uinfo = {
  270. .auth = {
  271. .icv_truncbits = 96,
  272. .icv_fullbits = 128,
  273. }
  274. },
  275. .pfkey_supported = 1,
  276. .desc = {
  277. .sadb_alg_id = SADB_X_AALG_AES_XCBC_MAC,
  278. .sadb_alg_ivlen = 0,
  279. .sadb_alg_minbits = 128,
  280. .sadb_alg_maxbits = 128
  281. }
  282. },
  283. {
  284. /* rfc4494 */
  285. .name = "cmac(aes)",
  286. .uinfo = {
  287. .auth = {
  288. .icv_truncbits = 96,
  289. .icv_fullbits = 128,
  290. }
  291. },
  292. .pfkey_supported = 0,
  293. },
  294. };
  295. static struct xfrm_algo_desc ealg_list[] = {
  296. {
  297. .name = "ecb(cipher_null)",
  298. .compat = "cipher_null",
  299. .uinfo = {
  300. .encr = {
  301. .blockbits = 8,
  302. .defkeybits = 0,
  303. }
  304. },
  305. .pfkey_supported = 1,
  306. .desc = {
  307. .sadb_alg_id = SADB_EALG_NULL,
  308. .sadb_alg_ivlen = 0,
  309. .sadb_alg_minbits = 0,
  310. .sadb_alg_maxbits = 0
  311. }
  312. },
  313. {
  314. .name = "cbc(des)",
  315. .compat = "des",
  316. .uinfo = {
  317. .encr = {
  318. .geniv = "echainiv",
  319. .blockbits = 64,
  320. .defkeybits = 64,
  321. }
  322. },
  323. .pfkey_supported = 1,
  324. .desc = {
  325. .sadb_alg_id = SADB_EALG_DESCBC,
  326. .sadb_alg_ivlen = 8,
  327. .sadb_alg_minbits = 64,
  328. .sadb_alg_maxbits = 64
  329. }
  330. },
  331. {
  332. .name = "cbc(des3_ede)",
  333. .compat = "des3_ede",
  334. .uinfo = {
  335. .encr = {
  336. .geniv = "echainiv",
  337. .blockbits = 64,
  338. .defkeybits = 192,
  339. }
  340. },
  341. .pfkey_supported = 1,
  342. .desc = {
  343. .sadb_alg_id = SADB_EALG_3DESCBC,
  344. .sadb_alg_ivlen = 8,
  345. .sadb_alg_minbits = 192,
  346. .sadb_alg_maxbits = 192
  347. }
  348. },
  349. {
  350. .name = "cbc(cast5)",
  351. .compat = "cast5",
  352. .uinfo = {
  353. .encr = {
  354. .geniv = "echainiv",
  355. .blockbits = 64,
  356. .defkeybits = 128,
  357. }
  358. },
  359. .pfkey_supported = 1,
  360. .desc = {
  361. .sadb_alg_id = SADB_X_EALG_CASTCBC,
  362. .sadb_alg_ivlen = 8,
  363. .sadb_alg_minbits = 40,
  364. .sadb_alg_maxbits = 128
  365. }
  366. },
  367. {
  368. .name = "cbc(blowfish)",
  369. .compat = "blowfish",
  370. .uinfo = {
  371. .encr = {
  372. .geniv = "echainiv",
  373. .blockbits = 64,
  374. .defkeybits = 128,
  375. }
  376. },
  377. .pfkey_supported = 1,
  378. .desc = {
  379. .sadb_alg_id = SADB_X_EALG_BLOWFISHCBC,
  380. .sadb_alg_ivlen = 8,
  381. .sadb_alg_minbits = 40,
  382. .sadb_alg_maxbits = 448
  383. }
  384. },
  385. {
  386. .name = "cbc(aes)",
  387. .compat = "aes",
  388. .uinfo = {
  389. .encr = {
  390. .geniv = "echainiv",
  391. .blockbits = 128,
  392. .defkeybits = 128,
  393. }
  394. },
  395. .pfkey_supported = 1,
  396. .desc = {
  397. .sadb_alg_id = SADB_X_EALG_AESCBC,
  398. .sadb_alg_ivlen = 8,
  399. .sadb_alg_minbits = 128,
  400. .sadb_alg_maxbits = 256
  401. }
  402. },
  403. {
  404. .name = "cbc(serpent)",
  405. .compat = "serpent",
  406. .uinfo = {
  407. .encr = {
  408. .geniv = "echainiv",
  409. .blockbits = 128,
  410. .defkeybits = 128,
  411. }
  412. },
  413. .pfkey_supported = 1,
  414. .desc = {
  415. .sadb_alg_id = SADB_X_EALG_SERPENTCBC,
  416. .sadb_alg_ivlen = 8,
  417. .sadb_alg_minbits = 128,
  418. .sadb_alg_maxbits = 256,
  419. }
  420. },
  421. {
  422. .name = "cbc(camellia)",
  423. .compat = "camellia",
  424. .uinfo = {
  425. .encr = {
  426. .geniv = "echainiv",
  427. .blockbits = 128,
  428. .defkeybits = 128,
  429. }
  430. },
  431. .pfkey_supported = 1,
  432. .desc = {
  433. .sadb_alg_id = SADB_X_EALG_CAMELLIACBC,
  434. .sadb_alg_ivlen = 8,
  435. .sadb_alg_minbits = 128,
  436. .sadb_alg_maxbits = 256
  437. }
  438. },
  439. {
  440. .name = "cbc(twofish)",
  441. .compat = "twofish",
  442. .uinfo = {
  443. .encr = {
  444. .geniv = "echainiv",
  445. .blockbits = 128,
  446. .defkeybits = 128,
  447. }
  448. },
  449. .pfkey_supported = 1,
  450. .desc = {
  451. .sadb_alg_id = SADB_X_EALG_TWOFISHCBC,
  452. .sadb_alg_ivlen = 8,
  453. .sadb_alg_minbits = 128,
  454. .sadb_alg_maxbits = 256
  455. }
  456. },
  457. {
  458. .name = "rfc3686(ctr(aes))",
  459. .uinfo = {
  460. .encr = {
  461. .geniv = "seqiv",
  462. .blockbits = 128,
  463. .defkeybits = 160, /* 128-bit key + 32-bit nonce */
  464. }
  465. },
  466. .pfkey_supported = 1,
  467. .desc = {
  468. .sadb_alg_id = SADB_X_EALG_AESCTR,
  469. .sadb_alg_ivlen = 8,
  470. .sadb_alg_minbits = 160,
  471. .sadb_alg_maxbits = 288
  472. }
  473. },
  474. };
  475. static struct xfrm_algo_desc calg_list[] = {
  476. {
  477. .name = "deflate",
  478. .uinfo = {
  479. .comp = {
  480. .threshold = 90,
  481. }
  482. },
  483. .pfkey_supported = 1,
  484. .desc = { .sadb_alg_id = SADB_X_CALG_DEFLATE }
  485. },
  486. {
  487. .name = "lzs",
  488. .uinfo = {
  489. .comp = {
  490. .threshold = 90,
  491. }
  492. },
  493. .pfkey_supported = 1,
  494. .desc = { .sadb_alg_id = SADB_X_CALG_LZS }
  495. },
  496. {
  497. .name = "lzjh",
  498. .uinfo = {
  499. .comp = {
  500. .threshold = 50,
  501. }
  502. },
  503. .pfkey_supported = 1,
  504. .desc = { .sadb_alg_id = SADB_X_CALG_LZJH }
  505. },
  506. };
  507. static inline int aalg_entries(void)
  508. {
  509. return ARRAY_SIZE(aalg_list);
  510. }
  511. static inline int ealg_entries(void)
  512. {
  513. return ARRAY_SIZE(ealg_list);
  514. }
  515. static inline int calg_entries(void)
  516. {
  517. return ARRAY_SIZE(calg_list);
  518. }
  519. struct xfrm_algo_list {
  520. struct xfrm_algo_desc *algs;
  521. int entries;
  522. u32 type;
  523. u32 mask;
  524. };
  525. static const struct xfrm_algo_list xfrm_aead_list = {
  526. .algs = aead_list,
  527. .entries = ARRAY_SIZE(aead_list),
  528. .type = CRYPTO_ALG_TYPE_AEAD,
  529. .mask = CRYPTO_ALG_TYPE_MASK,
  530. };
  531. static const struct xfrm_algo_list xfrm_aalg_list = {
  532. .algs = aalg_list,
  533. .entries = ARRAY_SIZE(aalg_list),
  534. .type = CRYPTO_ALG_TYPE_HASH,
  535. .mask = CRYPTO_ALG_TYPE_HASH_MASK,
  536. };
  537. static const struct xfrm_algo_list xfrm_ealg_list = {
  538. .algs = ealg_list,
  539. .entries = ARRAY_SIZE(ealg_list),
  540. .type = CRYPTO_ALG_TYPE_BLKCIPHER,
  541. .mask = CRYPTO_ALG_TYPE_BLKCIPHER_MASK,
  542. };
  543. static const struct xfrm_algo_list xfrm_calg_list = {
  544. .algs = calg_list,
  545. .entries = ARRAY_SIZE(calg_list),
  546. .type = CRYPTO_ALG_TYPE_COMPRESS,
  547. .mask = CRYPTO_ALG_TYPE_MASK,
  548. };
  549. static struct xfrm_algo_desc *xfrm_find_algo(
  550. const struct xfrm_algo_list *algo_list,
  551. int match(const struct xfrm_algo_desc *entry, const void *data),
  552. const void *data, int probe)
  553. {
  554. struct xfrm_algo_desc *list = algo_list->algs;
  555. int i, status;
  556. for (i = 0; i < algo_list->entries; i++) {
  557. if (!match(list + i, data))
  558. continue;
  559. if (list[i].available)
  560. return &list[i];
  561. if (!probe)
  562. break;
  563. status = crypto_has_alg(list[i].name, algo_list->type,
  564. algo_list->mask);
  565. if (!status)
  566. break;
  567. list[i].available = status;
  568. return &list[i];
  569. }
  570. return NULL;
  571. }
  572. static int xfrm_alg_id_match(const struct xfrm_algo_desc *entry,
  573. const void *data)
  574. {
  575. return entry->desc.sadb_alg_id == (unsigned long)data;
  576. }
  577. struct xfrm_algo_desc *xfrm_aalg_get_byid(int alg_id)
  578. {
  579. return xfrm_find_algo(&xfrm_aalg_list, xfrm_alg_id_match,
  580. (void *)(unsigned long)alg_id, 1);
  581. }
  582. EXPORT_SYMBOL_GPL(xfrm_aalg_get_byid);
  583. struct xfrm_algo_desc *xfrm_ealg_get_byid(int alg_id)
  584. {
  585. return xfrm_find_algo(&xfrm_ealg_list, xfrm_alg_id_match,
  586. (void *)(unsigned long)alg_id, 1);
  587. }
  588. EXPORT_SYMBOL_GPL(xfrm_ealg_get_byid);
  589. struct xfrm_algo_desc *xfrm_calg_get_byid(int alg_id)
  590. {
  591. return xfrm_find_algo(&xfrm_calg_list, xfrm_alg_id_match,
  592. (void *)(unsigned long)alg_id, 1);
  593. }
  594. EXPORT_SYMBOL_GPL(xfrm_calg_get_byid);
  595. static int xfrm_alg_name_match(const struct xfrm_algo_desc *entry,
  596. const void *data)
  597. {
  598. const char *name = data;
  599. return name && (!strcmp(name, entry->name) ||
  600. (entry->compat && !strcmp(name, entry->compat)));
  601. }
  602. struct xfrm_algo_desc *xfrm_aalg_get_byname(const char *name, int probe)
  603. {
  604. return xfrm_find_algo(&xfrm_aalg_list, xfrm_alg_name_match, name,
  605. probe);
  606. }
  607. EXPORT_SYMBOL_GPL(xfrm_aalg_get_byname);
  608. struct xfrm_algo_desc *xfrm_ealg_get_byname(const char *name, int probe)
  609. {
  610. return xfrm_find_algo(&xfrm_ealg_list, xfrm_alg_name_match, name,
  611. probe);
  612. }
  613. EXPORT_SYMBOL_GPL(xfrm_ealg_get_byname);
  614. struct xfrm_algo_desc *xfrm_calg_get_byname(const char *name, int probe)
  615. {
  616. return xfrm_find_algo(&xfrm_calg_list, xfrm_alg_name_match, name,
  617. probe);
  618. }
  619. EXPORT_SYMBOL_GPL(xfrm_calg_get_byname);
  620. struct xfrm_aead_name {
  621. const char *name;
  622. int icvbits;
  623. };
  624. static int xfrm_aead_name_match(const struct xfrm_algo_desc *entry,
  625. const void *data)
  626. {
  627. const struct xfrm_aead_name *aead = data;
  628. const char *name = aead->name;
  629. return aead->icvbits == entry->uinfo.aead.icv_truncbits && name &&
  630. !strcmp(name, entry->name);
  631. }
  632. struct xfrm_algo_desc *xfrm_aead_get_byname(const char *name, int icv_len, int probe)
  633. {
  634. struct xfrm_aead_name data = {
  635. .name = name,
  636. .icvbits = icv_len,
  637. };
  638. return xfrm_find_algo(&xfrm_aead_list, xfrm_aead_name_match, &data,
  639. probe);
  640. }
  641. EXPORT_SYMBOL_GPL(xfrm_aead_get_byname);
  642. struct xfrm_algo_desc *xfrm_aalg_get_byidx(unsigned int idx)
  643. {
  644. if (idx >= aalg_entries())
  645. return NULL;
  646. return &aalg_list[idx];
  647. }
  648. EXPORT_SYMBOL_GPL(xfrm_aalg_get_byidx);
  649. struct xfrm_algo_desc *xfrm_ealg_get_byidx(unsigned int idx)
  650. {
  651. if (idx >= ealg_entries())
  652. return NULL;
  653. return &ealg_list[idx];
  654. }
  655. EXPORT_SYMBOL_GPL(xfrm_ealg_get_byidx);
  656. /*
  657. * Probe for the availability of crypto algorithms, and set the available
  658. * flag for any algorithms found on the system. This is typically called by
  659. * pfkey during userspace SA add, update or register.
  660. */
  661. void xfrm_probe_algs(void)
  662. {
  663. int i, status;
  664. BUG_ON(in_softirq());
  665. for (i = 0; i < aalg_entries(); i++) {
  666. status = crypto_has_hash(aalg_list[i].name, 0,
  667. CRYPTO_ALG_ASYNC);
  668. if (aalg_list[i].available != status)
  669. aalg_list[i].available = status;
  670. }
  671. for (i = 0; i < ealg_entries(); i++) {
  672. status = crypto_has_ablkcipher(ealg_list[i].name, 0, 0);
  673. if (ealg_list[i].available != status)
  674. ealg_list[i].available = status;
  675. }
  676. for (i = 0; i < calg_entries(); i++) {
  677. status = crypto_has_comp(calg_list[i].name, 0,
  678. CRYPTO_ALG_ASYNC);
  679. if (calg_list[i].available != status)
  680. calg_list[i].available = status;
  681. }
  682. }
  683. EXPORT_SYMBOL_GPL(xfrm_probe_algs);
  684. int xfrm_count_pfkey_auth_supported(void)
  685. {
  686. int i, n;
  687. for (i = 0, n = 0; i < aalg_entries(); i++)
  688. if (aalg_list[i].available && aalg_list[i].pfkey_supported)
  689. n++;
  690. return n;
  691. }
  692. EXPORT_SYMBOL_GPL(xfrm_count_pfkey_auth_supported);
  693. int xfrm_count_pfkey_enc_supported(void)
  694. {
  695. int i, n;
  696. for (i = 0, n = 0; i < ealg_entries(); i++)
  697. if (ealg_list[i].available && ealg_list[i].pfkey_supported)
  698. n++;
  699. return n;
  700. }
  701. EXPORT_SYMBOL_GPL(xfrm_count_pfkey_enc_supported);
  702. MODULE_LICENSE("GPL");