xref: /freebsd/share/man/man9/crypto_session.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_SESSION 9
35*c0341432SJohn Baldwin.Os
36*c0341432SJohn Baldwin.Sh NAME
37*c0341432SJohn Baldwin.Nm crypto_session
38*c0341432SJohn Baldwin.Nd state used for symmetric cryptographic services
39*c0341432SJohn Baldwin.Sh SYNOPSIS
40*c0341432SJohn Baldwin.In opencrypto/cryptodev.h
41*c0341432SJohn Baldwin.Ft struct auth_hash *
42*c0341432SJohn Baldwin.Fn crypto_auth_hash "const struct crypto_session_params *csp"
43*c0341432SJohn Baldwin.Ft struct enc_xform *
44*c0341432SJohn Baldwin.Fn crypto_cipher "const struct crypto_session_params *csp"
45*c0341432SJohn Baldwin.Ft const struct crypto_session_params *
46*c0341432SJohn Baldwin.Fn crypto_get_params "crypto_session_t cses"
47*c0341432SJohn Baldwin.Ft int
48*c0341432SJohn Baldwin.Fo crypto_newsession
49*c0341432SJohn Baldwin.Fa "crypto_session_t *cses"
50*c0341432SJohn Baldwin.Fa "const struct crypto_session_params *csp"
51*c0341432SJohn Baldwin.Fa "int crid"
52*c0341432SJohn Baldwin.Fc
53*c0341432SJohn Baldwin.Ft int
54*c0341432SJohn Baldwin.Fn crypto_freesession "crypto_session_t cses"
55*c0341432SJohn Baldwin.Sh DESCRIPTION
56*c0341432SJohn BaldwinSymmetric cryptographic operations in the kernel are associated with
57*c0341432SJohn Baldwincryptographic sessions.
58*c0341432SJohn BaldwinSessions hold state shared across multiple requests.
59*c0341432SJohn BaldwinActive sessions are associated with a single cryptographic driver.
60*c0341432SJohn Baldwin.Pp
61*c0341432SJohn BaldwinThe
62*c0341432SJohn Baldwin.Vt crypto_session_t
63*c0341432SJohn Baldwintype represents an opaque reference to an active session.
64*c0341432SJohn BaldwinSession objects are allocated and managed by the cryptographic
65*c0341432SJohn Baldwinframework.
66*c0341432SJohn Baldwin.Pp
67*c0341432SJohn BaldwinNew sessions are created by
68*c0341432SJohn Baldwin.Fn crypto_newsession .
69*c0341432SJohn Baldwin.Fa csp
70*c0341432SJohn Baldwindescribes various parameters associated with the new session such as
71*c0341432SJohn Baldwinthe algorithms to use and any session-wide keys.
72*c0341432SJohn Baldwin.Fa crid
73*c0341432SJohn Baldwincan be used to request either a specific cryptographic driver or
74*c0341432SJohn Baldwinclasses of drivers.
75*c0341432SJohn BaldwinFor the latter case,
76*c0341432SJohn Baldwin.Fa crid
77*c0341432SJohn Baldwinshould be set to a mask of the following values:
78*c0341432SJohn Baldwin.Bl -tag -width "CRYPTOCAP_F_HARDWARE"
79*c0341432SJohn Baldwin.It Dv CRYPTOCAP_F_HARDWARE
80*c0341432SJohn BaldwinRequest hardware drivers.
81*c0341432SJohn BaldwinHardware drivers do not use the host CPU to perform operations.
82*c0341432SJohn BaldwinTypically, a separate co-processor performs the operations asynchronously.
83*c0341432SJohn Baldwin.It Dv CRYPTOCAP_F_SOFTWARE
84*c0341432SJohn BaldwinRequest software drivers.
85*c0341432SJohn BaldwinSoftware drivers use the host CPU to perform operations.
86*c0341432SJohn BaldwinThe kernel includes a simple, yet portable implementation of each supported
87*c0341432SJohn Baldwinalgorithm in the
88*c0341432SJohn Baldwin.Xr cryptosoft 4
89*c0341432SJohn Baldwindriver.
90*c0341432SJohn BaldwinAdditional software drivers may also be available on architectures which
91*c0341432SJohn Baldwinprovide instructions designed to accelerate cryptographic operations.
92*c0341432SJohn Baldwin.El
93*c0341432SJohn Baldwin.Pp
94*c0341432SJohn BaldwinIf both hardware and software drivers are requested,
95*c0341432SJohn Baldwinhardware drivers are preferred over software drivers.
96*c0341432SJohn BaldwinAccelerated software drivers are preferred over the baseline software driver.
97*c0341432SJohn BaldwinIf multiple hardware drivers are available,
98*c0341432SJohn Baldwinthe framework will distribute sessions across these drivers in a round-robin
99*c0341432SJohn Baldwinfashion.
100*c0341432SJohn Baldwin.Pp
101*c0341432SJohn BaldwinOn success,
102*c0341432SJohn Baldwin.Fn crypto_newsession
103*c0341432SJohn Baldwinsaves a reference to the newly created session in
104*c0341432SJohn Baldwin.Fa cses .
105*c0341432SJohn Baldwin.Pp
106*c0341432SJohn Baldwin.Fn crypto_freesession
107*c0341432SJohn Baldwinis used to free the resources associated with the session
108*c0341432SJohn Baldwin.Fa cses .
109*c0341432SJohn Baldwin.Pp
110*c0341432SJohn Baldwin.Fn crypto_auth_hash
111*c0341432SJohn Baldwinreturns a structure describing the baseline software implementation of an
112*c0341432SJohn Baldwinauthentication algorithm requested by
113*c0341432SJohn Baldwin.Fa csp .
114*c0341432SJohn BaldwinIf
115*c0341432SJohn Baldwin.Fa csp
116*c0341432SJohn Baldwindoes not specify an authentication algorithm,
117*c0341432SJohn Baldwinor requests an invalid algorithm,
118*c0341432SJohn Baldwin.Dv NULL
119*c0341432SJohn Baldwinis returned.
120*c0341432SJohn Baldwin.Pp
121*c0341432SJohn Baldwin.Fn crypto_cipher
122*c0341432SJohn Baldwinreturns a structure describing the baseline software implementation of an
123*c0341432SJohn Baldwinencryption algorithm requested by
124*c0341432SJohn Baldwin.Fa csp .
125*c0341432SJohn BaldwinIf
126*c0341432SJohn Baldwin.Fa csp
127*c0341432SJohn Baldwindoes not specify an encryption algorithm,
128*c0341432SJohn Baldwinor requests an invalid algorithm,
129*c0341432SJohn Baldwin.Dv NULL
130*c0341432SJohn Baldwinis returned.
131*c0341432SJohn Baldwin.Pp
132*c0341432SJohn Baldwin.Fn crypto_get_params
133*c0341432SJohn Baldwinreturns a pointer to the session parameters used by
134*c0341432SJohn Baldwin.Fa cses .
135*c0341432SJohn Baldwin.Ss Session Parameters
136*c0341432SJohn BaldwinSession parameters are used to describe the cryptographic operations
137*c0341432SJohn Baldwinperformed by cryptographic requests.
138*c0341432SJohn BaldwinParameters are stored in an instance of
139*c0341432SJohn Baldwin.Vt struct crypto_session_params .
140*c0341432SJohn BaldwinWhen initializing parameters to pass to
141*c0341432SJohn Baldwin.Fn crypto_newsession ,
142*c0341432SJohn Baldwinthe entire structure should first be zeroed.
143*c0341432SJohn BaldwinNeeded fields should then be set leaving unused fields as zero.
144*c0341432SJohn BaldwinThis structure contains the following fields:
145*c0341432SJohn Baldwin.Bl -tag -width csp_cipher_klen
146*c0341432SJohn Baldwin.It Fa csp_mode
147*c0341432SJohn BaldwinType of operation to perform.
148*c0341432SJohn BaldwinThis field must be set to one of the following:
149*c0341432SJohn Baldwin.Bl -tag -width CSP_MODE_COMPRESS
150*c0341432SJohn Baldwin.It Dv CSP_MODE_COMPRESS
151*c0341432SJohn BaldwinCompress or decompress request payload.
152*c0341432SJohn Baldwin.Pp
153*c0341432SJohn BaldwinThe compression algorithm is specified in
154*c0341432SJohn Baldwin.Fa csp_cipher_alg .
155*c0341432SJohn Baldwin.It Dv CSP_MODE_CIPHER
156*c0341432SJohn BaldwinEncrypt or decrypt request payload.
157*c0341432SJohn Baldwin.Pp
158*c0341432SJohn BaldwinThe encryption algorithm is specified in
159*c0341432SJohn Baldwin.Fa csp_cipher_alg .
160*c0341432SJohn Baldwin.It Dv CSP_MODE_DIGEST
161*c0341432SJohn BaldwinCompute or verify a digest, or hash, of request payload.
162*c0341432SJohn Baldwin.Pp
163*c0341432SJohn BaldwinThe authentication algorithm is specified in
164*c0341432SJohn Baldwin.Fa csp_auth_alg .
165*c0341432SJohn Baldwin.It Dv CSP_MODE_AEAD
166*c0341432SJohn BaldwinAuthenticated encryption with additional data.
167*c0341432SJohn BaldwinDecryption operations require the digest, or tag,
168*c0341432SJohn Baldwinand fail if it does not match.
169*c0341432SJohn Baldwin.Pp
170*c0341432SJohn BaldwinThe AEAD algorithm is specified in
171*c0341432SJohn Baldwin.Fa csp_cipher_alg .
172*c0341432SJohn Baldwin.It Dv CSP_MODE_ETA
173*c0341432SJohn BaldwinEncrypt-then-Authenticate.
174*c0341432SJohn BaldwinIn this mode, encryption operations encrypt the payload and then
175*c0341432SJohn Baldwincompute an authentication digest over the request additional authentication
176*c0341432SJohn Baldwindata followed by the encrypted payload.
177*c0341432SJohn BaldwinDecryption operations fail without decrypting the data if the provided digest
178*c0341432SJohn Baldwindoes not match.
179*c0341432SJohn Baldwin.Pp
180*c0341432SJohn BaldwinThe encryption algorithm is specified in
181*c0341432SJohn Baldwin.Fa csp_cipher_alg
182*c0341432SJohn Baldwinand the authentication algorithm is specified in
183*c0341432SJohn Baldwin.Fa csp_auth_alg .
184*c0341432SJohn Baldwin.El
185*c0341432SJohn Baldwin.It Fa csp_flags
186*c0341432SJohn BaldwinCurrently, no additional flags are defined and this field should be set to
187*c0341432SJohn Baldwinzero.
188*c0341432SJohn Baldwin.It Fa csp_ivlen
189*c0341432SJohn BaldwinIf either the cipher or authentication algorithms require an explicit
190*c0341432SJohn Baldwininitialization vector (IV) or nonce,
191*c0341432SJohn Baldwinthis specifies the length in bytes.
192*c0341432SJohn BaldwinAll requests for a session use the same IV length.
193*c0341432SJohn Baldwin.It Fa csp_cipher_alg
194*c0341432SJohn BaldwinEncryption or compression algorithm.
195*c0341432SJohn Baldwin.It Fa csp_cipher_klen
196*c0341432SJohn BaldwinLength of encryption or decryption key in bytes.
197*c0341432SJohn BaldwinAll requests for a session use the same key length.
198*c0341432SJohn Baldwin.It Fa csp_cipher_key
199*c0341432SJohn BaldwinPointer to encryption or decryption key.
200*c0341432SJohn BaldwinIf all requests for a session use request-specific keys,
201*c0341432SJohn Baldwinthis field should be left as
202*c0341432SJohn Baldwin.Dv NULL .
203*c0341432SJohn BaldwinThis pointer and associated key must remain valid for the duration of the
204*c0341432SJohn Baldwincrypto session.
205*c0341432SJohn Baldwin.It Fa csp_auth_alg
206*c0341432SJohn BaldwinAuthentication algorithm.
207*c0341432SJohn Baldwin.It Fa csp_auth_klen
208*c0341432SJohn BaldwinLength of authentication key in bytes.
209*c0341432SJohn BaldwinIf the authentication algorithm does not use a key,
210*c0341432SJohn Baldwinthis field should be left as zero.
211*c0341432SJohn Baldwin.It Fa csp_auth_key
212*c0341432SJohn BaldwinPointer to the authentication key.
213*c0341432SJohn BaldwinIf all requests for a session use request-specific keys,
214*c0341432SJohn Baldwinthis field should be left as
215*c0341432SJohn Baldwin.Dv NULL .
216*c0341432SJohn BaldwinThis pointer and associated key must remain valid for the duration of the
217*c0341432SJohn Baldwincrypto session.
218*c0341432SJohn Baldwin.It Fa csp_auth_mlen
219*c0341432SJohn BaldwinThe length in bytes of the digest.
220*c0341432SJohn BaldwinIf zero, the full length of the digest is used.
221*c0341432SJohn BaldwinIf non-zero, the first
222*c0341432SJohn Baldwin.Fa csp_auth_mlen
223*c0341432SJohn Baldwinbytes of the digest are used.
224*c0341432SJohn Baldwin.El
225*c0341432SJohn Baldwin.Sh RETURN VALUES
226*c0341432SJohn Baldwin.Fn crypto_newsession
227*c0341432SJohn Baldwinreturns a non-zero value if an error occurs or zero on success.
228*c0341432SJohn Baldwin.Pp
229*c0341432SJohn Baldwin.Fn crypto_auth_hash
230*c0341432SJohn Baldwinand
231*c0341432SJohn Baldwin.Fn crypto_cipher
232*c0341432SJohn Baldwinreturn
233*c0341432SJohn Baldwin.Dv NULL
234*c0341432SJohn Baldwinif the request is valid or a pointer to a structure on success.
235*c0341432SJohn Baldwin.Sh SEE ALSO
236*c0341432SJohn Baldwin.Xr crypto 7 ,
237*c0341432SJohn Baldwin.Xr crypto 9 ,
238*c0341432SJohn Baldwin.Xr crypto_request 9
239*c0341432SJohn Baldwin.Sh BUGS
240*c0341432SJohn BaldwinThe current implementation of
241*c0341432SJohn Baldwin.Nm crypto_freesession
242*c0341432SJohn Baldwindoes not provide a way for the caller to know that there are no other
243*c0341432SJohn Baldwinreferences to the keys stored in the session's associated parameters.
244*c0341432SJohn BaldwinThis function should probably sleep until any in-flight cryptographic
245*c0341432SJohn Baldwinoperations associated with the session are completed.
246