git: d84e0dd2f4e1 - stable/13 - safexcel: Set the context record unconditionally

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Mon, 25 Oct 2021 12:47:46 UTC
The branch stable/13 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=d84e0dd2f4e1865f8f99c208cedf9f3e07202d4d

commit d84e0dd2f4e1865f8f99c208cedf9f3e07202d4d
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2021-10-18 13:40:47 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2021-10-25 12:46:55 +0000

    safexcel: Set the context record unconditionally
    
    The condition added in commit 5bdb8b273aaf excludes plain SHA
    transforms, so for such sessions crypto operations would return
    incorrect results.
    
    Fixes:  5bdb8b273aaf ("safexcel: Maintain per-session context records")
    Sponsored by:   The FreeBSD Foundation
    
    (cherry picked from commit 36e4dcf47d45bbb87875ee4a9f5cc26a72a9f048)
---
 sys/dev/safexcel/safexcel.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/sys/dev/safexcel/safexcel.c b/sys/dev/safexcel/safexcel.c
index 807040a7a1d8..6095787330c1 100644
--- a/sys/dev/safexcel/safexcel.c
+++ b/sys/dev/safexcel/safexcel.c
@@ -2520,15 +2520,12 @@ safexcel_newsession(device_t dev, crypto_session_t cses,
 	if (csp->csp_auth_mlen != 0)
 		sess->digestlen = csp->csp_auth_mlen;
 
-	if ((csp->csp_cipher_alg == 0 || csp->csp_cipher_key != NULL) &&
-	    (csp->csp_auth_alg == 0 || csp->csp_auth_key != NULL)) {
-		sess->encctx.len = safexcel_set_context(&sess->encctx.ctx,
-		    CRYPTO_OP_ENCRYPT, csp->csp_cipher_key, csp->csp_auth_key,
-		    sess);
-		sess->decctx.len = safexcel_set_context(&sess->decctx.ctx,
-		    CRYPTO_OP_DECRYPT, csp->csp_cipher_key, csp->csp_auth_key,
-		    sess);
-	}
+	sess->encctx.len = safexcel_set_context(&sess->encctx.ctx,
+	    CRYPTO_OP_ENCRYPT, csp->csp_cipher_key, csp->csp_auth_key,
+	    sess);
+	sess->decctx.len = safexcel_set_context(&sess->decctx.ctx,
+	    CRYPTO_OP_DECRYPT, csp->csp_cipher_key, csp->csp_auth_key,
+	    sess);
 
 	return (0);
 }