xref: /freebsd/share/man/man9/crypto_request.9 (revision c03414326909ed7a740be3ba63fbbef01fe513a8)
1*c0341432SJohn Baldwin.\" Copyright (c) 2020, Chelsio Inc
2*c0341432SJohn Baldwin.\"
3*c0341432SJohn Baldwin.\" Redistribution and use in source and binary forms, with or without
4*c0341432SJohn Baldwin.\" modification, are permitted provided that the following conditions are met:
5*c0341432SJohn Baldwin.\"
6*c0341432SJohn Baldwin.\" 1. Redistributions of source code must retain the above copyright notice,
7*c0341432SJohn Baldwin.\"    this list of conditions and the following disclaimer.
8*c0341432SJohn Baldwin.\"
9*c0341432SJohn Baldwin.\" 2. Redistributions in binary form must reproduce the above copyright
10*c0341432SJohn Baldwin.\"    notice, this list of conditions and the following disclaimer in the
11*c0341432SJohn Baldwin.\"    documentation and/or other materials provided with the distribution.
12*c0341432SJohn Baldwin.\"
13*c0341432SJohn Baldwin.\" 3. Neither the name of the Chelsio Inc nor the names of its
14*c0341432SJohn Baldwin.\"    contributors may be used to endorse or promote products derived from
15*c0341432SJohn Baldwin.\"    this software without specific prior written permission.
16*c0341432SJohn Baldwin.\"
17*c0341432SJohn Baldwin.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18*c0341432SJohn Baldwin.\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19*c0341432SJohn Baldwin.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20*c0341432SJohn Baldwin.\" ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21*c0341432SJohn Baldwin.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22*c0341432SJohn Baldwin.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23*c0341432SJohn Baldwin.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24*c0341432SJohn Baldwin.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25*c0341432SJohn Baldwin.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26*c0341432SJohn Baldwin.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27*c0341432SJohn Baldwin.\" POSSIBILITY OF SUCH DAMAGE.
28*c0341432SJohn Baldwin.\"
29*c0341432SJohn Baldwin.\" * Other names and brands may be claimed as the property of others.
30*c0341432SJohn Baldwin.\"
31*c0341432SJohn Baldwin.\" $FreeBSD$
32*c0341432SJohn Baldwin.\"
33*c0341432SJohn Baldwin.Dd March 27, 2020
34*c0341432SJohn Baldwin.Dt CRYPTO_REQUEST 9
35*c0341432SJohn Baldwin.Os
36*c0341432SJohn Baldwin.Sh NAME
37*c0341432SJohn Baldwin.Nm crypto_request
38*c0341432SJohn Baldwin.Nd symmetric cryptographic operations
39*c0341432SJohn Baldwin.Sh SYNOPSIS
40*c0341432SJohn Baldwin.In opencrypto/cryptodev.h
41*c0341432SJohn Baldwin.Ft int
42*c0341432SJohn Baldwin.Fn crypto_dispatch "struct cryptop *crp"
43*c0341432SJohn Baldwin.Ft void
44*c0341432SJohn Baldwin.Fn crypto_freereq "struct cryptop *crp"
45*c0341432SJohn Baldwin.Ft "struct cryptop *"
46*c0341432SJohn Baldwin.Fn crypto_getreq "crypto_session_t cses" "int how"
47*c0341432SJohn Baldwin.Sh DESCRIPTION
48*c0341432SJohn BaldwinEach symmetric cryptographic operation in the kernel is described by
49*c0341432SJohn Baldwinan instance of
50*c0341432SJohn Baldwin.Vt struct cryptop
51*c0341432SJohn Baldwinand is associated with an active session.
52*c0341432SJohn Baldwin.Pp
53*c0341432SJohn BaldwinNew requests are allocated by
54*c0341432SJohn Baldwin.Fn crypto_getreq .
55*c0341432SJohn Baldwin.Fa cses
56*c0341432SJohn Baldwinis a reference to an active session.
57*c0341432SJohn Baldwin.Fa how
58*c0341432SJohn Baldwinis passed to
59*c0341432SJohn Baldwin.Xr malloc 9
60*c0341432SJohn Baldwinand should be set to either
61*c0341432SJohn Baldwin.Dv M_NOWAIT
62*c0341432SJohn Baldwinor
63*c0341432SJohn Baldwin.Dv M_WAITOK .
64*c0341432SJohn BaldwinThe caller should then set fields in the returned structure to describe
65*c0341432SJohn Baldwinrequest-specific parameters.
66*c0341432SJohn BaldwinUnused fields should be left as-is.
67*c0341432SJohn Baldwin.Pp
68*c0341432SJohn Baldwin.Fn crypto_dispatch
69*c0341432SJohn Baldwinpasses a crypto request to the driver attached to the request's session.
70*c0341432SJohn BaldwinIf there are errors in the request's fields, this function may return
71*c0341432SJohn Baldwinan error to the caller.
72*c0341432SJohn BaldwinIf errors are encountered while servicing the request, they will instead
73*c0341432SJohn Baldwinbe reported to the request's callback function
74*c0341432SJohn Baldwin.Pq Fa crp_callback
75*c0341432SJohn Baldwinvia
76*c0341432SJohn Baldwin.Fa crp_etype .
77*c0341432SJohn Baldwin.Pp
78*c0341432SJohn BaldwinNote that a request's callback function may be invoked before
79*c0341432SJohn Baldwin.Fn crypto_dispatch
80*c0341432SJohn Baldwinreturns.
81*c0341432SJohn Baldwin.Pp
82*c0341432SJohn BaldwinOnce a request has signaled completion by invoking its callback function,
83*c0341432SJohn Baldwinit should be feed via
84*c0341432SJohn Baldwin.Fn crypto_freereq .
85*c0341432SJohn Baldwin.Pp
86*c0341432SJohn BaldwinCryptographic operations include several fields to describe the request.
87*c0341432SJohn Baldwin.Ss Buffer Types
88*c0341432SJohn BaldwinRequests are associated with a single data buffer that is modified in place.
89*c0341432SJohn BaldwinThe type of the data buffer and the buffer itself are described by the
90*c0341432SJohn Baldwinfollowing fields:
91*c0341432SJohn Baldwin.Bl -tag -width crp_buf_type
92*c0341432SJohn Baldwin.It Fa crp_buf_type
93*c0341432SJohn BaldwinThe type of the data buffer.
94*c0341432SJohn BaldwinThe following types are supported:
95*c0341432SJohn Baldwin.Bl -tag -width CRYPTO_BUF_CONTIG
96*c0341432SJohn Baldwin.It Dv CRYPTO_BUF_CONTIG
97*c0341432SJohn BaldwinAn array of bytes mapped into the kernel's address space.
98*c0341432SJohn Baldwin.It Dv CRYPTO_BUF_UIO
99*c0341432SJohn BaldwinA scatter/gather list of kernel buffers as described in
100*c0341432SJohn Baldwin.Xr uio 9 .
101*c0341432SJohn Baldwin.It Dv CRYPTO_BUF_MBUF
102*c0341432SJohn BaldwinA network memory buffer as described in
103*c0341432SJohn Baldwin.Xr mbuf 9 .
104*c0341432SJohn Baldwin.El
105*c0341432SJohn Baldwin.It Fa crp_buf
106*c0341432SJohn BaldwinA pointer to the start of a
107*c0341432SJohn Baldwin.Dv CRYPTO_BUF_CONTIG
108*c0341432SJohn Baldwindata buffer.
109*c0341432SJohn Baldwin.It Fa crp_ilen
110*c0341432SJohn BaldwinThe length of a
111*c0341432SJohn Baldwin.Dv CRYPTO_BUF_CONTIG
112*c0341432SJohn Baldwindata buffer
113*c0341432SJohn Baldwin.It Fa crp_mbuf
114*c0341432SJohn BaldwinA pointer to a
115*c0341432SJohn Baldwin.Vt struct mbuf
116*c0341432SJohn Baldwinfor
117*c0341432SJohn Baldwin.Dv CRYPTO_BUF_MBUF .
118*c0341432SJohn Baldwin.It Fa crp_uio
119*c0341432SJohn BaldwinA pointer to a
120*c0341432SJohn Baldwin.Vt struct uio
121*c0341432SJohn Baldwinfor
122*c0341432SJohn Baldwin.Dv CRYPTO_BUF_UIO .
123*c0341432SJohn Baldwin.It Fa crp_olen
124*c0341432SJohn BaldwinUsed with compression and decompression requests to describe the updated
125*c0341432SJohn Baldwinlength of the payload region in the data buffer.
126*c0341432SJohn Baldwin.Pp
127*c0341432SJohn BaldwinIf a compression request increases the size of the payload,
128*c0341432SJohn Baldwinthen the data buffer is unmodified, the request completes successfully,
129*c0341432SJohn Baldwinand
130*c0341432SJohn Baldwin.Fa crp_olen
131*c0341432SJohn Baldwinis set to the size the compressed data would have used.
132*c0341432SJohn BaldwinCallers can compare this to the payload region length to determine if
133*c0341432SJohn Baldwinthe compressed data was discarded.
134*c0341432SJohn Baldwin.El
135*c0341432SJohn Baldwin.Ss Request Regions
136*c0341432SJohn BaldwinEach request describes one or more regions in the data buffer using.
137*c0341432SJohn BaldwinEach region is described by an offset relative to the start of the
138*c0341432SJohn Baldwindata buffer and a length.
139*c0341432SJohn BaldwinThe length of some regions is the same for all requests belonging to
140*c0341432SJohn Baldwina session.
141*c0341432SJohn BaldwinThose lengths are set in the session parameters of the associated
142*c0341432SJohn Baldwinsession.
143*c0341432SJohn BaldwinAll requests must define a payload region.
144*c0341432SJohn BaldwinOther regions are only required for specific session modes.
145*c0341432SJohn BaldwinThe following regions are defined:
146*c0341432SJohn Baldwin.Bl -column "Payload" "crp_payload_start" "crp_payload_length"
147*c0341432SJohn Baldwin.It Sy Region Ta Sy Start Ta Sy Length Ta Sy Description
148*c0341432SJohn Baldwin.It AAD Ta Fa crp_aad_start Ta Fa crp_aad_length Ta
149*c0341432SJohn BaldwinAdditional Authenticated Data
150*c0341432SJohn Baldwin.It IV Ta Fa crp_iv_start Ta Fa csp_ivlen Ta
151*c0341432SJohn BaldwinEmbedded IV or nonce
152*c0341432SJohn Baldwin.It Payload Ta Fa crp_payload_start Ta Fa crp_payload_length Ta
153*c0341432SJohn BaldwinData to encrypt, decrypt, compress, or decompress
154*c0341432SJohn Baldwin.It Digest Ta Fa crp_digest_start Ta Fa csp_auth_mlen Ta
155*c0341432SJohn BaldwinAuthentication digest, hash, or tag
156*c0341432SJohn Baldwin.El
157*c0341432SJohn Baldwin.Pp
158*c0341432SJohn BaldwinRequests are permitted to operate on only a subset of the data buffer.
159*c0341432SJohn BaldwinFor example,
160*c0341432SJohn Baldwinrequests from IPsec operate on network packets that include headers not
161*c0341432SJohn Baldwinused as either additional authentication data (AAD) or payload data.
162*c0341432SJohn Baldwin.Ss Request Operations
163*c0341432SJohn BaldwinAll requests must specify the type of operation to perform in
164*c0341432SJohn Baldwin.Fa crp_op .
165*c0341432SJohn BaldwinAvailable operations depend on the session's mode.
166*c0341432SJohn Baldwin.Pp
167*c0341432SJohn BaldwinCompression requests support the following operations:
168*c0341432SJohn Baldwin.Bl -tag -width CRYPTO_OP_DECOMPRESS
169*c0341432SJohn Baldwin.It Dv CRYPTO_OP_COMPRESS
170*c0341432SJohn BaldwinCompress the data in the payload region of the data buffer.
171*c0341432SJohn Baldwin.It Dv CRYPTO_OP_DECOMPRESS
172*c0341432SJohn BaldwinDecompress the data in the payload region of the data buffer.
173*c0341432SJohn Baldwin.El
174*c0341432SJohn Baldwin.Pp
175*c0341432SJohn BaldwinCipher requests support the following operations:
176*c0341432SJohn Baldwin.Bl -tag -width CRYPTO_OP_DECRYPT
177*c0341432SJohn Baldwin.It Dv CRYPTO_OP_ENCRYPT
178*c0341432SJohn BaldwinEncrypt the data in the payload region of the data buffer.
179*c0341432SJohn Baldwin.It Dv CRYPTO_OP_DECRYPT
180*c0341432SJohn BaldwinDecrypt the data in the payload region of the data buffer.
181*c0341432SJohn Baldwin.El
182*c0341432SJohn Baldwin.Pp
183*c0341432SJohn BaldwinDigest requests support the following operations:
184*c0341432SJohn Baldwin.Bl -tag -width CRYPTO_OP_COMPUTE_DIGEST
185*c0341432SJohn Baldwin.It Dv CRYPTO_OP_COMPUTE_DIGEST
186*c0341432SJohn BaldwinCalculate a digest over the payload region of the data buffer
187*c0341432SJohn Baldwinand store the result in the digest region.
188*c0341432SJohn Baldwin.It Dv CRYPTO_OP_VERIFY_DIGEST
189*c0341432SJohn BaldwinCalculate a digest over the payload region of the data buffer.
190*c0341432SJohn BaldwinCompare the calculated digest to the existing digest from the digest region.
191*c0341432SJohn BaldwinIf the digests match,
192*c0341432SJohn Baldwincomplete the request successfully.
193*c0341432SJohn BaldwinIf the digests do not match,
194*c0341432SJohn Baldwinfail the request with
195*c0341432SJohn Baldwin.Er EBADMSG .
196*c0341432SJohn Baldwin.El
197*c0341432SJohn Baldwin.Pp
198*c0341432SJohn BaldwinAEAD and Encrypt-then-Authenticate requests support the following
199*c0341432SJohn Baldwinoperations:
200*c0341432SJohn Baldwin.Bl -tag -width CRYPTO_OP
201*c0341432SJohn Baldwin.It Dv CRYPTO_OP_ENCRYPT | Dv CRYPTO_OP_COMPUTE_DIGEST
202*c0341432SJohn BaldwinEncrypt the data in the payload region of the data buffer.
203*c0341432SJohn BaldwinCalculate a digest over the AAD and payload regions and store the
204*c0341432SJohn Baldwinresult in the data buffer.
205*c0341432SJohn Baldwin.It Dv CRYPTO_OP_DECRYPT | Dv CRYPTO_OP_VERIFY_DIGEST
206*c0341432SJohn BaldwinCalculate a digest over the AAD and payload regions of the data buffer.
207*c0341432SJohn BaldwinCompare the calculated digest to the existing digest from the digest region.
208*c0341432SJohn BaldwinIf the digests match,
209*c0341432SJohn Baldwindecrypt the payload region.
210*c0341432SJohn BaldwinIf the digests do not match,
211*c0341432SJohn Baldwinfail the request with
212*c0341432SJohn Baldwin.Er EBADMSG .
213*c0341432SJohn Baldwin.El
214*c0341432SJohn Baldwin.Ss Request IV and/or Nonce
215*c0341432SJohn BaldwinSome cryptographic operations require an IV or nonce as an input.
216*c0341432SJohn BaldwinAn IV may be stored either in the IV region of the data buffer or in
217*c0341432SJohn Baldwin.Fa crp_iv .
218*c0341432SJohn BaldwinBy default,
219*c0341432SJohn Baldwinthe IV is assumed to be stored in the IV region.
220*c0341432SJohn BaldwinIf the IV is stored in
221*c0341432SJohn Baldwin.Fa crp_iv ,
222*c0341432SJohn Baldwin.Dv CRYPTO_F_IV_SEPARATE
223*c0341432SJohn Baldwinshould be set in
224*c0341432SJohn Baldwin.Fa crp_flags
225*c0341432SJohn Baldwinand
226*c0341432SJohn Baldwin.Fa crp_digest_start
227*c0341432SJohn Baldwinshould be left as zero.
228*c0341432SJohn Baldwin.Pp
229*c0341432SJohn BaldwinAn encryption request using an IV stored in the IV region may set
230*c0341432SJohn Baldwin.Dv CRYPTO_F_IV_GENERATE
231*c0341432SJohn Baldwinin
232*c0341432SJohn Baldwin.Fa crp_flags
233*c0341432SJohn Baldwinto request that the driver generate a random IV.
234*c0341432SJohn BaldwinNote that
235*c0341432SJohn Baldwin.Dv CRYPTO_F_IV_GENERATE
236*c0341432SJohn Baldwincannot be used with decryption operations or in combination with
237*c0341432SJohn Baldwin.Dv CRYPTO_F_IV_SEPARATE .
238*c0341432SJohn Baldwin.Pp
239*c0341432SJohn BaldwinRequests that store part, but not all, of the IV in the data buffer should
240*c0341432SJohn Baldwinstore the partial IV in the data buffer and pass the full IV separately in
241*c0341432SJohn Baldwin.Fa crp_iv .
242*c0341432SJohn Baldwin.Ss Request and Callback Scheduling
243*c0341432SJohn BaldwinThe crypto framework provides multiple methods of scheduling the dispatch
244*c0341432SJohn Baldwinof requests to drivers along with the processing of driver callbacks.
245*c0341432SJohn BaldwinRequests use flags in
246*c0341432SJohn Baldwin.Fa crp_flags
247*c0341432SJohn Baldwinto select the desired scheduling methods.
248*c0341432SJohn Baldwin.Pp
249*c0341432SJohn Baldwin.Fn crypto_dispatch
250*c0341432SJohn Baldwincan pass the request to the session's driver via three different methods:
251*c0341432SJohn Baldwin.Bl -enum
252*c0341432SJohn Baldwin.It
253*c0341432SJohn BaldwinThe request is queued to a taskqueue backed by a pool of worker threads.
254*c0341432SJohn BaldwinBy default the pool is sized to provide one thread for each CPU.
255*c0341432SJohn BaldwinWorker threads dequeue requests and pass them to the driver
256*c0341432SJohn Baldwinasynchronously.
257*c0341432SJohn Baldwin.It
258*c0341432SJohn BaldwinThe request is passed to the driver synchronously in the context of the
259*c0341432SJohn Baldwinthread invoking
260*c0341432SJohn Baldwin.Fn crypto_dispatch .
261*c0341432SJohn Baldwin.It
262*c0341432SJohn BaldwinThe request is queued to a queue of pending requests.
263*c0341432SJohn BaldwinA single worker thread dequeues requests and passes them to the driver
264*c0341432SJohn Baldwinasynchronously.
265*c0341432SJohn Baldwin.El
266*c0341432SJohn Baldwin.Pp
267*c0341432SJohn BaldwinTo select the first method (taskqueue backed by multiple threads),
268*c0341432SJohn Baldwinrequests should set
269*c0341432SJohn Baldwin.Dv CRYPTO_F_ASYNC .
270*c0341432SJohn BaldwinTo always use the third method (queue to single worker thread),
271*c0341432SJohn Baldwinrequests should set
272*c0341432SJohn Baldwin.Dv CRYPTO_F_BATCH .
273*c0341432SJohn BaldwinIf both flags are set,
274*c0341432SJohn Baldwin.Dv CRYPTO_F_ASYNC
275*c0341432SJohn Baldwintakes precedence.
276*c0341432SJohn BaldwinIf neither flag is set,
277*c0341432SJohn Baldwin.Fn crypto_dispatch
278*c0341432SJohn Baldwinwill first attempt the second method (invoke driver synchronously).
279*c0341432SJohn BaldwinIf the driver is blocked,
280*c0341432SJohn Baldwinthe request will be queued using the third method.
281*c0341432SJohn BaldwinOne caveat is that the first method is only used for requests using software
282*c0341432SJohn Baldwindrivers which use host CPUs to process requests.
283*c0341432SJohn BaldwinRequests whose session is associated with a hardware driver will ignore
284*c0341432SJohn Baldwin.Dv CRYPTO_F_ASYNC
285*c0341432SJohn Baldwinand only use
286*c0341432SJohn Baldwin.Dv CRYPTO_F_BATCH
287*c0341432SJohn Baldwinto determine how requests should be scheduled.
288*c0341432SJohn Baldwin.Pp
289*c0341432SJohn BaldwinIn addition to bypassing synchronous dispatch in
290*c0341432SJohn Baldwin.Fn crypto_dispatch ,
291*c0341432SJohn Baldwin.Dv CRYPTO_F_BATCH
292*c0341432SJohn Baldwinrequests additional changes aimed at optimizing batches of requests to
293*c0341432SJohn Baldwinthe same driver.
294*c0341432SJohn BaldwinWhen the worker thread processes a request with
295*c0341432SJohn Baldwin.Dv CRYPTO_F_BATCH ,
296*c0341432SJohn Baldwinit will search the pending request queue for any other requests for the same
297*c0341432SJohn Baldwindriver,
298*c0341432SJohn Baldwinincluding requests from different sessions.
299*c0341432SJohn BaldwinIf any other requests are present,
300*c0341432SJohn Baldwin.Dv CRYPTO_HINT_MORE
301*c0341432SJohn Baldwinis passed to the driver's process method.
302*c0341432SJohn BaldwinDrivers may use this to batch completion interrupts.
303*c0341432SJohn Baldwin.Pp
304*c0341432SJohn BaldwinCallback function scheduling is simpler than request scheduling.
305*c0341432SJohn BaldwinCallbacks can either be invoked synchronously from
306*c0341432SJohn Baldwin.Fn crypto_done ,
307*c0341432SJohn Baldwinor they can be queued to a pool of worker threads.
308*c0341432SJohn BaldwinThis pool of worker threads is also sized to provide one worker thread
309*c0341432SJohn Baldwinfor each CPU by default.
310*c0341432SJohn BaldwinNote that a callback function invoked synchronously from
311*c0341432SJohn Baldwin.Fn crypto_done
312*c0341432SJohn Baldwinmust follow the same restrictions placed on threaded interrupt handlers.
313*c0341432SJohn Baldwin.Pp
314*c0341432SJohn BaldwinBy default,
315*c0341432SJohn Baldwincallbacks are invoked asynchronously by a worker thread.
316*c0341432SJohn BaldwinIf
317*c0341432SJohn Baldwin.Dv CRYPTO_F_CBIMM
318*c0341432SJohn Baldwinis set,
319*c0341432SJohn Baldwinthe callback is always invoked synchronously from
320*c0341432SJohn Baldwin.Fn crypto_done .
321*c0341432SJohn BaldwinIf
322*c0341432SJohn Baldwin.Dv CRYPTO_F_CBIFSYNC
323*c0341432SJohn Baldwinis set,
324*c0341432SJohn Baldwinthe callback is invoked synchronously if the request was processed by a
325*c0341432SJohn Baldwinsoftware driver or asynchronously if the request was processed by a
326*c0341432SJohn Baldwinhardware driver.
327*c0341432SJohn Baldwin.Pp
328*c0341432SJohn BaldwinIf a request was scheduled to the taskqueue via
329*c0341432SJohn Baldwin.Dv CRYPTO_F_ASYNC ,
330*c0341432SJohn Baldwincallbacks are always invoked asynchronously ignoring
331*c0341432SJohn Baldwin.Dv CRYPTO_F_CBIMM
332*c0341432SJohn Baldwinand
333*c0341432SJohn Baldwin.Dv CRYPTO_F_CBIFSYNC .
334*c0341432SJohn BaldwinIn this case,
335*c0341432SJohn Baldwin.Dv CRYPTO_F_ASYNC_KEEPORDER
336*c0341432SJohn Baldwinmay be set to ensure that callbacks for requests on a given session are
337*c0341432SJohn Baldwininvoked in the same order that requests were queued to the session via
338*c0341432SJohn Baldwin.Fn crypto_dispatch .
339*c0341432SJohn BaldwinThis flag is used by IPsec to ensure that decrypted network packets are
340*c0341432SJohn Baldwinpassed up the network stack in roughly the same order they were received.
341*c0341432SJohn Baldwin.Pp
342*c0341432SJohn Baldwin.Ss Other Request Fields
343*c0341432SJohn BaldwinIn addition to the fields and flags enumerated above,
344*c0341432SJohn Baldwin.Vt struct cryptop
345*c0341432SJohn Baldwinincludes the following:
346*c0341432SJohn Baldwin.Bl -tag -width crp_payload_length
347*c0341432SJohn Baldwin.It Fa crp_session
348*c0341432SJohn BaldwinA reference to the active session.
349*c0341432SJohn BaldwinThis is set when the request is created by
350*c0341432SJohn Baldwin.Fn crypto_getreq
351*c0341432SJohn Baldwinand should not be modified.
352*c0341432SJohn BaldwinDrivers can use this to fetch driver-specific session state or
353*c0341432SJohn Baldwinsession parameters.
354*c0341432SJohn Baldwin.It Fa crp_etype
355*c0341432SJohn BaldwinError status.
356*c0341432SJohn BaldwinEither zero on success, or an error if a request fails.
357*c0341432SJohn BaldwinSet by drivers prior to completing a request via
358*c0341432SJohn Baldwin.Fn crypto_done .
359*c0341432SJohn Baldwin.It Fa crp_flags
360*c0341432SJohn BaldwinA bitmask of flags.
361*c0341432SJohn BaldwinThe following flags are available in addition to flags discussed previously:
362*c0341432SJohn Baldwin.Bl -tag -width CRYPTO_F_DONE
363*c0341432SJohn Baldwin.It Dv CRYPTO_F_DONE
364*c0341432SJohn BaldwinSet by
365*c0341432SJohn Baldwin.Fa crypto_done
366*c0341432SJohn Baldwinbefore calling
367*c0341432SJohn Baldwin.Fa crp_callback .
368*c0341432SJohn BaldwinThis flag is not very useful and will likely be removed in the future.
369*c0341432SJohn BaldwinIt can only be safely checked from the callback routine at which point
370*c0341432SJohn Baldwinit is always set.
371*c0341432SJohn Baldwin.El
372*c0341432SJohn Baldwin.It Fa crp_cipher_key
373*c0341432SJohn BaldwinPointer to a request-specific encryption key.
374*c0341432SJohn BaldwinIf this value is not set,
375*c0341432SJohn Baldwinthe request uses the session encryption key.
376*c0341432SJohn Baldwin.It Fa crp_auth_key
377*c0341432SJohn BaldwinPointer to a request-specific authentication key.
378*c0341432SJohn BaldwinIf this value is not set,
379*c0341432SJohn Baldwinthe request uses the session authentication key.
380*c0341432SJohn Baldwin.It Fa crp_opaque
381*c0341432SJohn BaldwinAn opaque pointer.
382*c0341432SJohn BaldwinThis pointer permits users of the cryptographic framework to store
383*c0341432SJohn Baldwininformation about a request to be used in the callback.
384*c0341432SJohn Baldwin.It Fa crp_callback
385*c0341432SJohn BaldwinCallback function.
386*c0341432SJohn BaldwinThis must point to a callback function of type
387*c0341432SJohn Baldwin.Vt void (*)(struct cryptop *) .
388*c0341432SJohn BaldwinThe callback function should inspect
389*c0341432SJohn Baldwin.Fa crp_etype
390*c0341432SJohn Baldwinto determine the status of the completed operation.
391*c0341432SJohn BaldwinIt should also arrange for the request to be freed via
392*c0341432SJohn Baldwin.Fn crypto_freereq .
393*c0341432SJohn Baldwin.El
394*c0341432SJohn Baldwin.Sh RETURN VALUES
395*c0341432SJohn Baldwin.Fn crypto_dispatch
396*c0341432SJohn Baldwinreturns an error if the request contained invalid fields,
397*c0341432SJohn Baldwinor zero if the request was valid.
398*c0341432SJohn Baldwin.Fn crypto_getreq
399*c0341432SJohn Baldwinreturns a pointer to a new request structure on success,
400*c0341432SJohn Baldwinor
401*c0341432SJohn Baldwin.Dv NULL
402*c0341432SJohn Baldwinon failure.
403*c0341432SJohn Baldwin.Dv NULL
404*c0341432SJohn Baldwincan only be returned if
405*c0341432SJohn Baldwin.Dv M_NOWAIT
406*c0341432SJohn Baldwinwas passed in
407*c0341432SJohn Baldwin.Fa how .
408*c0341432SJohn Baldwin.Sh SEE ALSO
409*c0341432SJohn Baldwin.Xr ipsec 4 ,
410*c0341432SJohn Baldwin.Xr crypto 7 ,
411*c0341432SJohn Baldwin.Xr crypto 9 ,
412*c0341432SJohn Baldwin.Xr crypto_session 9 ,
413*c0341432SJohn Baldwin.Xr mbuf 9
414*c0341432SJohn Baldwin.Xr uio 9
415*c0341432SJohn Baldwin.Sh BUGS
416*c0341432SJohn BaldwinNot all drivers properly handle mixing session and per-request keys
417*c0341432SJohn Baldwinwithin a single session.
418*c0341432SJohn BaldwinConsumers should either use a single key for a session specified in
419*c0341432SJohn Baldwinthe session parameters or always use per-request keys.
420