CRYPTO_BUFFER(9)
π NAME π
crypto_buffer β symmetric cryptographic request buffers. Welcome to CRYPTO_BUFFER(9) from the Kernel Developerβs Manual, bestie β this is the whole vibe for the lil buffer abstraction that symmetric crypto requests use. π¦
β¨ SYNOPSIS β¨
#include <opencrypto/cryptodev.h>
int
crypto_apply(struct cryptop *crp, int off, int len,
int (*f)(void *, void *, u_int), void *arg);
int
crypto_apply_buf(struct crypto_buffer *cb, int off, int len,
int (*f)(void *, void *, u_int), void *arg);
void *
crypto_buffer_contiguous_subsegment(struct crypto_buffer *cb,
size_t skip, size_t len);
size_t
crypto_buffer_len(struct crypto_buffer *cb);
void *
crypto_contiguous_subsegment(struct cryptop *crp, size_t skip,
size_t len);
void
crypto_cursor_init(struct crypto_buffer_cursor *cc,
const struct crypto_buffer *cb);
void
crypto_cursor_advance(struct crypto_buffer_cursor *cc, size_t amount);
void
crypto_cursor_copyback(struct crypto_buffer_cursor *cc, int size,
const void *src);
void
crypto_cursor_copydata(struct crypto_buffer_cursor *cc, int size,
void *dst);
void
crypto_cursor_copydata_noadv(struct crypto_buffer_cursor *cc, int size,
void *dst);
void *
crypto_cursor_segment(struct crypto_buffer_cursor *cc, size_t *len);
void
crypto_cursor_copy(const struct crypto_buffer_cursor *fromc,
struct crypto_buffer_cursor *toc);
bool
CRYPTO_HAS_OUTPUT_BUFFER(struct cryptop *crp);
π¦ DESCRIPTION π¦
Okay so symmetric cryptographic requests use data buffers to describe the data thatβs gonna be modified. A request can either specify a single data buffer whose contents are modified in place, or it can specify separate data buffers for input and output. struct crypto_buffer is the abstraction that lets crypto requests operate on different types of buffers. And struct crypto_cursor is what lets cryptographic drivers iterate over a data buffer. Main character energy, honestly. π
CRYPTO_HAS_OUTPUT_BUFFER() returns true if crp uses separate buffers for input and output, and false if crp uses a single buffer.
crypto_buffer_len() returns the length of data buffer cb in bytes.
crypto_apply_buf() invokes a caller-supplied function on a region of data buffer cb. The function f is called one or more times. For each invocation, the first argument to f is the value of arg passed to crypto_apply_buf(). The second and third arguments to f are a pointer and length to a segment of the buffer mapped into the kernel. The function is called enough times to cover the len bytes of the data buffer which starts at an offset off. If any invocation of f returns a non-zero value, crypto_apply_buf() immediately returns that value without invoking f on any remaining segments of the region; otherwise crypto_apply_buf() returns the value from the final call to f. crypto_apply() invokes the callback f on a region of the input data buffer for crp.
crypto_buffer_contiguous_subsegment() attempts to locate a single, virtually-contiguous segment of the data buffer cb. The segment must be len bytes long and start at an offset of skip bytes. If a segment is found, a pointer to the start of the segment is returned. Otherwise, NULL is returned. crypto_contiguous_subsegment() attempts to locate a single, virtually-contiguous segment in the input data buffer for crp.
π¦ Data Buffers π¦
Data buffers are described by an instance of struct crypto_buffer. The cb_type member contains the type of the data buffer. The following types are supported:
CRYPTO_BUF_NONEβ an invalid buffer. Itβs used to mark the output buffer when a crypto request uses a single data buffer.CRYPTO_BUF_CONTIGβ an array of bytes mapped into the kernelβs address space.CRYPTO_BUF_UIOβ a scatter/gather list of kernel buffers as described inuio(9).CRYPTO_BUF_MBUFβ a chain of network memory buffers as described inmbuf(9).CRYPTO_BUF_SINGLE_MBUFβ a single network memory buffer as described inmbuf(9).CRYPTO_BUF_VMPAGEβ a scatter/gather list ofvm_page_tstructures describing pages in the kernelβs address space. This buffer type is only available ifCRYPTO_HAS_VMPAGEistrue.
The structure also contains the following type-specific fields:
cb_bufβ a pointer to the start of aCRYPTO_BUF_CONTIGdata buffer.cb_buf_lenβ the length of aCRYPTO_BUF_CONTIGdata buffer.cb_mbufβ a pointer to astruct mbufforCRYPTO_BUF_MBUFandCRYPTO_BUF_SINGLE_MBUF.cb_uioβ a pointer to astruct uioforCRYPTO_BUF_UIO.cb_vm_pageβ a pointer to an array ofstruct vm_pageforCRYPTO_BUF_VMPAGE.cb_vm_page_lenβ the total amount of data included in thecb_vm_pagearray, in bytes.cb_vm_page_offsetβ offset in bytes in the first page ofcb_vm_pagewhere valid data begins.
π Cursors π
Cursors provide a mechanism for iterating over a data buffer. Theyβre primarily intended for use in software drivers which access data buffers via virtual addresses. Lowkey iconic. π«Ά
crypto_cursor_init()β initializes the cursorccto reference the start of the data buffercb.crypto_cursor_advance()β advances the cursoramountbytes forward in the data buffer.crypto_cursor_copyback()β copiessizebytes from the local buffer pointed to bysrcinto the data buffer associated withcc. The bytes are written to the current position ofcc, and the cursor is then advanced bysizebytes.crypto_cursor_copydata()β copiessizebytes out of the data buffer associated withccinto a local buffer pointed to bydst. The bytes are read from the current position ofcc, and the cursor is then advanced bysizebytes.crypto_cursor_copydata_noadv()β similar tocrypto_cursor_copydata()except that it does not change the current position ofcc.crypto_cursor_segment()β returns the start of the virtually-contiguous segment at the current position ofcc. The length of the segment is stored inlen.
π RETURN VALUES π
crypto_apply()andcrypto_apply_buf()return the return value from the caller-supplied callback function.crypto_buffer_contiguous_subsegment(),crypto_contiguous_subsegment(), andcrypto_cursor_segment()return a pointer to a contiguous segment orNULL.crypto_buffer_len()returns the length of a buffer in bytes.crypto_cursor_seglen()returns the length in bytes of a contiguous segment.crypto_cursor_copy()makes a deep copy of the cursorfromc. The two copies do not share any state and can thus be used independently.CRYPTO_HAS_OUTPUT_BUFFER()returnstrueif the request uses a separate output buffer.
π SEE ALSO π
ipsec(4)crypto(7)bus_dma(9)crypto(9)crypto_driver(9)crypto_request(9)crypto_session(9)mbuf(9)uio(9)
π HISTORY π
The crypto_buffer functions first appeared in FreeBSD 13. Periodt. β¨
π AUTHORS π
The crypto_buffer functions and this manual page were written by John Baldwin <jhb@FreeBSD.org>. π
Okay bestie, thatβs the whole vibe β this page is from Debian, dated February 11, 2022, and itβs the CRYPTO_BUFFER(9) manual. Bye and stay slay π β¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 2020, Chelsio Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms