Browse Source

Merge branch 'freebsd/current/master' into hardened/current/master

* freebsd/current/master:
  Use the real value of MK_TESTS_SUPPORT in _libraries.
  sys/netinet: remove spurious doubled ;s
  Some more uint32_t cleanups, no functional change.
  objdump: emit a deprecation notice at program start
  remove binutils ld leftovers
  Refactor driver and consumer interfaces for OCF (in-kernel crypto).
  [PowerPC] Fix LIB32WMAKEFLAGS definition
  loader.efi: conout->QueryMode() can fail to return screen dimensions
  loader: Fully reset terminal settings, not just colors
remotes/github/hardened/current/tmpfs_extattr
HardenedBSD Sync Service 4 months ago
parent
commit
7975f791c0
91 changed files with 8373 additions and 7958 deletions
  1. +2
    -1
      Makefile.inc1
  2. +5
    -0
      ObsoleteFiles.inc
  3. +2
    -0
      contrib/binutils/binutils/objdump.c
  4. +0
    -1
      gnu/usr.bin/binutils/Makefile
  5. +10
    -12
      share/man/man4/crypto.4
  6. +5
    -27
      share/man/man7/crypto.7
  7. +31
    -14
      share/man/man9/Makefile
  8. +18
    -3
      share/man/man9/bus_dma.9
  9. +89
    -664
      share/man/man9/crypto.9
  10. +178
    -0
      share/man/man9/crypto_asym.9
  11. +392
    -0
      share/man/man9/crypto_driver.9
  12. +419
    -0
      share/man/man9/crypto_request.9
  13. +245
    -0
      share/man/man9/crypto_session.9
  14. +2
    -1
      share/mk/bsd.compat.mk
  15. +13
    -5
      stand/efi/libefi/efi_console.c
  16. +6
    -0
      stand/forth/loader.4th
  17. +1
    -0
      stand/forth/loader.rc
  18. +3
    -0
      stand/forth/screen.4th
  19. +1
    -0
      stand/lua/core.lua
  20. +8
    -10
      stand/lua/loader.lua
  21. +360
    -474
      sys/crypto/aesni/aesni.c
  22. +7
    -7
      sys/crypto/aesni/aesni.h
  23. +21
    -37
      sys/crypto/aesni/aesni_wrap.c
  24. +82
    -162
      sys/crypto/armv8/armv8_crypto.c
  25. +90
    -125
      sys/crypto/blake2/blake2_cryptodev.c
  26. +219
    -249
      sys/crypto/ccp/ccp.c
  27. +10
    -9
      sys/crypto/ccp/ccp.h
  28. +102
    -132
      sys/crypto/ccp/ccp_hardware.c
  29. +52
    -88
      sys/crypto/via/padlock.c
  30. +5
    -5
      sys/crypto/via/padlock.h
  31. +57
    -67
      sys/crypto/via/padlock_cipher.c
  32. +68
    -50
      sys/crypto/via/padlock_hash.c
  33. +306
    -293
      sys/dev/cesa/cesa.c
  34. +0
    -5
      sys/dev/cesa/cesa.h
  35. +1
    -1
      sys/dev/cxgbe/adapter.h
  36. +589
    -710
      sys/dev/cxgbe/crypto/t4_crypto.c
  37. +7
    -33
      sys/dev/cxgbe/crypto/t4_keyctx.c
  38. +2
    -2
      sys/dev/cxgbe/tom/t4_tls.c
  39. +87
    -181
      sys/dev/glxsb/glxsb.c
  40. +2
    -4
      sys/dev/glxsb/glxsb.h
  41. +37
    -63
      sys/dev/glxsb/glxsb_hash.c
  42. +292
    -330
      sys/dev/hifn/hifn7751.c
  43. +4
    -11
      sys/dev/hifn/hifn7751var.h
  44. +396
    -519
      sys/dev/safe/safe.c
  45. +2
    -10
      sys/dev/safe/safevar.h
  46. +213
    -327
      sys/dev/sec/sec.c
  47. +5
    -13
      sys/dev/sec/sec.h
  48. +247
    -338
      sys/dev/ubsec/ubsec.c
  49. +1
    -9
      sys/dev/ubsec/ubsecvar.h
  50. +31
    -18
      sys/geom/eli/g_eli.c
  51. +20
    -0
      sys/geom/eli/g_eli.h
  52. +20
    -30
      sys/geom/eli/g_eli_crypto.c
  53. +99
    -84
      sys/geom/eli/g_eli_integrity.c
  54. +32
    -53
      sys/geom/eli/g_eli_privacy.c
  55. +51
    -0
      sys/kern/subr_bus_dma.c
  56. +3
    -0
      sys/kern/uipc_ktls.c
  57. +50
    -61
      sys/kgssapi/krb5/kcrypto_aes.c
  58. +24
    -31
      sys/kgssapi/krb5/kcrypto_des.c
  59. +52
    -58
      sys/kgssapi/krb5/kcrypto_des3.c
  60. +70
    -110
      sys/mips/cavium/cryptocteon/cavium_crypto.c
  61. +237
    -212
      sys/mips/cavium/cryptocteon/cryptocteon.c
  62. +2
    -10
      sys/mips/cavium/cryptocteon/cryptocteonvar.h
  63. +0
    -16
      sys/mips/nlm/dev/sec/nlmrsa.c
  64. +176
    -262
      sys/mips/nlm/dev/sec/nlmsec.c
  65. +72
    -53
      sys/mips/nlm/dev/sec/nlmseclib.c
  66. +12
    -10
      sys/mips/nlm/dev/sec/nlmseclib.h
  67. +2
    -2
      sys/mips/nlm/hal/nlmsaelib.h
  68. +1
    -1
      sys/netinet/ip_input.c
  69. +5
    -5
      sys/netinet/sctp_pcb.h
  70. +1
    -1
      sys/netinet/sctp_structs.h
  71. +5
    -6
      sys/netinet/sctp_timer.c
  72. +1
    -1
      sys/netinet/tcp_ratelimit.c
  73. +3
    -2
      sys/netipsec/xform.h
  74. +32
    -46
      sys/netipsec/xform_ah.c
  75. +67
    -106
      sys/netipsec/xform_esp.c
  76. +39
    -40
      sys/netipsec/xform_ipcomp.c
  77. +53
    -32
      sys/opencrypto/criov.c
  78. +865
    -444
      sys/opencrypto/crypto.c
  79. +333
    -226
      sys/opencrypto/cryptodev.c
  80. +94
    -56
      sys/opencrypto/cryptodev.h
  81. +112
    -6
      sys/opencrypto/cryptodev_if.m
  82. +903
    -802
      sys/opencrypto/cryptosoft.c
  83. +0
    -71
      sys/opencrypto/cryptosoft.h
  84. +33
    -62
      sys/opencrypto/ktls_ocf.c
  85. +3
    -3
      sys/opencrypto/xform_gmac.c
  86. +8
    -0
      sys/sys/bus_dma.h
  87. +1
    -1
      sys/sys/param.h
  88. +2
    -3
      tests/sys/opencrypto/cryptodev.py
  89. +0
    -3
      tests/sys/opencrypto/cryptodevh.py
  90. +1
    -7
      tests/sys/opencrypto/cryptotest.py
  91. +164
    -32
      tools/tools/crypto/cryptocheck.c

+ 2
- 1
Makefile.inc1 View File

@@ -1101,7 +1101,8 @@ _libraries:
@echo "--------------------------------------------------------------"
${_+_}cd ${.CURDIR}; \
${WMAKE} -DNO_FSCHG MK_HTML=no -DNO_LINT MK_MAN=no \
MK_PROFILE=no MK_TESTS=no MK_TESTS_SUPPORT=${MK_TESTS} libraries
MK_PROFILE=no MK_TESTS=no MK_TESTS_SUPPORT=${MK_TESTS_SUPPORT} \
libraries
everything: .PHONY
@echo
@echo "--------------------------------------------------------------"


+ 5
- 0
ObsoleteFiles.inc View File

@@ -36,6 +36,11 @@
# xargs -n1 | sort | uniq -d;
# done

# 20200327: OCF refactoring
OLD_FILES+=usr/share/man/man9/crypto_find_driver.9
OLD_FILES+=usr/share/man/man9/crypto_register.9
OLD_FILES+=usr/share/man/man9/crypto_unregister.9

# 20200323: INTERNALLIB don't install headers anymore
OLD_FILES+=usr/include/libelftc.h
OLD_FILES+=usr/include/libifconfig.h


+ 2
- 0
contrib/binutils/binutils/objdump.c View File

@@ -3248,6 +3248,8 @@ main (int argc, char **argv)
}
}

non_fatal (_("objdump 2.17.50 is deprecated in FreeBSD and will be removed"));

if (show_version)
print_version ("objdump");



+ 0
- 1
gnu/usr.bin/binutils/Makefile View File

@@ -19,7 +19,6 @@ SUBDIR.${MK_BINUTILS}+= as

SUBDIR_DEPEND_libbinutils=libbfd # for bfdver.h
SUBDIR_DEPEND_as=libbfd libiberty libopcodes
SUBDIR_DEPEND_ld=libbfd libiberty
SUBDIR_DEPEND_objdump=libbfd libiberty libbinutils libopcodes

