crypto.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784
  1. /*-
  2. * Linux port done by David McCullough <[email protected]>
  3. * Copyright (C) 2006-2010 David McCullough
  4. * Copyright (C) 2004-2005 Intel Corporation.
  5. * The license and original author are listed below.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * Copyright (c) 2002-2006 Sam Leffler. All rights reserved.
  9. *
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  19. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  20. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  21. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  23. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #if 0
  30. #include <sys/cdefs.h>
  31. __FBSDID("$FreeBSD: src/sys/opencrypto/crypto.c,v 1.27 2007/03/21 03:42:51 sam Exp $");
  32. #endif
  33. /*
  34. * Cryptographic Subsystem.
  35. *
  36. * This code is derived from the Openbsd Cryptographic Framework (OCF)
  37. * that has the copyright shown below. Very little of the original
  38. * code remains.
  39. */
  40. /*-
  41. * The author of this code is Angelos D. Keromytis ([email protected])
  42. *
  43. * This code was written by Angelos D. Keromytis in Athens, Greece, in
  44. * February 2000. Network Security Technologies Inc. (NSTI) kindly
  45. * supported the development of this code.
  46. *
  47. * Copyright (c) 2000, 2001 Angelos D. Keromytis
  48. *
  49. * Permission to use, copy, and modify this software with or without fee
  50. * is hereby granted, provided that this entire notice is included in
  51. * all source code copies of any software which is or includes a copy or
  52. * modification of this software.
  53. *
  54. * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
  55. * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
  56. * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
  57. * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
  58. * PURPOSE.
  59. *
  60. __FBSDID("$FreeBSD: src/sys/opencrypto/crypto.c,v 1.16 2005/01/07 02:29:16 imp Exp $");
  61. */
  62. #ifndef AUTOCONF_INCLUDED
  63. #include <linux/config.h>
  64. #endif
  65. #include <linux/module.h>
  66. #include <linux/init.h>
  67. #include <linux/list.h>
  68. #include <linux/slab.h>
  69. #include <linux/wait.h>
  70. #include <linux/sched.h>
  71. #include <linux/spinlock.h>
  72. #include <linux/version.h>
  73. #include <cryptodev.h>
  74. /*
  75. * keep track of whether or not we have been initialised, a big
  76. * issue if we are linked into the kernel and a driver gets started before
  77. * us
  78. */
  79. static int crypto_initted = 0;
  80. /*
  81. * Crypto drivers register themselves by allocating a slot in the
  82. * crypto_drivers table with crypto_get_driverid() and then registering
  83. * each algorithm they support with crypto_register() and crypto_kregister().
  84. */
  85. /*
  86. * lock on driver table
  87. * we track its state as spin_is_locked does not do anything on non-SMP boxes
  88. */
  89. static spinlock_t crypto_drivers_lock;
  90. static int crypto_drivers_locked; /* for non-SMP boxes */
  91. #define CRYPTO_DRIVER_LOCK() \
  92. ({ \
  93. spin_lock_irqsave(&crypto_drivers_lock, d_flags); \
  94. crypto_drivers_locked = 1; \
  95. dprintk("%s,%d: DRIVER_LOCK()\n", __FILE__, __LINE__); \
  96. })
  97. #define CRYPTO_DRIVER_UNLOCK() \
  98. ({ \
  99. dprintk("%s,%d: DRIVER_UNLOCK()\n", __FILE__, __LINE__); \
  100. crypto_drivers_locked = 0; \
  101. spin_unlock_irqrestore(&crypto_drivers_lock, d_flags); \
  102. })
  103. #define CRYPTO_DRIVER_ASSERT() \
  104. ({ \
  105. if (!crypto_drivers_locked) { \
  106. dprintk("%s,%d: DRIVER_ASSERT!\n", __FILE__, __LINE__); \
  107. } \
  108. })
  109. /*
  110. * Crypto device/driver capabilities structure.
  111. *
  112. * Synchronization:
  113. * (d) - protected by CRYPTO_DRIVER_LOCK()
  114. * (q) - protected by CRYPTO_Q_LOCK()
  115. * Not tagged fields are read-only.
  116. */
  117. struct cryptocap {
  118. device_t cc_dev; /* (d) device/driver */
  119. u_int32_t cc_sessions; /* (d) # of sessions */
  120. u_int32_t cc_koperations; /* (d) # os asym operations */
  121. /*
  122. * Largest possible operator length (in bits) for each type of
  123. * encryption algorithm. XXX not used
  124. */
  125. u_int16_t cc_max_op_len[CRYPTO_ALGORITHM_MAX + 1];
  126. u_int8_t cc_alg[CRYPTO_ALGORITHM_MAX + 1];
  127. u_int8_t cc_kalg[CRK_ALGORITHM_MAX + 1];
  128. int cc_flags; /* (d) flags */
  129. #define CRYPTOCAP_F_CLEANUP 0x80000000 /* needs resource cleanup */
  130. int cc_qblocked; /* (q) symmetric q blocked */
  131. int cc_kqblocked; /* (q) asymmetric q blocked */
  132. int cc_unqblocked; /* (q) symmetric q blocked */
  133. int cc_unkqblocked; /* (q) asymmetric q blocked */
  134. };
  135. static struct cryptocap *crypto_drivers = NULL;
  136. static int crypto_drivers_num = 0;
  137. /*
  138. * There are two queues for crypto requests; one for symmetric (e.g.
  139. * cipher) operations and one for asymmetric (e.g. MOD)operations.
  140. * A single mutex is used to lock access to both queues. We could
  141. * have one per-queue but having one simplifies handling of block/unblock
  142. * operations.
  143. */
  144. static int crp_sleep = 0;
  145. static LIST_HEAD(crp_q); /* request queues */
  146. static LIST_HEAD(crp_kq);
  147. static spinlock_t crypto_q_lock;
  148. int crypto_all_qblocked = 0; /* protect with Q_LOCK */
  149. module_param(crypto_all_qblocked, int, 0444);
  150. MODULE_PARM_DESC(crypto_all_qblocked, "Are all crypto queues blocked");
  151. int crypto_all_kqblocked = 0; /* protect with Q_LOCK */
  152. module_param(crypto_all_kqblocked, int, 0444);
  153. MODULE_PARM_DESC(crypto_all_kqblocked, "Are all asym crypto queues blocked");
  154. #define CRYPTO_Q_LOCK() \
  155. ({ \
  156. spin_lock_irqsave(&crypto_q_lock, q_flags); \
  157. dprintk("%s,%d: Q_LOCK()\n", __FILE__, __LINE__); \
  158. })
  159. #define CRYPTO_Q_UNLOCK() \
  160. ({ \
  161. dprintk("%s,%d: Q_UNLOCK()\n", __FILE__, __LINE__); \
  162. spin_unlock_irqrestore(&crypto_q_lock, q_flags); \
  163. })
  164. /*
  165. * There are two queues for processing completed crypto requests; one
  166. * for the symmetric and one for the asymmetric ops. We only need one
  167. * but have two to avoid type futzing (cryptop vs. cryptkop). A single
  168. * mutex is used to lock access to both queues. Note that this lock
  169. * must be separate from the lock on request queues to insure driver
  170. * callbacks don't generate lock order reversals.
  171. */
  172. static LIST_HEAD(crp_ret_q); /* callback queues */
  173. static LIST_HEAD(crp_ret_kq);
  174. static spinlock_t crypto_ret_q_lock;
  175. #define CRYPTO_RETQ_LOCK() \
  176. ({ \
  177. spin_lock_irqsave(&crypto_ret_q_lock, r_flags); \
  178. dprintk("%s,%d: RETQ_LOCK\n", __FILE__, __LINE__); \
  179. })
  180. #define CRYPTO_RETQ_UNLOCK() \
  181. ({ \
  182. dprintk("%s,%d: RETQ_UNLOCK\n", __FILE__, __LINE__); \
  183. spin_unlock_irqrestore(&crypto_ret_q_lock, r_flags); \
  184. })
  185. #define CRYPTO_RETQ_EMPTY() (list_empty(&crp_ret_q) && list_empty(&crp_ret_kq))
  186. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
  187. static kmem_cache_t *cryptop_zone;
  188. static kmem_cache_t *cryptodesc_zone;
  189. #else
  190. static struct kmem_cache *cryptop_zone;
  191. static struct kmem_cache *cryptodesc_zone;
  192. #endif
  193. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
  194. #include <linux/sched.h>
  195. #define kill_proc(p,s,v) send_sig(s,find_task_by_vpid(p),0)
  196. #endif
  197. #define debug crypto_debug
  198. int crypto_debug = 0;
  199. module_param(crypto_debug, int, 0644);
  200. MODULE_PARM_DESC(crypto_debug, "Enable debug");
  201. EXPORT_SYMBOL(crypto_debug);
  202. /*
  203. * Maximum number of outstanding crypto requests before we start
  204. * failing requests. We need this to prevent DOS when too many
  205. * requests are arriving for us to keep up. Otherwise we will
  206. * run the system out of memory. Since crypto is slow, we are
  207. * usually the bottleneck that needs to say, enough is enough.
  208. *
  209. * We cannot print errors when this condition occurs, we are already too
  210. * slow, printing anything will just kill us
  211. */
  212. static int crypto_q_cnt = 0;
  213. module_param(crypto_q_cnt, int, 0444);
  214. MODULE_PARM_DESC(crypto_q_cnt,
  215. "Current number of outstanding crypto requests");
  216. static int crypto_q_max = 1000;
  217. module_param(crypto_q_max, int, 0644);
  218. MODULE_PARM_DESC(crypto_q_max,
  219. "Maximum number of outstanding crypto requests");
  220. #define bootverbose crypto_verbose
  221. static int crypto_verbose = 0;
  222. module_param(crypto_verbose, int, 0644);
  223. MODULE_PARM_DESC(crypto_verbose,
  224. "Enable verbose crypto startup");
  225. int crypto_usercrypto = 1; /* userland may do crypto reqs */
  226. module_param(crypto_usercrypto, int, 0644);
  227. MODULE_PARM_DESC(crypto_usercrypto,
  228. "Enable/disable user-mode access to crypto support");
  229. int crypto_userasymcrypto = 1; /* userland may do asym crypto reqs */
  230. module_param(crypto_userasymcrypto, int, 0644);
  231. MODULE_PARM_DESC(crypto_userasymcrypto,
  232. "Enable/disable user-mode access to asymmetric crypto support");
  233. int crypto_devallowsoft = 0; /* only use hardware crypto */
  234. module_param(crypto_devallowsoft, int, 0644);
  235. MODULE_PARM_DESC(crypto_devallowsoft,
  236. "Enable/disable use of software crypto support");
  237. /*
  238. * This parameter controls the maximum number of crypto operations to
  239. * do consecutively in the crypto kernel thread before scheduling to allow
  240. * other processes to run. Without it, it is possible to get into a
  241. * situation where the crypto thread never allows any other processes to run.
  242. * Default to 1000 which should be less than one second.
  243. */
  244. static int crypto_max_loopcount = 1000;
  245. module_param(crypto_max_loopcount, int, 0644);
  246. MODULE_PARM_DESC(crypto_max_loopcount,
  247. "Maximum number of crypto ops to do before yielding to other processes");
  248. static pid_t cryptoproc = (pid_t) -1;
  249. static struct completion cryptoproc_exited;
  250. static DECLARE_WAIT_QUEUE_HEAD(cryptoproc_wait);
  251. static pid_t cryptoretproc = (pid_t) -1;
  252. static struct completion cryptoretproc_exited;
  253. static DECLARE_WAIT_QUEUE_HEAD(cryptoretproc_wait);
  254. static int crypto_proc(void *arg);
  255. static int crypto_ret_proc(void *arg);
  256. static int crypto_invoke(struct cryptocap *cap, struct cryptop *crp, int hint);
  257. static int crypto_kinvoke(struct cryptkop *krp, int flags);
  258. static void crypto_exit(void);
  259. static int crypto_init(void);
  260. static struct cryptostats cryptostats;
  261. static struct cryptocap *
  262. crypto_checkdriver(u_int32_t hid)
  263. {
  264. if (crypto_drivers == NULL)
  265. return NULL;
  266. return (hid >= crypto_drivers_num ? NULL : &crypto_drivers[hid]);
  267. }
  268. /*
  269. * Compare a driver's list of supported algorithms against another
  270. * list; return non-zero if all algorithms are supported.
  271. */
  272. static int
  273. driver_suitable(const struct cryptocap *cap, const struct cryptoini *cri)
  274. {
  275. const struct cryptoini *cr;
  276. /* See if all the algorithms are supported. */
  277. for (cr = cri; cr; cr = cr->cri_next)
  278. if (cap->cc_alg[cr->cri_alg] == 0)
  279. return 0;
  280. return 1;
  281. }
  282. /*
  283. * Select a driver for a new session that supports the specified
  284. * algorithms and, optionally, is constrained according to the flags.
  285. * The algorithm we use here is pretty stupid; just use the
  286. * first driver that supports all the algorithms we need. If there
  287. * are multiple drivers we choose the driver with the fewest active
  288. * sessions. We prefer hardware-backed drivers to software ones.
  289. *
  290. * XXX We need more smarts here (in real life too, but that's
  291. * XXX another story altogether).
  292. */
  293. static struct cryptocap *
  294. crypto_select_driver(const struct cryptoini *cri, int flags)
  295. {
  296. struct cryptocap *cap, *best;
  297. int match, hid;
  298. CRYPTO_DRIVER_ASSERT();
  299. /*
  300. * Look first for hardware crypto devices if permitted.
  301. */
  302. if (flags & CRYPTOCAP_F_HARDWARE)
  303. match = CRYPTOCAP_F_HARDWARE;
  304. else
  305. match = CRYPTOCAP_F_SOFTWARE;
  306. best = NULL;
  307. again:
  308. for (hid = 0; hid < crypto_drivers_num; hid++) {
  309. cap = &crypto_drivers[hid];
  310. /*
  311. * If it's not initialized, is in the process of
  312. * going away, or is not appropriate (hardware
  313. * or software based on match), then skip.
  314. */
  315. if (cap->cc_dev == NULL ||
  316. (cap->cc_flags & CRYPTOCAP_F_CLEANUP) ||
  317. (cap->cc_flags & match) == 0)
  318. continue;
  319. /* verify all the algorithms are supported. */
  320. if (driver_suitable(cap, cri)) {
  321. if (best == NULL ||
  322. cap->cc_sessions < best->cc_sessions)
  323. best = cap;
  324. }
  325. }
  326. if (best != NULL)
  327. return best;
  328. if (match == CRYPTOCAP_F_HARDWARE && (flags & CRYPTOCAP_F_SOFTWARE)) {
  329. /* sort of an Algol 68-style for loop */
  330. match = CRYPTOCAP_F_SOFTWARE;
  331. goto again;
  332. }
  333. return best;
  334. }
  335. /*
  336. * Create a new session. The crid argument specifies a crypto
  337. * driver to use or constraints on a driver to select (hardware
  338. * only, software only, either). Whatever driver is selected
  339. * must be capable of the requested crypto algorithms.
  340. */
  341. int
  342. crypto_newsession(u_int64_t *sid, struct cryptoini *cri, int crid)
  343. {
  344. struct cryptocap *cap;
  345. u_int32_t hid, lid;
  346. int err;
  347. unsigned long d_flags;
  348. CRYPTO_DRIVER_LOCK();
  349. if ((crid & (CRYPTOCAP_F_HARDWARE | CRYPTOCAP_F_SOFTWARE)) == 0) {
  350. /*
  351. * Use specified driver; verify it is capable.
  352. */
  353. cap = crypto_checkdriver(crid);
  354. if (cap != NULL && !driver_suitable(cap, cri))
  355. cap = NULL;
  356. } else {
  357. /*
  358. * No requested driver; select based on crid flags.
  359. */
  360. cap = crypto_select_driver(cri, crid);
  361. /*
  362. * if NULL then can't do everything in one session.
  363. * XXX Fix this. We need to inject a "virtual" session
  364. * XXX layer right about here.
  365. */
  366. }
  367. if (cap != NULL) {
  368. /* Call the driver initialization routine. */
  369. hid = cap - crypto_drivers;
  370. lid = hid; /* Pass the driver ID. */
  371. cap->cc_sessions++;
  372. CRYPTO_DRIVER_UNLOCK();
  373. err = CRYPTODEV_NEWSESSION(cap->cc_dev, &lid, cri);
  374. CRYPTO_DRIVER_LOCK();
  375. if (err == 0) {
  376. (*sid) = (cap->cc_flags & 0xff000000)
  377. | (hid & 0x00ffffff);
  378. (*sid) <<= 32;
  379. (*sid) |= (lid & 0xffffffff);
  380. } else
  381. cap->cc_sessions--;
  382. } else
  383. err = EINVAL;
  384. CRYPTO_DRIVER_UNLOCK();
  385. return err;
  386. }
  387. static void
  388. crypto_remove(struct cryptocap *cap)
  389. {
  390. CRYPTO_DRIVER_ASSERT();
  391. if (cap->cc_sessions == 0 && cap->cc_koperations == 0)
  392. bzero(cap, sizeof(*cap));
  393. }
  394. /*
  395. * Delete an existing session (or a reserved session on an unregistered
  396. * driver).
  397. */
  398. int
  399. crypto_freesession(u_int64_t sid)
  400. {
  401. struct cryptocap *cap;
  402. u_int32_t hid;
  403. int err = 0;
  404. unsigned long d_flags;
  405. dprintk("%s()\n", __FUNCTION__);
  406. CRYPTO_DRIVER_LOCK();
  407. if (crypto_drivers == NULL) {
  408. err = EINVAL;
  409. goto done;
  410. }
  411. /* Determine two IDs. */
  412. hid = CRYPTO_SESID2HID(sid);
  413. if (hid >= crypto_drivers_num) {
  414. dprintk("%s - INVALID DRIVER NUM %d\n", __FUNCTION__, hid);
  415. err = ENOENT;
  416. goto done;
  417. }
  418. cap = &crypto_drivers[hid];
  419. if (cap->cc_dev) {
  420. CRYPTO_DRIVER_UNLOCK();
  421. /* Call the driver cleanup routine, if available, unlocked. */
  422. err = CRYPTODEV_FREESESSION(cap->cc_dev, sid);
  423. CRYPTO_DRIVER_LOCK();
  424. }
  425. if (cap->cc_sessions)
  426. cap->cc_sessions--;
  427. if (cap->cc_flags & CRYPTOCAP_F_CLEANUP)
  428. crypto_remove(cap);
  429. done:
  430. CRYPTO_DRIVER_UNLOCK();
  431. return err;
  432. }
  433. /*
  434. * Return an unused driver id. Used by drivers prior to registering
  435. * support for the algorithms they handle.
  436. */
  437. int32_t
  438. crypto_get_driverid(device_t dev, int flags)
  439. {
  440. struct cryptocap *newdrv;
  441. int i;
  442. unsigned long d_flags;
  443. if ((flags & (CRYPTOCAP_F_HARDWARE | CRYPTOCAP_F_SOFTWARE)) == 0) {
  444. printf("%s: no flags specified when registering driver\n",
  445. device_get_nameunit(dev));
  446. return -1;
  447. }
  448. CRYPTO_DRIVER_LOCK();
  449. for (i = 0; i < crypto_drivers_num; i++) {
  450. if (crypto_drivers[i].cc_dev == NULL &&
  451. (crypto_drivers[i].cc_flags & CRYPTOCAP_F_CLEANUP) == 0) {
  452. break;
  453. }
  454. }
  455. /* Out of entries, allocate some more. */
  456. if (i == crypto_drivers_num) {
  457. /* Be careful about wrap-around. */
  458. if (2 * crypto_drivers_num <= crypto_drivers_num) {
  459. CRYPTO_DRIVER_UNLOCK();
  460. printk("crypto: driver count wraparound!\n");
  461. return -1;
  462. }
  463. newdrv = kmalloc(2 * crypto_drivers_num * sizeof(struct cryptocap),
  464. GFP_KERNEL);
  465. if (newdrv == NULL) {
  466. CRYPTO_DRIVER_UNLOCK();
  467. printk("crypto: no space to expand driver table!\n");
  468. return -1;
  469. }
  470. memcpy(newdrv, crypto_drivers,
  471. crypto_drivers_num * sizeof(struct cryptocap));
  472. memset(&newdrv[crypto_drivers_num], 0,
  473. crypto_drivers_num * sizeof(struct cryptocap));
  474. crypto_drivers_num *= 2;
  475. kfree(crypto_drivers);
  476. crypto_drivers = newdrv;
  477. }
  478. /* NB: state is zero'd on free */
  479. crypto_drivers[i].cc_sessions = 1; /* Mark */
  480. crypto_drivers[i].cc_dev = dev;
  481. crypto_drivers[i].cc_flags = flags;
  482. if (bootverbose)
  483. printf("crypto: assign %s driver id %u, flags %u\n",
  484. device_get_nameunit(dev), i, flags);
  485. CRYPTO_DRIVER_UNLOCK();
  486. return i;
  487. }
  488. /*
  489. * Lookup a driver by name. We match against the full device
  490. * name and unit, and against just the name. The latter gives
  491. * us a simple widlcarding by device name. On success return the
  492. * driver/hardware identifier; otherwise return -1.
  493. */
  494. int
  495. crypto_find_driver(const char *match)
  496. {
  497. int i, len = strlen(match);
  498. unsigned long d_flags;
  499. CRYPTO_DRIVER_LOCK();
  500. for (i = 0; i < crypto_drivers_num; i++) {
  501. device_t dev = crypto_drivers[i].cc_dev;
  502. if (dev == NULL ||
  503. (crypto_drivers[i].cc_flags & CRYPTOCAP_F_CLEANUP))
  504. continue;
  505. if (strncmp(match, device_get_nameunit(dev), len) == 0 ||
  506. strncmp(match, device_get_name(dev), len) == 0)
  507. break;
  508. }
  509. CRYPTO_DRIVER_UNLOCK();
  510. return i < crypto_drivers_num ? i : -1;
  511. }
  512. /*
  513. * Return the device_t for the specified driver or NULL
  514. * if the driver identifier is invalid.
  515. */
  516. device_t
  517. crypto_find_device_byhid(int hid)
  518. {
  519. struct cryptocap *cap = crypto_checkdriver(hid);
  520. return cap != NULL ? cap->cc_dev : NULL;
  521. }
  522. /*
  523. * Return the device/driver capabilities.
  524. */
  525. int
  526. crypto_getcaps(int hid)
  527. {
  528. struct cryptocap *cap = crypto_checkdriver(hid);
  529. return cap != NULL ? cap->cc_flags : 0;
  530. }
  531. /*
  532. * Register support for a key-related algorithm. This routine
  533. * is called once for each algorithm supported a driver.
  534. */
  535. int
  536. crypto_kregister(u_int32_t driverid, int kalg, u_int32_t flags)
  537. {
  538. struct cryptocap *cap;
  539. int err;
  540. unsigned long d_flags;
  541. dprintk("%s()\n", __FUNCTION__);
  542. CRYPTO_DRIVER_LOCK();
  543. cap = crypto_checkdriver(driverid);
  544. if (cap != NULL &&
  545. (CRK_ALGORITM_MIN <= kalg && kalg <= CRK_ALGORITHM_MAX)) {
  546. /*
  547. * XXX Do some performance testing to determine placing.
  548. * XXX We probably need an auxiliary data structure that
  549. * XXX describes relative performances.
  550. */
  551. cap->cc_kalg[kalg] = flags | CRYPTO_ALG_FLAG_SUPPORTED;
  552. if (bootverbose)
  553. printf("crypto: %s registers key alg %u flags %u\n"
  554. , device_get_nameunit(cap->cc_dev)
  555. , kalg
  556. , flags
  557. );
  558. err = 0;
  559. } else
  560. err = EINVAL;
  561. CRYPTO_DRIVER_UNLOCK();
  562. return err;
  563. }
  564. /*
  565. * Register support for a non-key-related algorithm. This routine
  566. * is called once for each such algorithm supported by a driver.
  567. */
  568. int
  569. crypto_register(u_int32_t driverid, int alg, u_int16_t maxoplen,
  570. u_int32_t flags)
  571. {
  572. struct cryptocap *cap;
  573. int err;
  574. unsigned long d_flags;
  575. dprintk("%s(id=0x%x, alg=%d, maxoplen=%d, flags=0x%x)\n", __FUNCTION__,
  576. driverid, alg, maxoplen, flags);
  577. CRYPTO_DRIVER_LOCK();
  578. cap = crypto_checkdriver(driverid);
  579. /* NB: algorithms are in the range [1..max] */
  580. if (cap != NULL &&
  581. (CRYPTO_ALGORITHM_MIN <= alg && alg <= CRYPTO_ALGORITHM_MAX)) {
  582. /*
  583. * XXX Do some performance testing to determine placing.
  584. * XXX We probably need an auxiliary data structure that
  585. * XXX describes relative performances.
  586. */
  587. cap->cc_alg[alg] = flags | CRYPTO_ALG_FLAG_SUPPORTED;
  588. cap->cc_max_op_len[alg] = maxoplen;
  589. if (bootverbose)
  590. printf("crypto: %s registers alg %u flags %u maxoplen %u\n"
  591. , device_get_nameunit(cap->cc_dev)
  592. , alg
  593. , flags
  594. , maxoplen
  595. );
  596. cap->cc_sessions = 0; /* Unmark */
  597. err = 0;
  598. } else
  599. err = EINVAL;
  600. CRYPTO_DRIVER_UNLOCK();
  601. return err;
  602. }
  603. static void
  604. driver_finis(struct cryptocap *cap)
  605. {
  606. u_int32_t ses, kops;
  607. CRYPTO_DRIVER_ASSERT();
  608. ses = cap->cc_sessions;
  609. kops = cap->cc_koperations;
  610. bzero(cap, sizeof(*cap));
  611. if (ses != 0 || kops != 0) {
  612. /*
  613. * If there are pending sessions,
  614. * just mark as invalid.
  615. */
  616. cap->cc_flags |= CRYPTOCAP_F_CLEANUP;
  617. cap->cc_sessions = ses;
  618. cap->cc_koperations = kops;
  619. }
  620. }
  621. /*
  622. * Unregister a crypto driver. If there are pending sessions using it,
  623. * leave enough information around so that subsequent calls using those
  624. * sessions will correctly detect the driver has been unregistered and
  625. * reroute requests.
  626. */
  627. int
  628. crypto_unregister(u_int32_t driverid, int alg)
  629. {
  630. struct cryptocap *cap;
  631. int i, err;
  632. unsigned long d_flags;
  633. dprintk("%s()\n", __FUNCTION__);
  634. CRYPTO_DRIVER_LOCK();
  635. cap = crypto_checkdriver(driverid);
  636. if (cap != NULL &&
  637. (CRYPTO_ALGORITHM_MIN <= alg && alg <= CRYPTO_ALGORITHM_MAX) &&
  638. cap->cc_alg[alg] != 0) {
  639. cap->cc_alg[alg] = 0;
  640. cap->cc_max_op_len[alg] = 0;
  641. /* Was this the last algorithm ? */
  642. for (i = 1; i <= CRYPTO_ALGORITHM_MAX; i++)
  643. if (cap->cc_alg[i] != 0)
  644. break;
  645. if (i == CRYPTO_ALGORITHM_MAX + 1)
  646. driver_finis(cap);
  647. err = 0;
  648. } else
  649. err = EINVAL;
  650. CRYPTO_DRIVER_UNLOCK();
  651. return err;
  652. }
  653. /*
  654. * Unregister all algorithms associated with a crypto driver.
  655. * If there are pending sessions using it, leave enough information
  656. * around so that subsequent calls using those sessions will
  657. * correctly detect the driver has been unregistered and reroute
  658. * requests.
  659. */
  660. int
  661. crypto_unregister_all(u_int32_t driverid)
  662. {
  663. struct cryptocap *cap;
  664. int err;
  665. unsigned long d_flags;
  666. dprintk("%s()\n", __FUNCTION__);
  667. CRYPTO_DRIVER_LOCK();
  668. cap = crypto_checkdriver(driverid);
  669. if (cap != NULL) {
  670. driver_finis(cap);
  671. err = 0;
  672. } else
  673. err = EINVAL;
  674. CRYPTO_DRIVER_UNLOCK();
  675. return err;
  676. }
  677. /*
  678. * Clear blockage on a driver. The what parameter indicates whether
  679. * the driver is now ready for cryptop's and/or cryptokop's.
  680. */
  681. int
  682. crypto_unblock(u_int32_t driverid, int what)
  683. {
  684. struct cryptocap *cap;
  685. int err;
  686. unsigned long q_flags;
  687. CRYPTO_Q_LOCK();
  688. cap = crypto_checkdriver(driverid);
  689. if (cap != NULL) {
  690. if (what & CRYPTO_SYMQ) {
  691. cap->cc_qblocked = 0;
  692. cap->cc_unqblocked = 0;
  693. crypto_all_qblocked = 0;
  694. }
  695. if (what & CRYPTO_ASYMQ) {
  696. cap->cc_kqblocked = 0;
  697. cap->cc_unkqblocked = 0;
  698. crypto_all_kqblocked = 0;
  699. }
  700. if (crp_sleep)
  701. wake_up_interruptible(&cryptoproc_wait);
  702. err = 0;
  703. } else
  704. err = EINVAL;
  705. CRYPTO_Q_UNLOCK(); //DAVIDM should this be a driver lock
  706. return err;
  707. }
  708. /*
  709. * Add a crypto request to a queue, to be processed by the kernel thread.
  710. */
  711. int
  712. crypto_dispatch(struct cryptop *crp)
  713. {
  714. struct cryptocap *cap;
  715. int result = -1;
  716. unsigned long q_flags;
  717. dprintk("%s()\n", __FUNCTION__);
  718. cryptostats.cs_ops++;
  719. CRYPTO_Q_LOCK();
  720. if (crypto_q_cnt >= crypto_q_max) {
  721. CRYPTO_Q_UNLOCK();
  722. cryptostats.cs_drops++;
  723. return ENOMEM;
  724. }
  725. crypto_q_cnt++;
  726. /* make sure we are starting a fresh run on this crp. */
  727. crp->crp_flags &= ~CRYPTO_F_DONE;
  728. crp->crp_etype = 0;
  729. /*
  730. * Caller marked the request to be processed immediately; dispatch
  731. * it directly to the driver unless the driver is currently blocked.
  732. */
  733. if ((crp->crp_flags & CRYPTO_F_BATCH) == 0) {
  734. int hid = CRYPTO_SESID2HID(crp->crp_sid);
  735. cap = crypto_checkdriver(hid);
  736. /* Driver cannot disappear when there is an active session. */
  737. KASSERT(cap != NULL, ("%s: Driver disappeared.", __func__));
  738. if (!cap->cc_qblocked) {
  739. crypto_all_qblocked = 0;
  740. crypto_drivers[hid].cc_unqblocked = 1;
  741. CRYPTO_Q_UNLOCK();
  742. result = crypto_invoke(cap, crp, 0);
  743. CRYPTO_Q_LOCK();
  744. if (result == ERESTART)
  745. if (crypto_drivers[hid].cc_unqblocked)
  746. crypto_drivers[hid].cc_qblocked = 1;
  747. crypto_drivers[hid].cc_unqblocked = 0;
  748. }
  749. }
  750. if (result == ERESTART) {
  751. /*
  752. * The driver ran out of resources, mark the
  753. * driver ``blocked'' for cryptop's and put
  754. * the request back in the queue. It would
  755. * best to put the request back where we got
  756. * it but that's hard so for now we put it
  757. * at the front. This should be ok; putting
  758. * it at the end does not work.
  759. */
  760. list_add(&crp->crp_next, &crp_q);
  761. cryptostats.cs_blocks++;
  762. result = 0;
  763. } else if (result == -1) {
  764. TAILQ_INSERT_TAIL(&crp_q, crp, crp_next);
  765. result = 0;
  766. }
  767. if (crp_sleep)
  768. wake_up_interruptible(&cryptoproc_wait);
  769. CRYPTO_Q_UNLOCK();
  770. return result;
  771. }
  772. /*
  773. * Add an asymetric crypto request to a queue,
  774. * to be processed by the kernel thread.
  775. */
  776. int
  777. crypto_kdispatch(struct cryptkop *krp)
  778. {
  779. int error;
  780. unsigned long q_flags;
  781. cryptostats.cs_kops++;
  782. error = crypto_kinvoke(krp, krp->krp_crid);
  783. if (error == ERESTART) {
  784. CRYPTO_Q_LOCK();
  785. TAILQ_INSERT_TAIL(&crp_kq, krp, krp_next);
  786. if (crp_sleep)
  787. wake_up_interruptible(&cryptoproc_wait);
  788. CRYPTO_Q_UNLOCK();
  789. error = 0;
  790. }
  791. return error;
  792. }
  793. /*
  794. * Verify a driver is suitable for the specified operation.
  795. */
  796. static __inline int
  797. kdriver_suitable(const struct cryptocap *cap, const struct cryptkop *krp)
  798. {
  799. return (cap->cc_kalg[krp->krp_op] & CRYPTO_ALG_FLAG_SUPPORTED) != 0;
  800. }
  801. /*
  802. * Select a driver for an asym operation. The driver must
  803. * support the necessary algorithm. The caller can constrain
  804. * which device is selected with the flags parameter. The
  805. * algorithm we use here is pretty stupid; just use the first
  806. * driver that supports the algorithms we need. If there are
  807. * multiple suitable drivers we choose the driver with the
  808. * fewest active operations. We prefer hardware-backed
  809. * drivers to software ones when either may be used.
  810. */
  811. static struct cryptocap *
  812. crypto_select_kdriver(const struct cryptkop *krp, int flags)
  813. {
  814. struct cryptocap *cap, *best, *blocked;
  815. int match, hid;
  816. CRYPTO_DRIVER_ASSERT();
  817. /*
  818. * Look first for hardware crypto devices if permitted.
  819. */
  820. if (flags & CRYPTOCAP_F_HARDWARE)
  821. match = CRYPTOCAP_F_HARDWARE;
  822. else
  823. match = CRYPTOCAP_F_SOFTWARE;
  824. best = NULL;
  825. blocked = NULL;
  826. again:
  827. for (hid = 0; hid < crypto_drivers_num; hid++) {
  828. cap = &crypto_drivers[hid];
  829. /*
  830. * If it's not initialized, is in the process of
  831. * going away, or is not appropriate (hardware
  832. * or software based on match), then skip.
  833. */
  834. if (cap->cc_dev == NULL ||
  835. (cap->cc_flags & CRYPTOCAP_F_CLEANUP) ||
  836. (cap->cc_flags & match) == 0)
  837. continue;
  838. /* verify all the algorithms are supported. */
  839. if (kdriver_suitable(cap, krp)) {
  840. if (best == NULL ||
  841. cap->cc_koperations < best->cc_koperations)
  842. best = cap;
  843. }
  844. }
  845. if (best != NULL)
  846. return best;
  847. if (match == CRYPTOCAP_F_HARDWARE && (flags & CRYPTOCAP_F_SOFTWARE)) {
  848. /* sort of an Algol 68-style for loop */
  849. match = CRYPTOCAP_F_SOFTWARE;
  850. goto again;
  851. }
  852. return best;
  853. }
  854. /*
  855. * Dispatch an assymetric crypto request.
  856. */
  857. static int
  858. crypto_kinvoke(struct cryptkop *krp, int crid)
  859. {
  860. struct cryptocap *cap = NULL;
  861. int error;
  862. unsigned long d_flags;
  863. KASSERT(krp != NULL, ("%s: krp == NULL", __func__));
  864. KASSERT(krp->krp_callback != NULL,
  865. ("%s: krp->crp_callback == NULL", __func__));
  866. CRYPTO_DRIVER_LOCK();
  867. if ((crid & (CRYPTOCAP_F_HARDWARE | CRYPTOCAP_F_SOFTWARE)) == 0) {
  868. cap = crypto_checkdriver(crid);
  869. if (cap != NULL) {
  870. /*
  871. * Driver present, it must support the necessary
  872. * algorithm and, if s/w drivers are excluded,
  873. * it must be registered as hardware-backed.
  874. */
  875. if (!kdriver_suitable(cap, krp) ||
  876. (!crypto_devallowsoft &&
  877. (cap->cc_flags & CRYPTOCAP_F_HARDWARE) == 0))
  878. cap = NULL;
  879. }
  880. } else {
  881. /*
  882. * No requested driver; select based on crid flags.
  883. */
  884. if (!crypto_devallowsoft) /* NB: disallow s/w drivers */
  885. crid &= ~CRYPTOCAP_F_SOFTWARE;
  886. cap = crypto_select_kdriver(krp, crid);
  887. }
  888. if (cap != NULL && !cap->cc_kqblocked) {
  889. krp->krp_hid = cap - crypto_drivers;
  890. cap->cc_koperations++;
  891. CRYPTO_DRIVER_UNLOCK();
  892. error = CRYPTODEV_KPROCESS(cap->cc_dev, krp, 0);
  893. CRYPTO_DRIVER_LOCK();
  894. if (error == ERESTART) {
  895. cap->cc_koperations--;
  896. CRYPTO_DRIVER_UNLOCK();
  897. return (error);
  898. }
  899. /* return the actual device used */
  900. krp->krp_crid = krp->krp_hid;
  901. } else {
  902. /*
  903. * NB: cap is !NULL if device is blocked; in
  904. * that case return ERESTART so the operation
  905. * is resubmitted if possible.
  906. */
  907. error = (cap == NULL) ? ENODEV : ERESTART;
  908. }
  909. CRYPTO_DRIVER_UNLOCK();
  910. if (error) {
  911. krp->krp_status = error;
  912. crypto_kdone(krp);
  913. }
  914. return 0;
  915. }
  916. /*
  917. * Dispatch a crypto request to the appropriate crypto devices.
  918. */
  919. static int
  920. crypto_invoke(struct cryptocap *cap, struct cryptop *crp, int hint)
  921. {
  922. KASSERT(crp != NULL, ("%s: crp == NULL", __func__));
  923. KASSERT(crp->crp_callback != NULL,
  924. ("%s: crp->crp_callback == NULL", __func__));
  925. KASSERT(crp->crp_desc != NULL, ("%s: crp->crp_desc == NULL", __func__));
  926. dprintk("%s()\n", __FUNCTION__);
  927. #ifdef CRYPTO_TIMING
  928. if (crypto_timing)
  929. crypto_tstat(&cryptostats.cs_invoke, &crp->crp_tstamp);
  930. #endif
  931. if (cap->cc_flags & CRYPTOCAP_F_CLEANUP) {
  932. struct cryptodesc *crd;
  933. u_int64_t nid;
  934. /*
  935. * Driver has unregistered; migrate the session and return
  936. * an error to the caller so they'll resubmit the op.
  937. *
  938. * XXX: What if there are more already queued requests for this
  939. * session?
  940. */
  941. crypto_freesession(crp->crp_sid);
  942. for (crd = crp->crp_desc; crd->crd_next; crd = crd->crd_next)
  943. crd->CRD_INI.cri_next = &(crd->crd_next->CRD_INI);
  944. /* XXX propagate flags from initial session? */
  945. if (crypto_newsession(&nid, &(crp->crp_desc->CRD_INI),
  946. CRYPTOCAP_F_HARDWARE | CRYPTOCAP_F_SOFTWARE) == 0)
  947. crp->crp_sid = nid;
  948. crp->crp_etype = EAGAIN;
  949. crypto_done(crp);
  950. return 0;
  951. } else {
  952. /*
  953. * Invoke the driver to process the request.
  954. */
  955. return CRYPTODEV_PROCESS(cap->cc_dev, crp, hint);
  956. }
  957. }
  958. /*
  959. * Release a set of crypto descriptors.
  960. */
  961. void
  962. crypto_freereq(struct cryptop *crp)
  963. {
  964. struct cryptodesc *crd;
  965. if (crp == NULL)
  966. return;
  967. #ifdef DIAGNOSTIC
  968. {
  969. struct cryptop *crp2;
  970. unsigned long q_flags;
  971. CRYPTO_Q_LOCK();
  972. TAILQ_FOREACH(crp2, &crp_q, crp_next) {
  973. KASSERT(crp2 != crp,
  974. ("Freeing cryptop from the crypto queue (%p).",
  975. crp));
  976. }
  977. CRYPTO_Q_UNLOCK();
  978. CRYPTO_RETQ_LOCK();
  979. TAILQ_FOREACH(crp2, &crp_ret_q, crp_next) {
  980. KASSERT(crp2 != crp,
  981. ("Freeing cryptop from the return queue (%p).",
  982. crp));
  983. }
  984. CRYPTO_RETQ_UNLOCK();
  985. }
  986. #endif
  987. while ((crd = crp->crp_desc) != NULL) {
  988. crp->crp_desc = crd->crd_next;
  989. kmem_cache_free(cryptodesc_zone, crd);
  990. }
  991. kmem_cache_free(cryptop_zone, crp);
  992. }
  993. /*
  994. * Acquire a set of crypto descriptors.
  995. */
  996. struct cryptop *
  997. crypto_getreq(int num)
  998. {
  999. struct cryptodesc *crd;
  1000. struct cryptop *crp;
  1001. crp = kmem_cache_alloc(cryptop_zone, SLAB_ATOMIC);
  1002. if (crp != NULL) {
  1003. memset(crp, 0, sizeof(*crp));
  1004. INIT_LIST_HEAD(&crp->crp_next);
  1005. init_waitqueue_head(&crp->crp_waitq);
  1006. while (num--) {
  1007. crd = kmem_cache_alloc(cryptodesc_zone, SLAB_ATOMIC);
  1008. if (crd == NULL) {
  1009. crypto_freereq(crp);
  1010. return NULL;
  1011. }
  1012. memset(crd, 0, sizeof(*crd));
  1013. crd->crd_next = crp->crp_desc;
  1014. crp->crp_desc = crd;
  1015. }
  1016. }
  1017. return crp;
  1018. }
  1019. /*
  1020. * Invoke the callback on behalf of the driver.
  1021. */
  1022. void
  1023. crypto_done(struct cryptop *crp)
  1024. {
  1025. unsigned long q_flags;
  1026. dprintk("%s()\n", __FUNCTION__);
  1027. if ((crp->crp_flags & CRYPTO_F_DONE) == 0) {
  1028. crp->crp_flags |= CRYPTO_F_DONE;
  1029. CRYPTO_Q_LOCK();
  1030. crypto_q_cnt--;
  1031. CRYPTO_Q_UNLOCK();
  1032. } else
  1033. printk("crypto: crypto_done op already done, flags 0x%x",
  1034. crp->crp_flags);
  1035. if (crp->crp_etype != 0)
  1036. cryptostats.cs_errs++;
  1037. /*
  1038. * CBIMM means unconditionally do the callback immediately;
  1039. * CBIFSYNC means do the callback immediately only if the
  1040. * operation was done synchronously. Both are used to avoid
  1041. * doing extraneous context switches; the latter is mostly
  1042. * used with the software crypto driver.
  1043. */
  1044. if ((crp->crp_flags & CRYPTO_F_CBIMM) ||
  1045. ((crp->crp_flags & CRYPTO_F_CBIFSYNC) &&
  1046. (CRYPTO_SESID2CAPS(crp->crp_sid) & CRYPTOCAP_F_SYNC))) {
  1047. /*
  1048. * Do the callback directly. This is ok when the
  1049. * callback routine does very little (e.g. the
  1050. * /dev/crypto callback method just does a wakeup).
  1051. */
  1052. crp->crp_callback(crp);
  1053. } else {
  1054. unsigned long r_flags;
  1055. /*
  1056. * Normal case; queue the callback for the thread.
  1057. */
  1058. CRYPTO_RETQ_LOCK();
  1059. if (CRYPTO_RETQ_EMPTY())
  1060. wake_up_interruptible(&cryptoretproc_wait);/* shared wait channel */
  1061. TAILQ_INSERT_TAIL(&crp_ret_q, crp, crp_next);
  1062. CRYPTO_RETQ_UNLOCK();
  1063. }
  1064. }
  1065. /*
  1066. * Invoke the callback on behalf of the driver.
  1067. */
  1068. void
  1069. crypto_kdone(struct cryptkop *krp)
  1070. {
  1071. struct cryptocap *cap;
  1072. unsigned long d_flags;
  1073. if ((krp->krp_flags & CRYPTO_KF_DONE) != 0)
  1074. printk("crypto: crypto_kdone op already done, flags 0x%x",
  1075. krp->krp_flags);
  1076. krp->krp_flags |= CRYPTO_KF_DONE;
  1077. if (krp->krp_status != 0)
  1078. cryptostats.cs_kerrs++;
  1079. CRYPTO_DRIVER_LOCK();
  1080. /* XXX: What if driver is loaded in the meantime? */
  1081. if (krp->krp_hid < crypto_drivers_num) {
  1082. cap = &crypto_drivers[krp->krp_hid];
  1083. cap->cc_koperations--;
  1084. KASSERT(cap->cc_koperations >= 0, ("cc_koperations < 0"));
  1085. if (cap->cc_flags & CRYPTOCAP_F_CLEANUP)
  1086. crypto_remove(cap);
  1087. }
  1088. CRYPTO_DRIVER_UNLOCK();
  1089. /*
  1090. * CBIMM means unconditionally do the callback immediately;
  1091. * This is used to avoid doing extraneous context switches
  1092. */
  1093. if ((krp->krp_flags & CRYPTO_KF_CBIMM)) {
  1094. /*
  1095. * Do the callback directly. This is ok when the
  1096. * callback routine does very little (e.g. the
  1097. * /dev/crypto callback method just does a wakeup).
  1098. */
  1099. krp->krp_callback(krp);
  1100. } else {
  1101. unsigned long r_flags;
  1102. /*
  1103. * Normal case; queue the callback for the thread.
  1104. */
  1105. CRYPTO_RETQ_LOCK();
  1106. if (CRYPTO_RETQ_EMPTY())
  1107. wake_up_interruptible(&cryptoretproc_wait);/* shared wait channel */
  1108. TAILQ_INSERT_TAIL(&crp_ret_kq, krp, krp_next);
  1109. CRYPTO_RETQ_UNLOCK();
  1110. }
  1111. }
  1112. int
  1113. crypto_getfeat(int *featp)
  1114. {
  1115. int hid, kalg, feat = 0;
  1116. unsigned long d_flags;
  1117. CRYPTO_DRIVER_LOCK();
  1118. for (hid = 0; hid < crypto_drivers_num; hid++) {
  1119. const struct cryptocap *cap = &crypto_drivers[hid];
  1120. if ((cap->cc_flags & CRYPTOCAP_F_SOFTWARE) &&
  1121. !crypto_devallowsoft) {
  1122. continue;
  1123. }
  1124. for (kalg = 0; kalg < CRK_ALGORITHM_MAX; kalg++)
  1125. if (cap->cc_kalg[kalg] & CRYPTO_ALG_FLAG_SUPPORTED)
  1126. feat |= 1 << kalg;
  1127. }
  1128. CRYPTO_DRIVER_UNLOCK();
  1129. *featp = feat;
  1130. return (0);
  1131. }
  1132. /*
  1133. * Crypto thread, dispatches crypto requests.
  1134. */
  1135. static int
  1136. crypto_proc(void *arg)
  1137. {
  1138. struct cryptop *crp, *submit;
  1139. struct cryptkop *krp, *krpp;
  1140. struct cryptocap *cap;
  1141. u_int32_t hid;
  1142. int result, hint;
  1143. unsigned long q_flags;
  1144. int loopcount = 0;
  1145. ocf_daemonize("crypto");
  1146. CRYPTO_Q_LOCK();
  1147. for (;;) {
  1148. /*
  1149. * we need to make sure we don't get into a busy loop with nothing
  1150. * to do, the two crypto_all_*blocked vars help us find out when
  1151. * we are all full and can do nothing on any driver or Q. If so we
  1152. * wait for an unblock.
  1153. */
  1154. crypto_all_qblocked = !list_empty(&crp_q);
  1155. /*
  1156. * Find the first element in the queue that can be
  1157. * processed and look-ahead to see if multiple ops
  1158. * are ready for the same driver.
  1159. */
  1160. submit = NULL;
  1161. hint = 0;
  1162. list_for_each_entry(crp, &crp_q, crp_next) {
  1163. hid = CRYPTO_SESID2HID(crp->crp_sid);
  1164. cap = crypto_checkdriver(hid);
  1165. /*
  1166. * Driver cannot disappear when there is an active
  1167. * session.
  1168. */
  1169. KASSERT(cap != NULL, ("%s:%u Driver disappeared.",
  1170. __func__, __LINE__));
  1171. if (cap == NULL || cap->cc_dev == NULL) {
  1172. /* Op needs to be migrated, process it. */
  1173. if (submit == NULL)
  1174. submit = crp;
  1175. break;
  1176. }
  1177. if (!cap->cc_qblocked) {
  1178. if (submit != NULL) {
  1179. /*
  1180. * We stop on finding another op,
  1181. * regardless whether its for the same
  1182. * driver or not. We could keep
  1183. * searching the queue but it might be
  1184. * better to just use a per-driver
  1185. * queue instead.
  1186. */
  1187. if (CRYPTO_SESID2HID(submit->crp_sid) == hid)
  1188. hint = CRYPTO_HINT_MORE;
  1189. break;
  1190. } else {
  1191. submit = crp;
  1192. if ((submit->crp_flags & CRYPTO_F_BATCH) == 0)
  1193. break;
  1194. /* keep scanning for more are q'd */
  1195. }
  1196. }
  1197. }
  1198. if (submit != NULL) {
  1199. hid = CRYPTO_SESID2HID(submit->crp_sid);
  1200. crypto_all_qblocked = 0;
  1201. list_del(&submit->crp_next);
  1202. crypto_drivers[hid].cc_unqblocked = 1;
  1203. cap = crypto_checkdriver(hid);
  1204. CRYPTO_Q_UNLOCK();
  1205. KASSERT(cap != NULL, ("%s:%u Driver disappeared.",
  1206. __func__, __LINE__));
  1207. result = crypto_invoke(cap, submit, hint);
  1208. CRYPTO_Q_LOCK();
  1209. if (result == ERESTART) {
  1210. /*
  1211. * The driver ran out of resources, mark the
  1212. * driver ``blocked'' for cryptop's and put
  1213. * the request back in the queue. It would
  1214. * best to put the request back where we got
  1215. * it but that's hard so for now we put it
  1216. * at the front. This should be ok; putting
  1217. * it at the end does not work.
  1218. */
  1219. /* XXX validate sid again? */
  1220. list_add(&submit->crp_next, &crp_q);
  1221. cryptostats.cs_blocks++;
  1222. if (crypto_drivers[hid].cc_unqblocked)
  1223. crypto_drivers[hid].cc_qblocked=0;
  1224. crypto_drivers[hid].cc_unqblocked=0;
  1225. }
  1226. crypto_drivers[hid].cc_unqblocked = 0;
  1227. }
  1228. crypto_all_kqblocked = !list_empty(&crp_kq);
  1229. /* As above, but for key ops */
  1230. krp = NULL;
  1231. list_for_each_entry(krpp, &crp_kq, krp_next) {
  1232. cap = crypto_checkdriver(krpp->krp_hid);
  1233. if (cap == NULL || cap->cc_dev == NULL) {
  1234. /*
  1235. * Operation needs to be migrated, invalidate
  1236. * the assigned device so it will reselect a
  1237. * new one below. Propagate the original
  1238. * crid selection flags if supplied.
  1239. */
  1240. krp->krp_hid = krp->krp_crid &
  1241. (CRYPTOCAP_F_SOFTWARE|CRYPTOCAP_F_HARDWARE);
  1242. if (krp->krp_hid == 0)
  1243. krp->krp_hid =
  1244. CRYPTOCAP_F_SOFTWARE|CRYPTOCAP_F_HARDWARE;
  1245. break;
  1246. }
  1247. if (!cap->cc_kqblocked) {
  1248. krp = krpp;
  1249. break;
  1250. }
  1251. }
  1252. if (krp != NULL) {
  1253. crypto_all_kqblocked = 0;
  1254. list_del(&krp->krp_next);
  1255. crypto_drivers[krp->krp_hid].cc_kqblocked = 1;
  1256. CRYPTO_Q_UNLOCK();
  1257. result = crypto_kinvoke(krp, krp->krp_hid);
  1258. CRYPTO_Q_LOCK();
  1259. if (result == ERESTART) {
  1260. /*
  1261. * The driver ran out of resources, mark the
  1262. * driver ``blocked'' for cryptkop's and put
  1263. * the request back in the queue. It would
  1264. * best to put the request back where we got
  1265. * it but that's hard so for now we put it
  1266. * at the front. This should be ok; putting
  1267. * it at the end does not work.
  1268. */
  1269. /* XXX validate sid again? */
  1270. list_add(&krp->krp_next, &crp_kq);
  1271. cryptostats.cs_kblocks++;
  1272. } else
  1273. crypto_drivers[krp->krp_hid].cc_kqblocked = 0;
  1274. }
  1275. if (submit == NULL && krp == NULL) {
  1276. /*
  1277. * Nothing more to be processed. Sleep until we're
  1278. * woken because there are more ops to process.
  1279. * This happens either by submission or by a driver
  1280. * becoming unblocked and notifying us through
  1281. * crypto_unblock. Note that when we wakeup we
  1282. * start processing each queue again from the
  1283. * front. It's not clear that it's important to
  1284. * preserve this ordering since ops may finish
  1285. * out of order if dispatched to different devices
  1286. * and some become blocked while others do not.
  1287. */
  1288. dprintk("%s - sleeping (qe=%d qb=%d kqe=%d kqb=%d)\n",
  1289. __FUNCTION__,
  1290. list_empty(&crp_q), crypto_all_qblocked,
  1291. list_empty(&crp_kq), crypto_all_kqblocked);
  1292. loopcount = 0;
  1293. CRYPTO_Q_UNLOCK();
  1294. crp_sleep = 1;
  1295. wait_event_interruptible(cryptoproc_wait,
  1296. !(list_empty(&crp_q) || crypto_all_qblocked) ||
  1297. !(list_empty(&crp_kq) || crypto_all_kqblocked) ||
  1298. cryptoproc == (pid_t) -1);
  1299. crp_sleep = 0;
  1300. if (signal_pending (current)) {
  1301. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  1302. spin_lock_irq(&current->sigmask_lock);
  1303. #endif
  1304. flush_signals(current);
  1305. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  1306. spin_unlock_irq(&current->sigmask_lock);
  1307. #endif
  1308. }
  1309. CRYPTO_Q_LOCK();
  1310. dprintk("%s - awake\n", __FUNCTION__);
  1311. if (cryptoproc == (pid_t) -1)
  1312. break;
  1313. cryptostats.cs_intrs++;
  1314. } else if (loopcount > crypto_max_loopcount) {
  1315. /*
  1316. * Give other processes a chance to run if we've
  1317. * been using the CPU exclusively for a while.
  1318. */
  1319. loopcount = 0;
  1320. schedule();
  1321. }
  1322. loopcount++;
  1323. }
  1324. CRYPTO_Q_UNLOCK();
  1325. complete_and_exit(&cryptoproc_exited, 0);
  1326. }
  1327. /*
  1328. * Crypto returns thread, does callbacks for processed crypto requests.
  1329. * Callbacks are done here, rather than in the crypto drivers, because
  1330. * callbacks typically are expensive and would slow interrupt handling.
  1331. */
  1332. static int
  1333. crypto_ret_proc(void *arg)
  1334. {
  1335. struct cryptop *crpt;
  1336. struct cryptkop *krpt;
  1337. unsigned long r_flags;
  1338. ocf_daemonize("crypto_ret");
  1339. CRYPTO_RETQ_LOCK();
  1340. for (;;) {
  1341. /* Harvest return q's for completed ops */
  1342. crpt = NULL;
  1343. if (!list_empty(&crp_ret_q))
  1344. crpt = list_entry(crp_ret_q.next, typeof(*crpt), crp_next);
  1345. if (crpt != NULL)
  1346. list_del(&crpt->crp_next);
  1347. krpt = NULL;
  1348. if (!list_empty(&crp_ret_kq))
  1349. krpt = list_entry(crp_ret_kq.next, typeof(*krpt), krp_next);
  1350. if (krpt != NULL)
  1351. list_del(&krpt->krp_next);
  1352. if (crpt != NULL || krpt != NULL) {
  1353. CRYPTO_RETQ_UNLOCK();
  1354. /*
  1355. * Run callbacks unlocked.
  1356. */
  1357. if (crpt != NULL)
  1358. crpt->crp_callback(crpt);
  1359. if (krpt != NULL)
  1360. krpt->krp_callback(krpt);
  1361. CRYPTO_RETQ_LOCK();
  1362. } else {
  1363. /*
  1364. * Nothing more to be processed. Sleep until we're
  1365. * woken because there are more returns to process.
  1366. */
  1367. dprintk("%s - sleeping\n", __FUNCTION__);
  1368. CRYPTO_RETQ_UNLOCK();
  1369. wait_event_interruptible(cryptoretproc_wait,
  1370. cryptoretproc == (pid_t) -1 ||
  1371. !list_empty(&crp_ret_q) ||
  1372. !list_empty(&crp_ret_kq));
  1373. if (signal_pending (current)) {
  1374. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  1375. spin_lock_irq(&current->sigmask_lock);
  1376. #endif
  1377. flush_signals(current);
  1378. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  1379. spin_unlock_irq(&current->sigmask_lock);
  1380. #endif
  1381. }
  1382. CRYPTO_RETQ_LOCK();
  1383. dprintk("%s - awake\n", __FUNCTION__);
  1384. if (cryptoretproc == (pid_t) -1) {
  1385. dprintk("%s - EXITING!\n", __FUNCTION__);
  1386. break;
  1387. }
  1388. cryptostats.cs_rets++;
  1389. }
  1390. }
  1391. CRYPTO_RETQ_UNLOCK();
  1392. complete_and_exit(&cryptoretproc_exited, 0);
  1393. }
  1394. #if 0 /* should put this into /proc or something */
  1395. static void
  1396. db_show_drivers(void)
  1397. {
  1398. int hid;
  1399. db_printf("%12s %4s %4s %8s %2s %2s\n"
  1400. , "Device"
  1401. , "Ses"
  1402. , "Kops"
  1403. , "Flags"
  1404. , "QB"
  1405. , "KB"
  1406. );
  1407. for (hid = 0; hid < crypto_drivers_num; hid++) {
  1408. const struct cryptocap *cap = &crypto_drivers[hid];
  1409. if (cap->cc_dev == NULL)
  1410. continue;
  1411. db_printf("%-12s %4u %4u %08x %2u %2u\n"
  1412. , device_get_nameunit(cap->cc_dev)
  1413. , cap->cc_sessions
  1414. , cap->cc_koperations
  1415. , cap->cc_flags
  1416. , cap->cc_qblocked
  1417. , cap->cc_kqblocked
  1418. );
  1419. }
  1420. }
  1421. DB_SHOW_COMMAND(crypto, db_show_crypto)
  1422. {
  1423. struct cryptop *crp;
  1424. db_show_drivers();
  1425. db_printf("\n");
  1426. db_printf("%4s %8s %4s %4s %4s %4s %8s %8s\n",
  1427. "HID", "Caps", "Ilen", "Olen", "Etype", "Flags",
  1428. "Desc", "Callback");
  1429. TAILQ_FOREACH(crp, &crp_q, crp_next) {
  1430. db_printf("%4u %08x %4u %4u %4u %04x %8p %8p\n"
  1431. , (int) CRYPTO_SESID2HID(crp->crp_sid)
  1432. , (int) CRYPTO_SESID2CAPS(crp->crp_sid)
  1433. , crp->crp_ilen, crp->crp_olen
  1434. , crp->crp_etype
  1435. , crp->crp_flags
  1436. , crp->crp_desc
  1437. , crp->crp_callback
  1438. );
  1439. }
  1440. if (!TAILQ_EMPTY(&crp_ret_q)) {
  1441. db_printf("\n%4s %4s %4s %8s\n",
  1442. "HID", "Etype", "Flags", "Callback");
  1443. TAILQ_FOREACH(crp, &crp_ret_q, crp_next) {
  1444. db_printf("%4u %4u %04x %8p\n"
  1445. , (int) CRYPTO_SESID2HID(crp->crp_sid)
  1446. , crp->crp_etype
  1447. , crp->crp_flags
  1448. , crp->crp_callback
  1449. );
  1450. }
  1451. }
  1452. }
  1453. DB_SHOW_COMMAND(kcrypto, db_show_kcrypto)
  1454. {
  1455. struct cryptkop *krp;
  1456. db_show_drivers();
  1457. db_printf("\n");
  1458. db_printf("%4s %5s %4s %4s %8s %4s %8s\n",
  1459. "Op", "Status", "#IP", "#OP", "CRID", "HID", "Callback");
  1460. TAILQ_FOREACH(krp, &crp_kq, krp_next) {
  1461. db_printf("%4u %5u %4u %4u %08x %4u %8p\n"
  1462. , krp->krp_op
  1463. , krp->krp_status
  1464. , krp->krp_iparams, krp->krp_oparams
  1465. , krp->krp_crid, krp->krp_hid
  1466. , krp->krp_callback
  1467. );
  1468. }
  1469. if (!TAILQ_EMPTY(&crp_ret_q)) {
  1470. db_printf("%4s %5s %8s %4s %8s\n",
  1471. "Op", "Status", "CRID", "HID", "Callback");
  1472. TAILQ_FOREACH(krp, &crp_ret_kq, krp_next) {
  1473. db_printf("%4u %5u %08x %4u %8p\n"
  1474. , krp->krp_op
  1475. , krp->krp_status
  1476. , krp->krp_crid, krp->krp_hid
  1477. , krp->krp_callback
  1478. );
  1479. }
  1480. }
  1481. }
  1482. #endif
  1483. static int
  1484. crypto_init(void)
  1485. {
  1486. int error;
  1487. dprintk("%s(%p)\n", __FUNCTION__, (void *) crypto_init);
  1488. if (crypto_initted)
  1489. return 0;
  1490. crypto_initted = 1;
  1491. spin_lock_init(&crypto_drivers_lock);
  1492. spin_lock_init(&crypto_q_lock);
  1493. spin_lock_init(&crypto_ret_q_lock);
  1494. cryptop_zone = kmem_cache_create("cryptop", sizeof(struct cryptop),
  1495. 0, SLAB_HWCACHE_ALIGN, NULL
  1496. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
  1497. , NULL
  1498. #endif
  1499. );
  1500. cryptodesc_zone = kmem_cache_create("cryptodesc", sizeof(struct cryptodesc),
  1501. 0, SLAB_HWCACHE_ALIGN, NULL
  1502. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
  1503. , NULL
  1504. #endif
  1505. );
  1506. if (cryptodesc_zone == NULL || cryptop_zone == NULL) {
  1507. printk("crypto: crypto_init cannot setup crypto zones\n");
  1508. error = ENOMEM;
  1509. goto bad;
  1510. }
  1511. crypto_drivers_num = CRYPTO_DRIVERS_INITIAL;
  1512. crypto_drivers = kmalloc(crypto_drivers_num * sizeof(struct cryptocap),
  1513. GFP_KERNEL);
  1514. if (crypto_drivers == NULL) {
  1515. printk("crypto: crypto_init cannot setup crypto drivers\n");
  1516. error = ENOMEM;
  1517. goto bad;
  1518. }
  1519. memset(crypto_drivers, 0, crypto_drivers_num * sizeof(struct cryptocap));
  1520. init_completion(&cryptoproc_exited);
  1521. init_completion(&cryptoretproc_exited);
  1522. cryptoproc = 0; /* to avoid race condition where proc runs first */
  1523. cryptoproc = kernel_thread(crypto_proc, NULL, CLONE_FS|CLONE_FILES);
  1524. if (cryptoproc < 0) {
  1525. error = cryptoproc;
  1526. printk("crypto: crypto_init cannot start crypto thread; error %d",
  1527. error);
  1528. goto bad;
  1529. }
  1530. cryptoretproc = 0; /* to avoid race condition where proc runs first */
  1531. cryptoretproc = kernel_thread(crypto_ret_proc, NULL, CLONE_FS|CLONE_FILES);
  1532. if (cryptoretproc < 0) {
  1533. error = cryptoretproc;
  1534. printk("crypto: crypto_init cannot start cryptoret thread; error %d",
  1535. error);
  1536. goto bad;
  1537. }
  1538. return 0;
  1539. bad:
  1540. crypto_exit();
  1541. return error;
  1542. }
  1543. static void
  1544. crypto_exit(void)
  1545. {
  1546. pid_t p;
  1547. unsigned long d_flags;
  1548. dprintk("%s()\n", __FUNCTION__);
  1549. /*
  1550. * Terminate any crypto threads.
  1551. */
  1552. CRYPTO_DRIVER_LOCK();
  1553. p = cryptoproc;
  1554. cryptoproc = (pid_t) -1;
  1555. kill_proc(p, SIGTERM, 1);
  1556. wake_up_interruptible(&cryptoproc_wait);
  1557. CRYPTO_DRIVER_UNLOCK();
  1558. wait_for_completion(&cryptoproc_exited);
  1559. CRYPTO_DRIVER_LOCK();
  1560. p = cryptoretproc;
  1561. cryptoretproc = (pid_t) -1;
  1562. kill_proc(p, SIGTERM, 1);
  1563. wake_up_interruptible(&cryptoretproc_wait);
  1564. CRYPTO_DRIVER_UNLOCK();
  1565. wait_for_completion(&cryptoretproc_exited);
  1566. /* XXX flush queues??? */
  1567. /*
  1568. * Reclaim dynamically allocated resources.
  1569. */
  1570. if (crypto_drivers != NULL)
  1571. kfree(crypto_drivers);
  1572. if (cryptodesc_zone != NULL)
  1573. kmem_cache_destroy(cryptodesc_zone);
  1574. if (cryptop_zone != NULL)
  1575. kmem_cache_destroy(cryptop_zone);
  1576. }
  1577. EXPORT_SYMBOL(crypto_newsession);
  1578. EXPORT_SYMBOL(crypto_freesession);
  1579. EXPORT_SYMBOL(crypto_get_driverid);
  1580. EXPORT_SYMBOL(crypto_kregister);
  1581. EXPORT_SYMBOL(crypto_register);
  1582. EXPORT_SYMBOL(crypto_unregister);
  1583. EXPORT_SYMBOL(crypto_unregister_all);
  1584. EXPORT_SYMBOL(crypto_unblock);
  1585. EXPORT_SYMBOL(crypto_dispatch);
  1586. EXPORT_SYMBOL(crypto_kdispatch);
  1587. EXPORT_SYMBOL(crypto_freereq);
  1588. EXPORT_SYMBOL(crypto_getreq);
  1589. EXPORT_SYMBOL(crypto_done);
  1590. EXPORT_SYMBOL(crypto_kdone);
  1591. EXPORT_SYMBOL(crypto_getfeat);
  1592. EXPORT_SYMBOL(crypto_userasymcrypto);
  1593. EXPORT_SYMBOL(crypto_getcaps);
  1594. EXPORT_SYMBOL(crypto_find_driver);
  1595. EXPORT_SYMBOL(crypto_find_device_byhid);
  1596. module_init(crypto_init);
  1597. module_exit(crypto_exit);
  1598. MODULE_LICENSE("BSD");
  1599. MODULE_AUTHOR("David McCullough <[email protected]>");
  1600. MODULE_DESCRIPTION("OCF (OpenBSD Cryptographic Framework)");