]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Add support for optional separate output buffers to in-kernel crypto.
authorjhb <jhb@FreeBSD.org>
Mon, 25 May 2020 22:12:04 +0000 (22:12 +0000)
committerjhb <jhb@FreeBSD.org>
Mon, 25 May 2020 22:12:04 +0000 (22:12 +0000)
commit8f001f91aa996ed64d663bf792b0118fc90d5ce5
tree30ce1a860bcb9456d7c684bc82df9b370545b172
parent6aef78af13c3cb5f2bdf0355e2479fd225db0a99
Add support for optional separate output buffers to in-kernel crypto.

Some crypto consumers such as GELI and KTLS for file-backed sendfile
need to store their output in a separate buffer from the input.
Currently these consumers copy the contents of the input buffer into
the output buffer and queue an in-place crypto operation on the output
buffer.  Using a separate output buffer avoids this copy.

- Create a new 'struct crypto_buffer' describing a crypto buffer
  containing a type and type-specific fields.  crp_ilen is gone,
  instead buffers that use a flat kernel buffer have a cb_buf_len
  field for their length.  The length of other buffer types is
  inferred from the backing store (e.g. uio_resid for a uio).
  Requests now have two such structures: crp_buf for the input buffer,
  and crp_obuf for the output buffer.

- Consumers now use helper functions (crypto_use_*,
  e.g. crypto_use_mbuf()) to configure the input buffer.  If an output
  buffer is not configured, the request still modifies the input
  buffer in-place.  A consumer uses a second set of helper functions
  (crypto_use_output_*) to configure an output buffer.

- Consumers must request support for separate output buffers when
  creating a crypto session via the CSP_F_SEPARATE_OUTPUT flag and are
  only permitted to queue a request with a separate output buffer on
  sessions with this flag set.  Existing drivers already reject
  sessions with unknown flags, so this permits drivers to be modified
  to support this extension without requiring all drivers to change.

- Several data-related functions now have matching versions that
  operate on an explicit buffer (e.g. crypto_apply_buf,
  crypto_contiguous_subsegment_buf, bus_dma_load_crp_buf).

- Most of the existing data-related functions operate on the input
  buffer.  However crypto_copyback always writes to the output buffer
  if a request uses a separate output buffer.

- For the regions in input/output buffers, the following conventions
  are followed:
  - AAD and IV are always present in input only and their
    fields are offsets into the input buffer.
  - payload is always present in both buffers.  If a request uses a
    separate output buffer, it must set a new crp_payload_start_output
    field to the offset of the payload in the output buffer.
  - digest is in the input buffer for verify operations, and in the
    output buffer for compute operations.  crp_digest_start is relative
    to the appropriate buffer.

- Add a crypto buffer cursor abstraction.  This is a more general form
  of some bits in the cryptosoft driver that tried to always use uio's.
  However, compared to the original code, this avoids rewalking the uio
  iovec array for requests with multiple vectors.  It also avoids
  allocate an iovec array for mbufs and populating it by instead walking
  the mbuf chain directly.

- Update the cryptosoft(4) driver to support separate output buffers
  making use of the cursor abstraction.

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D24545
25 files changed:
share/man/man9/Makefile
share/man/man9/bus_dma.9
share/man/man9/crypto_buffer.9 [new file with mode: 0644]
share/man/man9/crypto_driver.9
share/man/man9/crypto_request.9
share/man/man9/crypto_session.9
sys/crypto/ccp/ccp.c
sys/dev/cxgbe/crypto/t4_crypto.c
sys/dev/hifn/hifn7751.c
sys/dev/safe/safe.c
sys/geom/eli/g_eli_crypto.c
sys/geom/eli/g_eli_integrity.c
sys/geom/eli/g_eli_privacy.c
sys/kern/subr_bus_dma.c
sys/kgssapi/krb5/kcrypto_aes.c
sys/netipsec/xform_ah.c
sys/netipsec/xform_esp.c
sys/netipsec/xform_ipcomp.c
sys/opencrypto/criov.c
sys/opencrypto/crypto.c
sys/opencrypto/cryptodev.c
sys/opencrypto/cryptodev.h
sys/opencrypto/cryptosoft.c
sys/opencrypto/ktls_ocf.c
sys/sys/bus_dma.h