]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man9/crypto.9
lockmgr: remove the ADAPTIVE_LOCKMGRS option
[FreeBSD/FreeBSD.git] / share / man / man9 / crypto.9
1 .\"     $OpenBSD: crypto.9,v 1.19 2002/07/16 06:31:57 angelos Exp $
2 .\"
3 .\" The author of this manual page is Angelos D. Keromytis (angelos@cis.upenn.edu)
4 .\"
5 .\" Copyright (c) 2000, 2001 Angelos D. Keromytis
6 .\"
7 .\" Permission to use, copy, and modify this software with or without fee
8 .\" is hereby granted, provided that this entire notice is included in
9 .\" all source code copies of any software which is or includes a copy or
10 .\" modification of this software.
11 .\"
12 .\" THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
13 .\" IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
14 .\" REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
15 .\" MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
16 .\" PURPOSE.
17 .\"
18 .\" $FreeBSD$
19 .\"
20 .Dd July 10, 2015
21 .Dt CRYPTO 9
22 .Os
23 .Sh NAME
24 .Nm crypto
25 .Nd API for cryptographic services in the kernel
26 .Sh SYNOPSIS
27 .In opencrypto/cryptodev.h
28 .Ft int32_t
29 .Fn crypto_get_driverid device_t int
30 .Ft int
31 .Fn crypto_register uint32_t int uint16_t uint32_t "int \*[lp]*\*[rp]\*[lp]void *, uint32_t *, struct cryptoini *\*[rp]" "int \*[lp]*\*[rp]\*[lp]void *, uint64_t\*[rp]" "int \*[lp]*\*[rp]\*[lp]void *, struct cryptop *\*[rp]" "void *"
32 .Ft int
33 .Fn crypto_kregister uint32_t int uint32_t "int \*[lp]*\*[rp]\*[lp]void *, struct cryptkop *\*[rp]" "void *"
34 .Ft int
35 .Fn crypto_unregister uint32_t int
36 .Ft int
37 .Fn crypto_unregister_all uint32_t
38 .Ft void
39 .Fn crypto_done "struct cryptop *"
40 .Ft void
41 .Fn crypto_kdone "struct cryptkop *"
42 .Ft int
43 .Fn crypto_find_driver "const char *"
44 .Ft int
45 .Fn crypto_newsession "uint64_t *" "struct cryptoini *" int
46 .Ft int
47 .Fn crypto_freesession uint64_t
48 .Ft int
49 .Fn crypto_dispatch "struct cryptop *"
50 .Ft int
51 .Fn crypto_kdispatch "struct cryptkop *"
52 .Ft int
53 .Fn crypto_unblock uint32_t int
54 .Ft "struct cryptop *"
55 .Fn crypto_getreq int
56 .Ft void
57 .Fn crypto_freereq void
58 .Bd -literal
59 #define CRYPTO_SYMQ     0x1
60 #define CRYPTO_ASYMQ    0x2
61
62 #define EALG_MAX_BLOCK_LEN      16
63
64 struct cryptoini {
65         int                cri_alg;
66         int                cri_klen;
67         int                cri_mlen;
68         caddr_t            cri_key;
69         uint8_t            cri_iv[EALG_MAX_BLOCK_LEN];
70         struct cryptoini  *cri_next;
71 };
72
73 struct cryptodesc {
74         int                crd_skip;
75         int                crd_len;
76         int                crd_inject;
77         int                crd_flags;
78         struct cryptoini   CRD_INI;
79 #define crd_iv          CRD_INI.cri_iv
80 #define crd_key         CRD_INI.cri_key
81 #define crd_alg         CRD_INI.cri_alg
82 #define crd_klen        CRD_INI.cri_klen
83         struct cryptodesc *crd_next;
84 };
85
86 struct cryptop {
87         TAILQ_ENTRY(cryptop) crp_next;
88         uint64_t           crp_sid;
89         int                crp_ilen;
90         int                crp_olen;
91         int                crp_etype;
92         int                crp_flags;
93         caddr_t            crp_buf;
94         caddr_t            crp_opaque;
95         struct cryptodesc *crp_desc;
96         int              (*crp_callback) (struct cryptop *);
97         caddr_t            crp_mac;
98 };
99
100 struct crparam {
101         caddr_t         crp_p;
102         u_int           crp_nbits;
103 };
104
105 #define CRK_MAXPARAM    8
106
107 struct cryptkop {
108         TAILQ_ENTRY(cryptkop) krp_next;
109         u_int              krp_op;         /* ie. CRK_MOD_EXP or other */
110         u_int              krp_status;     /* return status */
111         u_short            krp_iparams;    /* # of input parameters */
112         u_short            krp_oparams;    /* # of output parameters */
113         uint32_t           krp_hid;
114         struct crparam     krp_param[CRK_MAXPARAM];
115         int               (*krp_callback)(struct cryptkop *);
116 };
117 .Ed
118 .Sh DESCRIPTION
119 .Nm
120 is a framework for drivers of cryptographic hardware to register with
121 the kernel so
122 .Dq consumers
123 (other kernel subsystems, and
124 users through the
125 .Pa /dev/crypto
126 device) are able to make use of it.
127 Drivers register with the framework the algorithms they support,
128 and provide entry points (functions) the framework may call to
129 establish, use, and tear down sessions.
130 Sessions are used to cache cryptographic information in a particular driver
131 (or associated hardware), so initialization is not needed with every request.
132 Consumers of cryptographic services pass a set of
133 descriptors that instruct the framework (and the drivers registered
134 with it) of the operations that should be applied on the data (more
135 than one cryptographic operation can be requested).
136 .Pp
137 Keying operations are supported as well.
138 Unlike the symmetric operators described above,
139 these sessionless commands perform mathematical operations using
140 input and output parameters.
141 .Pp
142 Since the consumers may not be associated with a process, drivers may
143 not
144 .Xr sleep 9 .
145 The same holds for the framework.
146 Thus, a callback mechanism is used
147 to notify a consumer that a request has been completed (the
148 callback is specified by the consumer on a per-request basis).
149 The callback is invoked by the framework whether the request was
150 successfully completed or not.
151 An error indication is provided in the latter case.
152 A specific error code,
153 .Er EAGAIN ,
154 is used to indicate that a session number has changed and that the
155 request may be re-submitted immediately with the new session number.
156 Errors are only returned to the invoking function if not
157 enough information to call the callback is available (meaning, there
158 was a fatal error in verifying the arguments).
159 For session initialization and teardown there is no callback mechanism used.
160 .Pp
161 The
162 .Fn crypto_find_driver
163 function may be called to return the specific id of the provided name.
164 If the specified driver could not be found, the returned id is -1.
165 .Pp
166 The
167 .Fn crypto_newsession
168 routine is called by consumers of cryptographic services (such as the
169 .Xr ipsec 4
170 stack) that wish to establish a new session with the framework.
171 The second argument contains all the necessary information for
172 the driver to establish the session.
173 The third argument is either a specific driver id, or one or both
174 of
175 .Dv CRYPTOCAP_F_HARDWARE ,
176 to select hardware devices,
177 or
178 .Dv CRYPTOCAP_F_SOFTWARE ,
179 to select software devices.
180 If both are specified, a hardware device will be returned
181 before a software device will be.
182 On success, the value pointed to by the first argument will be the
183 Session IDentifier (SID).
184 The various fields in the
185 .Vt cryptoini
186 structure are:
187 .Bl -tag -width ".Va cri_next"
188 .It Va cri_alg
189 Contains an algorithm identifier.
190 Currently supported algorithms are:
191 .Pp
192 .Bl -tag -width ".Dv CRYPTO_RIPEMD160_HMAC" -compact
193 .It Dv CRYPTO_AES_128_NIST_GMAC
194 .It Dv CRYPTO_AES_192_NIST_GMAC
195 .It Dv CRYPTO_AES_256_NIST_GMAC
196 .It Dv CRYPTO_AES_CBC
197 .It Dv CRYPTO_AES_ICM
198 .It Dv CRYPTO_AES_NIST_GCM_16
199 .It Dv CRYPTO_AES_NIST_GMAC
200 .It Dv CRYPTO_AES_XTS
201 .It Dv CRYPTO_ARC4
202 .It Dv CRYPTO_BLF_CBC
203 .It Dv CRYPTO_CAMELLIA_CBC
204 .It Dv CRYPTO_CAST_CBC
205 .It Dv CRYPTO_DEFLATE_COMP
206 .It Dv CRYPTO_DES_CBC
207 .It Dv CRYPTO_3DES_CBC
208 .It Dv CRYPTO_MD5
209 .It Dv CRYPTO_MD5_HMAC
210 .It Dv CRYPTO_MD5_KPDK
211 .It Dv CRYPTO_NULL_HMAC
212 .It Dv CRYPTO_NULL_CBC
213 .It Dv CRYPTO_RIPEMD160_HMAC
214 .It Dv CRYPTO_SHA1
215 .It Dv CRYPTO_SHA1_HMAC
216 .It Dv CRYPTO_SHA1_KPDK
217 .It Dv CRYPTO_SHA2_256_HMAC
218 .It Dv CRYPTO_SHA2_384_HMAC
219 .It Dv CRYPTO_SHA2_512_HMAC
220 .It Dv CRYPTO_SKIPJACK_CBC
221 .El
222 .It Va cri_klen
223 Specifies the length of the key in bits, for variable-size key
224 algorithms.
225 .It Va cri_mlen
226 Specifies how many bytes from the calculated hash should be copied back.
227 0 means entire hash.
228 .It Va cri_key
229 Contains the key to be used with the algorithm.
230 .It Va cri_iv
231 Contains an explicit initialization vector (IV), if it does not prefix
232 the data.
233 This field is ignored during initialization
234 .Pq Nm crypto_newsession .
235 If no IV is explicitly passed (see below on details), a random IV is used
236 by the device driver processing the request.
237 .It Va cri_next
238 Contains a pointer to another
239 .Vt cryptoini
240 structure.
241 Multiple such structures may be linked to establish multi-algorithm sessions
242 .Xr ( ipsec 4
243 is an example consumer of such a feature).
244 .El
245 .Pp
246 The
247 .Vt cryptoini
248 structure and its contents will not be modified by the framework (or
249 the drivers used).
250 Subsequent requests for processing that use the
251 SID returned will avoid the cost of re-initializing the hardware (in
252 essence, SID acts as an index in the session cache of the driver).
253 .Pp
254 .Fn crypto_freesession
255 is called with the SID returned by
256 .Fn crypto_newsession
257 to disestablish the session.
258 .Pp
259 .Fn crypto_dispatch
260 is called to process a request.
261 The various fields in the
262 .Vt cryptop
263 structure are:
264 .Bl -tag -width ".Va crp_callback"
265 .It Va crp_sid
266 Contains the SID.
267 .It Va crp_ilen
268 Indicates the total length in bytes of the buffer to be processed.
269 .It Va crp_olen
270 On return, contains the total length of the result.
271 For symmetric crypto operations, this will be the same as the input length.
272 This will be used if the framework needs to allocate a new
273 buffer for the result (or for re-formatting the input).
274 .It Va crp_callback
275 This routine is invoked upon completion of the request, whether
276 successful or not.
277 It is invoked through the
278 .Fn crypto_done
279 routine.
280 If the request was not successful, an error code is set in the
281 .Va crp_etype
282 field.
283 It is the responsibility of the callback routine to set the appropriate
284 .Xr spl 9
285 level.
286 .It Va crp_etype
287 Contains the error type, if any errors were encountered, or zero if
288 the request was successfully processed.
289 If the
290 .Er EAGAIN
291 error code is returned, the SID has changed (and has been recorded in the
292 .Va crp_sid
293 field).
294 The consumer should record the new SID and use it in all subsequent requests.
295 In this case, the request may be re-submitted immediately.
296 This mechanism is used by the framework to perform
297 session migration (move a session from one driver to another, because
298 of availability, performance, or other considerations).
299 .Pp
300 Note that this field only makes sense when examined by
301 the callback routine specified in
302 .Va crp_callback .
303 Errors are returned to the invoker of
304 .Fn crypto_process
305 only when enough information is not present to call the callback
306 routine (i.e., if the pointer passed is
307 .Dv NULL
308 or if no callback routine was specified).
309 .It Va crp_flags
310 Is a bitmask of flags associated with this request.
311 Currently defined flags are:
312 .Bl -tag -width ".Dv CRYPTO_F_CBIFSYNC"
313 .It Dv CRYPTO_F_IMBUF
314 The buffer pointed to by
315 .Va crp_buf
316 is an mbuf chain.
317 .It Dv CRYPTO_F_IOV
318 The buffer pointed to by
319 .Va crp_buf
320 is an
321 .Vt uio
322 structure.
323 .It Dv CRYPTO_F_BATCH
324 Batch operation if possible.
325 .It Dv CRYPTO_F_CBIMM
326 Do callback immediately instead of doing it from a dedicated kernel thread.
327 .It Dv CRYPTO_F_DONE
328 Operation completed.
329 .It Dv CRYPTO_F_CBIFSYNC
330 Do callback immediately if operation is synchronous (that the driver
331 specified the
332 .Dv CRYPTOCAP_F_SYNC
333 flag).
334 .It Dv CRYPTO_F_ASYNC
335 Try to do the crypto operation in a pool of workers
336 if the operation is synchronous (that the driver specified the
337 .Dv CRYPTOCAP_F_SYNC
338 flag). It aims to speed up processing by dispatching crypto operations
339 on different processors.
340 .It Dv CRYPTO_F_ASYNC_KEEPORDER
341 Dispatch callbacks in the same order they are posted.
342 Only relevant if the
343 .Dv CRYPTO_F_ASYNC
344 flag is set and if the operation is synchronous.
345 .El
346 .It Va crp_buf
347 Points to the input buffer.
348 On return (when the callback is invoked),
349 it contains the result of the request.
350 The input buffer may be an mbuf
351 chain or a contiguous buffer,
352 depending on
353 .Va crp_flags .
354 .It Va crp_opaque
355 This is passed through the crypto framework untouched and is
356 intended for the invoking application's use.
357 .It Va crp_desc
358 This is a linked list of descriptors.
359 Each descriptor provides
360 information about what type of cryptographic operation should be done
361 on the input buffer.
362 The various fields are:
363 .Bl -tag -width ".Va crd_inject"
364 .It Va crd_iv
365 When the flag
366 .Dv CRD_F_IV_EXPLICIT
367 is set, this field contains the IV.
368 .It Va crd_key
369 When the
370 .Dv CRD_F_KEY_EXPLICIT
371 flag is set, the
372 .Va crd_key
373 points to a buffer with encryption or authentication key.
374 .It Va crd_alg
375 An algorithm to use.
376 Must be the same as the one given at newsession time.
377 .It Va crd_klen
378 The
379 .Va crd_key
380 key length.
381 .It Va crd_skip
382 The offset in the input buffer where processing should start.
383 .It Va crd_len
384 How many bytes, after
385 .Va crd_skip ,
386 should be processed.
387 .It Va crd_inject
388 The
389 .Va crd_inject
390 field specifies an offset in bytes from the beginning of the buffer.
391 For encryption algorithms, this may be where the IV will be inserted
392 when encrypting or where the IV may be found for
393 decryption (subject to
394 .Va crd_flags ) .
395 For MAC algorithms, this is where the result of the keyed hash will be
396 inserted.
397 .It Va crd_flags
398 The following flags are defined:
399 .Bl -tag -width 3n
400 .It Dv CRD_F_ENCRYPT
401 For encryption algorithms, this bit is set when encryption is required
402 (when not set, decryption is performed).
403 .It Dv CRD_F_IV_PRESENT
404 .\" This flag name has nothing to do w/ it's behavior, fix the name.
405 For encryption, if this bit is not set the IV used to encrypt the packet
406 will be written at the location pointed to by
407 .Va crd_inject .
408 The IV length is assumed to be equal to the blocksize of the
409 encryption algorithm.
410 For encryption, if this bit is set, nothing is done.
411 For decryption, this flag has no meaning.
412 Applications that do special
413 .Dq "IV cooking" ,
414 such as the half-IV mode in
415 .Xr ipsec 4 ,
416 can use this flag to indicate that the IV should not be written on the packet.
417 This flag is typically used in conjunction with the
418 .Dv CRD_F_IV_EXPLICIT
419 flag.
420 .It Dv CRD_F_IV_EXPLICIT
421 This bit is set when the IV is explicitly
422 provided by the consumer in the
423 .Va crd_iv
424 field.
425 Otherwise, for encryption operations the IV is provided for by
426 the driver used to perform the operation, whereas for decryption
427 operations the offset of the IV is provided by the
428 .Va crd_inject
429 field.
430 This flag is typically used when the IV is calculated
431 .Dq "on the fly"
432 by the consumer, and does not precede the data (some
433 .Xr ipsec 4
434 configurations, and the encrypted swap are two such examples).
435 .It Dv CRD_F_KEY_EXPLICIT
436 For encryption and authentication (MAC) algorithms, this bit is set when the key
437 is explicitly provided by the consumer in the
438 .Va crd_key
439 field for the given operation.
440 Otherwise, the key is taken at newsession time from the
441 .Va cri_key
442 field.
443 As calculating the key schedule may take a while, it is recommended that often
444 used keys are given their own session.
445 .It Dv CRD_F_COMP
446 For compression algorithms, this bit is set when compression is required (when
447 not set, decompression is performed).
448 .El
449 .It Va CRD_INI
450 This
451 .Vt cryptoini
452 structure will not be modified by the framework or the device drivers.
453 Since this information accompanies every cryptographic
454 operation request, drivers may re-initialize state on-demand
455 (typically an expensive operation).
456 Furthermore, the cryptographic
457 framework may re-route requests as a result of full queues or hardware
458 failure, as described above.
459 .It Va crd_next
460 Point to the next descriptor.
461 Linked operations are useful in protocols such as
462 .Xr ipsec 4 ,
463 where multiple cryptographic transforms may be applied on the same
464 block of data.
465 .El
466 .El
467 .Pp
468 .Fn crypto_getreq
469 allocates a
470 .Vt cryptop
471 structure with a linked list of as many
472 .Vt cryptodesc
473 structures as were specified in the argument passed to it.
474 .Pp
475 .Fn crypto_freereq
476 deallocates a structure
477 .Vt cryptop
478 and any
479 .Vt cryptodesc
480 structures linked to it.
481 Note that it is the responsibility of the
482 callback routine to do the necessary cleanups associated with the
483 opaque field in the
484 .Vt cryptop
485 structure.
486 .Pp
487 .Fn crypto_kdispatch
488 is called to perform a keying operation.
489 The various fields in the
490 .Vt cryptkop
491 structure are:
492 .Bl -tag -width ".Va krp_callback"
493 .It Va krp_op
494 Operation code, such as
495 .Dv CRK_MOD_EXP .
496 .It Va krp_status
497 Return code.
498 This
499 .Va errno Ns -style
500 variable indicates whether lower level reasons
501 for operation failure.
502 .It Va krp_iparams
503 Number if input parameters to the specified operation.
504 Note that each operation has a (typically hardwired) number of such parameters.
505 .It Va krp_oparams
506 Number if output parameters from the specified operation.
507 Note that each operation has a (typically hardwired) number of such parameters.
508 .It Va krp_kvp
509 An array of kernel memory blocks containing the parameters.
510 .It Va krp_hid
511 Identifier specifying which low-level driver is being used.
512 .It Va krp_callback
513 Callback called on completion of a keying operation.
514 .El
515 .Sh DRIVER-SIDE API
516 The
517 .Fn crypto_get_driverid ,
518 .Fn crypto_register ,
519 .Fn crypto_kregister ,
520 .Fn crypto_unregister ,
521 .Fn crypto_unblock ,
522 and
523 .Fn crypto_done
524 routines are used by drivers that provide support for cryptographic
525 primitives to register and unregister with the kernel crypto services
526 framework.
527 .Pp
528 Drivers must first use the
529 .Fn crypto_get_driverid
530 function to acquire a driver identifier, specifying the
531 .Fa flags
532 as an argument.
533 One of
534 .Dv CRYPTOCAP_F_SOFTWARE
535 or
536 .Dv CRYPTOCAP_F_HARDWARE
537 must be specified.
538 The
539 .Dv CRYPTOCAP_F_SYNC
540 may also be specified, and should be specified if the driver does all of
541 it's operations synchronously.
542 .Pp
543 For each algorithm the driver supports, it must then call
544 .Fn crypto_register .
545 The first two arguments are the driver and algorithm identifiers.
546 The next two arguments specify the largest possible operator length (in bits,
547 important for public key operations) and flags for this algorithm.
548 The last four arguments must be provided in the first call to
549 .Fn crypto_register
550 and are ignored in all subsequent calls.
551 They are pointers to three
552 driver-provided functions that the framework may call to establish new
553 cryptographic context with the driver, free already established
554 context, and ask for a request to be processed (encrypt, decrypt,
555 etc.); and an opaque parameter to pass when calling each of these routines.
556 .Pp
557 .Fn crypto_unregister
558 is called by drivers that wish to withdraw support for an algorithm.
559 The two arguments are the driver and algorithm identifiers, respectively.
560 Typically, drivers for
561 PCMCIA
562 crypto cards that are being ejected will invoke this routine for all
563 algorithms supported by the card.
564 .Fn crypto_unregister_all
565 will unregister all algorithms registered by a driver
566 and the driver will be disabled (no new sessions will be allocated on
567 that driver, and any existing sessions will be migrated to other
568 drivers).
569 The same will be done if all algorithms associated with a driver are
570 unregistered one by one.
571 After a call to
572 .Fn crypto_unregister_all
573 there will be no threads in either the newsession or freesession function
574 of the driver.
575 .Pp
576 The calling convention for the three driver-supplied routines are:
577 .Pp
578 .Bl -item -compact
579 .It
580 .Ft int
581 .Fn \*[lp]*newsession\*[rp] "device_t" "uint32_t *" "struct cryptoini *" ;
582 .It
583 .Ft int
584 .Fn \*[lp]*freesession\*[rp] "device_t" "uint64_t" ;
585 .It
586 .Ft int
587 .Fn \*[lp]*process\*[rp] "device_t" "struct cryptop *" "int" ;
588 .It
589 .Ft int
590 .Fn \*[lp]*kprocess\*[rp] "device_t" "struct cryptkop *" "int" ;
591 .El
592 .Pp
593 On invocation, the first argument to
594 all routines is the
595 .Fa device_t
596 that was provided to
597 .Fn crypto_get_driverid .
598 The second argument to
599 .Fn newsession
600 contains the driver identifier obtained via
601 .Fn crypto_get_driverid .
602 On successful return, it should contain a driver-specific session
603 identifier.
604 The third argument is identical to that of
605 .Fn crypto_newsession .
606 .Pp
607 The
608 .Fn freesession
609 routine takes as arguments the opaque data value and the SID
610 (which is the concatenation of the
611 driver identifier and the driver-specific session identifier).
612 It should clear any context associated with the session (clear hardware
613 registers, memory, etc.).
614 .Pp
615 The
616 .Fn process
617 routine is invoked with a request to perform crypto processing.
618 This routine must not block or sleep, but should queue the request and return
619 immediately or process the request to completion.
620 In case of an unrecoverable error, the error indication must be placed in the
621 .Va crp_etype
622 field of the
623 .Vt cryptop
624 structure.
625 When the request is completed, or an error is detected, the
626 .Fn process
627 routine must invoke
628 .Fn crypto_done .
629 Session migration may be performed, as mentioned previously.
630 .Pp
631 In case of a temporary resource exhaustion, the
632 .Fn process
633 routine may return
634 .Er ERESTART
635 in which case the crypto services will requeue the request, mark the driver
636 as
637 .Dq blocked ,
638 and stop submitting requests for processing.
639 The driver is then responsible for notifying the crypto services
640 when it is again able to process requests through the
641 .Fn crypto_unblock
642 routine.
643 This simple flow control mechanism should only be used for short-lived
644 resource exhaustion as it causes operations to be queued in the crypto
645 layer.
646 Doing so is preferable to returning an error in such cases as
647 it can cause network protocols to degrade performance by treating the
648 failure much like a lost packet.
649 .Pp
650 The
651 .Fn kprocess
652 routine is invoked with a request to perform crypto key processing.
653 This routine must not block, but should queue the request and return
654 immediately.
655 Upon processing the request, the callback routine should be invoked.
656 In case of an unrecoverable error, the error indication must be placed in the
657 .Va krp_status
658 field of the
659 .Vt cryptkop
660 structure.
661 When the request is completed, or an error is detected, the
662 .Fn kprocess
663 routine should invoked
664 .Fn crypto_kdone .
665 .Sh RETURN VALUES
666 .Fn crypto_register ,
667 .Fn crypto_kregister ,
668 .Fn crypto_unregister ,
669 .Fn crypto_newsession ,
670 .Fn crypto_freesession ,
671 and
672 .Fn crypto_unblock
673 return 0 on success, or an error code on failure.
674 .Fn crypto_get_driverid
675 returns a non-negative value on error, and \-1 on failure.
676 .Fn crypto_getreq
677 returns a pointer to a
678 .Vt cryptop
679 structure and
680 .Dv NULL
681 on failure.
682 .Fn crypto_dispatch
683 returns
684 .Er EINVAL
685 if its argument or the callback function was
686 .Dv NULL ,
687 and 0 otherwise.
688 The callback is provided with an error code in case of failure, in the
689 .Va crp_etype
690 field.
691 .Sh FILES
692 .Bl -tag -width ".Pa sys/opencrypto/crypto.c"
693 .It Pa sys/opencrypto/crypto.c
694 most of the framework code
695 .El
696 .Sh SEE ALSO
697 .Xr crypto 4 ,
698 .Xr ipsec 4 ,
699 .Xr crypto 7 ,
700 .Xr malloc 9 ,
701 .Xr sleep 9
702 .Sh HISTORY
703 The cryptographic framework first appeared in
704 .Ox 2.7
705 and was written by
706 .An Angelos D. Keromytis Aq Mt angelos@openbsd.org .
707 .Sh BUGS
708 The framework currently assumes that all the algorithms in a
709 .Fn crypto_newsession
710 operation must be available by the same driver.
711 If that is not the case, session initialization will fail.
712 .Pp
713 The framework also needs a mechanism for determining which driver is
714 best for a specific set of algorithms associated with a session.
715 Some type of benchmarking is in order here.
716 .Pp
717 Multiple instances of the same algorithm in the same session are not
718 supported.
719 Note that 3DES is considered one algorithm (and not three
720 instances of DES).
721 Thus, 3DES and DES could be mixed in the same request.