xref: /freebsd/share/man/man9/crypto_session.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.\"
319b774dc0SJohn Baldwin.Dd June 22, 2020
32c0341432SJohn Baldwin.Dt CRYPTO_SESSION 9
33c0341432SJohn Baldwin.Os
34c0341432SJohn Baldwin.Sh NAME
35c0341432SJohn Baldwin.Nm crypto_session
36c0341432SJohn Baldwin.Nd state used for symmetric cryptographic services
37c0341432SJohn Baldwin.Sh SYNOPSIS
38c0341432SJohn Baldwin.In opencrypto/cryptodev.h
39c0341432SJohn Baldwin.Ft struct auth_hash *
40c0341432SJohn Baldwin.Fn crypto_auth_hash "const struct crypto_session_params *csp"
41c0341432SJohn Baldwin.Ft struct enc_xform *
42c0341432SJohn Baldwin.Fn crypto_cipher "const struct crypto_session_params *csp"
43c0341432SJohn Baldwin.Ft const struct crypto_session_params *
44c0341432SJohn Baldwin.Fn crypto_get_params "crypto_session_t cses"
45c0341432SJohn Baldwin.Ft int
46c0341432SJohn Baldwin.Fo crypto_newsession
47c0341432SJohn Baldwin.Fa "crypto_session_t *cses"
48c0341432SJohn Baldwin.Fa "const struct crypto_session_params *csp"
49c0341432SJohn Baldwin.Fa "int crid"
50c0341432SJohn Baldwin.Fc
51c0341432SJohn Baldwin.Ft int
52c0341432SJohn Baldwin.Fn crypto_freesession "crypto_session_t cses"
53c0341432SJohn Baldwin.Sh DESCRIPTION
54c0341432SJohn BaldwinSymmetric cryptographic operations in the kernel are associated with
55c0341432SJohn Baldwincryptographic sessions.
56c0341432SJohn BaldwinSessions hold state shared across multiple requests.
57c0341432SJohn BaldwinActive sessions are associated with a single cryptographic driver.
58c0341432SJohn Baldwin.Pp
59c0341432SJohn BaldwinThe
60c0341432SJohn Baldwin.Vt crypto_session_t
61c0341432SJohn Baldwintype represents an opaque reference to an active session.
62c0341432SJohn BaldwinSession objects are allocated and managed by the cryptographic
63c0341432SJohn Baldwinframework.
64c0341432SJohn Baldwin.Pp
65c0341432SJohn BaldwinNew sessions are created by
66c0341432SJohn Baldwin.Fn crypto_newsession .
67c0341432SJohn Baldwin.Fa csp
68c0341432SJohn Baldwindescribes various parameters associated with the new session such as
69c0341432SJohn Baldwinthe algorithms to use and any session-wide keys.
70c0341432SJohn Baldwin.Fa crid
71c0341432SJohn Baldwincan be used to request either a specific cryptographic driver or
72c0341432SJohn Baldwinclasses of drivers.
73c0341432SJohn BaldwinFor the latter case,
74c0341432SJohn Baldwin.Fa crid
75c0341432SJohn Baldwinshould be set to a mask of the following values:
76c0341432SJohn Baldwin.Bl -tag -width "CRYPTOCAP_F_HARDWARE"
77c0341432SJohn Baldwin.It Dv CRYPTOCAP_F_HARDWARE
78c0341432SJohn BaldwinRequest hardware drivers.
79c0341432SJohn BaldwinHardware drivers do not use the host CPU to perform operations.
80c0341432SJohn BaldwinTypically, a separate co-processor performs the operations asynchronously.
81c0341432SJohn Baldwin.It Dv CRYPTOCAP_F_SOFTWARE
82c0341432SJohn BaldwinRequest software drivers.
83c0341432SJohn BaldwinSoftware drivers use the host CPU to perform operations.
84c0341432SJohn BaldwinThe kernel includes a simple, yet portable implementation of each supported
85c0341432SJohn Baldwinalgorithm in the
86c0341432SJohn Baldwin.Xr cryptosoft 4
87c0341432SJohn Baldwindriver.
88c0341432SJohn BaldwinAdditional software drivers may also be available on architectures which
89c0341432SJohn Baldwinprovide instructions designed to accelerate cryptographic operations.
90c0341432SJohn Baldwin.El
91c0341432SJohn Baldwin.Pp
92c0341432SJohn BaldwinIf both hardware and software drivers are requested,
93c0341432SJohn Baldwinhardware drivers are preferred over software drivers.
94c0341432SJohn BaldwinAccelerated software drivers are preferred over the baseline software driver.
95c0341432SJohn BaldwinIf multiple hardware drivers are available,
96c0341432SJohn Baldwinthe framework will distribute sessions across these drivers in a round-robin
97c0341432SJohn Baldwinfashion.
98c0341432SJohn Baldwin.Pp
99c0341432SJohn BaldwinOn success,
100c0341432SJohn Baldwin.Fn crypto_newsession
101c0341432SJohn Baldwinsaves a reference to the newly created session in
102c0341432SJohn Baldwin.Fa cses .
103c0341432SJohn Baldwin.Pp
104c0341432SJohn Baldwin.Fn crypto_freesession
105c0341432SJohn Baldwinis used to free the resources associated with the session
106c0341432SJohn Baldwin.Fa cses .
107c0341432SJohn Baldwin.Pp
108c0341432SJohn Baldwin.Fn crypto_auth_hash
109c0341432SJohn Baldwinreturns a structure describing the baseline software implementation of an
110c0341432SJohn Baldwinauthentication algorithm requested by
111c0341432SJohn Baldwin.Fa csp .
112c0341432SJohn BaldwinIf
113c0341432SJohn Baldwin.Fa csp
114c0341432SJohn Baldwindoes not specify an authentication algorithm,
115c0341432SJohn Baldwinor requests an invalid algorithm,
116c0341432SJohn Baldwin.Dv NULL
117c0341432SJohn Baldwinis returned.
118c0341432SJohn Baldwin.Pp
119c0341432SJohn Baldwin.Fn crypto_cipher
120c0341432SJohn Baldwinreturns a structure describing the baseline software implementation of an
121c0341432SJohn Baldwinencryption algorithm requested by
122c0341432SJohn Baldwin.Fa csp .
123c0341432SJohn BaldwinIf
124c0341432SJohn Baldwin.Fa csp
125c0341432SJohn Baldwindoes not specify an encryption algorithm,
126c0341432SJohn Baldwinor requests an invalid algorithm,
127c0341432SJohn Baldwin.Dv NULL
128c0341432SJohn Baldwinis returned.
129c0341432SJohn Baldwin.Pp
130c0341432SJohn Baldwin.Fn crypto_get_params
131c0341432SJohn Baldwinreturns a pointer to the session parameters used by
132c0341432SJohn Baldwin.Fa cses .
133c0341432SJohn Baldwin.Ss Session Parameters
134c0341432SJohn BaldwinSession parameters are used to describe the cryptographic operations
135c0341432SJohn Baldwinperformed by cryptographic requests.
136c0341432SJohn BaldwinParameters are stored in an instance of
137c0341432SJohn Baldwin.Vt struct crypto_session_params .
138c0341432SJohn BaldwinWhen initializing parameters to pass to
139c0341432SJohn Baldwin.Fn crypto_newsession ,
140c0341432SJohn Baldwinthe entire structure should first be zeroed.
141c0341432SJohn BaldwinNeeded fields should then be set leaving unused fields as zero.
142c0341432SJohn BaldwinThis structure contains the following fields:
143c0341432SJohn Baldwin.Bl -tag -width csp_cipher_klen
144c0341432SJohn Baldwin.It Fa csp_mode
145c0341432SJohn BaldwinType of operation to perform.
146c0341432SJohn BaldwinThis field must be set to one of the following:
147c0341432SJohn Baldwin.Bl -tag -width CSP_MODE_COMPRESS
148c0341432SJohn Baldwin.It Dv CSP_MODE_COMPRESS
149c0341432SJohn BaldwinCompress or decompress request payload.
150c0341432SJohn Baldwin.Pp
151c0341432SJohn BaldwinThe compression algorithm is specified in
152c0341432SJohn Baldwin.Fa csp_cipher_alg .
153c0341432SJohn Baldwin.It Dv CSP_MODE_CIPHER
154c0341432SJohn BaldwinEncrypt or decrypt request payload.
155c0341432SJohn Baldwin.Pp
156c0341432SJohn BaldwinThe encryption algorithm is specified in
157c0341432SJohn Baldwin.Fa csp_cipher_alg .
158c0341432SJohn Baldwin.It Dv CSP_MODE_DIGEST
159c0341432SJohn BaldwinCompute or verify a digest, or hash, of request payload.
160c0341432SJohn Baldwin.Pp
161c0341432SJohn BaldwinThe authentication algorithm is specified in
162c0341432SJohn Baldwin.Fa csp_auth_alg .
163c0341432SJohn Baldwin.It Dv CSP_MODE_AEAD
164c0341432SJohn BaldwinAuthenticated encryption with additional data.
165c0341432SJohn BaldwinDecryption operations require the digest, or tag,
166c0341432SJohn Baldwinand fail if it does not match.
167c0341432SJohn Baldwin.Pp
168c0341432SJohn BaldwinThe AEAD algorithm is specified in
169c0341432SJohn Baldwin.Fa csp_cipher_alg .
170c0341432SJohn Baldwin.It Dv CSP_MODE_ETA
171c0341432SJohn BaldwinEncrypt-then-Authenticate.
172c0341432SJohn BaldwinIn this mode, encryption operations encrypt the payload and then
173c0341432SJohn Baldwincompute an authentication digest over the request additional authentication
174c0341432SJohn Baldwindata followed by the encrypted payload.
175c0341432SJohn BaldwinDecryption operations fail without decrypting the data if the provided digest
176c0341432SJohn Baldwindoes not match.
177c0341432SJohn Baldwin.Pp
178c0341432SJohn BaldwinThe encryption algorithm is specified in
179c0341432SJohn Baldwin.Fa csp_cipher_alg
180c0341432SJohn Baldwinand the authentication algorithm is specified in
181c0341432SJohn Baldwin.Fa csp_auth_alg .
182c0341432SJohn Baldwin.El
183c0341432SJohn Baldwin.It Fa csp_flags
1849c0e3d3aSJohn BaldwinA mask of optional driver features.
1859c0e3d3aSJohn BaldwinDrivers will only attach to a session if they support all of the
1869c0e3d3aSJohn Baldwinrequested features.
1879c0e3d3aSJohn Baldwin.Bl -tag -width CSP_F_SEPARATE_OUTPUT
1889c0e3d3aSJohn Baldwin.It Dv CSP_F_SEPARATE_OUTPUT
1899c0e3d3aSJohn BaldwinSupport requests that use separate input and output buffers.
1909c0e3d3aSJohn BaldwinSessions with this flag set permit requests with either a single buffer
1919c0e3d3aSJohn Baldwinthat is modified in-place, or requests with separate input and output
1929c0e3d3aSJohn Baldwinbuffers.
1939c0e3d3aSJohn BaldwinSessions without this flag only permit requests with a single buffer that
1949c0e3d3aSJohn Baldwinis modified in-place.
1959b774dc0SJohn Baldwin.It Dv CSP_F_SEPARATE_AAD
1969b774dc0SJohn BaldwinSupport requests that use a separate buffer for AAD rather than providing
1979b774dc0SJohn BaldwinAAD as a region in the input buffer.
1989b774dc0SJohn BaldwinSessions with this flag set permit requests with AAD passed in either in
1999b774dc0SJohn Baldwina region of the input buffer or in a single, virtually-contiguous buffer.
2009b774dc0SJohn BaldwinSessions without this flag only permit requests with AAD passed in as
2019b774dc0SJohn Baldwina region in the input buffer.
202*7e89ae49SMarcin Wojtas.It Dv CSP_F_ESN
203*7e89ae49SMarcin WojtasSupport requests that use a separate buffer for IPsec ESN (Extended Sequence
204*7e89ae49SMarcin WojtasNumbers).
205*7e89ae49SMarcin Wojtas.Pp
206*7e89ae49SMarcin WojtasSessions with this flag set permit requests with IPsec ESN passed in special
207*7e89ae49SMarcin Wojtasbuffer.
208*7e89ae49SMarcin WojtasIt is required for IPsec ESN support of encrypt and authenticate mode where
209*7e89ae49SMarcin Wojtasthe high-order 32 bits of the sequence number are appended after the Next
210*7e89ae49SMarcin WojtasHeader (RFC 4303).
2119c0e3d3aSJohn Baldwin.El
212c0341432SJohn Baldwin.It Fa csp_ivlen
213c0341432SJohn BaldwinIf either the cipher or authentication algorithms require an explicit
214c0341432SJohn Baldwininitialization vector (IV) or nonce,
215c0341432SJohn Baldwinthis specifies the length in bytes.
216c0341432SJohn BaldwinAll requests for a session use the same IV length.
217c0341432SJohn Baldwin.It Fa csp_cipher_alg
218c0341432SJohn BaldwinEncryption or compression algorithm.
219c0341432SJohn Baldwin.It Fa csp_cipher_klen
220c0341432SJohn BaldwinLength of encryption or decryption key in bytes.
221c0341432SJohn BaldwinAll requests for a session use the same key length.
222c0341432SJohn Baldwin.It Fa csp_cipher_key
223c0341432SJohn BaldwinPointer to encryption or decryption key.
224c0341432SJohn BaldwinIf all requests for a session use request-specific keys,
225c0341432SJohn Baldwinthis field should be left as
226c0341432SJohn Baldwin.Dv NULL .
227c0341432SJohn BaldwinThis pointer and associated key must remain valid for the duration of the
228c0341432SJohn Baldwincrypto session.
229c0341432SJohn Baldwin.It Fa csp_auth_alg
230c0341432SJohn BaldwinAuthentication algorithm.
231c0341432SJohn Baldwin.It Fa csp_auth_klen
232c0341432SJohn BaldwinLength of authentication key in bytes.
233c0341432SJohn BaldwinIf the authentication algorithm does not use a key,
234c0341432SJohn Baldwinthis field should be left as zero.
235c0341432SJohn Baldwin.It Fa csp_auth_key
236c0341432SJohn BaldwinPointer to the authentication key.
237c0341432SJohn BaldwinIf all requests for a session use request-specific keys,
238c0341432SJohn Baldwinthis field should be left as
239c0341432SJohn Baldwin.Dv NULL .
240c0341432SJohn BaldwinThis pointer and associated key must remain valid for the duration of the
241c0341432SJohn Baldwincrypto session.
242c0341432SJohn Baldwin.It Fa csp_auth_mlen
243c0341432SJohn BaldwinThe length in bytes of the digest.
244c0341432SJohn BaldwinIf zero, the full length of the digest is used.
245c0341432SJohn BaldwinIf non-zero, the first
246c0341432SJohn Baldwin.Fa csp_auth_mlen
247c0341432SJohn Baldwinbytes of the digest are used.
248c0341432SJohn Baldwin.El
249c0341432SJohn Baldwin.Sh RETURN VALUES
250c0341432SJohn Baldwin.Fn crypto_newsession
251c0341432SJohn Baldwinreturns a non-zero value if an error occurs or zero on success.
252c0341432SJohn Baldwin.Pp
253c0341432SJohn Baldwin.Fn crypto_auth_hash
254c0341432SJohn Baldwinand
255c0341432SJohn Baldwin.Fn crypto_cipher
256c0341432SJohn Baldwinreturn
257c0341432SJohn Baldwin.Dv NULL
258c0341432SJohn Baldwinif the request is valid or a pointer to a structure on success.
259c0341432SJohn Baldwin.Sh SEE ALSO
260c0341432SJohn Baldwin.Xr crypto 7 ,
261c0341432SJohn Baldwin.Xr crypto 9 ,
262c0341432SJohn Baldwin.Xr crypto_request 9
263c0341432SJohn Baldwin.Sh BUGS
264c0341432SJohn BaldwinThe current implementation of
265c0341432SJohn Baldwin.Nm crypto_freesession
266c0341432SJohn Baldwindoes not provide a way for the caller to know that there are no other
267c0341432SJohn Baldwinreferences to the keys stored in the session's associated parameters.
268c0341432SJohn BaldwinThis function should probably sleep until any in-flight cryptographic
269c0341432SJohn Baldwinoperations associated with the session are completed.
270