xref: /freebsd/share/man/man9/crypto_buffer.9 (revision 9c0e3d3a534c3e3e7f6bfce0a150ed2a0841685a)
1*9c0e3d3aSJohn Baldwin.\" Copyright (c) 2020, Chelsio Inc
2*9c0e3d3aSJohn Baldwin.\"
3*9c0e3d3aSJohn Baldwin.\" Redistribution and use in source and binary forms, with or without
4*9c0e3d3aSJohn Baldwin.\" modification, are permitted provided that the following conditions are met:
5*9c0e3d3aSJohn Baldwin.\"
6*9c0e3d3aSJohn Baldwin.\" 1. Redistributions of source code must retain the above copyright notice,
7*9c0e3d3aSJohn Baldwin.\"    this list of conditions and the following disclaimer.
8*9c0e3d3aSJohn Baldwin.\"
9*9c0e3d3aSJohn Baldwin.\" 2. Redistributions in binary form must reproduce the above copyright
10*9c0e3d3aSJohn Baldwin.\"    notice, this list of conditions and the following disclaimer in the
11*9c0e3d3aSJohn Baldwin.\"    documentation and/or other materials provided with the distribution.
12*9c0e3d3aSJohn Baldwin.\"
13*9c0e3d3aSJohn Baldwin.\" 3. Neither the name of the Chelsio Inc nor the names of its
14*9c0e3d3aSJohn Baldwin.\"    contributors may be used to endorse or promote products derived from
15*9c0e3d3aSJohn Baldwin.\"    this software without specific prior written permission.
16*9c0e3d3aSJohn Baldwin.\"
17*9c0e3d3aSJohn Baldwin.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18*9c0e3d3aSJohn Baldwin.\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19*9c0e3d3aSJohn Baldwin.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20*9c0e3d3aSJohn Baldwin.\" ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21*9c0e3d3aSJohn Baldwin.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22*9c0e3d3aSJohn Baldwin.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23*9c0e3d3aSJohn Baldwin.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24*9c0e3d3aSJohn Baldwin.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25*9c0e3d3aSJohn Baldwin.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26*9c0e3d3aSJohn Baldwin.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27*9c0e3d3aSJohn Baldwin.\" POSSIBILITY OF SUCH DAMAGE.
28*9c0e3d3aSJohn Baldwin.\"
29*9c0e3d3aSJohn Baldwin.\" * Other names and brands may be claimed as the property of others.
30*9c0e3d3aSJohn Baldwin.\"
31*9c0e3d3aSJohn Baldwin.\" $FreeBSD$
32*9c0e3d3aSJohn Baldwin.\"
33*9c0e3d3aSJohn Baldwin.Dd May 25, 2020
34*9c0e3d3aSJohn Baldwin.Dt CRYPTO_BUFFER 9
35*9c0e3d3aSJohn Baldwin.Os
36*9c0e3d3aSJohn Baldwin.Sh NAME
37*9c0e3d3aSJohn Baldwin.Nm crypto_buffer
38*9c0e3d3aSJohn Baldwin.Nd symmetric cryptographic request buffers
39*9c0e3d3aSJohn Baldwin.Sh SYNOPSIS
40*9c0e3d3aSJohn Baldwin.In opencrypto/cryptodev.h
41*9c0e3d3aSJohn Baldwin.Ft int
42*9c0e3d3aSJohn Baldwin.Fo crypto_apply
43*9c0e3d3aSJohn Baldwin.Fa "struct cryptop *crp"
44*9c0e3d3aSJohn Baldwin.Fa "int off"
45*9c0e3d3aSJohn Baldwin.Fa "int len"
46*9c0e3d3aSJohn Baldwin.Fa "int (*f)(void *, void *, u_int)"
47*9c0e3d3aSJohn Baldwin.Fa "void *arg"
48*9c0e3d3aSJohn Baldwin.Fc
49*9c0e3d3aSJohn Baldwin.Ft int
50*9c0e3d3aSJohn Baldwin.Fo crypto_apply_buf
51*9c0e3d3aSJohn Baldwin.Fa "struct crypto_buffer *cb"
52*9c0e3d3aSJohn Baldwin.Fa "int off"
53*9c0e3d3aSJohn Baldwin.Fa "int len"
54*9c0e3d3aSJohn Baldwin.Fa "int (*f)(void *, void *, u_int)"
55*9c0e3d3aSJohn Baldwin.Fa "void *arg"
56*9c0e3d3aSJohn Baldwin.Fc
57*9c0e3d3aSJohn Baldwin.Ft void *
58*9c0e3d3aSJohn Baldwin.Fo crypto_buffer_contiguous_subsegment
59*9c0e3d3aSJohn Baldwin.Fa "struct crypto_buffer *cb"
60*9c0e3d3aSJohn Baldwin.Fa "size_t skip"
61*9c0e3d3aSJohn Baldwin.Fa "size_t len"
62*9c0e3d3aSJohn Baldwin.Fc
63*9c0e3d3aSJohn Baldwin.Ft size_t
64*9c0e3d3aSJohn Baldwin.Fn crypto_buffer_len "struct crypto_buffer *cb"
65*9c0e3d3aSJohn Baldwin.Ft void *
66*9c0e3d3aSJohn Baldwin.Fo crypto_contiguous_subsegment
67*9c0e3d3aSJohn Baldwin.Fa "struct cryptop *crp"
68*9c0e3d3aSJohn Baldwin.Fa "size_t skip"
69*9c0e3d3aSJohn Baldwin.Fa "size_t len"
70*9c0e3d3aSJohn Baldwin.Fc
71*9c0e3d3aSJohn Baldwin.Ft void
72*9c0e3d3aSJohn Baldwin.Fo crypto_cursor_init
73*9c0e3d3aSJohn Baldwin.Fa "struct crypto_buffer_cursor *cc"
74*9c0e3d3aSJohn Baldwin.Fa "const struct crypto_buffer *cb"
75*9c0e3d3aSJohn Baldwin.Fc
76*9c0e3d3aSJohn Baldwin.Ft void
77*9c0e3d3aSJohn Baldwin.Fn crypto_cursor_advance "struct crypto_buffer_cursor *cc" "size_t amount"
78*9c0e3d3aSJohn Baldwin.Ft void
79*9c0e3d3aSJohn Baldwin.Fo crypto_cursor_copyback
80*9c0e3d3aSJohn Baldwin.Fa "struct crypto_buffer_cursor *cc"
81*9c0e3d3aSJohn Baldwin.Fa "int size"
82*9c0e3d3aSJohn Baldwin.Fa "const void *src"
83*9c0e3d3aSJohn Baldwin.Fc
84*9c0e3d3aSJohn Baldwin.Ft void
85*9c0e3d3aSJohn Baldwin.Fo crypto_cursor_copydata
86*9c0e3d3aSJohn Baldwin.Fa "struct crypto_buffer_cursor *cc"
87*9c0e3d3aSJohn Baldwin.Fa "int size"
88*9c0e3d3aSJohn Baldwin.Fa "void *dst"
89*9c0e3d3aSJohn Baldwin.Fc
90*9c0e3d3aSJohn Baldwin.Ft void
91*9c0e3d3aSJohn Baldwin.Fo crypto_cursor_copydata_noadv
92*9c0e3d3aSJohn Baldwin.Fa "struct crypto_buffer_cursor *cc"
93*9c0e3d3aSJohn Baldwin.Fa "int size"
94*9c0e3d3aSJohn Baldwin.Fa "void *dst"
95*9c0e3d3aSJohn Baldwin.Fc
96*9c0e3d3aSJohn Baldwin.Ft void *
97*9c0e3d3aSJohn Baldwin.Fn crypto_cursor_segbase "struct crypto_buffer_cursor *cc"
98*9c0e3d3aSJohn Baldwin.Ft size_t
99*9c0e3d3aSJohn Baldwin.Fn crypto_cursor_seglen "struct crypto_buffer_cursor *cc"
100*9c0e3d3aSJohn Baldwin.Ft bool
101*9c0e3d3aSJohn Baldwin.Fn CRYPTO_HAS_OUTPUT_BUFFER "struct cryptop *crp"
102*9c0e3d3aSJohn Baldwin.Sh DESCRIPTION
103*9c0e3d3aSJohn BaldwinSymmetric cryptographic requests use data buffers to describe the data to
104*9c0e3d3aSJohn Baldwinbe modified.
105*9c0e3d3aSJohn BaldwinRequests can either specify a single data buffer whose contents are modified
106*9c0e3d3aSJohn Baldwinin place,
107*9c0e3d3aSJohn Baldwinor requests may specify separate data buffers for input and output.
108*9c0e3d3aSJohn Baldwin.Vt struct crypto_buffer
109*9c0e3d3aSJohn Baldwinprovides an abstraction that permits cryptographic requests to operate on
110*9c0e3d3aSJohn Baldwindifferent types of buffers.
111*9c0e3d3aSJohn Baldwin.Vt struct crypto_cursor
112*9c0e3d3aSJohn Baldwinallows cryptographic drivers to iterate over a data buffer.
113*9c0e3d3aSJohn Baldwin.Pp
114*9c0e3d3aSJohn Baldwin.Fn CRYPTO_HAS_OUTPUT_BUFFER
115*9c0e3d3aSJohn Baldwinreturns true if
116*9c0e3d3aSJohn Baldwin.Fa crp
117*9c0e3d3aSJohn Baldwinuses separate buffers for input and output and false if
118*9c0e3d3aSJohn Baldwin.Fa crp
119*9c0e3d3aSJohn Baldwinuses a single buffer.
120*9c0e3d3aSJohn Baldwin.Pp
121*9c0e3d3aSJohn Baldwin.Fn crypto_buffer_len
122*9c0e3d3aSJohn Baldwinreturns the length of data buffer
123*9c0e3d3aSJohn Baldwin.Fa cb
124*9c0e3d3aSJohn Baldwinin bytes.
125*9c0e3d3aSJohn Baldwin.Pp
126*9c0e3d3aSJohn Baldwin.Fn crypto_apply_buf
127*9c0e3d3aSJohn Baldwininvokes a caller-supplied function
128*9c0e3d3aSJohn Baldwinto a region of the data buffer
129*9c0e3d3aSJohn Baldwin.Fa cb .
130*9c0e3d3aSJohn BaldwinThe function
131*9c0e3d3aSJohn Baldwin.Fa f
132*9c0e3d3aSJohn Baldwinis called one or more times.
133*9c0e3d3aSJohn BaldwinFor each invocation,
134*9c0e3d3aSJohn Baldwinthe first argument to
135*9c0e3d3aSJohn Baldwin.Fa f
136*9c0e3d3aSJohn Baldwinis the value of
137*9c0e3d3aSJohn Baldwin.Fa arg
138*9c0e3d3aSJohn Baldwinpassed to
139*9c0e3d3aSJohn Baldwin.Fn crypto_apply_buf .
140*9c0e3d3aSJohn BaldwinThe second and third arguments to
141*9c0e3d3aSJohn Baldwin.Fa f
142*9c0e3d3aSJohn Baldwinare a pointer and length to a segment of the buffer mapped into the kernel.
143*9c0e3d3aSJohn BaldwinThe function is called enough times to cover the
144*9c0e3d3aSJohn Baldwin.Fa len
145*9c0e3d3aSJohn Baldwinbytes of the data buffer which starts at an offset
146*9c0e3d3aSJohn Baldwin.Fa off .
147*9c0e3d3aSJohn BaldwinIf any invocation of
148*9c0e3d3aSJohn Baldwin.Fa f
149*9c0e3d3aSJohn Baldwinreturns a non-zero value,
150*9c0e3d3aSJohn Baldwin.Fn crypto_apply_buf
151*9c0e3d3aSJohn Baldwinimmediately returns that value without invoking
152*9c0e3d3aSJohn Baldwin.Fa f
153*9c0e3d3aSJohn Baldwinon any remaining segments of the region,
154*9c0e3d3aSJohn Baldwinotherwise
155*9c0e3d3aSJohn Baldwin.Fn crypto_apply_buf
156*9c0e3d3aSJohn Baldwinreturns the value from the final call to
157*9c0e3d3aSJohn Baldwin.Fa f .
158*9c0e3d3aSJohn Baldwin.Fn crypto_apply
159*9c0e3d3aSJohn Baldwininvokes the callback
160*9c0e3d3aSJohn Baldwin.Fa f
161*9c0e3d3aSJohn Baldwinon a region of the input data buffer for
162*9c0e3d3aSJohn Baldwin.Fa crp .
163*9c0e3d3aSJohn Baldwin.Pp
164*9c0e3d3aSJohn Baldwin.Fn crypto_buffer_contiguous_subsegment
165*9c0e3d3aSJohn Baldwinattempts to locate a single, virtually-contiguous segment of the data buffer
166*9c0e3d3aSJohn Baldwin.Fa cb .
167*9c0e3d3aSJohn BaldwinThe segment must be
168*9c0e3d3aSJohn Baldwin.Fa len
169*9c0e3d3aSJohn Baldwinbytes long and start at an offset of
170*9c0e3d3aSJohn Baldwin.Fa skip
171*9c0e3d3aSJohn Baldwinbytes.
172*9c0e3d3aSJohn BaldwinIf a segment is found,
173*9c0e3d3aSJohn Baldwina pointer to the start of the segment is returned.
174*9c0e3d3aSJohn BaldwinOtherwise,
175*9c0e3d3aSJohn Baldwin.Dv NULL
176*9c0e3d3aSJohn Baldwinis returned.
177*9c0e3d3aSJohn Baldwin.Fn crypto_contiguous_subsegment
178*9c0e3d3aSJohn Baldwinattempts to locate a single, virtually-contiguous segment in the input data
179*9c0e3d3aSJohn Baldwinbuffer for
180*9c0e3d3aSJohn Baldwin.Fa crp .
181*9c0e3d3aSJohn Baldwin.Ss Data Buffers
182*9c0e3d3aSJohn BaldwinData buffers are described by an instance of
183*9c0e3d3aSJohn Baldwin.Vt struct crypto buffer .
184*9c0e3d3aSJohn BaldwinThe
185*9c0e3d3aSJohn Baldwin.Fa cb_type
186*9c0e3d3aSJohn Baldwinmember contains the type of the data buffer.
187*9c0e3d3aSJohn BaldwinThe following types are supported:
188*9c0e3d3aSJohn Baldwin.Bl -tag -width "  CRYPTO_BUF_CONTIG"
189*9c0e3d3aSJohn Baldwin.It Dv CRYPTO_BUF_NONE
190*9c0e3d3aSJohn BaldwinAn invalid buffer.
191*9c0e3d3aSJohn BaldwinUsed to mark the output buffer when a crypto request uses a single data buffer.
192*9c0e3d3aSJohn Baldwin.It Dv CRYPTO_BUF_CONTIG
193*9c0e3d3aSJohn BaldwinAn array of bytes mapped into the kernel's address space.
194*9c0e3d3aSJohn Baldwin.It Dv CRYPTO_BUF_UIO
195*9c0e3d3aSJohn BaldwinA scatter/gather list of kernel buffers as described in
196*9c0e3d3aSJohn Baldwin.Xr uio 9 .
197*9c0e3d3aSJohn Baldwin.It Dv CRYPTO_BUF_MBUF
198*9c0e3d3aSJohn BaldwinA network memory buffer as described in
199*9c0e3d3aSJohn Baldwin.Xr mbuf 9 .
200*9c0e3d3aSJohn Baldwin.El
201*9c0e3d3aSJohn Baldwin.Pp
202*9c0e3d3aSJohn BaldwinThe structure also contains the following type-specific fields:
203*9c0e3d3aSJohn Baldwin.Bl -tag -width "  cb_buf_len"
204*9c0e3d3aSJohn Baldwin.It Fa cb_buf
205*9c0e3d3aSJohn BaldwinA pointer to the start of a
206*9c0e3d3aSJohn Baldwin.Dv CRYPTO_BUF_CONTIG
207*9c0e3d3aSJohn Baldwindata buffer.
208*9c0e3d3aSJohn Baldwin.It Fa cb_buf_len
209*9c0e3d3aSJohn BaldwinThe length of a
210*9c0e3d3aSJohn Baldwin.Dv CRYPTO_BUF_CONTIG
211*9c0e3d3aSJohn Baldwindata buffer
212*9c0e3d3aSJohn Baldwin.It Fa cb_mbuf
213*9c0e3d3aSJohn BaldwinA pointer to a
214*9c0e3d3aSJohn Baldwin.Vt struct mbuf
215*9c0e3d3aSJohn Baldwinfor
216*9c0e3d3aSJohn Baldwin.Dv CRYPTO_BUF_MBUF .
217*9c0e3d3aSJohn Baldwin.It Fa cb_uio
218*9c0e3d3aSJohn BaldwinA pointer to a
219*9c0e3d3aSJohn Baldwin.Vt struct uio
220*9c0e3d3aSJohn Baldwinfor
221*9c0e3d3aSJohn Baldwin.Dv CRYPTO_BUF_UIO .
222*9c0e3d3aSJohn Baldwin.El
223*9c0e3d3aSJohn Baldwin.Ss Cursors
224*9c0e3d3aSJohn BaldwinCursors provide a mechanism for iterating over a data buffer.
225*9c0e3d3aSJohn BaldwinThey are primarily intended for use in software drivers which access data
226*9c0e3d3aSJohn Baldwinbuffers via virtual addresses.
227*9c0e3d3aSJohn Baldwin.Pp
228*9c0e3d3aSJohn Baldwin.Fn crypto_cursor_init
229*9c0e3d3aSJohn Baldwininitializes the cursor
230*9c0e3d3aSJohn Baldwin.Fa cc
231*9c0e3d3aSJohn Baldwinto reference the start of the data buffer
232*9c0e3d3aSJohn Baldwin.Fa cb .
233*9c0e3d3aSJohn Baldwin.Pp
234*9c0e3d3aSJohn Baldwin.Fn crypto_cursor_advance
235*9c0e3d3aSJohn Baldwinadvances the cursor
236*9c0e3d3aSJohn Baldwin.Fa amount
237*9c0e3d3aSJohn Baldwinbytes forward in the data buffer.
238*9c0e3d3aSJohn Baldwin.Pp
239*9c0e3d3aSJohn Baldwin.Fn crypto_cursor_copyback
240*9c0e3d3aSJohn Baldwincopies
241*9c0e3d3aSJohn Baldwin.Fa size
242*9c0e3d3aSJohn Baldwinbytes from the local buffer pointed to by
243*9c0e3d3aSJohn Baldwin.Fa src
244*9c0e3d3aSJohn Baldwininto the data buffer associated with
245*9c0e3d3aSJohn Baldwin.Fa cc .
246*9c0e3d3aSJohn BaldwinThe bytes are written to the current position of
247*9c0e3d3aSJohn Baldwin.Fa cc ,
248*9c0e3d3aSJohn Baldwinand the cursor is then advanced by
249*9c0e3d3aSJohn Baldwin.Fa size
250*9c0e3d3aSJohn Baldwinbytes.
251*9c0e3d3aSJohn Baldwin.Pp
252*9c0e3d3aSJohn Baldwin.Fn crypto_cursor_copydata
253*9c0e3d3aSJohn Baldwincopies
254*9c0e3d3aSJohn Baldwin.Fa size
255*9c0e3d3aSJohn Baldwinbytes out of the data buffer associated with
256*9c0e3d3aSJohn Baldwin.Fa cc
257*9c0e3d3aSJohn Baldwininto a local buffer pointed to by
258*9c0e3d3aSJohn Baldwin.Fa dst .
259*9c0e3d3aSJohn BaldwinThe bytes are read from the current position of
260*9c0e3d3aSJohn Baldwin.Fa cc ,
261*9c0e3d3aSJohn Baldwinand the cursor is then advanced by
262*9c0e3d3aSJohn Baldwin.Fa size
263*9c0e3d3aSJohn Baldwinbytes.
264*9c0e3d3aSJohn Baldwin.Pp
265*9c0e3d3aSJohn Baldwin.Fn crypto_cursor_copydata_noadv
266*9c0e3d3aSJohn Baldwinis similar to
267*9c0e3d3aSJohn Baldwin.Fn crypto_cursor_copydata
268*9c0e3d3aSJohn Baldwinexcept that it does not change the current position of
269*9c0e3d3aSJohn Baldwin.Fa cc .
270*9c0e3d3aSJohn Baldwin.Pp
271*9c0e3d3aSJohn Baldwin.Fn crypto_cursor_segbase
272*9c0e3d3aSJohn Baldwinand
273*9c0e3d3aSJohn Baldwin.Fn crypto_cursor_seglen
274*9c0e3d3aSJohn Baldwinreturn the start and length, respectively,
275*9c0e3d3aSJohn Baldwinof the virtually-contiguous segment at the current position of
276*9c0e3d3aSJohn Baldwin.Fa cc .
277*9c0e3d3aSJohn Baldwin.Sh RETURN VALUES
278*9c0e3d3aSJohn Baldwin.Fn crypto_apply
279*9c0e3d3aSJohn Baldwinand
280*9c0e3d3aSJohn Baldwin.Fn crypto_apply_buf
281*9c0e3d3aSJohn Baldwinreturn the return value from the caller-supplied callback function.
282*9c0e3d3aSJohn Baldwin.Pp
283*9c0e3d3aSJohn Baldwin.Fn crypto_buffer_contiguous_subsegment ,
284*9c0e3d3aSJohn Baldwin.Fn crypto_contiguous_subsegment ,
285*9c0e3d3aSJohn Baldwinand
286*9c0e3d3aSJohn Baldwin.Fn crypto_cursor_segbase ,
287*9c0e3d3aSJohn Baldwinreturn a pointer to a contiguous segment or
288*9c0e3d3aSJohn Baldwin.Dv NULL .
289*9c0e3d3aSJohn Baldwin.Pp
290*9c0e3d3aSJohn Baldwin.Fn crypto_buffer_len
291*9c0e3d3aSJohn Baldwinreturns the length of a buffer in bytes.
292*9c0e3d3aSJohn Baldwin.Pp
293*9c0e3d3aSJohn Baldwin.Fn crypto_cursor_seglen
294*9c0e3d3aSJohn Baldwinreturns the length in bytes of a contiguous segment.
295*9c0e3d3aSJohn Baldwin.Pp
296*9c0e3d3aSJohn Baldwin.Fn CRYPTO_HAS_OUTPUT_BUFFER
297*9c0e3d3aSJohn Baldwinreturns true if the request uses a separate output buffer.
298*9c0e3d3aSJohn Baldwin.Sh SEE ALSO
299*9c0e3d3aSJohn Baldwin.Xr ipsec 4 ,
300*9c0e3d3aSJohn Baldwin.Xr bus_dma 9 ,
301*9c0e3d3aSJohn Baldwin.Xr crypto 7 ,
302*9c0e3d3aSJohn Baldwin.Xr crypto 9 ,
303*9c0e3d3aSJohn Baldwin.Xr crypto_request 9 ,
304*9c0e3d3aSJohn Baldwin.Xr crypto_driver 9 ,
305*9c0e3d3aSJohn Baldwin.Xr crypto_session 9 ,
306*9c0e3d3aSJohn Baldwin.Xr mbuf 9
307*9c0e3d3aSJohn Baldwin.Xr uio 9
308