xref: /freebsd/share/man/man9/crypto_request.9 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
1c0341432SJohn Baldwin.\" Copyright (c) 2020, Chelsio Inc
2c0341432SJohn Baldwin.\"
3c0341432SJohn Baldwin.\" Redistribution and use in source and binary forms, with or without
4c0341432SJohn Baldwin.\" modification, are permitted provided that the following conditions are met:
5c0341432SJohn Baldwin.\"
6c0341432SJohn Baldwin.\" 1. Redistributions of source code must retain the above copyright notice,
7c0341432SJohn Baldwin.\"    this list of conditions and the following disclaimer.
8c0341432SJohn Baldwin.\"
9c0341432SJohn Baldwin.\" 2. Redistributions in binary form must reproduce the above copyright
10c0341432SJohn Baldwin.\"    notice, this list of conditions and the following disclaimer in the
11c0341432SJohn Baldwin.\"    documentation and/or other materials provided with the distribution.
12c0341432SJohn Baldwin.\"
13c0341432SJohn Baldwin.\" 3. Neither the name of the Chelsio Inc nor the names of its
14c0341432SJohn Baldwin.\"    contributors may be used to endorse or promote products derived from
15c0341432SJohn Baldwin.\"    this software without specific prior written permission.
16c0341432SJohn Baldwin.\"
17c0341432SJohn Baldwin.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18c0341432SJohn Baldwin.\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19c0341432SJohn Baldwin.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20c0341432SJohn Baldwin.\" ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21c0341432SJohn Baldwin.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22c0341432SJohn Baldwin.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23c0341432SJohn Baldwin.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24c0341432SJohn Baldwin.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25c0341432SJohn Baldwin.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26c0341432SJohn Baldwin.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27c0341432SJohn Baldwin.\" POSSIBILITY OF SUCH DAMAGE.
28c0341432SJohn Baldwin.\"
29c0341432SJohn Baldwin.\" * Other names and brands may be claimed as the property of others.
30c0341432SJohn Baldwin.\"
31*002c47baSAlan Somers.Dd November 2, 2022
32c0341432SJohn Baldwin.Dt CRYPTO_REQUEST 9
33c0341432SJohn Baldwin.Os
34c0341432SJohn Baldwin.Sh NAME
35c0341432SJohn Baldwin.Nm crypto_request
36c0341432SJohn Baldwin.Nd symmetric cryptographic operations
37c0341432SJohn Baldwin.Sh SYNOPSIS
38c0341432SJohn Baldwin.In opencrypto/cryptodev.h
3974d3f1b6SJohn Baldwin.Ft "struct cryptop *"
4074d3f1b6SJohn Baldwin.Fn crypto_clonereq "crypto_session_t cses" "struct cryptop *crp" "int how"
41c0341432SJohn Baldwin.Ft int
42c0341432SJohn Baldwin.Fn crypto_dispatch "struct cryptop *crp"
4368f6800cSMark Johnston.Ft int
4468f6800cSMark Johnston.Fn crypto_dispatch_async "struct cryptop *crp" "int flags"
4568f6800cSMark Johnston.Ft void
4668f6800cSMark Johnston.Fn crypto_dispatch_batch "struct cryptopq *crpq" "int flags"
47c0341432SJohn Baldwin.Ft void
48946b8f6fSJohn Baldwin.Fn crypto_destroyreq "struct cryptop *crp"
49946b8f6fSJohn Baldwin.Ft void
50c0341432SJohn Baldwin.Fn crypto_freereq "struct cryptop *crp"
51c0341432SJohn Baldwin.Ft "struct cryptop *"
52c0341432SJohn Baldwin.Fn crypto_getreq "crypto_session_t cses" "int how"
539c0e3d3aSJohn Baldwin.Ft void
54946b8f6fSJohn Baldwin.Fn crypto_initreq "crypto_session_t cses" "int how"
55946b8f6fSJohn Baldwin.Ft void
569c0e3d3aSJohn Baldwin.Fn crypto_use_buf "struct cryptop *crp" "void *buf" "int len"
579c0e3d3aSJohn Baldwin.Ft void
589c0e3d3aSJohn Baldwin.Fn crypto_use_mbuf "struct cryptop *crp" "struct mbuf *m"
599c0e3d3aSJohn Baldwin.Ft void
609c0e3d3aSJohn Baldwin.Fn crypto_use_uio "struct cryptop *crp" "struct uio *uio"
619c0e3d3aSJohn Baldwin.Ft void
62e6f6d0c9SAlan Somers.Fn crypto_use_vmpage "struct cryptop *crp" "vm_page_t *pages" "int len" "int offset"
63e6f6d0c9SAlan Somers.Ft void
649c0e3d3aSJohn Baldwin.Fn crypto_use_output_buf "struct cryptop *crp" "void *buf" "int len"
659c0e3d3aSJohn Baldwin.Ft void
669c0e3d3aSJohn Baldwin.Fn crypto_use_output_mbuf "struct cryptop *crp" "struct mbuf *m"
679c0e3d3aSJohn Baldwin.Ft void
689c0e3d3aSJohn Baldwin.Fn crypto_use_output_uio "struct cryptop *crp" "struct uio *uio"
69e6f6d0c9SAlan Somers.Ft void
70e6f6d0c9SAlan Somers.Fn crypto_use_output_vmpage "struct cryptop *crp" "vm_page_t *pages" "int len" "int offset"
71c0341432SJohn Baldwin.Sh DESCRIPTION
72c0341432SJohn BaldwinEach symmetric cryptographic operation in the kernel is described by
73c0341432SJohn Baldwinan instance of
74c0341432SJohn Baldwin.Vt struct cryptop
75c0341432SJohn Baldwinand is associated with an active session.
76c0341432SJohn Baldwin.Pp
77946b8f6fSJohn BaldwinRequests can either be allocated dynamically or use caller-supplied
78946b8f6fSJohn Baldwinstorage.
7974d3f1b6SJohn BaldwinDynamically allocated requests should be allocated by either
80946b8f6fSJohn Baldwin.Fn crypto_getreq
8174d3f1b6SJohn Baldwinor
8274d3f1b6SJohn Baldwin.Fn crypto_clonereq ,
83946b8f6fSJohn Baldwinand freed by
84946b8f6fSJohn Baldwin.Fn crypto_freereq
85946b8f6fSJohn Baldwinonce the request has completed.
86946b8f6fSJohn BaldwinRequests using caller-supplied storage should be initialized by
87946b8f6fSJohn Baldwin.Fn crypto_initreq
88946b8f6fSJohn Baldwinat the start of each operation and destroyed by
89946b8f6fSJohn Baldwin.Fn crypto_destroyreq
90946b8f6fSJohn Baldwinonce the request has completed.
91946b8f6fSJohn Baldwin.Pp
9274d3f1b6SJohn BaldwinFor
9374d3f1b6SJohn Baldwin.Fn crypto_clonereq ,
9474d3f1b6SJohn Baldwin.Fn crypto_getreq ,
95946b8f6fSJohn Baldwinand
96946b8f6fSJohn Baldwin.Fn crypto_initreq ,
97c0341432SJohn Baldwin.Fa cses
98c0341432SJohn Baldwinis a reference to an active session.
99946b8f6fSJohn BaldwinFor
10074d3f1b6SJohn Baldwin.Fn crypto_clonereq
10174d3f1b6SJohn Baldwinand
102946b8f6fSJohn Baldwin.Fn crypto_getreq ,
103c0341432SJohn Baldwin.Fa how
104c0341432SJohn Baldwinis passed to
105c0341432SJohn Baldwin.Xr malloc 9
106c0341432SJohn Baldwinand should be set to either
107c0341432SJohn Baldwin.Dv M_NOWAIT
108c0341432SJohn Baldwinor
109c0341432SJohn Baldwin.Dv M_WAITOK .
110946b8f6fSJohn Baldwin.Pp
11174d3f1b6SJohn Baldwin.Fn crypto_clonereq
11274d3f1b6SJohn Baldwinallocates a new request that inherits request inputs such as request buffers
11374d3f1b6SJohn Baldwinfrom the original
11474d3f1b6SJohn Baldwin.Fa crp
11574d3f1b6SJohn Baldwinrequest.
11674d3f1b6SJohn BaldwinHowever, the new request is associated with the
11774d3f1b6SJohn Baldwin.Fa cses
11874d3f1b6SJohn Baldwinsession rather than inheriting the session from
11974d3f1b6SJohn Baldwin.Fa crp .
12074d3f1b6SJohn Baldwin.Fa crp
12174d3f1b6SJohn Baldwinmust not be a completed request.
12274d3f1b6SJohn Baldwin.Pp
123946b8f6fSJohn BaldwinOnce a request has been initialized,
124946b8f6fSJohn Baldwinthe caller should set fields in the structure to describe
125c0341432SJohn Baldwinrequest-specific parameters.
126c0341432SJohn BaldwinUnused fields should be left as-is.
127c0341432SJohn Baldwin.Pp
12868f6800cSMark JohnstonThe
12968f6800cSMark Johnston.Fn crypto_dispatch ,
13068f6800cSMark Johnston.Fn crypto_dispatch_async ,
13168f6800cSMark Johnstonand
13268f6800cSMark Johnston.Fn crypto_dispatch_batch
13368f6800cSMark Johnstonfunctions pass one or more crypto requests to the driver attached to the
13468f6800cSMark Johnstonrequest's session.
13568f6800cSMark JohnstonIf there are errors in the request's fields, these functions may return an
13668f6800cSMark Johnstonerror to the caller.
137c0341432SJohn BaldwinIf errors are encountered while servicing the request, they will instead
138c0341432SJohn Baldwinbe reported to the request's callback function
139c0341432SJohn Baldwin.Pq Fa crp_callback
140c0341432SJohn Baldwinvia
141c0341432SJohn Baldwin.Fa crp_etype .
142c0341432SJohn Baldwin.Pp
143c0341432SJohn BaldwinNote that a request's callback function may be invoked before
144c0341432SJohn Baldwin.Fn crypto_dispatch
145c0341432SJohn Baldwinreturns.
146c0341432SJohn Baldwin.Pp
147c0341432SJohn BaldwinOnce a request has signaled completion by invoking its callback function,
148946b8f6fSJohn Baldwinit should be freed via
149946b8f6fSJohn Baldwin.Fn crypto_destroyreq
150946b8f6fSJohn Baldwinor
151c0341432SJohn Baldwin.Fn crypto_freereq .
152c0341432SJohn Baldwin.Pp
153c0341432SJohn BaldwinCryptographic operations include several fields to describe the request.
1549c0e3d3aSJohn Baldwin.Ss Request Buffers
1559c0e3d3aSJohn BaldwinRequests can either specify a single data buffer that is modified in place
1569c0e3d3aSJohn Baldwin.Po
1579c0e3d3aSJohn Baldwin.Fa crp_buf
1589c0e3d3aSJohn Baldwin.Pc
1599c0e3d3aSJohn Baldwinor separate input
1609c0e3d3aSJohn Baldwin.Po
1619c0e3d3aSJohn Baldwin.Fa crp_buf
1629c0e3d3aSJohn Baldwin.Pc
1639c0e3d3aSJohn Baldwinand output
1649c0e3d3aSJohn Baldwin.Po
1659c0e3d3aSJohn Baldwin.Fa crp_obuf
1669c0e3d3aSJohn Baldwin.Pc
1679c0e3d3aSJohn Baldwinbuffers.
1689c0e3d3aSJohn BaldwinNote that separate input and output buffers are not supported for compression
1699c0e3d3aSJohn Baldwinmode requests.
170c0341432SJohn Baldwin.Pp
1719c0e3d3aSJohn BaldwinAll requests must have a valid
1729c0e3d3aSJohn Baldwin.Fa crp_buf
1739c0e3d3aSJohn Baldwininitialized by one of the following functions:
174e6f6d0c9SAlan Somers.Bl -tag -width "Fn crypto_use_vmpage"
1759c0e3d3aSJohn Baldwin.It Fn crypto_use_buf
1769c0e3d3aSJohn BaldwinUses an array of
1779c0e3d3aSJohn Baldwin.Fa len
1789c0e3d3aSJohn Baldwinbytes pointed to by
1799c0e3d3aSJohn Baldwin.Fa buf
1809c0e3d3aSJohn Baldwinas the data buffer.
1819c0e3d3aSJohn Baldwin.It Fn crypto_use_mbuf
1829c0e3d3aSJohn BaldwinUses the network memory buffer
1839c0e3d3aSJohn Baldwin.Fa m
1849c0e3d3aSJohn Baldwinas the data buffer.
1859c0e3d3aSJohn Baldwin.It Fn crypto_use_uio
1869c0e3d3aSJohn BaldwinUses the scatter/gather list
1879c0e3d3aSJohn Baldwin.Fa uio
1889c0e3d3aSJohn Baldwinas the data buffer.
189e6f6d0c9SAlan Somers.It Fn crypto_use_vmpage
190e6f6d0c9SAlan SomersUses the array of
191e6f6d0c9SAlan Somers.Vt vm_page_t
192e6f6d0c9SAlan Somersstructures as the data buffer.
1939c0e3d3aSJohn Baldwin.El
1949c0e3d3aSJohn Baldwin.Pp
1959c0e3d3aSJohn BaldwinOne of the following functions should be used to initialize
1969c0e3d3aSJohn Baldwin.Fa crp_obuf
1979c0e3d3aSJohn Baldwinfor requests that use separate input and output buffers:
198e6f6d0c9SAlan Somers.Bl -tag -width "Fn crypto_use_output_vmpage"
1999c0e3d3aSJohn Baldwin.It Fn crypto_use_output_buf
2009c0e3d3aSJohn BaldwinUses an array of
2019c0e3d3aSJohn Baldwin.Fa len
2029c0e3d3aSJohn Baldwinbytes pointed to by
2039c0e3d3aSJohn Baldwin.Fa buf
2049c0e3d3aSJohn Baldwinas the output buffer.
2059c0e3d3aSJohn Baldwin.It Fn crypto_use_output_mbuf
2069c0e3d3aSJohn BaldwinUses the network memory buffer
2079c0e3d3aSJohn Baldwin.Fa m
2089c0e3d3aSJohn Baldwinas the output buffer.
2099c0e3d3aSJohn Baldwin.It Fn crypto_use_output_uio
2109c0e3d3aSJohn BaldwinUses the scatter/gather list
2119c0e3d3aSJohn Baldwin.Fa uio
2129c0e3d3aSJohn Baldwinas the output buffer.
213e6f6d0c9SAlan Somers.It Fn crypto_use_output_vmpage
214e6f6d0c9SAlan SomersUses the array of
215e6f6d0c9SAlan Somers.Vt vm_page_t
216e6f6d0c9SAlan Somersstructures as the output buffer.
217c0341432SJohn Baldwin.El
218c0341432SJohn Baldwin.Ss Request Regions
2199c0e3d3aSJohn BaldwinEach request describes one or more regions in the data buffers.
2209c0e3d3aSJohn BaldwinEach region is described by an offset relative to the start of a
221c0341432SJohn Baldwindata buffer and a length.
222c0341432SJohn BaldwinThe length of some regions is the same for all requests belonging to
223c0341432SJohn Baldwina session.
224c0341432SJohn BaldwinThose lengths are set in the session parameters of the associated
225c0341432SJohn Baldwinsession.
226c0341432SJohn BaldwinAll requests must define a payload region.
227c0341432SJohn BaldwinOther regions are only required for specific session modes.
2289c0e3d3aSJohn Baldwin.Pp
2299c0e3d3aSJohn BaldwinFor requests with separate input and output data buffers,
2309c0e3d3aSJohn Baldwinthe AAD, IV, and payload regions are always defined as regions in the
2319c0e3d3aSJohn Baldwininput buffer,
2329c0e3d3aSJohn Baldwinand a separate payload output region is defined to hold the output of
2339c0e3d3aSJohn Baldwinencryption or decryption in the output buffer.
2349c0e3d3aSJohn BaldwinThe digest region describes a region in the input data buffer for
2359c0e3d3aSJohn Baldwinrequests that verify an existing digest.
2369c0e3d3aSJohn BaldwinFor requests that compute a digest,
2379c0e3d3aSJohn Baldwinthe digest region describes a region in the output data buffer.
2389c0e3d3aSJohn BaldwinNote that the only data written to the output buffer is the encryption
2399c0e3d3aSJohn Baldwinor decryption result and any computed digest.
2409c0e3d3aSJohn BaldwinAAD and IV regions are not copied from the input buffer into the output
2419c0e3d3aSJohn Baldwinbuffer but are only used as inputs.
2429c0e3d3aSJohn Baldwin.Pp
243c0341432SJohn BaldwinThe following regions are defined:
2449c0e3d3aSJohn Baldwin.Bl -column "Payload Output" "Input/Output"
2459c0e3d3aSJohn Baldwin.It Sy Region Ta Sy Buffer Ta Sy Description
2469c0e3d3aSJohn Baldwin.It AAD Ta Input Ta
2479b774dc0SJohn BaldwinEmbedded Additional Authenticated Data
2489c0e3d3aSJohn Baldwin.It IV Ta Input Ta
249c0341432SJohn BaldwinEmbedded IV or nonce
2509c0e3d3aSJohn Baldwin.It Payload Ta Input Ta
251c0341432SJohn BaldwinData to encrypt, decrypt, compress, or decompress
2529c0e3d3aSJohn Baldwin.It Payload Output Ta Output Ta
2539c0e3d3aSJohn BaldwinEncrypted or decrypted data
2549c0e3d3aSJohn Baldwin.It Digest Ta Input/Output Ta
255c0341432SJohn BaldwinAuthentication digest, hash, or tag
256c0341432SJohn Baldwin.El
2579c0e3d3aSJohn Baldwin.Bl -column "Payload Output" ".Fa crp_payload_output_start"
2589c0e3d3aSJohn Baldwin.It Sy Region Ta Sy Start Ta Sy Length
2599c0e3d3aSJohn Baldwin.It AAD Ta Fa crp_aad_start Ta Fa crp_aad_length
2609c0e3d3aSJohn Baldwin.It IV Ta Fa crp_iv_start Ta Fa csp_ivlen
2619c0e3d3aSJohn Baldwin.It Payload Ta Fa crp_payload_start Ta Fa crp_payload_length
2629c0e3d3aSJohn Baldwin.It Payload Output Ta Fa crp_payload_output_start Ta Fa crp_payload_length
2639c0e3d3aSJohn Baldwin.It Digest Ta Fa crp_digest_start Ta Fa csp_auth_mlen
2649c0e3d3aSJohn Baldwin.El
265c0341432SJohn Baldwin.Pp
266c0341432SJohn BaldwinRequests are permitted to operate on only a subset of the data buffer.
267c0341432SJohn BaldwinFor example,
268c0341432SJohn Baldwinrequests from IPsec operate on network packets that include headers not
269c0341432SJohn Baldwinused as either additional authentication data (AAD) or payload data.
270c0341432SJohn Baldwin.Ss Request Operations
271c0341432SJohn BaldwinAll requests must specify the type of operation to perform in
272c0341432SJohn Baldwin.Fa crp_op .
273c0341432SJohn BaldwinAvailable operations depend on the session's mode.
274c0341432SJohn Baldwin.Pp
275c0341432SJohn BaldwinCompression requests support the following operations:
276c0341432SJohn Baldwin.Bl -tag -width CRYPTO_OP_DECOMPRESS
277c0341432SJohn Baldwin.It Dv CRYPTO_OP_COMPRESS
278c0341432SJohn BaldwinCompress the data in the payload region of the data buffer.
279c0341432SJohn Baldwin.It Dv CRYPTO_OP_DECOMPRESS
280c0341432SJohn BaldwinDecompress the data in the payload region of the data buffer.
281c0341432SJohn Baldwin.El
282c0341432SJohn Baldwin.Pp
283c0341432SJohn BaldwinCipher requests support the following operations:
284c0341432SJohn Baldwin.Bl -tag -width CRYPTO_OP_DECRYPT
285c0341432SJohn Baldwin.It Dv CRYPTO_OP_ENCRYPT
286c0341432SJohn BaldwinEncrypt the data in the payload region of the data buffer.
287c0341432SJohn Baldwin.It Dv CRYPTO_OP_DECRYPT
288c0341432SJohn BaldwinDecrypt the data in the payload region of the data buffer.
289c0341432SJohn Baldwin.El
290c0341432SJohn Baldwin.Pp
291c0341432SJohn BaldwinDigest requests support the following operations:
292c0341432SJohn Baldwin.Bl -tag -width CRYPTO_OP_COMPUTE_DIGEST
293c0341432SJohn Baldwin.It Dv CRYPTO_OP_COMPUTE_DIGEST
294c0341432SJohn BaldwinCalculate a digest over the payload region of the data buffer
295c0341432SJohn Baldwinand store the result in the digest region.
296c0341432SJohn Baldwin.It Dv CRYPTO_OP_VERIFY_DIGEST
297c0341432SJohn BaldwinCalculate a digest over the payload region of the data buffer.
298c0341432SJohn BaldwinCompare the calculated digest to the existing digest from the digest region.
299c0341432SJohn BaldwinIf the digests match,
300c0341432SJohn Baldwincomplete the request successfully.
301c0341432SJohn BaldwinIf the digests do not match,
302c0341432SJohn Baldwinfail the request with
303c0341432SJohn Baldwin.Er EBADMSG .
304c0341432SJohn Baldwin.El
305c0341432SJohn Baldwin.Pp
306c0341432SJohn BaldwinAEAD and Encrypt-then-Authenticate requests support the following
307c0341432SJohn Baldwinoperations:
308c0341432SJohn Baldwin.Bl -tag -width CRYPTO_OP
309c0341432SJohn Baldwin.It Dv CRYPTO_OP_ENCRYPT | Dv CRYPTO_OP_COMPUTE_DIGEST
310c0341432SJohn BaldwinEncrypt the data in the payload region of the data buffer.
311c0341432SJohn BaldwinCalculate a digest over the AAD and payload regions and store the
312c0341432SJohn Baldwinresult in the data buffer.
313c0341432SJohn Baldwin.It Dv CRYPTO_OP_DECRYPT | Dv CRYPTO_OP_VERIFY_DIGEST
314c0341432SJohn BaldwinCalculate a digest over the AAD and payload regions of the data buffer.
315c0341432SJohn BaldwinCompare the calculated digest to the existing digest from the digest region.
316c0341432SJohn BaldwinIf the digests match,
317c0341432SJohn Baldwindecrypt the payload region.
318c0341432SJohn BaldwinIf the digests do not match,
319c0341432SJohn Baldwinfail the request with
320c0341432SJohn Baldwin.Er EBADMSG .
321c0341432SJohn Baldwin.El
3229b774dc0SJohn Baldwin.Ss Request AAD
3239b774dc0SJohn BaldwinAEAD and Encrypt-then-Authenticate requests may optionally include
3249b774dc0SJohn BaldwinAdditional Authenticated Data.
3259b774dc0SJohn BaldwinAAD may either be supplied in the AAD region of the input buffer or
3269b774dc0SJohn Baldwinas a single buffer pointed to by
3279b774dc0SJohn Baldwin.Fa crp_aad .
3289b774dc0SJohn BaldwinIn either case,
3299b774dc0SJohn Baldwin.Fa crp_aad_length
3309b774dc0SJohn Baldwinalways indicates the amount of AAD in bytes.
3317e89ae49SMarcin Wojtas.Ss Request ESN
3327e89ae49SMarcin WojtasIPsec requests may optionally include Extended Sequence Numbers (ESN).
3337e89ae49SMarcin WojtasESN may either be supplied in
3347e89ae49SMarcin Wojtas.Fa crp_esn
3357e89ae49SMarcin Wojtasor as part of the AAD pointed to by
3367e89ae49SMarcin Wojtas.Fa crp_aad .
3377e89ae49SMarcin Wojtas.Pp
3387e89ae49SMarcin WojtasIf the ESN is stored in
3397e89ae49SMarcin Wojtas.Fa crp_esn ,
3407e89ae49SMarcin Wojtas.Dv CSP_F_ESN
3417e89ae49SMarcin Wojtasshould be set in
3427e89ae49SMarcin Wojtas.Fa csp_flags .
3437e89ae49SMarcin WojtasThis use case is dedicated for encrypt and authenticate mode, since the
3447e89ae49SMarcin Wojtashigh-order 32 bits of the sequence number are appended after the Next Header
3457e89ae49SMarcin Wojtas(RFC 4303).
3467e89ae49SMarcin Wojtas.Pp
3477e89ae49SMarcin WojtasAEAD modes supply the ESN in a separate AAD buffer (see e.g. RFC 4106, Chapter 5
3487e89ae49SMarcin WojtasAAD Construction).
349c0341432SJohn Baldwin.Ss Request IV and/or Nonce
350c0341432SJohn BaldwinSome cryptographic operations require an IV or nonce as an input.
351c0341432SJohn BaldwinAn IV may be stored either in the IV region of the data buffer or in
352c0341432SJohn Baldwin.Fa crp_iv .
353c0341432SJohn BaldwinBy default,
354c0341432SJohn Baldwinthe IV is assumed to be stored in the IV region.
355c0341432SJohn BaldwinIf the IV is stored in
356c0341432SJohn Baldwin.Fa crp_iv ,
357c0341432SJohn Baldwin.Dv CRYPTO_F_IV_SEPARATE
358c0341432SJohn Baldwinshould be set in
359c0341432SJohn Baldwin.Fa crp_flags
360c0341432SJohn Baldwinand
3619c0e3d3aSJohn Baldwin.Fa crp_iv_start
362c0341432SJohn Baldwinshould be left as zero.
363c0341432SJohn Baldwin.Pp
364c0341432SJohn BaldwinRequests that store part, but not all, of the IV in the data buffer should
365c0341432SJohn Baldwinstore the partial IV in the data buffer and pass the full IV separately in
366c0341432SJohn Baldwin.Fa crp_iv .
367c0341432SJohn Baldwin.Ss Request and Callback Scheduling
368c0341432SJohn BaldwinThe crypto framework provides multiple methods of scheduling the dispatch
369c0341432SJohn Baldwinof requests to drivers along with the processing of driver callbacks.
37068f6800cSMark JohnstonThe
371c0341432SJohn Baldwin.Fn crypto_dispatch ,
37268f6800cSMark Johnston.Fn crypto_dispatch_async ,
37368f6800cSMark Johnstonand
37468f6800cSMark Johnston.Fn crypto_dispatch_batch
37568f6800cSMark Johnstonfunctions can be used to request different dispatch scheduling policies.
37668f6800cSMark Johnston.Pp
37768f6800cSMark Johnston.Fn crypto_dispatch
37868f6800cSMark Johnstonsynchronously passes the request to the driver.
37968f6800cSMark JohnstonThe driver itself may process the request synchronously or asynchronously
38068f6800cSMark Johnstondepending on whether the driver is implemented by software or hardware.
38168f6800cSMark Johnston.Pp
38268f6800cSMark Johnston.Fn crypto_dispatch_async
38368f6800cSMark Johnstondispatches the request asynchronously.
38468f6800cSMark JohnstonIf the driver is inherently synchronous, the request is queued to a taskqueue
38568f6800cSMark Johnstonbacked by a pool of worker threads.
38668f6800cSMark JohnstonThis can increase througput by allowing requests from a single producer to be
38768f6800cSMark Johnstonprocessed in parallel.
38868f6800cSMark JohnstonBy default the pool is sized to provide one thread for each CPU.
38968f6800cSMark JohnstonWorker threads dequeue requests and pass them to the driver asynchronously.
39068f6800cSMark Johnston.Fn crypto_dispatch_async
39168f6800cSMark Johnstonadditionally takes a
39268f6800cSMark Johnston.Va flags
39368f6800cSMark Johnstonparameter.
39468f6800cSMark JohnstonThe
39568f6800cSMark Johnston.Dv CRYPTO_ASYNC_ORDERED
39668f6800cSMark Johnstonflag indicates that completion callbacks for requests must be called in the
39768f6800cSMark Johnstonsame order as requests were dispatched.
39868f6800cSMark JohnstonIf the driver is asynchronous, the behavior of
39968f6800cSMark Johnston.Fn crypto_dispatch_async
40068f6800cSMark Johnstonis identical to that of
40168f6800cSMark Johnston.Fn crypto_dispatch .
40268f6800cSMark Johnston.Pp
40368f6800cSMark Johnston.Fn crypto_dispatch_batch
40468f6800cSMark Johnstonallows the caller to collect a batch of requests and submit them to the driver
40568f6800cSMark Johnstonat the same time.
40668f6800cSMark JohnstonThis allows hardware drivers to optimize the scheduling of request processing
40768f6800cSMark Johnstonand batch completion interrupts.
40868f6800cSMark JohnstonA batch is submitted to the driver by invoking the driver's process method on
40968f6800cSMark Johnstoneach request, specifying
410c0341432SJohn Baldwin.Dv CRYPTO_HINT_MORE
41168f6800cSMark Johnstonwith each request except for the last.
41268f6800cSMark JohnstonThe
41368f6800cSMark Johnston.Fa flags
41468f6800cSMark Johnstonparameter to
41568f6800cSMark Johnston.Fn crypto_dispatch_batch
41668f6800cSMark Johnstonis currently ignored.
417c0341432SJohn Baldwin.Pp
418c0341432SJohn BaldwinCallback function scheduling is simpler than request scheduling.
419c0341432SJohn BaldwinCallbacks can either be invoked synchronously from
420c0341432SJohn Baldwin.Fn crypto_done ,
421c0341432SJohn Baldwinor they can be queued to a pool of worker threads.
422c0341432SJohn BaldwinThis pool of worker threads is also sized to provide one worker thread
423c0341432SJohn Baldwinfor each CPU by default.
424c0341432SJohn BaldwinNote that a callback function invoked synchronously from
425c0341432SJohn Baldwin.Fn crypto_done
426c0341432SJohn Baldwinmust follow the same restrictions placed on threaded interrupt handlers.
427c0341432SJohn Baldwin.Pp
428c0341432SJohn BaldwinBy default,
429c0341432SJohn Baldwincallbacks are invoked asynchronously by a worker thread.
430c0341432SJohn BaldwinIf
431c0341432SJohn Baldwin.Dv CRYPTO_F_CBIMM
432c0341432SJohn Baldwinis set,
433c0341432SJohn Baldwinthe callback is always invoked synchronously from
434c0341432SJohn Baldwin.Fn crypto_done .
435c0341432SJohn BaldwinIf
436c0341432SJohn Baldwin.Dv CRYPTO_F_CBIFSYNC
437c0341432SJohn Baldwinis set,
438c0341432SJohn Baldwinthe callback is invoked synchronously if the request was processed by a
439c0341432SJohn Baldwinsoftware driver or asynchronously if the request was processed by a
440c0341432SJohn Baldwinhardware driver.
441c0341432SJohn Baldwin.Pp
442*002c47baSAlan SomersIf a request was scheduled to the taskqueue with
443*002c47baSAlan Somers.Dv CRYPTO_ASYNC_ORDERED ,
444c0341432SJohn Baldwincallbacks are always invoked asynchronously ignoring
445c0341432SJohn Baldwin.Dv CRYPTO_F_CBIMM
446c0341432SJohn Baldwinand
447c0341432SJohn Baldwin.Dv CRYPTO_F_CBIFSYNC .
448c0341432SJohn BaldwinThis flag is used by IPsec to ensure that decrypted network packets are
449c0341432SJohn Baldwinpassed up the network stack in roughly the same order they were received.
450c0341432SJohn Baldwin.Ss Other Request Fields
451c0341432SJohn BaldwinIn addition to the fields and flags enumerated above,
452c0341432SJohn Baldwin.Vt struct cryptop
453c0341432SJohn Baldwinincludes the following:
454c0341432SJohn Baldwin.Bl -tag -width crp_payload_length
455c0341432SJohn Baldwin.It Fa crp_session
456c0341432SJohn BaldwinA reference to the active session.
457c0341432SJohn BaldwinThis is set when the request is created by
458c0341432SJohn Baldwin.Fn crypto_getreq
459c0341432SJohn Baldwinand should not be modified.
460c0341432SJohn BaldwinDrivers can use this to fetch driver-specific session state or
461c0341432SJohn Baldwinsession parameters.
462c0341432SJohn Baldwin.It Fa crp_etype
463c0341432SJohn BaldwinError status.
464c0341432SJohn BaldwinEither zero on success, or an error if a request fails.
465c0341432SJohn BaldwinSet by drivers prior to completing a request via
466c0341432SJohn Baldwin.Fn crypto_done .
467c0341432SJohn Baldwin.It Fa crp_flags
468c0341432SJohn BaldwinA bitmask of flags.
469c0341432SJohn BaldwinThe following flags are available in addition to flags discussed previously:
470c0341432SJohn Baldwin.Bl -tag -width CRYPTO_F_DONE
471c0341432SJohn Baldwin.It Dv CRYPTO_F_DONE
472c0341432SJohn BaldwinSet by
473c0341432SJohn Baldwin.Fa crypto_done
474c0341432SJohn Baldwinbefore calling
475c0341432SJohn Baldwin.Fa crp_callback .
476c0341432SJohn BaldwinThis flag is not very useful and will likely be removed in the future.
477c0341432SJohn BaldwinIt can only be safely checked from the callback routine at which point
478c0341432SJohn Baldwinit is always set.
479c0341432SJohn Baldwin.El
480c0341432SJohn Baldwin.It Fa crp_cipher_key
481c0341432SJohn BaldwinPointer to a request-specific encryption key.
482c0341432SJohn BaldwinIf this value is not set,
483c0341432SJohn Baldwinthe request uses the session encryption key.
484c0341432SJohn Baldwin.It Fa crp_auth_key
485c0341432SJohn BaldwinPointer to a request-specific authentication key.
486c0341432SJohn BaldwinIf this value is not set,
487c0341432SJohn Baldwinthe request uses the session authentication key.
488c0341432SJohn Baldwin.It Fa crp_opaque
489c0341432SJohn BaldwinAn opaque pointer.
490c0341432SJohn BaldwinThis pointer permits users of the cryptographic framework to store
491c0341432SJohn Baldwininformation about a request to be used in the callback.
492c0341432SJohn Baldwin.It Fa crp_callback
493c0341432SJohn BaldwinCallback function.
494c0341432SJohn BaldwinThis must point to a callback function of type
495c0341432SJohn Baldwin.Vt void (*)(struct cryptop *) .
496c0341432SJohn BaldwinThe callback function should inspect
497c0341432SJohn Baldwin.Fa crp_etype
498c0341432SJohn Baldwinto determine the status of the completed operation.
499c0341432SJohn BaldwinIt should also arrange for the request to be freed via
500c0341432SJohn Baldwin.Fn crypto_freereq .
5019c0e3d3aSJohn Baldwin.It Fa crp_olen
5029c0e3d3aSJohn BaldwinUsed with compression and decompression requests to describe the updated
5039c0e3d3aSJohn Baldwinlength of the payload region in the data buffer.
5049c0e3d3aSJohn Baldwin.Pp
5059c0e3d3aSJohn BaldwinIf a compression request increases the size of the payload,
5069c0e3d3aSJohn Baldwinthen the data buffer is unmodified, the request completes successfully,
5079c0e3d3aSJohn Baldwinand
5089c0e3d3aSJohn Baldwin.Fa crp_olen
5099c0e3d3aSJohn Baldwinis set to the size the compressed data would have used.
5109c0e3d3aSJohn BaldwinCallers can compare this to the payload region length to determine if
5119c0e3d3aSJohn Baldwinthe compressed data was discarded.
512c0341432SJohn Baldwin.El
513c0341432SJohn Baldwin.Sh RETURN VALUES
514c0341432SJohn Baldwin.Fn crypto_dispatch
515c0341432SJohn Baldwinreturns an error if the request contained invalid fields,
516c0341432SJohn Baldwinor zero if the request was valid.
517c0341432SJohn Baldwin.Fn crypto_getreq
518c0341432SJohn Baldwinreturns a pointer to a new request structure on success,
519c0341432SJohn Baldwinor
520c0341432SJohn Baldwin.Dv NULL
521c0341432SJohn Baldwinon failure.
522c0341432SJohn Baldwin.Dv NULL
523c0341432SJohn Baldwincan only be returned if
524c0341432SJohn Baldwin.Dv M_NOWAIT
525c0341432SJohn Baldwinwas passed in
526c0341432SJohn Baldwin.Fa how .
527c0341432SJohn Baldwin.Sh SEE ALSO
528c0341432SJohn Baldwin.Xr ipsec 4 ,
529c0341432SJohn Baldwin.Xr crypto 7 ,
530c0341432SJohn Baldwin.Xr crypto 9 ,
531c0341432SJohn Baldwin.Xr crypto_session 9 ,
53232068667SChristian Brueffer.Xr mbuf 9 ,
533c0341432SJohn Baldwin.Xr uio 9
534c0341432SJohn Baldwin.Sh BUGS
535c0341432SJohn BaldwinNot all drivers properly handle mixing session and per-request keys
536c0341432SJohn Baldwinwithin a single session.
537c0341432SJohn BaldwinConsumers should either use a single key for a session specified in
538c0341432SJohn Baldwinthe session parameters or always use per-request keys.
539