From nobody Tue Jan 11 22:38:11 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 2A431194C0F9; Tue, 11 Jan 2022 22:38:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JYQZX59vZz4mDC; Tue, 11 Jan 2022 22:38:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id BA6DC21C18; Tue, 11 Jan 2022 22:38:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 20BMcBlL075882; Tue, 11 Jan 2022 22:38:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20BMcBgx075881; Tue, 11 Jan 2022 22:38:11 GMT (envelope-from git) Date: Tue, 11 Jan 2022 22:38:11 GMT Message-Id: <202201112238.20BMcBgx075881@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: cfb7b942bed7 - main - cryptosoft: Use multi-block encrypt/decrypt for non-AEAD ciphers. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: cfb7b942bed72cb798b869d2e36e0097dbd243b2 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1641940693; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=MaDXdfOfd6Z7FT7rZBcpWOGmXT6EYgQ0haIwTbc178Q=; b=Od1oHLtdxHFPi/pisjZKGW93EepEFCZ3uGAoY+ivkXOCAGtjb2IA9ToZELZ0lEpu+ywH85 XQTlp2b6GQn81S9lvLK6nh9eZwj3vlMvj9gj+8MbWGOa6BqOy2DnYiDmUuVVxHqImjR8Vi OhjVAXmgzhK2hy2oQp89kWGYwTbfrHpkJKbElDlUGfPv9yFmFCdT+GoRv0wdYvRl19l2B6 iNAyEfSYpPQ+G3CG+12jd8typpfeT5aTtMtzy0isb3MjHO60HZn+YJA7RQbyixJIve/ZIX 5FsLVDjppc696ZlUZDiqu6/orNPWQLb/bJcEXD+Q7XhNRHQbRFyfBAukUr0UYQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1641940693; a=rsa-sha256; cv=none; b=MstvzSLHRl6SudCGpfCu9x1hkft+Q5vj0RPrixUhwtOIlKDDMaEW2KGFEhudbQz+4pou+r jLx9p+YHEI4CoLnNU+D+zexdhxuqY1bDLw5kgzTPOolDzhJP5+HSj72OnCP3SP4uangYx0 gR4laSGk+dTaozn7FPI44BOfC71dnKJ1ebL/ex/Bmj2X88AB/j9J7P1FIVJnB2/2gizQbR OIRgG2T2u8lkieg3IW+obGMS3aYwrgs6nQNxx58v1Hz2HGG5MdYq05dn0YnKdT5XVcUuxX /bk0qDMyuLskFoTV33dcuSAcpF71RYrvY1WbBiNKxRWe3HDuy0iaPD+ezTKn5Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=cfb7b942bed72cb798b869d2e36e0097dbd243b2 commit cfb7b942bed72cb798b869d2e36e0097dbd243b2 Author: John Baldwin AuthorDate: 2022-01-11 22:18:57 +0000 Commit: John Baldwin CommitDate: 2022-01-11 22:18:57 +0000 cryptosoft: Use multi-block encrypt/decrypt for non-AEAD ciphers. Reviewed by: markj Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D33531 --- sys/opencrypto/cryptosoft.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/sys/opencrypto/cryptosoft.c b/sys/opencrypto/cryptosoft.c index 65eb29bdfd91..78fa786f0f72 100644 --- a/sys/opencrypto/cryptosoft.c +++ b/sys/opencrypto/cryptosoft.c @@ -105,7 +105,7 @@ swcr_encdec(const struct swcr_session *ses, struct cryptop *crp) const struct enc_xform *exf; const struct swcr_encdec *sw; void *ctx; - size_t inlen, outlen; + size_t inlen, outlen, todo; int blks, resid; struct crypto_buffer_cursor cc_in, cc_out; const unsigned char *inblk; @@ -154,7 +154,6 @@ swcr_encdec(const struct swcr_session *ses, struct cryptop *crp) cc_out = cc_in; outblk = crypto_cursor_segment(&cc_out, &outlen); - resid = crp->crp_payload_length; encrypting = CRYPTO_OP_IS_ENCRYPT(crp->crp_op); /* @@ -163,7 +162,7 @@ swcr_encdec(const struct swcr_session *ses, struct cryptop *crp) * 'outlen' is the remaining length of current segment in the * output buffer. */ - while (resid >= blks) { + for (resid = crp->crp_payload_length; resid >= blks; resid -= todo) { /* * If the current block is not contained within the * current input/output segment, use 'blk' as a local @@ -172,33 +171,41 @@ swcr_encdec(const struct swcr_session *ses, struct cryptop *crp) if (inlen < blks) { crypto_cursor_copydata(&cc_in, blks, blk); inblk = blk; + inlen = blks; } - if (outlen < blks) + if (outlen < blks) { outblk = blk; + outlen = blks; + } + + todo = rounddown2(MIN(resid, MIN(inlen, outlen)), blks); if (encrypting) - exf->encrypt(ctx, inblk, outblk); + exf->encrypt_multi(ctx, inblk, outblk, todo); else - exf->decrypt(ctx, inblk, outblk); + exf->decrypt_multi(ctx, inblk, outblk, todo); - if (inlen < blks) { + if (inblk == blk) { inblk = crypto_cursor_segment(&cc_in, &inlen); } else { - crypto_cursor_advance(&cc_in, blks); - inlen -= blks; - inblk += blks; + crypto_cursor_advance(&cc_in, todo); + inlen -= todo; + inblk += todo; + if (inlen == 0) + inblk = crypto_cursor_segment(&cc_in, &inlen); } - if (outlen < blks) { + if (outblk == blk) { crypto_cursor_copyback(&cc_out, blks, blk); outblk = crypto_cursor_segment(&cc_out, &outlen); } else { - crypto_cursor_advance(&cc_out, blks); - outlen -= blks; - outblk += blks; + crypto_cursor_advance(&cc_out, todo); + outlen -= todo; + outblk += todo; + if (outlen == 0) + outblk = crypto_cursor_segment(&cc_out, + &outlen); } - - resid -= blks; } /* Handle trailing partial block for stream ciphers. */