xref: /freebsd/share/man/man9/crypto_buffer.9 (revision 16694347a9214b23a550578b7a73e78c0f68e36d)
19c0e3d3aSJohn Baldwin.\" Copyright (c) 2020, Chelsio Inc
29c0e3d3aSJohn Baldwin.\"
39c0e3d3aSJohn Baldwin.\" Redistribution and use in source and binary forms, with or without
49c0e3d3aSJohn Baldwin.\" modification, are permitted provided that the following conditions are met:
59c0e3d3aSJohn Baldwin.\"
69c0e3d3aSJohn Baldwin.\" 1. Redistributions of source code must retain the above copyright notice,
79c0e3d3aSJohn Baldwin.\"    this list of conditions and the following disclaimer.
89c0e3d3aSJohn Baldwin.\"
99c0e3d3aSJohn Baldwin.\" 2. Redistributions in binary form must reproduce the above copyright
109c0e3d3aSJohn Baldwin.\"    notice, this list of conditions and the following disclaimer in the
119c0e3d3aSJohn Baldwin.\"    documentation and/or other materials provided with the distribution.
129c0e3d3aSJohn Baldwin.\"
139c0e3d3aSJohn Baldwin.\" 3. Neither the name of the Chelsio Inc nor the names of its
149c0e3d3aSJohn Baldwin.\"    contributors may be used to endorse or promote products derived from
159c0e3d3aSJohn Baldwin.\"    this software without specific prior written permission.
169c0e3d3aSJohn Baldwin.\"
179c0e3d3aSJohn Baldwin.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
189c0e3d3aSJohn Baldwin.\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199c0e3d3aSJohn Baldwin.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
209c0e3d3aSJohn Baldwin.\" ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
219c0e3d3aSJohn Baldwin.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
229c0e3d3aSJohn Baldwin.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
239c0e3d3aSJohn Baldwin.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
249c0e3d3aSJohn Baldwin.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
259c0e3d3aSJohn Baldwin.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
269c0e3d3aSJohn Baldwin.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
279c0e3d3aSJohn Baldwin.\" POSSIBILITY OF SUCH DAMAGE.
289c0e3d3aSJohn Baldwin.\"
299c0e3d3aSJohn Baldwin.\" * Other names and brands may be claimed as the property of others.
309c0e3d3aSJohn Baldwin.\"
319c0e3d3aSJohn Baldwin.\" $FreeBSD$
329c0e3d3aSJohn Baldwin.\"
33e6f6d0c9SAlan Somers.Dd August 12, 2020
349c0e3d3aSJohn Baldwin.Dt CRYPTO_BUFFER 9
359c0e3d3aSJohn Baldwin.Os
369c0e3d3aSJohn Baldwin.Sh NAME
379c0e3d3aSJohn Baldwin.Nm crypto_buffer
389c0e3d3aSJohn Baldwin.Nd symmetric cryptographic request buffers
399c0e3d3aSJohn Baldwin.Sh SYNOPSIS
409c0e3d3aSJohn Baldwin.In opencrypto/cryptodev.h
419c0e3d3aSJohn Baldwin.Ft int
429c0e3d3aSJohn Baldwin.Fo crypto_apply
439c0e3d3aSJohn Baldwin.Fa "struct cryptop *crp"
449c0e3d3aSJohn Baldwin.Fa "int off"
459c0e3d3aSJohn Baldwin.Fa "int len"
469c0e3d3aSJohn Baldwin.Fa "int (*f)(void *, void *, u_int)"
479c0e3d3aSJohn Baldwin.Fa "void *arg"
489c0e3d3aSJohn Baldwin.Fc
499c0e3d3aSJohn Baldwin.Ft int
509c0e3d3aSJohn Baldwin.Fo crypto_apply_buf
519c0e3d3aSJohn Baldwin.Fa "struct crypto_buffer *cb"
529c0e3d3aSJohn Baldwin.Fa "int off"
539c0e3d3aSJohn Baldwin.Fa "int len"
549c0e3d3aSJohn Baldwin.Fa "int (*f)(void *, void *, u_int)"
559c0e3d3aSJohn Baldwin.Fa "void *arg"
569c0e3d3aSJohn Baldwin.Fc
579c0e3d3aSJohn Baldwin.Ft void *
589c0e3d3aSJohn Baldwin.Fo crypto_buffer_contiguous_subsegment
599c0e3d3aSJohn Baldwin.Fa "struct crypto_buffer *cb"
609c0e3d3aSJohn Baldwin.Fa "size_t skip"
619c0e3d3aSJohn Baldwin.Fa "size_t len"
629c0e3d3aSJohn Baldwin.Fc
639c0e3d3aSJohn Baldwin.Ft size_t
649c0e3d3aSJohn Baldwin.Fn crypto_buffer_len "struct crypto_buffer *cb"
659c0e3d3aSJohn Baldwin.Ft void *
669c0e3d3aSJohn Baldwin.Fo crypto_contiguous_subsegment
679c0e3d3aSJohn Baldwin.Fa "struct cryptop *crp"
689c0e3d3aSJohn Baldwin.Fa "size_t skip"
699c0e3d3aSJohn Baldwin.Fa "size_t len"
709c0e3d3aSJohn Baldwin.Fc
719c0e3d3aSJohn Baldwin.Ft void
729c0e3d3aSJohn Baldwin.Fo crypto_cursor_init
739c0e3d3aSJohn Baldwin.Fa "struct crypto_buffer_cursor *cc"
749c0e3d3aSJohn Baldwin.Fa "const struct crypto_buffer *cb"
759c0e3d3aSJohn Baldwin.Fc
769c0e3d3aSJohn Baldwin.Ft void
779c0e3d3aSJohn Baldwin.Fn crypto_cursor_advance "struct crypto_buffer_cursor *cc" "size_t amount"
789c0e3d3aSJohn Baldwin.Ft void
799c0e3d3aSJohn Baldwin.Fo crypto_cursor_copyback
809c0e3d3aSJohn Baldwin.Fa "struct crypto_buffer_cursor *cc"
819c0e3d3aSJohn Baldwin.Fa "int size"
829c0e3d3aSJohn Baldwin.Fa "const void *src"
839c0e3d3aSJohn Baldwin.Fc
849c0e3d3aSJohn Baldwin.Ft void
859c0e3d3aSJohn Baldwin.Fo crypto_cursor_copydata
869c0e3d3aSJohn Baldwin.Fa "struct crypto_buffer_cursor *cc"
879c0e3d3aSJohn Baldwin.Fa "int size"
889c0e3d3aSJohn Baldwin.Fa "void *dst"
899c0e3d3aSJohn Baldwin.Fc
909c0e3d3aSJohn Baldwin.Ft void
919c0e3d3aSJohn Baldwin.Fo crypto_cursor_copydata_noadv
929c0e3d3aSJohn Baldwin.Fa "struct crypto_buffer_cursor *cc"
939c0e3d3aSJohn Baldwin.Fa "int size"
949c0e3d3aSJohn Baldwin.Fa "void *dst"
959c0e3d3aSJohn Baldwin.Fc
969c0e3d3aSJohn Baldwin.Ft void *
979c0e3d3aSJohn Baldwin.Fn crypto_cursor_segbase "struct crypto_buffer_cursor *cc"
989c0e3d3aSJohn Baldwin.Ft size_t
999c0e3d3aSJohn Baldwin.Fn crypto_cursor_seglen "struct crypto_buffer_cursor *cc"
1009c0e3d3aSJohn Baldwin.Ft bool
1019c0e3d3aSJohn Baldwin.Fn CRYPTO_HAS_OUTPUT_BUFFER "struct cryptop *crp"
1029c0e3d3aSJohn Baldwin.Sh DESCRIPTION
1039c0e3d3aSJohn BaldwinSymmetric cryptographic requests use data buffers to describe the data to
1049c0e3d3aSJohn Baldwinbe modified.
1059c0e3d3aSJohn BaldwinRequests can either specify a single data buffer whose contents are modified
1069c0e3d3aSJohn Baldwinin place,
1079c0e3d3aSJohn Baldwinor requests may specify separate data buffers for input and output.
1089c0e3d3aSJohn Baldwin.Vt struct crypto_buffer
1099c0e3d3aSJohn Baldwinprovides an abstraction that permits cryptographic requests to operate on
1109c0e3d3aSJohn Baldwindifferent types of buffers.
1119c0e3d3aSJohn Baldwin.Vt struct crypto_cursor
1129c0e3d3aSJohn Baldwinallows cryptographic drivers to iterate over a data buffer.
1139c0e3d3aSJohn Baldwin.Pp
1149c0e3d3aSJohn Baldwin.Fn CRYPTO_HAS_OUTPUT_BUFFER
1159c0e3d3aSJohn Baldwinreturns true if
1169c0e3d3aSJohn Baldwin.Fa crp
1179c0e3d3aSJohn Baldwinuses separate buffers for input and output and false if
1189c0e3d3aSJohn Baldwin.Fa crp
1199c0e3d3aSJohn Baldwinuses a single buffer.
1209c0e3d3aSJohn Baldwin.Pp
1219c0e3d3aSJohn Baldwin.Fn crypto_buffer_len
1229c0e3d3aSJohn Baldwinreturns the length of data buffer
1239c0e3d3aSJohn Baldwin.Fa cb
1249c0e3d3aSJohn Baldwinin bytes.
1259c0e3d3aSJohn Baldwin.Pp
1269c0e3d3aSJohn Baldwin.Fn crypto_apply_buf
1279c0e3d3aSJohn Baldwininvokes a caller-supplied function
1289c0e3d3aSJohn Baldwinto a region of the data buffer
1299c0e3d3aSJohn Baldwin.Fa cb .
1309c0e3d3aSJohn BaldwinThe function
1319c0e3d3aSJohn Baldwin.Fa f
1329c0e3d3aSJohn Baldwinis called one or more times.
1339c0e3d3aSJohn BaldwinFor each invocation,
1349c0e3d3aSJohn Baldwinthe first argument to
1359c0e3d3aSJohn Baldwin.Fa f
1369c0e3d3aSJohn Baldwinis the value of
1379c0e3d3aSJohn Baldwin.Fa arg
1389c0e3d3aSJohn Baldwinpassed to
1399c0e3d3aSJohn Baldwin.Fn crypto_apply_buf .
1409c0e3d3aSJohn BaldwinThe second and third arguments to
1419c0e3d3aSJohn Baldwin.Fa f
1429c0e3d3aSJohn Baldwinare a pointer and length to a segment of the buffer mapped into the kernel.
1439c0e3d3aSJohn BaldwinThe function is called enough times to cover the
1449c0e3d3aSJohn Baldwin.Fa len
1459c0e3d3aSJohn Baldwinbytes of the data buffer which starts at an offset
1469c0e3d3aSJohn Baldwin.Fa off .
1479c0e3d3aSJohn BaldwinIf any invocation of
1489c0e3d3aSJohn Baldwin.Fa f
1499c0e3d3aSJohn Baldwinreturns a non-zero value,
1509c0e3d3aSJohn Baldwin.Fn crypto_apply_buf
1519c0e3d3aSJohn Baldwinimmediately returns that value without invoking
1529c0e3d3aSJohn Baldwin.Fa f
1539c0e3d3aSJohn Baldwinon any remaining segments of the region,
1549c0e3d3aSJohn Baldwinotherwise
1559c0e3d3aSJohn Baldwin.Fn crypto_apply_buf
1569c0e3d3aSJohn Baldwinreturns the value from the final call to
1579c0e3d3aSJohn Baldwin.Fa f .
1589c0e3d3aSJohn Baldwin.Fn crypto_apply
1599c0e3d3aSJohn Baldwininvokes the callback
1609c0e3d3aSJohn Baldwin.Fa f
1619c0e3d3aSJohn Baldwinon a region of the input data buffer for
1629c0e3d3aSJohn Baldwin.Fa crp .
1639c0e3d3aSJohn Baldwin.Pp
1649c0e3d3aSJohn Baldwin.Fn crypto_buffer_contiguous_subsegment
1659c0e3d3aSJohn Baldwinattempts to locate a single, virtually-contiguous segment of the data buffer
1669c0e3d3aSJohn Baldwin.Fa cb .
1679c0e3d3aSJohn BaldwinThe segment must be
1689c0e3d3aSJohn Baldwin.Fa len
1699c0e3d3aSJohn Baldwinbytes long and start at an offset of
1709c0e3d3aSJohn Baldwin.Fa skip
1719c0e3d3aSJohn Baldwinbytes.
1729c0e3d3aSJohn BaldwinIf a segment is found,
1739c0e3d3aSJohn Baldwina pointer to the start of the segment is returned.
1749c0e3d3aSJohn BaldwinOtherwise,
1759c0e3d3aSJohn Baldwin.Dv NULL
1769c0e3d3aSJohn Baldwinis returned.
1779c0e3d3aSJohn Baldwin.Fn crypto_contiguous_subsegment
1789c0e3d3aSJohn Baldwinattempts to locate a single, virtually-contiguous segment in the input data
1799c0e3d3aSJohn Baldwinbuffer for
1809c0e3d3aSJohn Baldwin.Fa crp .
1819c0e3d3aSJohn Baldwin.Ss Data Buffers
1829c0e3d3aSJohn BaldwinData buffers are described by an instance of
1839c0e3d3aSJohn Baldwin.Vt struct crypto buffer .
1849c0e3d3aSJohn BaldwinThe
1859c0e3d3aSJohn Baldwin.Fa cb_type
1869c0e3d3aSJohn Baldwinmember contains the type of the data buffer.
1879c0e3d3aSJohn BaldwinThe following types are supported:
1889c0e3d3aSJohn Baldwin.Bl -tag -width "  CRYPTO_BUF_CONTIG"
1899c0e3d3aSJohn Baldwin.It Dv CRYPTO_BUF_NONE
1909c0e3d3aSJohn BaldwinAn invalid buffer.
1919c0e3d3aSJohn BaldwinUsed to mark the output buffer when a crypto request uses a single data buffer.
1929c0e3d3aSJohn Baldwin.It Dv CRYPTO_BUF_CONTIG
1939c0e3d3aSJohn BaldwinAn array of bytes mapped into the kernel's address space.
1949c0e3d3aSJohn Baldwin.It Dv CRYPTO_BUF_UIO
1959c0e3d3aSJohn BaldwinA scatter/gather list of kernel buffers as described in
1969c0e3d3aSJohn Baldwin.Xr uio 9 .
1979c0e3d3aSJohn Baldwin.It Dv CRYPTO_BUF_MBUF
1989c0e3d3aSJohn BaldwinA network memory buffer as described in
1999c0e3d3aSJohn Baldwin.Xr mbuf 9 .
200e6f6d0c9SAlan Somers.It Dv CRYPTO_BUF_VMPAGE
201e6f6d0c9SAlan SomersA scatter/gather list of
202e6f6d0c9SAlan Somers.Vt vm_page_t
203e6f6d0c9SAlan Somersstructures describing pages in the kernel's address space.
204e6f6d0c9SAlan SomersThis buffer type is only available if
205e6f6d0c9SAlan Somers.Dv CRYPTO_HAS_VMPAGE
206e6f6d0c9SAlan Somersis true.
2079c0e3d3aSJohn Baldwin.El
2089c0e3d3aSJohn Baldwin.Pp
2099c0e3d3aSJohn BaldwinThe structure also contains the following type-specific fields:
210e6f6d0c9SAlan Somers.Bl -tag -width "  cb_vm_page_offset"
2119c0e3d3aSJohn Baldwin.It Fa cb_buf
2129c0e3d3aSJohn BaldwinA pointer to the start of a
2139c0e3d3aSJohn Baldwin.Dv CRYPTO_BUF_CONTIG
2149c0e3d3aSJohn Baldwindata buffer.
2159c0e3d3aSJohn Baldwin.It Fa cb_buf_len
2169c0e3d3aSJohn BaldwinThe length of a
2179c0e3d3aSJohn Baldwin.Dv CRYPTO_BUF_CONTIG
2189c0e3d3aSJohn Baldwindata buffer
2199c0e3d3aSJohn Baldwin.It Fa cb_mbuf
2209c0e3d3aSJohn BaldwinA pointer to a
2219c0e3d3aSJohn Baldwin.Vt struct mbuf
2229c0e3d3aSJohn Baldwinfor
2239c0e3d3aSJohn Baldwin.Dv CRYPTO_BUF_MBUF .
2249c0e3d3aSJohn Baldwin.It Fa cb_uio
2259c0e3d3aSJohn BaldwinA pointer to a
2269c0e3d3aSJohn Baldwin.Vt struct uio
2279c0e3d3aSJohn Baldwinfor
2289c0e3d3aSJohn Baldwin.Dv CRYPTO_BUF_UIO .
229e6f6d0c9SAlan Somers.It Fa cb_vm_page
230e6f6d0c9SAlan SomersA pointer to an array of
231e6f6d0c9SAlan Somers.Vt struct vm_page
232e6f6d0c9SAlan Somersfor
233e6f6d0c9SAlan Somers.Dv CRYPTO_BUF_VMPAGE .
234e6f6d0c9SAlan Somers.It Fa cb_vm_page_len
235e6f6d0c9SAlan SomersThe total amount of data included in the
236e6f6d0c9SAlan Somers.Fa cb_vm_page
237e6f6d0c9SAlan Somersarray, in bytes.
238e6f6d0c9SAlan Somers.It Fa cb_vm_page_offset
239e6f6d0c9SAlan SomersOffset in bytes in the first page of
240e6f6d0c9SAlan Somers.Fa cb_vm_page
241e6f6d0c9SAlan Somerswhere valid data begins.
2429c0e3d3aSJohn Baldwin.El
2439c0e3d3aSJohn Baldwin.Ss Cursors
2449c0e3d3aSJohn BaldwinCursors provide a mechanism for iterating over a data buffer.
2459c0e3d3aSJohn BaldwinThey are primarily intended for use in software drivers which access data
2469c0e3d3aSJohn Baldwinbuffers via virtual addresses.
2479c0e3d3aSJohn Baldwin.Pp
2489c0e3d3aSJohn Baldwin.Fn crypto_cursor_init
2499c0e3d3aSJohn Baldwininitializes the cursor
2509c0e3d3aSJohn Baldwin.Fa cc
2519c0e3d3aSJohn Baldwinto reference the start of the data buffer
2529c0e3d3aSJohn Baldwin.Fa cb .
2539c0e3d3aSJohn Baldwin.Pp
2549c0e3d3aSJohn Baldwin.Fn crypto_cursor_advance
2559c0e3d3aSJohn Baldwinadvances the cursor
2569c0e3d3aSJohn Baldwin.Fa amount
2579c0e3d3aSJohn Baldwinbytes forward in the data buffer.
2589c0e3d3aSJohn Baldwin.Pp
2599c0e3d3aSJohn Baldwin.Fn crypto_cursor_copyback
2609c0e3d3aSJohn Baldwincopies
2619c0e3d3aSJohn Baldwin.Fa size
2629c0e3d3aSJohn Baldwinbytes from the local buffer pointed to by
2639c0e3d3aSJohn Baldwin.Fa src
2649c0e3d3aSJohn Baldwininto the data buffer associated with
2659c0e3d3aSJohn Baldwin.Fa cc .
2669c0e3d3aSJohn BaldwinThe bytes are written to the current position of
2679c0e3d3aSJohn Baldwin.Fa cc ,
2689c0e3d3aSJohn Baldwinand the cursor is then advanced by
2699c0e3d3aSJohn Baldwin.Fa size
2709c0e3d3aSJohn Baldwinbytes.
2719c0e3d3aSJohn Baldwin.Pp
2729c0e3d3aSJohn Baldwin.Fn crypto_cursor_copydata
2739c0e3d3aSJohn Baldwincopies
2749c0e3d3aSJohn Baldwin.Fa size
2759c0e3d3aSJohn Baldwinbytes out of the data buffer associated with
2769c0e3d3aSJohn Baldwin.Fa cc
2779c0e3d3aSJohn Baldwininto a local buffer pointed to by
2789c0e3d3aSJohn Baldwin.Fa dst .
2799c0e3d3aSJohn BaldwinThe bytes are read from the current position of
2809c0e3d3aSJohn Baldwin.Fa cc ,
2819c0e3d3aSJohn Baldwinand the cursor is then advanced by
2829c0e3d3aSJohn Baldwin.Fa size
2839c0e3d3aSJohn Baldwinbytes.
2849c0e3d3aSJohn Baldwin.Pp
2859c0e3d3aSJohn Baldwin.Fn crypto_cursor_copydata_noadv
2869c0e3d3aSJohn Baldwinis similar to
2879c0e3d3aSJohn Baldwin.Fn crypto_cursor_copydata
2889c0e3d3aSJohn Baldwinexcept that it does not change the current position of
2899c0e3d3aSJohn Baldwin.Fa cc .
2909c0e3d3aSJohn Baldwin.Pp
2919c0e3d3aSJohn Baldwin.Fn crypto_cursor_segbase
2929c0e3d3aSJohn Baldwinand
2939c0e3d3aSJohn Baldwin.Fn crypto_cursor_seglen
2949c0e3d3aSJohn Baldwinreturn the start and length, respectively,
2959c0e3d3aSJohn Baldwinof the virtually-contiguous segment at the current position of
2969c0e3d3aSJohn Baldwin.Fa cc .
2979c0e3d3aSJohn Baldwin.Sh RETURN VALUES
2989c0e3d3aSJohn Baldwin.Fn crypto_apply
2999c0e3d3aSJohn Baldwinand
3009c0e3d3aSJohn Baldwin.Fn crypto_apply_buf
3019c0e3d3aSJohn Baldwinreturn the return value from the caller-supplied callback function.
3029c0e3d3aSJohn Baldwin.Pp
3039c0e3d3aSJohn Baldwin.Fn crypto_buffer_contiguous_subsegment ,
3049c0e3d3aSJohn Baldwin.Fn crypto_contiguous_subsegment ,
3059c0e3d3aSJohn Baldwinand
3069c0e3d3aSJohn Baldwin.Fn crypto_cursor_segbase ,
3079c0e3d3aSJohn Baldwinreturn a pointer to a contiguous segment or
3089c0e3d3aSJohn Baldwin.Dv NULL .
3099c0e3d3aSJohn Baldwin.Pp
3109c0e3d3aSJohn Baldwin.Fn crypto_buffer_len
3119c0e3d3aSJohn Baldwinreturns the length of a buffer in bytes.
3129c0e3d3aSJohn Baldwin.Pp
3139c0e3d3aSJohn Baldwin.Fn crypto_cursor_seglen
3149c0e3d3aSJohn Baldwinreturns the length in bytes of a contiguous segment.
3159c0e3d3aSJohn Baldwin.Pp
3169c0e3d3aSJohn Baldwin.Fn CRYPTO_HAS_OUTPUT_BUFFER
3179c0e3d3aSJohn Baldwinreturns true if the request uses a separate output buffer.
3189c0e3d3aSJohn Baldwin.Sh SEE ALSO
3199c0e3d3aSJohn Baldwin.Xr ipsec 4 ,
3209c0e3d3aSJohn Baldwin.Xr crypto 7 ,
321*16694347SGordon Bergling.Xr bus_dma 9 ,
3229c0e3d3aSJohn Baldwin.Xr crypto 9 ,
3239c0e3d3aSJohn Baldwin.Xr crypto_driver 9 ,
324fade09c8SGordon Bergling.Xr crypto_request 9 ,
3259c0e3d3aSJohn Baldwin.Xr crypto_session 9 ,
326fade09c8SGordon Bergling.Xr mbuf 9 ,
3279c0e3d3aSJohn Baldwin.Xr uio 9
328