1 .\" Copyright (c) 2020, Chelsio Inc
3 .\" Redistribution and use in source and binary forms, with or without
4 .\" modification, are permitted provided that the following conditions are met:
6 .\" 1. Redistributions of source code must retain the above copyright notice,
7 .\" this list of conditions and the following disclaimer.
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.
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.
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.
29 .\" * Other names and brands may be claimed as the property of others.
38 .Nd symmetric cryptographic request buffers
40 .In opencrypto/cryptodev.h
43 .Fa "struct cryptop *crp"
46 .Fa "int (*f)(void *, void *, u_int)"
51 .Fa "struct crypto_buffer *cb"
54 .Fa "int (*f)(void *, void *, u_int)"
58 .Fo crypto_buffer_contiguous_subsegment
59 .Fa "struct crypto_buffer *cb"
64 .Fn crypto_buffer_len "struct crypto_buffer *cb"
66 .Fo crypto_contiguous_subsegment
67 .Fa "struct cryptop *crp"
72 .Fo crypto_cursor_init
73 .Fa "struct crypto_buffer_cursor *cc"
74 .Fa "const struct crypto_buffer *cb"
77 .Fn crypto_cursor_advance "struct crypto_buffer_cursor *cc" "size_t amount"
79 .Fo crypto_cursor_copyback
80 .Fa "struct crypto_buffer_cursor *cc"
85 .Fo crypto_cursor_copydata
86 .Fa "struct crypto_buffer_cursor *cc"
91 .Fo crypto_cursor_copydata_noadv
92 .Fa "struct crypto_buffer_cursor *cc"
97 .Fn crypto_cursor_segment "struct crypto_buffer_cursor *cc" "size_t *len"
99 .Fo crypto_cursor_copy
100 .Fa "const struct crypto_buffer_cursor *fromc"
101 .Fa "struct crypto_buffer_cursor *toc"
104 .Fn CRYPTO_HAS_OUTPUT_BUFFER "struct cryptop *crp"
106 Symmetric cryptographic requests use data buffers to describe the data to
108 Requests can either specify a single data buffer whose contents are modified
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.
117 .Fn CRYPTO_HAS_OUTPUT_BUFFER
120 uses separate buffers for input and output and false if
122 uses a single buffer.
124 .Fn crypto_buffer_len
125 returns the length of data buffer
130 invokes a caller-supplied function
131 to a region of the data buffer
135 is called one or more times.
137 the first argument to
142 .Fn crypto_apply_buf .
143 The second and third arguments to
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
148 bytes of the data buffer which starts at an offset
152 returns a non-zero value,
154 immediately returns that value without invoking
156 on any remaining segments of the region,
159 returns the value from the final call to
164 on a region of the input data buffer for
167 .Fn crypto_buffer_contiguous_subsegment
168 attempts to locate a single, virtually-contiguous segment of the data buffer
172 bytes long and start at an offset of
175 If a segment is found,
176 a pointer to the start of the segment is returned.
180 .Fn crypto_contiguous_subsegment
181 attempts to locate a single, virtually-contiguous segment in the input data
185 Data buffers are described by an instance of
186 .Vt struct crypto buffer .
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
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
200 .It Dv CRYPTO_BUF_MBUF
201 A chain of network memory buffers as described in
203 .It Dv CRYPTO_BUF_SINGLE_MBUF
204 A single network memory buffer as described in
206 .It Dv CRYPTO_BUF_VMPAGE
207 A scatter/gather list of
209 structures describing pages in the kernel's address space.
210 This buffer type is only available if
211 .Dv CRYPTO_HAS_VMPAGE
215 The structure also contains the following type-specific fields:
216 .Bl -tag -width " cb_vm_page_offset"
218 A pointer to the start of a
219 .Dv CRYPTO_BUF_CONTIG
223 .Dv CRYPTO_BUF_CONTIG
231 .Dv CRYPTO_BUF_SINGLE_MBUF .
238 A pointer to an array of
241 .Dv CRYPTO_BUF_VMPAGE .
242 .It Fa cb_vm_page_len
243 The total amount of data included in the
246 .It Fa cb_vm_page_offset
247 Offset in bytes in the first page of
249 where valid data begins.
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.
256 .Fn crypto_cursor_init
257 initializes the cursor
259 to reference the start of the data buffer
262 .Fn crypto_cursor_advance
265 bytes forward in the data buffer.
267 .Fn crypto_cursor_copyback
270 bytes from the local buffer pointed to by
272 into the data buffer associated with
274 The bytes are written to the current position of
276 and the cursor is then advanced by
280 .Fn crypto_cursor_copydata
283 bytes out of the data buffer associated with
285 into a local buffer pointed to by
287 The bytes are read from the current position of
289 and the cursor is then advanced by
293 .Fn crypto_cursor_copydata_noadv
295 .Fn crypto_cursor_copydata
296 except that it does not change the current position of
299 .Fn crypto_cursor_segment
300 returns the start of the virtually-contiguous segment at the current position of
302 The length of the segment is stored in
308 return the return value from the caller-supplied callback function.
310 .Fn crypto_buffer_contiguous_subsegment ,
311 .Fn crypto_contiguous_subsegment ,
313 .Fn crypto_cursor_segment
314 return a pointer to a contiguous segment or
317 .Fn crypto_buffer_len
318 returns the length of a buffer in bytes.
320 .Fn crypto_cursor_seglen
321 returns the length in bytes of a contiguous segment.
323 .Fn crypto_cursor_copy
324 makes a deep copy of the cursor
326 The two copies do not share any state and can thus be used
329 .Fn CRYPTO_HAS_OUTPUT_BUFFER
330 returns true if the request uses a separate output buffer.
336 .Xr crypto_driver 9 ,
337 .Xr crypto_request 9 ,
338 .Xr crypto_session 9 ,
344 functions first appeared in
349 functions and this manual page were written by
350 .An John Baldwin Aq Mt jhb@FreeBSD.org .