aboutsummaryrefslogtreecommitdiff
path: root/sys/netipsec
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2020-04-20 22:20:26 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2020-04-20 22:20:26 +0000
commit8cbde414199b0d2fd91c8eb770e74ec23852a9d4 (patch)
tree419d83334ed8fcb8d89534701c2f3b21ab3862bb /sys/netipsec
parent5c94a873415a8fb0c77885978e1952bbdf484a35 (diff)
downloadsrc-8cbde414199b0d2fd91c8eb770e74ec23852a9d4.tar.gz
src-8cbde414199b0d2fd91c8eb770e74ec23852a9d4.zip
Generate IVs directly in esp_output.
This is the only place that uses CRYPTO_F_IV_GENERATE. All crypto drivers currently duplicate the same boilerplate code to handle this case. Doing the generation directly removes complexity from drivers. It also simplifies support for separate input and output buffers. Reviewed by: cem Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D24449
Notes
Notes: svn path=/head/; revision=360135
Diffstat (limited to 'sys/netipsec')
-rw-r--r--sys/netipsec/xform_esp.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/sys/netipsec/xform_esp.c b/sys/netipsec/xform_esp.c
index c9c65aef6c4c..a36fb8c7d9e3 100644
--- a/sys/netipsec/xform_esp.c
+++ b/sys/netipsec/xform_esp.c
@@ -813,10 +813,9 @@ esp_output(struct mbuf *m, struct secpolicy *sp, struct secasvar *sav,
crp->crp_payload_length = m->m_pkthdr.len - (skip + hlen + alen);
crp->crp_op = CRYPTO_OP_ENCRYPT;
- /* Encryption operation. */
+ /* Generate IV / nonce. */
+ ivp = &crp->crp_iv[0];
if (SAV_ISCTRORGCM(sav)) {
- ivp = &crp->crp_iv[0];
-
/* GCM IV Format: RFC4106 4 */
/* CTR IV Format: RFC3686 4 */
/* Salt is last four bytes of key, RFC4106 8.1 */
@@ -833,8 +832,9 @@ esp_output(struct mbuf *m, struct secpolicy *sp, struct secasvar *sav,
m_copyback(m, skip + hlen - sav->ivlen, sav->ivlen, &ivp[4]);
crp->crp_flags |= CRYPTO_F_IV_SEPARATE;
} else if (sav->ivlen != 0) {
+ arc4rand(ivp, sav->ivlen, 0);
crp->crp_iv_start = skip + hlen - sav->ivlen;
- crp->crp_flags |= CRYPTO_F_IV_GENERATE;
+ m_copyback(m, crp->crp_iv_start, sav->ivlen, ivp);
}
/* Callback parameters */