]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man9/crypto_buffer.9
Add 'contrib/spleen/' from commit '5eab6333fa27e2b6954c6927859d462a004e57bb'
[FreeBSD/FreeBSD.git] / share / man / man9 / crypto_buffer.9
1 .\" Copyright (c) 2020, Chelsio Inc
2 .\"
3 .\" Redistribution and use in source and binary forms, with or without
4 .\" modification, are permitted provided that the following conditions are met:
5 .\"
6 .\" 1. Redistributions of source code must retain the above copyright notice,
7 .\"    this list of conditions and the following disclaimer.
8 .\"
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\"
13 .\" 3. Neither the name of the Chelsio Inc nor the names of its
14 .\"    contributors may be used to endorse or promote products derived from
15 .\"    this software without specific prior written permission.
16 .\"
17 .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 .\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 .\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 .\" POSSIBILITY OF SUCH DAMAGE.
28 .\"
29 .\" * Other names and brands may be claimed as the property of others.
30 .\"
31 .\" $FreeBSD$
32 .\"
33 .Dd February 11, 2022
34 .Dt CRYPTO_BUFFER 9
35 .Os
36 .Sh NAME
37 .Nm crypto_buffer
38 .Nd symmetric cryptographic request buffers
39 .Sh SYNOPSIS
40 .In opencrypto/cryptodev.h
41 .Ft int
42 .Fo crypto_apply
43 .Fa "struct cryptop *crp"
44 .Fa "int off"
45 .Fa "int len"
46 .Fa "int (*f)(void *, void *, u_int)"
47 .Fa "void *arg"
48 .Fc
49 .Ft int
50 .Fo crypto_apply_buf
51 .Fa "struct crypto_buffer *cb"
52 .Fa "int off"
53 .Fa "int len"
54 .Fa "int (*f)(void *, void *, u_int)"
55 .Fa "void *arg"
56 .Fc
57 .Ft void *
58 .Fo crypto_buffer_contiguous_subsegment
59 .Fa "struct crypto_buffer *cb"
60 .Fa "size_t skip"
61 .Fa "size_t len"
62 .Fc
63 .Ft size_t
64 .Fn crypto_buffer_len "struct crypto_buffer *cb"
65 .Ft void *
66 .Fo crypto_contiguous_subsegment
67 .Fa "struct cryptop *crp"
68 .Fa "size_t skip"
69 .Fa "size_t len"
70 .Fc
71 .Ft void
72 .Fo crypto_cursor_init
73 .Fa "struct crypto_buffer_cursor *cc"
74 .Fa "const struct crypto_buffer *cb"
75 .Fc
76 .Ft void
77 .Fn crypto_cursor_advance "struct crypto_buffer_cursor *cc" "size_t amount"
78 .Ft void
79 .Fo crypto_cursor_copyback
80 .Fa "struct crypto_buffer_cursor *cc"
81 .Fa "int size"
82 .Fa "const void *src"
83 .Fc
84 .Ft void
85 .Fo crypto_cursor_copydata
86 .Fa "struct crypto_buffer_cursor *cc"
87 .Fa "int size"
88 .Fa "void *dst"
89 .Fc
90 .Ft void
91 .Fo crypto_cursor_copydata_noadv
92 .Fa "struct crypto_buffer_cursor *cc"
93 .Fa "int size"
94 .Fa "void *dst"
95 .Fc
96 .Ft void *
97 .Fn crypto_cursor_segment "struct crypto_buffer_cursor *cc" "size_t *len"
98 .Ft void
99 .Fo crypto_cursor_copy
100 .Fa "const struct crypto_buffer_cursor *fromc"
101 .Fa "struct crypto_buffer_cursor *toc"
102 .Fc
103 .Ft bool
104 .Fn CRYPTO_HAS_OUTPUT_BUFFER "struct cryptop *crp"
105 .Sh DESCRIPTION
106 Symmetric cryptographic requests use data buffers to describe the data to
107 be modified.
108 Requests can either specify a single data buffer whose contents are modified
109 in place,
110 or requests may specify separate data buffers for input and output.
111 .Vt struct crypto_buffer
112 provides an abstraction that permits cryptographic requests to operate on
113 different types of buffers.
114 .Vt struct crypto_cursor
115 allows cryptographic drivers to iterate over a data buffer.
116 .Pp
117 .Fn CRYPTO_HAS_OUTPUT_BUFFER
118 returns true if
119 .Fa crp
120 uses separate buffers for input and output and false if
121 .Fa crp
122 uses a single buffer.
123 .Pp
124 .Fn crypto_buffer_len
125 returns the length of data buffer
126 .Fa cb
127 in bytes.
128 .Pp
129 .Fn crypto_apply_buf
130 invokes a caller-supplied function
131 to a region of the data buffer
132 .Fa cb .
133 The function
134 .Fa f
135 is called one or more times.
136 For each invocation,
137 the first argument to
138 .Fa f
139 is the value of
140 .Fa arg
141 passed to
142 .Fn crypto_apply_buf .
143 The second and third arguments to
144 .Fa f
145 are a pointer and length to a segment of the buffer mapped into the kernel.
146 The function is called enough times to cover the
147 .Fa len
148 bytes of the data buffer which starts at an offset
149 .Fa off .
150 If any invocation of
151 .Fa f
152 returns a non-zero value,
153 .Fn crypto_apply_buf
154 immediately returns that value without invoking
155 .Fa f
156 on any remaining segments of the region,
157 otherwise
158 .Fn crypto_apply_buf
159 returns the value from the final call to
160 .Fa f .
161 .Fn crypto_apply
162 invokes the callback
163 .Fa f
164 on a region of the input data buffer for
165 .Fa crp .
166 .Pp
167 .Fn crypto_buffer_contiguous_subsegment
168 attempts to locate a single, virtually-contiguous segment of the data buffer
169 .Fa cb .
170 The segment must be
171 .Fa len
172 bytes long and start at an offset of
173 .Fa skip
174 bytes.
175 If a segment is found,
176 a pointer to the start of the segment is returned.
177 Otherwise,
178 .Dv NULL
179 is returned.
180 .Fn crypto_contiguous_subsegment
181 attempts to locate a single, virtually-contiguous segment in the input data
182 buffer for
183 .Fa crp .
184 .Ss Data Buffers
185 Data buffers are described by an instance of
186 .Vt struct crypto buffer .
187 The
188 .Fa cb_type
189 member contains the type of the data buffer.
190 The following types are supported:
191 .Bl -tag -width "  CRYPTO_BUF_CONTIG"
192 .It Dv CRYPTO_BUF_NONE
193 An invalid buffer.
194 Used to mark the output buffer when a crypto request uses a single data buffer.
195 .It Dv CRYPTO_BUF_CONTIG
196 An array of bytes mapped into the kernel's address space.
197 .It Dv CRYPTO_BUF_UIO
198 A scatter/gather list of kernel buffers as described in
199 .Xr uio 9 .
200 .It Dv CRYPTO_BUF_MBUF
201 A chain of network memory buffers as described in
202 .Xr mbuf 9 .
203 .It Dv CRYPTO_BUF_SINGLE_MBUF
204 A single network memory buffer as described in
205 .Xr mbuf 9 .
206 .It Dv CRYPTO_BUF_VMPAGE
207 A scatter/gather list of
208 .Vt vm_page_t
209 structures describing pages in the kernel's address space.
210 This buffer type is only available if
211 .Dv CRYPTO_HAS_VMPAGE
212 is true.
213 .El
214 .Pp
215 The structure also contains the following type-specific fields:
216 .Bl -tag -width "  cb_vm_page_offset"
217 .It Fa cb_buf
218 A pointer to the start of a
219 .Dv CRYPTO_BUF_CONTIG
220 data buffer.
221 .It Fa cb_buf_len
222 The length of a
223 .Dv CRYPTO_BUF_CONTIG
224 data buffer
225 .It Fa cb_mbuf
226 A pointer to a
227 .Vt struct mbuf
228 for
229 .Dv CRYPTO_BUF_MBUF
230 and
231 .Dv CRYPTO_BUF_SINGLE_MBUF .
232 .It Fa cb_uio
233 A pointer to a
234 .Vt struct uio
235 for
236 .Dv CRYPTO_BUF_UIO .
237 .It Fa cb_vm_page
238 A pointer to an array of
239 .Vt struct vm_page
240 for
241 .Dv CRYPTO_BUF_VMPAGE .
242 .It Fa cb_vm_page_len
243 The total amount of data included in the
244 .Fa cb_vm_page
245 array, in bytes.
246 .It Fa cb_vm_page_offset
247 Offset in bytes in the first page of
248 .Fa cb_vm_page
249 where valid data begins.
250 .El
251 .Ss Cursors
252 Cursors provide a mechanism for iterating over a data buffer.
253 They are primarily intended for use in software drivers which access data
254 buffers via virtual addresses.
255 .Pp
256 .Fn crypto_cursor_init
257 initializes the cursor
258 .Fa cc
259 to reference the start of the data buffer
260 .Fa cb .
261 .Pp
262 .Fn crypto_cursor_advance
263 advances the cursor
264 .Fa amount
265 bytes forward in the data buffer.
266 .Pp
267 .Fn crypto_cursor_copyback
268 copies
269 .Fa size
270 bytes from the local buffer pointed to by
271 .Fa src
272 into the data buffer associated with
273 .Fa cc .
274 The bytes are written to the current position of
275 .Fa cc ,
276 and the cursor is then advanced by
277 .Fa size
278 bytes.
279 .Pp
280 .Fn crypto_cursor_copydata
281 copies
282 .Fa size
283 bytes out of the data buffer associated with
284 .Fa cc
285 into a local buffer pointed to by
286 .Fa dst .
287 The bytes are read from the current position of
288 .Fa cc ,
289 and the cursor is then advanced by
290 .Fa size
291 bytes.
292 .Pp
293 .Fn crypto_cursor_copydata_noadv
294 is similar to
295 .Fn crypto_cursor_copydata
296 except that it does not change the current position of
297 .Fa cc .
298 .Pp
299 .Fn crypto_cursor_segment
300 returns the start of the virtually-contiguous segment at the current position of
301 .Fa cc .
302 The length of the segment is stored in
303 .Fa len .
304 .Sh RETURN VALUES
305 .Fn crypto_apply
306 and
307 .Fn crypto_apply_buf
308 return the return value from the caller-supplied callback function.
309 .Pp
310 .Fn crypto_buffer_contiguous_subsegment ,
311 .Fn crypto_contiguous_subsegment ,
312 and
313 .Fn crypto_cursor_segment
314 return a pointer to a contiguous segment or
315 .Dv NULL .
316 .Pp
317 .Fn crypto_buffer_len
318 returns the length of a buffer in bytes.
319 .Pp
320 .Fn crypto_cursor_seglen
321 returns the length in bytes of a contiguous segment.
322 .Pp
323 .Fn crypto_cursor_copy
324 makes a deep copy of the cursor
325 .Fa fromc .
326 The two copies do not share any state and can thus be used
327 independently.
328 .Pp
329 .Fn CRYPTO_HAS_OUTPUT_BUFFER
330 returns true if the request uses a separate output buffer.
331 .Sh SEE ALSO
332 .Xr ipsec 4 ,
333 .Xr crypto 7 ,
334 .Xr bus_dma 9 ,
335 .Xr crypto 9 ,
336 .Xr crypto_driver 9 ,
337 .Xr crypto_request 9 ,
338 .Xr crypto_session 9 ,
339 .Xr mbuf 9 ,
340 .Xr uio 9
341 .Sh HISTORY
342 The
343 .Nm
344 functions first appeared in
345 .Fx 13 .
346 .Sh AUTHORS
347 The
348 .Nm
349 functions and this manual page were written by
350 .An John Baldwin Aq Mt jhb@FreeBSD.org .