aboutsummaryrefslogtreecommitdiff
path: root/sys/opencrypto/cryptosoft.c
diff options
context:
space:
mode:
authorMarcin Wojtas <mw@FreeBSD.org>2020-10-16 11:18:13 +0000
committerMarcin Wojtas <mw@FreeBSD.org>2020-10-16 11:18:13 +0000
commit6038018ab16a448e5a791febb69283991bf4c4db (patch)
tree7753fd192748d21d60f49dc82156797c5236e7ff /sys/opencrypto/cryptosoft.c
parent7e89ae49db749715b17ae2358cc60b6e74fed69f (diff)
downloadsrc-6038018ab16a448e5a791febb69283991bf4c4db.tar.gz
src-6038018ab16a448e5a791febb69283991bf4c4db.zip
Add support for ESN in cryptosoft
This patch adds support for IPsec ESN (Extended Sequence Numbers) in encrypt and authenticate mode (eg. AES-CBC and SHA256) and combined mode (eg. AES-GCM). For encrypt and authenticate mode the ESN is stored in separate crp_esn buffer because the high-order 32 bits of the sequence number are appended after the Next Header (RFC 4303). For combined modes the high-order 32 bits of the sequence number [e.g. RFC 4106, Chapter 5 AAD Construction] are part of crp_aad (prepared by netipsec layer in case of ESN support enabled), therefore non visible diff around combined modes. Submitted by: Grzegorz Jaszczyk <jaz@semihalf.com> Patryk Duda <pdk@semihalf.com> Reviewed by: jhb Differential revision: https://reviews.freebsd.org/D22364 Obtained from: Semihalf Sponsored by: Stormshield
Notes
Notes: svn path=/head/; revision=366753
Diffstat (limited to 'sys/opencrypto/cryptosoft.c')
-rw-r--r--sys/opencrypto/cryptosoft.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/sys/opencrypto/cryptosoft.c b/sys/opencrypto/cryptosoft.c
index 0d3ca7217b25..877ceddc851e 100644
--- a/sys/opencrypto/cryptosoft.c
+++ b/sys/opencrypto/cryptosoft.c
@@ -327,8 +327,8 @@ swcr_authcompute(struct swcr_session *ses, struct cryptop *crp)
axf = sw->sw_axf;
+ csp = crypto_get_params(crp->crp_session);
if (crp->crp_auth_key != NULL) {
- csp = crypto_get_params(crp->crp_session);
swcr_authprepare(axf, sw, crp->crp_auth_key,
csp->csp_auth_klen);
}
@@ -354,6 +354,9 @@ swcr_authcompute(struct swcr_session *ses, struct cryptop *crp)
if (err)
goto out;
+ if (csp->csp_flags & CSP_F_ESN)
+ axf->Update(&ctx, crp->crp_esn, 4);
+
axf->Final(aalg, &ctx);
if (sw->sw_octx != NULL) {
bcopy(sw->sw_octx, &ctx, axf->ctxsize);
@@ -1235,12 +1238,12 @@ swcr_cipher_supported(const struct crypto_session_params *csp)
return (true);
}
+#define SUPPORTED_SES (CSP_F_SEPARATE_OUTPUT | CSP_F_SEPARATE_AAD | CSP_F_ESN)
+
static int
swcr_probesession(device_t dev, const struct crypto_session_params *csp)
{
-
- if ((csp->csp_flags & ~(CSP_F_SEPARATE_OUTPUT | CSP_F_SEPARATE_AAD)) !=
- 0)
+ if ((csp->csp_flags & ~(SUPPORTED_SES)) != 0)
return (EINVAL);
switch (csp->csp_mode) {
case CSP_MODE_COMPRESS: