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