.if !make(install)


+ 10
- 12
share/man/man4/crypto.4 View File

@@ -60,7 +60,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd December 17, 2019
.Dd March 27, 2020
.Dt CRYPTO 4
.Os
.Sh NAME
@@ -156,7 +156,7 @@ file desriptor.
The symmetric-key operation mode provides a context-based API
to traditional symmetric-key encryption (or privacy) algorithms,
or to keyed and unkeyed one-way hash (HMAC and MAC) algorithms.
The symmetric-key mode also permits fused operation,
The symmetric-key mode also permits encrypt-then-authenticate fused operation,
where the hardware performs both a privacy algorithm and an integrity-check
algorithm in a single pass over the data: either a fused
encrypt/HMAC-generate operation, or a fused HMAC-verify/decrypt operation.
@@ -314,16 +314,14 @@ supplies the length of the input buffer; the fields
.Fa cr_op-\*[Gt]iv
supply the addresses of the input buffer, output buffer,
one-way hash, and initialization vector, respectively.
If a session is using both a privacy algorithm and a hash algorithm,
the request will generate a hash of the input buffer before
generating the output buffer by default.
If the
.Dv COP_F_CIPHER_FIRST
flag is included in the
.Fa cr_op-\*[Gt]flags
field,
then the request will generate a hash of the output buffer after
executing the privacy algorithm.
.Pp
If a session is using either fused encrypt-then-authenticate or
an AEAD algorithm,
decryption operations require the associated hash as an input.
If the hash is incorrect, the
operation will fail with
.Dv EBADMSG
and the output buffer will remain unchanged.
.It Dv CIOCCRYPTAEAD Fa struct crypt_aead *cr_aead
.Bd -literal
struct crypt_aead {


+ 5
- 27
share/man/man7/crypto.7 View File

@@ -27,7 +27,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd January 2, 2015
.Dd March 27, 2020
.Dt CRYPTO 7
.Os
.Sh NAME
@@ -68,19 +68,13 @@ This algorithm implements Cipher-block chaining.
.El
.Pp
This algorithm implements Galois/Counter Mode.
This is the cipher part of an AEAD
This cipher uses AEAD
.Pq Authenticated Encryption with Associated Data
mode.
This requires use of the use of a proper authentication mode, one of
.Dv CRYPTO_AES_128_NIST_GMAC ,
.Dv CRYPTO_AES_192_NIST_GMAC
or
.Dv CRYPTO_AES_256_NIST_GMAC ,
that corresponds with the number of bits in the key that you are using.
.Pp
The associated data (if any) must be provided by the authentication mode op.
The authentication tag will be read/written from/to the offset crd_inject
specified in the descriptor for the authentication mode.
The authentication tag will be read/written from/to the offset
.Va crp_digest_start
specified in the request.
.Pp
Note: You must provide an IV on every call.
.It Dv CRYPTO_AES_ICM
@@ -118,22 +112,6 @@ as defined in NIST SP 800-38E.
NOTE: The ciphertext stealing part is not implemented which is why this cipher
is listed as having a block size of 16 instead of 1.
.El
.Pp
Authentication algorithms:
.Bl -tag -width ".Dv CRYPTO_AES_256_NIST_GMAC"
.It CRYPTO_AES_128_NIST_GMAC
See
.Dv CRYPTO_AES_NIST_GCM_16
in the cipher mode section.
.It CRYPTO_AES_192_NIST_GMAC
See
.Dv CRYPTO_AES_NIST_GCM_16
in the cipher mode section.
.It CRYPTO_AES_256_NIST_GMAC
See
.Dv CRYPTO_AES_NIST_GCM_16
in the cipher mode section.
.El
.Sh SEE ALSO
.Xr crypto 4 ,
.Xr crypto 9


+ 31
- 14
share/man/man9/Makefile View File

@@ -71,6 +71,10 @@ MAN= accept_filter.9 \
cr_seeothergids.9 \
cr_seeotheruids.9 \
crypto.9 \
crypto_asym.9 \
crypto_driver.9 \
crypto_request.9 \
crypto_session.9 \
CTASSERT.9 \
DB_COMMAND.9 \
DECLARE_GEOM_CLASS.9 \
@@ -889,20 +893,33 @@ MLINKS+=cpuset.9 CPUSET_T_INITIALIZER.9 \
cpuset.9 CPU_COPY_STORE_REL.9
MLINKS+=critical_enter.9 critical.9 \
critical_enter.9 critical_exit.9
MLINKS+=crypto.9 crypto_dispatch.9 \
crypto.9 crypto_done.9 \
crypto.9 crypto_freereq.9 \
crypto.9 crypto_freesession.9 \
crypto.9 crypto_get_driverid.9 \
crypto.9 crypto_getreq.9 \
crypto.9 crypto_kdispatch.9 \
crypto.9 crypto_kdone.9 \
crypto.9 crypto_kregister.9 \
crypto.9 crypto_newsession.9 \
crypto.9 crypto_register.9 \
crypto.9 crypto_unblock.9 \
crypto.9 crypto_unregister.9 \
crypto.9 crypto_unregister_all.9
MLINKS+=crypto_asym.9 crypto_kdispatch.9 \
crypto_asym.9 crypto_kdone.9 \
crypto_asym.9 crypto_kregister.9 \
crypto_asym.9 CRYPTODEV_KPROCESS.9
MLINKS+=crypto_driver.9 crypto_apply.9 \
crypto_driver.9 crypto_contiguous_segment.9 \
crypto_driver.9 crypto_copyback.9 \
crypto_driver.9 crypto_copydata.9 \
crypto_driver.9 crypto_done.9 \
crypto_driver.9 crypto_get_driverid.9 \
crypto_driver.9 crypto_get_driver_session.9 \
crypto_driver.9 crypto_unblock.9 \
crypto_driver.9 crypto_unregister_all.9 \
crypto_driver.9 CRYPTODEV_FREESESSION.9 \
crypto_driver.9 CRYPTODEV_NEWSESSION.9 \
crypto_driver.9 CRYPTODEV_PROBESESSION.9 \
crypto_driver.9 CRYPTODEV_PROCESS.9 \
crypto_driver.9 hmac_init_ipad.9 \
crypto_driver.9 hmac_init_opad.9
MLINKS+=crypto_request.9 crypto_dispatch.9 \
crypto_request.9 crypto_freereq.9 \
crypto_request.9 crypto_getreq.9
MLINKS+=crypto_session.9 crypto_auth_hash.9 \
crypto_session.9 crypto_cipher.9 \
crypto_session.9 crypto_get_params.9 \
crypto_session.9 crypto_newsession.9 \
crypto_session.9 crypto_freesession.9
MLINKS+=DB_COMMAND.9 DB_SHOW_ALL_COMMAND.9 \
DB_COMMAND.9 DB_SHOW_COMMAND.9
MLINKS+=DECLARE_MODULE.9 DECLARE_MODULE_TIED.9


+ 18
- 3
share/man/man9/bus_dma.9 View File

@@ -53,7 +53,7 @@
.\" $FreeBSD$
.\" $NetBSD: bus_dma.9,v 1.25 2002/10/14 13:43:16 wiz Exp $
.\"
.Dd August 11, 2018
.Dd March 27, 2020
.Dt BUS_DMA 9
.Os
.Sh NAME
@@ -68,6 +68,7 @@
.Nm bus_dmamap_load ,
.Nm bus_dmamap_load_bio ,
.Nm bus_dmamap_load_ccb ,
.Nm bus_dmamap_load_crp ,
.Nm bus_dmamap_load_mbuf ,
.Nm bus_dmamap_load_mbuf_sg ,
.Nm bus_dmamap_load_uio ,
@@ -118,6 +119,10 @@
"union ccb *ccb" "bus_dmamap_callback_t *callback" "void *callback_arg" \
"int flags"
.Ft int
.Fn bus_dmamap_load_crp "bus_dma_tag_t dmat" "bus_dmamap_t map" \
"struct crypto *crp" "bus_dmamap_callback_t *callback" "void *callback_arg" \
"int flags"
.Ft int
.Fn bus_dmamap_load_mbuf "bus_dma_tag_t dmat" "bus_dmamap_t map" \
"struct mbuf *mbuf" "bus_dmamap_callback2_t *callback" "void *callback_arg" \
"int flags"
@@ -387,9 +392,10 @@ the load of a
.Vt bus_dmamap_t
via
.Fn bus_dmamap_load ,
.Fn bus_dmamap_load_bio
.Fn bus_dmamap_load_bio ,
.Fn bus_dmamap_load_ccb ,
or
.Fn bus_dmamap_load_ccb .
.Fn bus_dmamap_load_crp .
Callbacks are of the format:
.Bl -tag -width indent
.It Ft void
@@ -879,6 +885,15 @@ XPT_CONT_TARGET_IO
.It
XPT_SCSI_IO
.El
.It Fn bus_dmamap_load_crp "dmat" "map" "crp" "callback" "callback_arg" "flags"
This is a variation of
.Fn bus_dmamap_load
which maps buffers pointed to by
.Fa crp
for DMA transfers.
The
.Dv BUS_DMA_NOWAIT
flag is implied, thus no callback deferral will happen.
.It Fn bus_dmamap_load_mbuf "dmat" "map" "mbuf" "callback2" "callback_arg" \
"flags"
This is a variation of


+ 89
- 664
share/man/man9/crypto.9 View File

@@ -17,7 +17,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd December 17, 2019
.Dd March 27, 2020
.Dt CRYPTO 9
.Os
.Sh NAME
@@ -25,120 +25,50 @@
.Nd API for cryptographic services in the kernel
.Sh SYNOPSIS
.In opencrypto/cryptodev.h
.Ft int32_t
.Fn crypto_get_driverid "device_t dev" "size_t session_size" "int flags"
.Ft int
.Fn crypto_register "uint32_t driverid" "int alg" "uint16_t maxoplen" "uint32_t flags"
.Ft int
.Fn crypto_kregister "uint32_t driverid" "int kalg" "uint32_t flags"
.Ft int
.Fn crypto_unregister "uint32_t driverid" "int alg"
.Ft int
.Fn crypto_unregister_all "uint32_t driverid"
.Ft void
.Fn crypto_done "struct cryptop *crp"
.Ft void
.Fn crypto_kdone "struct cryptkop *krp"
.Ft int
.Fn crypto_find_driver "const char *match"
.Ft int
.Fn crypto_newsession "crypto_session_t *cses" "struct cryptoini *cri" "int crid"
.Ft int
.Fn crypto_freesession "crypto_session_t cses"
.Ft int
.Fn crypto_dispatch "struct cryptop *crp"
.Ft int
.Fn crypto_kdispatch "struct cryptkop *krp"
.Ft int
.Fn crypto_unblock "uint32_t driverid" "int what"
.Ft "struct cryptop *"
.Fn crypto_getreq "int num"
.Ft void
.Fn crypto_freereq "struct cryptop *crp"
.Bd -literal
#define CRYPTO_SYMQ 0x1
#define CRYPTO_ASYMQ 0x2

#define EALG_MAX_BLOCK_LEN 16

struct cryptoini {
int cri_alg;
int cri_klen;
int cri_mlen;
caddr_t cri_key;
uint8_t cri_iv[EALG_MAX_BLOCK_LEN];
struct cryptoini *cri_next;
};

struct cryptodesc {
int crd_skip;
int crd_len;
int crd_inject;
int crd_flags;
struct cryptoini CRD_INI;
#define crd_iv CRD_INI.cri_iv
#define crd_key CRD_INI.cri_key
#define crd_alg CRD_INI.cri_alg
#define crd_klen CRD_INI.cri_klen
struct cryptodesc *crd_next;
};

struct cryptop {
TAILQ_ENTRY(cryptop) crp_next;
crypto_session_t crp_session;
int crp_ilen;
int crp_olen;
int crp_etype;
int crp_flags;
caddr_t crp_buf;
caddr_t crp_opaque;
struct cryptodesc *crp_desc;
int (*crp_callback) (struct cryptop *);
caddr_t crp_mac;
};

struct crparam {
caddr_t crp_p;
u_int crp_nbits;
};

#define CRK_MAXPARAM 8

struct cryptkop {
TAILQ_ENTRY(cryptkop) krp_next;
u_int krp_op; /* ie. CRK_MOD_EXP or other */
u_int krp_status; /* return status */
u_short krp_iparams; /* # of input parameters */
u_short krp_oparams; /* # of output parameters */
uint32_t krp_hid;
struct crparam krp_param[CRK_MAXPARAM];
int (*krp_callback)(struct cryptkop *);
};
.Ed
.Sh DESCRIPTION
.Nm
is a framework for drivers of cryptographic hardware to register with
the kernel so
.Dq consumers
(other kernel subsystems, and
users through the
is a framework for in-kernel cryptography.
It permits in-kernel consumers to encrypt and decrypt data
and also enables userland applications to use cryptographic hardware
through the
.Pa /dev/crypto
device) are able to make use of it.
Drivers register with the framework the algorithms they support,
and provide entry points (functions) the framework may call to
establish, use, and tear down sessions.
Sessions are used to cache cryptographic information in a particular driver
(or associated hardware), so initialization is not needed with every request.
Consumers of cryptographic services pass a set of
descriptors that instruct the framework (and the drivers registered
with it) of the operations that should be applied on the data (more
than one cryptographic operation can be requested).
.Pp
Keying operations are supported as well.
Unlike the symmetric operators described above,
these sessionless commands perform mathematical operations using
input and output parameters.
device.
.Pp
.Nm
supports two modes of operation:
one mode for symmetric-keyed cryptographic requests and digest,
and a second mode for asymmetric-key requests and modular arithmetic.
.Ss Symmetric-Key Mode
Symmetric-key operations include encryption and decryption operations
using block and stream ciphers as well as computation and verification
of message authentication codes (MACs).
In this mode,
consumers allocate sessions to describe a transform as discussed in
.Xr crypto_session 9 .
Consumers then allocate request objects to describe each transformation
such as encrypting a network packet or decrypting a disk sector.
Requests are described in
.Xr crypto_request 9 .
.Pp
Device drivers are responsible for processing requests submitted by
consumers.
.Xr crypto_driver 9
describes the interfaces drivers use to register with the framework,
helper routines the framework provides to faciliate request processing,
and the interfaces drivers are required to provide.
.Ss Asymmetric-Key Mode
Assymteric-key operations do not use sessions.
Instead,
these operations perform individual mathematical operations using a set
of input and output parameters.
These operations are described in
.Xr crypto_asym 9 .
Drivers that support asymmetric operations use additional interfaces
described in
.Xr crypto_asym 9
in addition to the base interfaces described in
.Xr crypto_driver 9 .
.Ss Callbacks
Since the consumers may not be associated with a process, drivers may
not
.Xr sleep 9 .
@@ -148,88 +78,38 @@ to notify a consumer that a request has been completed (the
callback is specified by the consumer on a per-request basis).
The callback is invoked by the framework whether the request was
successfully completed or not.
An error indication is provided in the latter case.
A specific error code,
Errors are reported to the callback function.
.Pp
Session initialization does not use callbacks and returns errors
synchronously.
.Ss Session Migration
For symmetric-key operations,
a specific error code,
.Er EAGAIN ,
is used to indicate that a session handle has changed and that the
request may be re-submitted immediately with the new session.
Errors are only returned to the invoking function if not
enough information to call the callback is available (meaning, there
was a fatal error in verifying the arguments).
For session initialization and teardown no callback mechanism is used.
.Pp
The
.Fn crypto_find_driver
returns the driver id of the device whose name matches
.Fa match .
.Fa match
can either be the exact name of a device including the unit
or the driver name without a unit.
In the latter case,
the id of the first device with the matching driver name is returned.
If no matching device is found,
the value -1 is returned.
.Pp
The
.Fn crypto_newsession
routine is called by consumers of cryptographic services (such as the
.Xr ipsec 4
stack) that wish to establish a new session with the framework.
The
.Fa cri
argument points to a
.Vt cryptoini
structure containing all the necessary information for
the driver to establish the session.
The
.Fa crid
argument is either a specific driver id or a bitmask of flags.
The flags are
.Dv CRYPTOCAP_F_HARDWARE ,
to select hardware devices,
or
.Dv CRYPTOCAP_F_SOFTWARE ,
to select software devices.
If both are specified, hardware devices are preferred over software
devices.
On success, the opaque session handle of the new session will be stored in
.Fa *cses .
The
.Vt cryptoini
structure pointed to by
.Fa cri
contains these fields:
.Bl -tag -width ".Va cri_next"
.It Va cri_alg
An algorithm identifier.
Currently supported algorithms are:
.Pp
.Bl -tag -width ".Dv CRYPTO_RIPEMD160_HMAC" -compact
.It Dv CRYPTO_AES_128_NIST_GMAC
.It Dv CRYPTO_AES_192_NIST_GMAC
.It Dv CRYPTO_AES_256_NIST_GMAC
.It Dv CRYPTO_AES_CBC
.It Dv CRYPTO_AES_CCM_16
The consumer should update its saved copy of the session handle
to the value of
.Fa crp_session
so that future requests use the new session.
.Ss Supported Algorithms
More details on some algorithms may be found in
.Xr crypto 7 .
These algorithms are used for symmetric-mode operations.
Asymmetric-mode operations support operations described in
.Xr crypto_asym 9 .
.Pp
The following authentication algorithms are supported:
.Pp
.Bl -tag -offset indent -width CRYPTO_AES_CCM_CBC_MAC -compact
.It Dv CRYPTO_AES_CCM_CBC_MAC
.It Dv CRYPTO_AES_ICM
.It Dv CRYPTO_AES_NIST_GCM_16
.It Dv CRYPTO_AES_NIST_GMAC
.It Dv CRYPTO_AES_XTS
.It Dv CRYPTO_ARC4
.It Dv CRYPTO_BLAKE2B
.It Dv CRYPTO_BLAKE2S
.It Dv CRYPTO_BLF_CBC
.It Dv CRYPTO_CAMELLIA_CBC
.It Dv CRYPTO_CAST_CBC
.It Dv CRYPTO_CHACHA20
.It Dv CRYPTO_DEFLATE_COMP
.It Dv CRYPTO_DES_CBC
.It Dv CRYPTO_3DES_CBC
.It Dv CRYPTO_MD5
.It Dv CRYPTO_MD5_HMAC
.It Dv CRYPTO_MD5_KPDK
.It Dv CRYPTO_NULL_HMAC
.It Dv CRYPTO_NULL_CBC
.It Dv CRYPTO_POLY1305
.It Dv CRYPTO_RIPEMD160
.It Dv CRYPTO_RIPEMD160_HMAC
@@ -244,488 +124,38 @@ Currently supported algorithms are:
.It Dv CRYPTO_SHA2_384_HMAC
.It Dv CRYPTO_SHA2_512
.It Dv CRYPTO_SHA2_512_HMAC
.It Dv CRYPTO_SKIPJACK_CBC
.El
.It Va cri_klen
For variable-size key algorithms, the length of the key in bits.
.It Va cri_mlen
If non-zero, truncate the calculated hash to this many bytes.
.It Va cri_key
The key to be used.
.It Va cri_iv
An explicit initialization vector if it does not prefix
the data.
This field is ignored during initialization
.Pq Nm crypto_newsession .
If no IV is explicitly passed (see below on details), a random IV is used
by the device driver processing the request.
.It Va cri_next
Pointer to another
.Vt cryptoini
structure.
This is used to establish dual-algorithm sessions, such as combining a
cipher with a MAC.
.El
.Pp
The
.Vt cryptoini
structure and its contents will not be modified or referenced by the
framework or any cryptographic drivers.
The memory associated with
.Fa cri
can be released once
.Fn crypto_newsession
returns.
The following encryption algorithms are supported:
.Pp
.Fn crypto_freesession
is called with the session handle returned by
.Fn crypto_newsession
to free the session.
.Pp
.Fn crypto_dispatch
is called to process a request.
The various fields in the
.Vt cryptop
structure are:
.Bl -tag -width ".Va crp_callback"
.It Va crp_session
The session handle.
.It Va crp_ilen
The total length in bytes of the buffer to be processed.
.It Va crp_olen
On return, contains the total length of the result.
For symmetric crypto operations, this will be the same as the input length.
This will be used if the framework needs to allocate a new
buffer for the result (or for re-formatting the input).
.It Va crp_callback
Callback routine invoked when a request is completed via
.Fn crypto_done .
The callback routine should inspect the
.Va crp_etype
to determine if the request was successfully completed.
.It Va crp_etype
The error type, if any errors were encountered, or zero if
the request was successfully processed.
If the
.Er EAGAIN
error code is returned, the session handle has changed (and has been recorded
in the
.Va crp_session
field).
The consumer should record the new session handle and use it in all subsequent
requests.
In this case, the request may be re-submitted immediately.
This mechanism is used by the framework to perform
session migration (move a session from one driver to another, because
of availability, performance, or other considerations).
.Pp
This field is only valid in the context of the callback routine specified by
.Va crp_callback .
Errors are returned to the invoker of
.Fn crypto_process
only when enough information is not present to call the callback
routine (i.e., if the pointer passed is
.Dv NULL
or if no callback routine was specified).
.It Va crp_flags
A bitmask of flags associated with this request.
Currently defined flags are:
.Bl -tag -width ".Dv CRYPTO_F_CBIFSYNC"
.It Dv CRYPTO_F_IMBUF
The buffer is an mbuf chain pointed to by
.Va crp_mbuf .
.It Dv CRYPTO_F_IOV
The buffer is a
.Vt uio
structure pointed to by
.Va crp_uio .
.It Dv CRYPTO_F_BATCH
Batch operation if possible.
.It Dv CRYPTO_F_CBIMM
Do callback immediately instead of doing it from a dedicated kernel thread.
.It Dv CRYPTO_F_DONE
Operation completed.
.It Dv CRYPTO_F_CBIFSYNC
Do callback immediately if operation is synchronous (that the driver
specified the
.Dv CRYPTOCAP_F_SYNC
flag).
.It Dv CRYPTO_F_ASYNC
Try to do the crypto operation in a pool of workers
if the operation is synchronous (that is, if the driver specified the
.Dv CRYPTOCAP_F_SYNC
flag).
It aims to speed up processing by dispatching crypto operations
on different processors.
.It Dv CRYPTO_F_ASYNC_KEEPORDER
Dispatch callbacks in the same order they are posted.
Only relevant if the
.Dv CRYPTO_F_ASYNC
flag is set and if the operation is synchronous.
.El
.It Va crp_buf
Data buffer unless
.Dv CRYPTO_F_IMBUF
or
.Dv CRYPTO_F_IOV
is set in
.Va crp_flags .
The length in bytes is set in
.Va crp_ilen .
.It Va crp_mbuf
Data buffer mbuf chain when
.Dv CRYPTO_F_IMBUF
is set in
.Va crp_flags .
.It Va crp_uio
.Vt struct uio
data buffer when
.Dv CRYPTO_F_IOV
is set in
.Va crp_flags .
.It Va crp_opaque
Cookie passed through the crypto framework untouched.
It is
intended for the invoking application's use.
.It Va crp_desc
A linked list of descriptors.
Each descriptor provides
information about what type of cryptographic operation should be done
on the input buffer.
The various fields are:
.Bl -tag -width ".Va crd_inject"
.It Va crd_iv
When the flag
.Dv CRD_F_IV_EXPLICIT
is set, this field contains the IV.
.It Va crd_key
When the
.Dv CRD_F_KEY_EXPLICIT
flag is set, the
.Va crd_key
points to a buffer with encryption or authentication key.
.It Va crd_alg
An algorithm to use.
Must be the same as the one given at newsession time.
.It Va crd_klen
The
.Va crd_key
key length.
.It Va crd_skip
The offset in the input buffer where processing should start.
.It Va crd_len
How many bytes, after
.Va crd_skip ,
should be processed.
.It Va crd_inject
The
.Va crd_inject
field specifies an offset in bytes from the beginning of the buffer.
For encryption algorithms, this may be where the IV will be inserted
when encrypting or where the IV may be found for
decryption (subject to
.Va crd_flags ) .
For MAC algorithms, this is where the result of the keyed hash will be
inserted.
.It Va crd_flags
The following flags are defined:
.Bl -tag -width 3n
.It Dv CRD_F_ENCRYPT
For encryption algorithms, this bit is set when encryption is required
(when not set, decryption is performed).
.It Dv CRD_F_IV_PRESENT
.\" This flag name has nothing to do w/ it's behavior, fix the name.
For encryption, if this bit is not set the IV used to encrypt the packet
will be written at the location pointed to by
.Va crd_inject .
The IV length is assumed to be equal to the blocksize of the
encryption algorithm.
For encryption, if this bit is set, nothing is done.
For decryption, this flag has no meaning.
Applications that do special
.Dq "IV cooking" ,
such as the half-IV mode in
.Xr ipsec 4 ,
can use this flag to indicate that the IV should not be written on the packet.
This flag is typically used in conjunction with the
.Dv CRD_F_IV_EXPLICIT
flag.
.It Dv CRD_F_IV_EXPLICIT
This bit is set when the IV is explicitly
provided by the consumer in the
.Va crd_iv
field.
Otherwise, for encryption operations the IV is provided for by
the driver used to perform the operation, whereas for decryption
operations the offset of the IV is provided by the
.Va crd_inject
field.
This flag is typically used when the IV is calculated
.Dq "on the fly"
by the consumer, and does not precede the data.
.It Dv CRD_F_KEY_EXPLICIT
For encryption and authentication (MAC) algorithms, this bit is set when the key
is explicitly provided by the consumer in the
.Va crd_key
field for the given operation.
Otherwise, the key is taken at newsession time from the
.Va cri_key
field.
As calculating the key schedule may take a while, it is recommended that often
used keys are given their own session.
.It Dv CRD_F_COMP
For compression algorithms, this bit is set when compression is required (when
not set, decompression is performed).
.El
.It Va CRD_INI
This
.Vt cryptoini
structure will not be modified by the framework or the device drivers.
Since this information accompanies every cryptographic
operation request, drivers may re-initialize state on-demand
(typically an expensive operation).
Furthermore, the cryptographic
framework may re-route requests as a result of full queues or hardware
failure, as described above.
.It Va crd_next
Point to the next descriptor.
Linked operations are useful in protocols such as
.Xr ipsec 4 ,
where multiple cryptographic transforms may be applied on the same
block of data.
.El
.Bl -tag -offset indent -width CRYPTO_CAMELLIA_CBC -compact
.It Dv CRYPTO_AES_CBC
.It Dv CRYPTO_AES_ICM
.It Dv CRYPTO_AES_XTS
.It Dv CRYPTO_ARC4
.It Dv CRYPTO_BLF_CBC
.It Dv CRYPTO_CAMELLIA_CBC
.It Dv CRYPTO_CAST_CBC
.It Dv CRYPTO_CHACHA20
.It Dv CRYPTO_DES_CBC
.It Dv CRYPTO_3DES_CBC
.It Dv CRYPTO_NULL_CBC
.It Dv CRYPTO_SKIPJACK_CBC
.El
.Pp
.Fn crypto_getreq
allocates a
.Vt cryptop
structure with a linked list of
.Fa num
.Vt cryptodesc
structures.
.Pp
.Fn crypto_freereq
deallocates a structure
.Vt cryptop
and any
.Vt cryptodesc
structures linked to it.
Note that it is the responsibility of the
callback routine to do the necessary cleanups associated with the
opaque field in the
.Vt cryptop
structure.
The following authenticated encryption with additional data (AEAD)
algorithms are supported:
.Pp
.Fn crypto_kdispatch
is called to perform a keying operation.
The various fields in the
.Vt cryptkop
structure are:
.Bl -tag -width ".Va krp_callback"
.It Va krp_op
Operation code, such as
.Dv CRK_MOD_EXP .
.It Va krp_status
Return code.
This
.Va errno Ns -style
variable indicates whether lower level reasons
for operation failure.
.It Va krp_iparams
Number of input parameters to the specified operation.
Note that each operation has a (typically hardwired) number of such parameters.
.It Va krp_oparams
Number of output parameters from the specified operation.
Note that each operation has a (typically hardwired) number of such parameters.
.It Va krp_kvp
An array of kernel memory blocks containing the parameters.
.It Va krp_hid
Identifier specifying which low-level driver is being used.
.It Va krp_callback
Callback called on completion of a keying operation.
.Bl -tag -offset indent -width CRYPTO_AES_NIST_GCM_16 -compact
.It Dv CRYPTO_AES_CCM_16
.It Dv CRYPTO_AES_NIST_GCM_16
.El
.Sh DRIVER-SIDE API
The
.Fn crypto_get_driverid ,
.Fn crypto_get_driver_session ,
.Fn crypto_register ,
.Fn crypto_kregister ,
.Fn crypto_unregister ,
.Fn crypto_unblock ,
and
.Fn crypto_done
routines are used by drivers that provide support for cryptographic
primitives to register and unregister with the kernel crypto services
framework.
.Pp
Drivers must first use the
.Fn crypto_get_driverid
function to acquire a driver identifier, specifying the
.Fa flags
as an argument.
One of
.Dv CRYPTOCAP_F_SOFTWARE
or
.Dv CRYPTOCAP_F_HARDWARE
must be specified.
The
.Dv CRYPTOCAP_F_SYNC
may also be specified, and should be specified if the driver does all of
it's operations synchronously.
Drivers must pass the size of their session structure as the second argument.
An appropriately sized memory will be allocated by the framework, zeroed, and
passed to the driver's
.Fn newsession
method.
.Pp
For each algorithm the driver supports, it must then call
.Fn crypto_register .
The first two arguments are the driver and algorithm identifiers.
The next two arguments specify the largest possible operator length (in bits,
important for public key operations) and flags for this algorithm.
.Pp
.Fn crypto_unregister
is called by drivers that wish to withdraw support for an algorithm.
The two arguments are the driver and algorithm identifiers, respectively.
Typically, drivers for
PCMCIA
crypto cards that are being ejected will invoke this routine for all
algorithms supported by the card.
.Fn crypto_unregister_all
will unregister all algorithms registered by a driver
and the driver will be disabled (no new sessions will be allocated on
that driver, and any existing sessions will be migrated to other
drivers).
The same will be done if all algorithms associated with a driver are
unregistered one by one.
After a call to
.Fn crypto_unregister_all
there will be no threads in either the newsession or freesession function
of the driver.
.Pp
The calling convention for the driver-supplied routines are:
The following compression algorithms are supported:
.Pp
.Bl -item -compact
.It
.Ft int
.Fn \*[lp]*newsession\*[rp] "device_t" "crypto_session_t" "struct cryptoini *" ;
.It
.Ft void
.Fn \*[lp]*freesession\*[rp] "device_t" "crypto_session_t" ;
.It
.Ft int
.Fn \*[lp]*process\*[rp] "device_t" "struct cryptop *" "int" ;
.It
.Ft int
.Fn \*[lp]*kprocess\*[rp] "device_t" "struct cryptkop *" "int" ;
.Bl -tag -offset indent -width CRYPTO_DEFLATE_COMP -compact
.It Dv CRYPTO_DEFLATE_COMP
.El
.Pp
On invocation, the first argument to
all routines is the
.Fa device_t
that was provided to
.Fn crypto_get_driverid .
The second argument to
.Fn newsession
is the opaque session handle for the new session.
The third argument is identical to that of
.Fn crypto_newsession .
.Pp
Drivers obtain a pointer to their session memory by invoking
.Fn crypto_get_driver_session
on the opaque
.Vt crypto_session_t
handle.
.Pp
The
.Fn freesession
routine takes as arguments the opaque data value and the session handle.
It should clear any context associated with the session (clear hardware
registers, memory, etc.).
If no resources need to be released other than the contents of session memory,
the method is optional.
The
.Nm
framework will zero and release the allocated session memory (after running the
.Fn freesession
method, if one exists).
.Pp
The
.Fn process
routine is invoked with a request to perform crypto processing.
This routine must not block or sleep, but should queue the request and return
immediately or process the request to completion.
In case of an unrecoverable error, the error indication must be placed in the
.Va crp_etype
field of the
.Vt cryptop
structure.
When the request is completed, or an error is detected, the
.Fn process
routine must invoke
.Fn crypto_done .
Session migration may be performed, as mentioned previously.
.Pp
In case of a temporary resource exhaustion, the
.Fn process
routine may return
.Er ERESTART
in which case the crypto services will requeue the request, mark the driver
as
.Dq blocked ,
and stop submitting requests for processing.
The driver is then responsible for notifying the crypto services
when it is again able to process requests through the
.Fn crypto_unblock
routine.
This simple flow control mechanism should only be used for short-lived
resource exhaustion as it causes operations to be queued in the crypto
layer.
Doing so is preferable to returning an error in such cases as
it can cause network protocols to degrade performance by treating the
failure much like a lost packet.
.Pp
The
.Fn kprocess
routine is invoked with a request to perform crypto key processing.
This routine must not block, but should queue the request and return
immediately.
Upon processing the request, the callback routine should be invoked.
In case of an unrecoverable error, the error indication must be placed in the
.Va krp_status
field of the
.Vt cryptkop
structure.
When the request is completed, or an error is detected, the
.Fn kprocess
routine should invoked
.Fn crypto_kdone .
.Sh RETURN VALUES
.Fn crypto_register ,
.Fn crypto_kregister ,
.Fn crypto_unregister ,
.Fn crypto_newsession ,
.Fn crypto_freesession ,
and
.Fn crypto_unblock
return 0 on success, or an error code on failure.
.Fn crypto_get_driverid
returns a non-negative value on error, and \-1 on failure.
.Fn crypto_getreq
returns a pointer to a
.Vt cryptop
structure and
.Dv NULL
on failure.
.Fn crypto_dispatch
returns
.Er EINVAL
if its argument or the callback function was
.Dv NULL ,
and 0 otherwise.
The callback is provided with an error code in case of failure, in the
.Va crp_etype
field.
.Sh FILES
.Bl -tag -width ".Pa sys/opencrypto/crypto.c"
.It Pa sys/opencrypto/crypto.c
@@ -735,7 +165,10 @@ most of the framework code
.Xr crypto 4 ,
.Xr ipsec 4 ,
.Xr crypto 7 ,
.Xr malloc 9 ,
.Xr crypto_asym 9 ,
.Xr crypto_driver 9 ,
.Xr crypto_request 9 ,
.Xr crypto_session 9 ,
.Xr sleep 9
.Sh HISTORY
The cryptographic framework first appeared in
@@ -743,14 +176,6 @@ The cryptographic framework first appeared in
and was written by
.An Angelos D. Keromytis Aq Mt angelos@openbsd.org .
.Sh BUGS
The framework currently assumes that all the algorithms in a
.Fn crypto_newsession
operation must be available by the same driver.
If that is not the case, session initialization will fail.
.Pp
The framework also needs a mechanism for determining which driver is
The framework needs a mechanism for determining which driver is
best for a specific set of algorithms associated with a session.
Some type of benchmarking is in order here.
.Pp
Multiple instances of the same algorithm in the same session are not
supported.

+ 178
- 0
share/man/man9/crypto_asym.9 View File

@@ -0,0 +1,178 @@
.\" Copyright (c) 2020, Chelsio Inc
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions are met:
.\"
.\" 1. Redistributions of source code must retain the above copyright notice,
.\" this list of conditions and the following disclaimer.
.\"
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" 3. Neither the name of the Chelsio Inc nor the names of its
.\" contributors may be used to endorse or promote products derived from
.\" this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
.\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.\" * Other names and brands may be claimed as the property of others.
.\"
.\" $FreeBSD$
.\"
.Dd March 27, 2020
.Dt CRYPTO_ASYM 9
.Os
.Sh NAME
.Nm crypto_asym
.Nd asymmetric cryptographic operations
.Sh SYNOPSIS
.In opencrypto/cryptodev.h
.Ft int
.Fn crypto_kdispatch "struct cryptkop *krp"
.Ft void
.Fn crypto_kdone "struct cryptkop *krp"
.Ft int
.Fn crypto_kregister "uint32_t driverid" "int kalg" "uint32_t flags"
.Ft int
.Fn CRYPTODEV_KPROCESS "device_t dev" "struct cryptop *krp" "int flags"
.Sh DESCRIPTION
The in-kernel cryptographic kernel framework supports asymmetric
requests (keying requests) in addition to symmetric operations.
There are currently no in-kernel users of these requests,
but applications can make requests of hardware drivers via the
.Pa /dev/crypto
device .
.Pp
Some APIs are shared with the framework's symmetric request support.
This manual describes the APIs and data structures unique to
asymmetric requests.
.Pp
.Ss Request Objects
A request is described by a
.Vt struct cryptkop
containing the following fields:
.Bl -tag -width "krp_callback"
.It Fa krp_op
Operation to perform.
Available operations include
.Dv CRK_MOD_EXP ,
.Dv CRK_MOD_EXP_CRT ,
.Dv CRK_DSA_SIGN ,
.Dv CRK_DSA_VERIFY ,
and
.Dv CRK_DH_COMPUTE_KEY .
.It Fa krp_status
Error status.
Either zero on success,
or an error if an operation fails.
Set by drivers prior to completing a request via
.Fn crypto_kdone .
.It Fa krp_iparams
Count of input parameters.
.It Fa krp_oparams
Count of output parameters.
.It Fa krp_crid
Requested device.
.It Fa krp_hid
Device used to complete the request.
.It Fa krp_param
Array of parameters.
The array contains the input parameters first followed by the output
parameters.
Each parameter is stored as a bignum.
Each bignum is described by a
.Vt struct crparam
containing the following fields:
.Bl -tag -width "crp_nbits"
.It Fa crp_p
Pointer to array of packed bytes.
.It Fa crp_nbits
Size of bignum in bits.
.El
.It Fa krp_callback
Callback function.
This must point to a callback function of type
.Vt void (*)(struct cryptkop *) .
The callback function should inspect
.Fa krp_status
to determine the status of the completed operation.
.El
.Pp
New requests should be initialized to zero before setting fields to
appropriate values.
Once the request has been populated,
it should be passed to
.Fn crypto_kdispatch .
.Pp
.Fn crypto_kdispatch
will choose a device driver to perform the operation described by
.Fa krp
and invoke that driver's
.Fn CRYPTO_KPROCESS
method.
.Ss Driver API
Drivers register support for asymmetric operations by calling
.Fn crypto_kregister
for each supported algorithm.
.Fa driverid
should be the value returned by an earlier call to
.Fn crypto_get_driverid .
.Fa kalg
should list one of the operations that can be set in
.Fa krp_op .
.Fa flags
is a bitmask of zero or more of the following values:
.Bl -tag -width "CRYPTO_ALG_FLAG_RNG_ENABLE"
.It Dv CRYPTO_ALG_FLAG_RNG_ENABLE
Device has a hardware RNG for DH/DSA.
.It Dv CRYPTO_ALG_FLAG_DSA_SHA
Device can compute a SHA digest of a message.
.El
.Pp
Drivers unregister with the framework via
.Fn crypto_unregister_all .
.Pp
Similar to
.Fn CRYPTO_PROCESS ,
.Fn CRYPTO_KPROCESS
should complete the request or schedule it for asynchronous
completion.
If this method is not able to complete a request due to insufficient
resources,
it can defer the request (and future asymmetric requests) by returning
.Dv ERESTART .
Once resources are available,
the driver should invoke
.Fn crypto_unblock
with
.Dv CRYPTO_ASYMQ
to resume processing of asymmetric requests.
.Pp
Once a request is completed,
the driver should set
.Fa krp_status
and then call
.Fn crypto_kdone .
.Sh RETURN VALUES
.Fn crypto_kdispatch ,
.Fn crypto_kregister ,
and
.Fn CRYPTODEV_KPROCESS
return zero on success or an error on failure.
.Sh SEE ALSO
.Xr crypto 7 ,
.Xr crypto 9 ,
.Xr crypto_driver 9 ,
.Xr crypto_request 9 ,
.Xr crypto_session 9

+ 392
- 0
share/man/man9/crypto_driver.9 View File

@@ -0,0 +1,392 @@
.\" Copyright (c) 2020, Chelsio Inc
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions are met:
.\"
.\" 1. Redistributions of source code must retain the above copyright notice,
.\" this list of conditions and the following disclaimer.
.\"
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" 3. Neither the name of the Chelsio Inc nor the names of its
.\" contributors may be used to endorse or promote products derived from
.\" this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
.\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.\" * Other names and brands may be claimed as the property of others.
.\"
.\" $FreeBSD$
.\"
.Dd March 27, 2020
.Dt CRYPTO_DRIVER 9
.Os
.Sh NAME
.Nm crypto_driver
.Nd interface for symmetric cryptographic drivers
.Sh SYNOPSIS
.In opencrypto/cryptodev.h
.Ft int
.Fo crypto_apply
.Fa "struct cryptop *crp"
.Fa "int off"
.Fa "int len"
.Fa "int (*f)(void *, void *, u_int)"
.Fa "void *arg"
.Fc
.Ft void *
.Fo crypto_contiguous_subsegment
.Fa "struct cryptop *crp"
.Fa "size_t skip"
.Fa "size_t len"
.Fc
.Ft void
.Fn crypto_copyback "struct cryptop *crp" "int off" "int size" "const void *src"
.Ft void
.Fn crypto_copydata "struct cryptop *crp" "int off" "int size" "void *dst"
.Ft void
.Fn crypto_done "struct cryptop *crp"
.Ft int32_t
.Fn crypto_get_driverid "device_t dev" "size_t session_size" "int flags"
.Ft void *
.Fn crypto_get_driver_session "crypto_session_t crypto_session"
.Ft int
.Fn crypto_unblock "uint32_t driverid" "int what"
.Ft int
.Fn crypto_unregister_all "uint32_t driverid"
.Ft int
.Fn CRYPTODEV_FREESESSION "device_t dev" "crypto_session_t crypto_session"
.Ft int
.Fo CRYPTODEV_NEWSESSION
.Fa "device_t dev"
.Fa "crypto_session_t crypto_session"
.Fa "const struct crypto_session_params *csp"
.Fc
.Ft int
.Fo CRYPTODEV_PROBESESSION
.Fa "device_t dev"
.Fa "const struct crypto_session_params *csp"
.Fc
.Ft int
.Fn CRYPTODEV_PROCESS "device_t dev" "struct cryptop *crp" "int flags"
.Ft void
.Fo hmac_init_ipad
.Fa "struct auth_hash *axf"
.Fa "const char *key"
.Fa "int klen"
.Fa "void *auth_ctx"
.Fc
.Ft void
.Fo hmac_init_opad
.Fa "struct auth_hash *axf"
.Fa "const char *key"
.Fa "int klen"
.Fa "void *auth_ctx"
.Fc
.Sh DESCRIPTION
Symmetric cryptographic drivers process cryptographic requests
submitted to sessions associated with the driver.
.Pp
Cryptographic drivers call
.Fn crypto_get_driverid
to register with the cryptographic framework.
.Fa dev
is the device used to service requests.
The
.Fn CRYPTODEV
methods are defined in the method table for the device driver attached to
.Fa dev .
.Fa session_size
specifies the size of a driver-specific per-session structure allocated by
the cryptographic framework.
.Fa flags
is a bitmask of properties about the driver.
Exactly one of
.Dv CRYPTOCAP_F_SOFTWARE
or
.Dv CRYPTOCAP_F_HARDWARE
must be specified.
.Dv CRYPTOCAP_F_SOFTWARE
should be used for drivers which process requests using host CPUs.
.Dv CRYPTOCAP_F_HARDWARE
should be used for drivers which process requests on separate co-processors.
.Dv CRYPTOCAP_F_SYNC
should be set for drivers which process requests synchronously in
.Fn CRYPTODEV_PROCESS .
.Fn crypto_get_driverid
returns an opaque driver id.
.Pp
.Fn crypto_unregister_all
unregisters a driver from the cryptographic framework.
If there are any pending operations or open sessions,
this function will sleep.
.Fa driverid
is the value returned by an earlier call to
.Fn crypto_get_driverid .
.Pp
When a new session is created by
.Fn crypto_newsession ,
.Fn CRYPTODEV_PROBESESSION
is invoked by the cryptographic framework on each active driver to
determine the best driver to use for the session.
This method should inspect the session parameters in
.Fa csp .
If a driver does not support requests described by
.Fa csp ,
this method should return an error value.
If the driver does support requests described by
.Fa csp ,
it should return a negative value.
The framework prefers drivers with the largest negative value,
similar to
.Xr DEVICE_PROBE 9 .
The following values are defined for non-error return values from this
method:
.Bl -tag -width "CRYPTODEV_PROBE_ACCEL_SOFTWARE"
.It Dv CRYPTODEV_PROBE_HARDWARE
The driver processes requests via a co-processor.
.It Dv CRYPTODEV_PROBE_ACCEL_SOFTWARE
The driver processes requests on the host CPU using optimized instructions
such as AES-NI.
.It Dv CRYPTODEV_PROBE_SOFTWARE
The driver processes requests on the host CPU.
.El
.Pp
This method should not sleep.
.Pp
Once the framework has chosen a driver for a session,
the framework invokes the
.Fn CRYPTODEV_NEWSESSION
method to initialize driver-specific session state.
Prior to calling this method,
the framework allocates a per-session driver-specific data structure.
This structure is initialized with zeroes,
and its size is set by the
.Fa session_size
passed to
.Fn crypto_get_driverid .
This method can retrieve a pointer to this data structure by passing
.Fa crypto_session
to
.Fn crypto_get_driver_session .
Session parameters are described in
.Fa csp .
.Pp
This method should not sleep.
.Pp
.Fn CRYPTODEV_FREESESSION
is invoked to release any driver-specific state when a session is
destroyed.
The per-session driver-specific data structure is explicitly zeroed
and freed by the framework after this method returns.
If a driver requires no additional tear-down steps, it can leave
this method undefined.
.Pp
This method should not sleep.
.Pp
.Fn CRYPTODEV_PROCESS
is invoked for each request submitted to an active session.
This method can either complete a request synchronously or
schedule it to be completed asynchronously,
but it must not sleep.
.Pp
If this method is not able to complete a request due to insufficient
resources such as a full command queue,
it can defer the request by returning
.Dv ERESTART .
The request will be queued by the framework and retried once the
driver releases pending requests via
.Fn crypto_unblock .
Any requests submitted to sessions belonging to the driver will also
be queued until
.Fn crypto_unblock
is called.
.Pp
If a driver encounters errors while processing a request,
it should report them via the
.Fa crp_etype
field of
.Fa crp
rather than returning an error directly.
.Pp
.Fa flags
may be set to
.Dv CRYPTO_HINT_MORE
if there are additional requests queued for this driver.
The driver can use this as a hint to batch completion interrupts.
Note that these additional requests may be from different sessions.
.Pp
.Fn crypto_get_driver_session
returns a pointer to the driver-specific per-session data structure
for the session
.Fa crypto_session .
This function can be used in the
.Fn CRYPTODEV_NEWSESSION ,
.Fn CRYPTODEV_PROCESS ,
and
.Fn CRYPTODEV_FREESESSION
callbacks.
.Pp
.Fn crypto_copydata
copies
.Fa size
bytes out of the data buffer for
.Fa crp
into a local buffer pointed to by
.Fa dst .
The bytes are read starting at an offset of
.Fa off
bytes in the request's data buffer.
.Pp
.Fn crypto_copyback
copies
.Fa size
bytes from the local buffer pointed to by
.Fa src
into the data buffer for
.Fa crp .
The bytes are written starting at an offset of
.Fa off
bytes in the request's data buffer.
.Pp
A driver calls
.Fn crypto_done
to mark the request
.Fa crp
as completed.
Any errors should be set in
.Fa crp_etype
prior to calling this function.
.Pp
If a driver defers a request by returning
.Dv ERESTART
from
.Dv CRYPTO_PROCESS ,
the framework will queue all requests for the driver until the driver calls
.Fn crypto_unblock
to indicate that the temporary resource shortage has been relieved.
For example,
if a driver returns
.Dv ERESTART
due to a full command ring,
it would invoke
.Fn crypto_unblock
from a command completion interrupt that makes a command ring entry available.
.Fa driverid
is the value returned by
.Fn crypto_get_driverid .
.Fa what
indicates which types of requests the driver is able to handle again:
.Bl -tag -width "CRYPTO_ASYMQ"
.It Dv CRYPTO_SYMQ
indicates that the driver is able to handle symmetric requests passed to
.Fn CRYPTODEV_PROCESS .
.It Dv CRYPTO_ASYMQ
indicates that the driver is able to handle asymmetric requests passed to
.Fn CRYPTODEV_KPROCESS .
.El
.Pp
.Fn crypto_apply
is a helper routine that can be used to invoke a caller-supplied function
to a region of the data buffer for
.Fa crp .
The function
.Fa f
is called one or more times.
For each invocation,
the first argument to
.Fa f
is the value of
.Fa arg passed to
.Fn crypto_apply .
The second and third arguments to
.Fa 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
.Fa len
bytes of the data buffer which starts at an offset
.Fa off .
If any invocation of
.Fa f
returns a non-zero value,
.Fn crypto_apply
immediately returns that value without invoking
.Fa f
on any remaining segments of the region,
otherwise
.Fn crypto_apply
returns the value from the final call to
.Fa f .
.Pp
.Fn crypto_contiguous_subsegment
attempts to locate a single, virtually-contiguous segment of the data buffer
for
.Fa crp .
The segment must be
.Fa len
bytes long and start at an offset of
.Fa skip
bytes.
If a segment is found,
a pointer to the start of the segment is returned.
Otherwise,
.Dv NULL
is returned.
.Pp
.Fn hmac_init_ipad
prepares an authentication context to generate the inner hash of an HMAC.
.Fa axf
is a software implementation of an authentication algorithm such as the
value returned by
.Fn crypto_auth_hash .
.Fa key
is a pointer to a HMAC key of
.Fa klen
bytes.
.Fa auth_ctx
points to a valid authentication context for the desired algorithm.
The function initializes the context with the supplied key.
.Pp
.Fn hmac_init_opad
is similar to
.Fn hmac_init_ipad
except that it prepares an authentication context to generate the
outer hash of an HMAC.
.Sh RETURN VALUES
.Fn crypto_apply
returns the return value from the caller-supplied callback function.
.Pp
.Fn crypto_contiguous_subsegment
returns a pointer to a contiguous segment or
.Dv NULL .
.Pp
.Fn crypto_get_driverid
returns a driver identifier on success or -1 on error.
.Pp
.Fn crypto_unblock ,
.Fn crypto_unregister_all ,
.Fn CRYPTODEV_FREESESSION ,
.Fn CRYPTODEV_NEWSESSION ,
and
.Fn CRYPTODEV_PROCESS
return zero on success or an error on failure.
.Pp
.Fn CRYPTODEV_PROBESESSION
returns a negative value on success or an error on failure.
.Sh SEE ALSO
.Xr crypto 7 ,
.Xr crypto 9 ,
.Xr crypto_request 9 ,
.Xr crypto_session 9

+ 419
- 0
share/man/man9/crypto_request.9 View File

@@ -0,0 +1,419 @@
.\" Copyright (c) 2020, Chelsio Inc
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions are met:
.\"
.\" 1. Redistributions of source code must retain the above copyright notice,
.\" this list of conditions and the following disclaimer.
.\"
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" 3. Neither the name of the Chelsio Inc nor the names of its
.\" contributors may be used to endorse or promote products derived from
.\" this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
.\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.\" * Other names and brands may be claimed as the property of others.
.\"
.\" $FreeBSD$
.\"
.Dd March 27, 2020
.Dt CRYPTO_REQUEST 9
.Os
.Sh NAME
.Nm crypto_request
.Nd symmetric cryptographic operations
.Sh SYNOPSIS
.In opencrypto/cryptodev.h
.Ft int
.Fn crypto_dispatch "struct cryptop *crp"
.Ft void
.Fn crypto_freereq "struct cryptop *crp"
.Ft "struct cryptop *"
.Fn crypto_getreq "crypto_session_t cses" "int how"
.Sh DESCRIPTION
Each symmetric cryptographic operation in the kernel is described by
an instance of
.Vt struct cryptop
and is associated with an active session.
.Pp
New requests are allocated by
.Fn crypto_getreq .
.Fa cses
is a reference to an active session.
.Fa how
is passed to
.Xr malloc 9
and should be set to either
.Dv M_NOWAIT
or
.Dv M_WAITOK .
The caller should then set fields in the returned structure to describe
request-specific parameters.
Unused fields should be left as-is.
.Pp
.Fn crypto_dispatch
passes a crypto request to the driver attached to the request's session.
If there are errors in the request's fields, this function may return
an error to the caller.
If errors are encountered while servicing the request, they will instead
be reported to the request's callback function
.Pq Fa crp_callback
via
.Fa crp_etype .
.Pp
Note that a request's callback function may be invoked before
.Fn crypto_dispatch
returns.
.Pp
Once a request has signaled completion by invoking its callback function,
it should be feed via
.Fn crypto_freereq .
.Pp
Cryptographic operations include several fields to describe the request.
.Ss Buffer Types
Requests are associated with a single data buffer that is modified in place.
The type of the data buffer and the buffer itself are described by the
following fields:
.Bl -tag -width crp_buf_type
.It Fa crp_buf_type
The type of the data buffer.
The following types are supported:
.Bl -tag -width CRYPTO_BUF_CONTIG
.It Dv CRYPTO_BUF_CONTIG
An array of bytes mapped into the kernel's address space.
.It Dv CRYPTO_BUF_UIO
A scatter/gather list of kernel buffers as described in
.Xr uio 9 .
.It Dv CRYPTO_BUF_MBUF
A network memory buffer as described in
.Xr mbuf 9 .
.El
.It Fa crp_buf
A pointer to the start of a
.Dv CRYPTO_BUF_CONTIG
data buffer.
.It Fa crp_ilen
The length of a
.Dv CRYPTO_BUF_CONTIG
data buffer
.It Fa crp_mbuf
A pointer to a
.Vt struct mbuf
for
.Dv CRYPTO_BUF_MBUF .
.It Fa crp_uio
A pointer to a
.Vt struct uio
for
.Dv CRYPTO_BUF_UIO .
.It Fa crp_olen
Used with compression and decompression requests to describe the updated
length of the payload region in the data buffer.
.Pp
If a compression request increases the size of the payload,
then the data buffer is unmodified, the request completes successfully,
and
.Fa crp_olen
is set to the size the compressed data would have used.
Callers can compare this to the payload region length to determine if
the compressed data was discarded.
.El
.Ss Request Regions
Each request describes one or more regions in the data buffer using.
Each region is described by an offset relative to the start of the
data buffer and a length.
The length of some regions is the same for all requests belonging to
a session.
Those lengths are set in the session parameters of the associated
session.
All requests must define a payload region.
Other regions are only required for specific session modes.
The following regions are defined:
.Bl -column "Payload" "crp_payload_start" "crp_payload_length"
.It Sy Region Ta Sy Start Ta Sy Length Ta Sy Description
.It AAD Ta Fa crp_aad_start Ta Fa crp_aad_length Ta
Additional Authenticated Data
.It IV Ta Fa crp_iv_start Ta Fa csp_ivlen Ta
Embedded IV or nonce
.It Payload Ta Fa crp_payload_start Ta Fa crp_payload_length Ta
Data to encrypt, decrypt, compress, or decompress
.It Digest Ta Fa crp_digest_start Ta Fa csp_auth_mlen Ta
Authentication digest, hash, or tag
.El
.Pp
Requests are permitted to operate on only a subset of the data buffer.
For example,
requests from IPsec operate on network packets that include headers not
used as either additional authentication data (AAD) or payload data.
.Ss Request Operations
All requests must specify the type of operation to perform in
.Fa crp_op .
Available operations depend on the session's mode.
.Pp
Compression requests support the following operations:
.Bl -tag -width CRYPTO_OP_DECOMPRESS
.It Dv CRYPTO_OP_COMPRESS
Compress the data in the payload region of the data buffer.
.It Dv CRYPTO_OP_DECOMPRESS
Decompress the data in the payload region of the data buffer.
.El
.Pp
Cipher requests support the following operations:
.Bl -tag -width CRYPTO_OP_DECRYPT
.It Dv CRYPTO_OP_ENCRYPT
Encrypt the data in the payload region of the data buffer.
.It Dv CRYPTO_OP_DECRYPT
Decrypt the data in the payload region of the data buffer.
.El
.Pp
Digest requests support the following operations:
.Bl -tag -width CRYPTO_OP_COMPUTE_DIGEST
.It Dv CRYPTO_OP_COMPUTE_DIGEST
Calculate a digest over the payload region of the data buffer
and store the result in the digest region.
.It Dv CRYPTO_OP_VERIFY_DIGEST
Calculate a digest over the payload region of the data buffer.
Compare the calculated digest to the existing digest from the digest region.
If the digests match,
complete the request successfully.
If the digests do not match,
fail the request with
.Er EBADMSG .
.El
.Pp
AEAD and Encrypt-then-Authenticate requests support the following
operations:
.Bl -tag -width CRYPTO_OP
.It Dv CRYPTO_OP_ENCRYPT | Dv CRYPTO_OP_COMPUTE_DIGEST
Encrypt the data in the payload region of the data buffer.
Calculate a digest over the AAD and payload regions and store the
result in the data buffer.
.It Dv CRYPTO_OP_DECRYPT | Dv CRYPTO_OP_VERIFY_DIGEST
Calculate a digest over the AAD and payload regions of the data buffer.
Compare the calculated digest to the existing digest from the digest region.
If the digests match,
decrypt the payload region.
If the digests do not match,
fail the request with
.Er EBADMSG .
.El
.Ss Request IV and/or Nonce
Some cryptographic operations require an IV or nonce as an input.
An IV may be stored either in the IV region of the data buffer or in
.Fa crp_iv .
By default,
the IV is assumed to be stored in the IV region.
If the IV is stored in
.Fa crp_iv ,
.Dv CRYPTO_F_IV_SEPARATE
should be set in
.Fa crp_flags
and
.Fa crp_digest_start
should be left as zero.
.Pp
An encryption request using an IV stored in the IV region may set
.Dv CRYPTO_F_IV_GENERATE
in
.Fa crp_flags
to request that the driver generate a random IV.
Note that
.Dv CRYPTO_F_IV_GENERATE
cannot be used with decryption operations or in combination with
.Dv CRYPTO_F_IV_SEPARATE .
.Pp
Requests that store part, but not all, of the IV in the data buffer should
store the partial IV in the data buffer and pass the full IV separately in
.Fa crp_iv .
.Ss Request and Callback Scheduling
The crypto framework provides multiple methods of scheduling the dispatch
of requests to drivers along with the processing of driver callbacks.
Requests use flags in
.Fa crp_flags
to select the desired scheduling methods.
.Pp
.Fn crypto_dispatch
can pass the request to the session's driver via three different methods:
.Bl -enum
.It
The request is queued to a taskqueue backed by a pool of worker threads.
By default the pool is sized to provide one thread for each CPU.
Worker threads dequeue requests and pass them to the driver
asynchronously.
.It
The request is passed to the driver synchronously in the context of the
thread invoking
.Fn crypto_dispatch .
.It
The request is queued to a queue of pending requests.
A single worker thread dequeues requests and passes them to the driver
asynchronously.
.El
.Pp
To select the first method (taskqueue backed by multiple threads),
requests should set
.Dv CRYPTO_F_ASYNC .
To always use the third method (queue to single worker thread),
requests should set
.Dv CRYPTO_F_BATCH .
If both flags are set,
.Dv CRYPTO_F_ASYNC
takes precedence.
If neither flag is set,
.Fn crypto_dispatch
will first attempt the second method (invoke driver synchronously).
If the driver is blocked,
the request will be queued using the third method.
One caveat is that the first method is only used for requests using software
drivers which use host CPUs to process requests.
Requests whose session is associated with a hardware driver will ignore
.Dv CRYPTO_F_ASYNC
and only use
.Dv CRYPTO_F_BATCH
to determine how requests should be scheduled.
.Pp
In addition to bypassing synchronous dispatch in
.Fn crypto_dispatch ,
.Dv CRYPTO_F_BATCH
requests additional changes aimed at optimizing batches of requests to
the same driver.
When the worker thread processes a request with
.Dv CRYPTO_F_BATCH ,
it will search the pending request queue for any other requests for the same
driver,
including requests from different sessions.
If any other requests are present,
.Dv CRYPTO_HINT_MORE
is passed to the driver's process method.
Drivers may use this to batch completion interrupts.
.Pp
Callback function scheduling is simpler than request scheduling.
Callbacks can either be invoked synchronously from
.Fn crypto_done ,
or they can be queued to a pool of worker threads.
This pool of worker threads is also sized to provide one worker thread
for each CPU by default.
Note that a callback function invoked synchronously from
.Fn crypto_done
must follow the same restrictions placed on threaded interrupt handlers.
.Pp
By default,
callbacks are invoked asynchronously by a worker thread.
If
.Dv CRYPTO_F_CBIMM
is set,
the callback is always invoked synchronously from
.Fn crypto_done .
If
.Dv CRYPTO_F_CBIFSYNC
is set,
the callback is invoked synchronously if the request was processed by a
software driver or asynchronously if the request was processed by a
hardware driver.
.Pp
If a request was scheduled to the taskqueue via
.Dv CRYPTO_F_ASYNC ,
callbacks are always invoked asynchronously ignoring
.Dv CRYPTO_F_CBIMM
and
.Dv CRYPTO_F_CBIFSYNC .
In this case,
.Dv CRYPTO_F_ASYNC_KEEPORDER
may be set to ensure that callbacks for requests on a given session are
invoked in the same order that requests were queued to the session via
.Fn crypto_dispatch .
This flag is used by IPsec to ensure that decrypted network packets are
passed up the network stack in roughly the same order they were received.
.Pp
.Ss Other Request Fields
In addition to the fields and flags enumerated above,
.Vt struct cryptop
includes the following:
.Bl -tag -width crp_payload_length
.It Fa crp_session
A reference to the active session.
This is set when the request is created by
.Fn crypto_getreq
and should not be modified.
Drivers can use this to fetch driver-specific session state or
session parameters.
.It Fa crp_etype
Error status.
Either zero on success, or an error if a request fails.
Set by drivers prior to completing a request via
.Fn crypto_done .
.It Fa crp_flags
A bitmask of flags.
The following flags are available in addition to flags discussed previous