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 .Fn crypto_cursor_segbase "struct crypto_buffer_cursor *cc"
101 .Fn crypto_cursor_seglen "struct crypto_buffer_cursor *cc"
103 .Fn CRYPTO_HAS_OUTPUT_BUFFER "struct cryptop *crp"
105 Symmetric cryptographic requests use data buffers to describe the data to
107 Requests can either specify a single data buffer whose contents are modified
109 or requests may specify separate data buffers for input and output.
110 .Vt struct crypto_buffer
111 provides an abstraction that permits cryptographic requests to operate on
112 different types of buffers.
113 .Vt struct crypto_cursor
114 allows cryptographic drivers to iterate over a data buffer.
116 .Fn CRYPTO_HAS_OUTPUT_BUFFER
119 uses separate buffers for input and output and false if
121 uses a single buffer.
123 .Fn crypto_buffer_len
124 returns the length of data buffer
129 invokes a caller-supplied function
130 to a region of the data buffer
134 is called one or more times.
136 the first argument to
141 .Fn crypto_apply_buf .
142 The second and third arguments to
144 are a pointer and length to a segment of the buffer mapped into the kernel.
145 The function is called enough times to cover the
147 bytes of the data buffer which starts at an offset
151 returns a non-zero value,
153 immediately returns that value without invoking
155 on any remaining segments of the region,
158 returns the value from the final call to
163 on a region of the input data buffer for
166 .Fn crypto_buffer_contiguous_subsegment
167 attempts to locate a single, virtually-contiguous segment of the data buffer
171 bytes long and start at an offset of
174 If a segment is found,
175 a pointer to the start of the segment is returned.
179 .Fn crypto_contiguous_subsegment
180 attempts to locate a single, virtually-contiguous segment in the input data
184 Data buffers are described by an instance of
185 .Vt struct crypto buffer .
188 member contains the type of the data buffer.
189 The following types are supported:
190 .Bl -tag -width " CRYPTO_BUF_CONTIG"
191 .It Dv CRYPTO_BUF_NONE
193 Used to mark the output buffer when a crypto request uses a single data buffer.
194 .It Dv CRYPTO_BUF_CONTIG
195 An array of bytes mapped into the kernel's address space.
196 .It Dv CRYPTO_BUF_UIO
197 A scatter/gather list of kernel buffers as described in
199 .It Dv CRYPTO_BUF_MBUF
200 A chain of network memory buffers as described in
202 .It Dv CRYPTO_BUF_SINGLE_MBUF
203 A single network memory buffer as described in
205 .It Dv CRYPTO_BUF_VMPAGE
206 A scatter/gather list of
208 structures describing pages in the kernel's address space.
209 This buffer type is only available if
210 .Dv CRYPTO_HAS_VMPAGE
214 The structure also contains the following type-specific fields:
215 .Bl -tag -width " cb_vm_page_offset"
217 A pointer to the start of a
218 .Dv CRYPTO_BUF_CONTIG
222 .Dv CRYPTO_BUF_CONTIG
230 .Dv CRYPTO_BUF_SINGLE_MBUF .
237 A pointer to an array of
240 .Dv CRYPTO_BUF_VMPAGE .
241 .It Fa cb_vm_page_len
242 The total amount of data included in the
245 .It Fa cb_vm_page_offset
246 Offset in bytes in the first page of
248 where valid data begins.
251 Cursors provide a mechanism for iterating over a data buffer.
252 They are primarily intended for use in software drivers which access data
253 buffers via virtual addresses.
255 .Fn crypto_cursor_init
256 initializes the cursor
258 to reference the start of the data buffer
261 .Fn crypto_cursor_advance
264 bytes forward in the data buffer.
266 .Fn crypto_cursor_copyback
269 bytes from the local buffer pointed to by
271 into the data buffer associated with
273 The bytes are written to the current position of
275 and the cursor is then advanced by
279 .Fn crypto_cursor_copydata
282 bytes out of the data buffer associated with
284 into a local buffer pointed to by
286 The bytes are read from the current position of
288 and the cursor is then advanced by
292 .Fn crypto_cursor_copydata_noadv
294 .Fn crypto_cursor_copydata
295 except that it does not change the current position of
298 .Fn crypto_cursor_segment
299 returns the start of the virtually-contiguous segment at the current position of
301 The length of the segment is stored in
304 .Fn crypto_cursor_segbase
306 .Fn crypto_cursor_seglen
307 return the start and length, respectively,
308 of the virtually-contiguous segment at the current position of
314 return the return value from the caller-supplied callback function.
316 .Fn crypto_buffer_contiguous_subsegment ,
317 .Fn crypto_contiguous_subsegment ,
318 .Fn crypto_cursor_segbase ,
320 .Fn crypto_cursor_segment
321 return a pointer to a contiguous segment or
324 .Fn crypto_buffer_len
325 returns the length of a buffer in bytes.
327 .Fn crypto_cursor_seglen
328 returns the length in bytes of a contiguous segment.
330 .Fn CRYPTO_HAS_OUTPUT_BUFFER
331 returns true if the request uses a separate output buffer.
337 .Xr crypto_driver 9 ,
338 .Xr crypto_request 9 ,
339 .Xr crypto_session 9 ,
345 functions first appeared in
350 functions and this manual page were written by
351 .An John Baldwin Aq Mt jhb@FreeBSD.org .