Add crypto_initreq() and crypto_destroyreq().
These routines are similar to crypto_getreq() and crypto_freereq() but operate on caller-supplied storage instead of allocating crypto requests from a UMA zone. Reviewed by: markj Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D25691
This commit is contained in:
parent
03caca368a
commit
946b8f6fb0
@ -927,9 +927,11 @@ MLINKS+=crypto_driver.9 crypto_copyback.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 \
|
||||
MLINKS+=crypto_request.9 crypto_destroyreq.9 \
|
||||
crypto_request.9 crypto_dispatch.9 \
|
||||
crypto_request.9 crypto_freereq.9 \
|
||||
crypto_request.9 crypto_getreq.9 \
|
||||
crypto_request.9 crypto_initreq.9 \
|
||||
crypto_request.9 crypto_use_buf.9 \
|
||||
crypto_request.9 crypto_use_mbuf.9 \
|
||||
crypto_request.9 crypto_use_output_buf.9 \
|
||||
|
@ -30,7 +30,7 @@
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd June 22, 2020
|
||||
.Dd July 16, 2020
|
||||
.Dt CRYPTO_REQUEST 9
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -41,10 +41,14 @@
|
||||
.Ft int
|
||||
.Fn crypto_dispatch "struct cryptop *crp"
|
||||
.Ft void
|
||||
.Fn crypto_destroyreq "struct cryptop *crp"
|
||||
.Ft void
|
||||
.Fn crypto_freereq "struct cryptop *crp"
|
||||
.Ft "struct cryptop *"
|
||||
.Fn crypto_getreq "crypto_session_t cses" "int how"
|
||||
.Ft void
|
||||
.Fn crypto_initreq "crypto_session_t cses" "int how"
|
||||
.Ft void
|
||||
.Fn crypto_use_buf "struct cryptop *crp" "void *buf" "int len"
|
||||
.Ft void
|
||||
.Fn crypto_use_mbuf "struct cryptop *crp" "struct mbuf *m"
|
||||
@ -62,10 +66,27 @@ an instance of
|
||||
.Vt struct cryptop
|
||||
and is associated with an active session.
|
||||
.Pp
|
||||
New requests are allocated by
|
||||
.Fn crypto_getreq .
|
||||
Requests can either be allocated dynamically or use caller-supplied
|
||||
storage.
|
||||
Dynamically allocated requests should be allocated by
|
||||
.Fn crypto_getreq
|
||||
and freed by
|
||||
.Fn crypto_freereq
|
||||
once the request has completed.
|
||||
Requests using caller-supplied storage should be initialized by
|
||||
.Fn crypto_initreq
|
||||
at the start of each operation and destroyed by
|
||||
.Fn crypto_destroyreq
|
||||
once the request has completed.
|
||||
.Pp
|
||||
For both
|
||||
.Fn crypto_getreq
|
||||
and
|
||||
.Fn crypto_initreq ,
|
||||
.Fa cses
|
||||
is a reference to an active session.
|
||||
For
|
||||
.Fn crypto_getreq ,
|
||||
.Fa how
|
||||
is passed to
|
||||
.Xr malloc 9
|
||||
@ -73,7 +94,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
|
||||
.Pp
|
||||
Once a request has been initialized,
|
||||
the caller should set fields in the structure to describe
|
||||
request-specific parameters.
|
||||
Unused fields should be left as-is.
|
||||
.Pp
|
||||
@ -92,7 +115,9 @@ Note that a request's callback function may be invoked before
|
||||
returns.
|
||||
.Pp
|
||||
Once a request has signaled completion by invoking its callback function,
|
||||
it should be feed via
|
||||
it should be freed via
|
||||
.Fn crypto_destroyreq
|
||||
or
|
||||
.Fn crypto_freereq .
|
||||
.Pp
|
||||
Cryptographic operations include several fields to describe the request.
|
||||
|
@ -1734,12 +1734,8 @@ crypto_invoke(struct cryptocap *cap, struct cryptop *crp, int hint)
|
||||
}
|
||||
|
||||
void
|
||||
crypto_freereq(struct cryptop *crp)
|
||||
crypto_destroyreq(struct cryptop *crp)
|
||||
{
|
||||
|
||||
if (crp == NULL)
|
||||
return;
|
||||
|
||||
#ifdef DIAGNOSTIC
|
||||
{
|
||||
struct cryptop *crp2;
|
||||
@ -1764,10 +1760,31 @@ crypto_freereq(struct cryptop *crp)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
crypto_freereq(struct cryptop *crp)
|
||||
{
|
||||
if (crp == NULL)
|
||||
return;
|
||||
|
||||
crypto_destroyreq(crp);
|
||||
uma_zfree(cryptop_zone, crp);
|
||||
}
|
||||
|
||||
static void
|
||||
_crypto_initreq(struct cryptop *crp, crypto_session_t cses)
|
||||
{
|
||||
crp->crp_session = cses;
|
||||
}
|
||||
|
||||
void
|
||||
crypto_initreq(struct cryptop *crp, crypto_session_t cses)
|
||||
{
|
||||
memset(crp, 0, sizeof(*crp));
|
||||
_crypto_initreq(crp, cses);
|
||||
}
|
||||
|
||||
struct cryptop *
|
||||
crypto_getreq(crypto_session_t cses, int how)
|
||||
{
|
||||
@ -1775,7 +1792,8 @@ crypto_getreq(crypto_session_t cses, int how)
|
||||
|
||||
MPASS(how == M_WAITOK || how == M_NOWAIT);
|
||||
crp = uma_zalloc(cryptop_zone, how | M_ZERO);
|
||||
crp->crp_session = cses;
|
||||
if (crp != NULL)
|
||||
_crypto_initreq(crp, cses);
|
||||
return (crp);
|
||||
}
|
||||
|
||||
|
@ -622,6 +622,8 @@ extern void crypto_done(struct cryptop *crp);
|
||||
extern void crypto_kdone(struct cryptkop *);
|
||||
extern int crypto_getfeat(int *);
|
||||
|
||||
extern void crypto_destroyreq(struct cryptop *crp);
|
||||
extern void crypto_initreq(struct cryptop *crp, crypto_session_t cses);
|
||||
extern void crypto_freereq(struct cryptop *crp);
|
||||
extern struct cryptop *crypto_getreq(crypto_session_t cses, int how);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user