From: <Ryan.Wanner@microchip.com> To: <herbert@gondor.apana.org.au>, <davem@davemloft.net>, <nicolas.ferre@microchip.com>, <alexandre.belloni@bootlin.com>, <claudiu.beznea@microchip.com> Cc: <linux-crypto@vger.kernel.org>, <linux-arm-kernel@lists.infradead.org>, <linux-kernel@vger.kernel.org>, Ryan Wanner <Ryan.Wanner@microchip.com> Subject: [PATCH 2/4] crypto: atmel-tdes - Detecting in-place operations with two sg lists Date: Tue, 28 Mar 2023 12:56:27 -0700 [thread overview] Message-ID: <ad0815e3b8ffcb9d627895fe2464ef15dbb44a56.1680019905.git.Ryan.Wanner@microchip.com> (raw) In-Reply-To: <cover.1680019905.git.Ryan.Wanner@microchip.com> From: Ryan Wanner <Ryan.Wanner@microchip.com> Avoiding detecting finely in-place operations with different scatter lists. Copying the source data for decryption into rctx->lastc regardless if the operation is in-place or not. This allows in-place operations with different scatter lists without affecting other operations. This approach takes less resources than parsing both scatter lists to check if they are equal. Signed-off-by: Ryan Wanner <Ryan.Wanner@microchip.com> --- drivers/crypto/atmel-tdes.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/crypto/atmel-tdes.c b/drivers/crypto/atmel-tdes.c index 8b7bc1076e0d..edf18073516e 100644 --- a/drivers/crypto/atmel-tdes.c +++ b/drivers/crypto/atmel-tdes.c @@ -565,17 +565,12 @@ atmel_tdes_set_iv_as_last_ciphertext_block(struct atmel_tdes_dev *dd) if (req->cryptlen < ivsize) return; - if (rctx->mode & TDES_FLAGS_ENCRYPT) { + if (rctx->mode & TDES_FLAGS_ENCRYPT) scatterwalk_map_and_copy(req->iv, req->dst, req->cryptlen - ivsize, ivsize, 0); - } else { - if (req->src == req->dst) - memcpy(req->iv, rctx->lastc, ivsize); - else - scatterwalk_map_and_copy(req->iv, req->src, - req->cryptlen - ivsize, - ivsize, 0); - } + else + memcpy(req->iv, rctx->lastc, ivsize); + } static void atmel_tdes_finish_req(struct atmel_tdes_dev *dd, int err) @@ -722,7 +717,7 @@ static int atmel_tdes_crypt(struct skcipher_request *req, unsigned long mode) rctx->mode = mode; if ((mode & TDES_FLAGS_OPMODE_MASK) != TDES_FLAGS_ECB && - !(mode & TDES_FLAGS_ENCRYPT) && req->src == req->dst) { + !(mode & TDES_FLAGS_ENCRYPT)) { unsigned int ivsize = crypto_skcipher_ivsize(skcipher); if (req->cryptlen >= ivsize) -- 2.37.2
WARNING: multiple messages have this Message-ID (diff)
From: <Ryan.Wanner@microchip.com> To: <herbert@gondor.apana.org.au>, <davem@davemloft.net>, <nicolas.ferre@microchip.com>, <alexandre.belloni@bootlin.com>, <claudiu.beznea@microchip.com> Cc: <linux-crypto@vger.kernel.org>, <linux-arm-kernel@lists.infradead.org>, <linux-kernel@vger.kernel.org>, Ryan Wanner <Ryan.Wanner@microchip.com> Subject: [PATCH 2/4] crypto: atmel-tdes - Detecting in-place operations with two sg lists Date: Tue, 28 Mar 2023 12:56:27 -0700 [thread overview] Message-ID: <ad0815e3b8ffcb9d627895fe2464ef15dbb44a56.1680019905.git.Ryan.Wanner@microchip.com> (raw) In-Reply-To: <cover.1680019905.git.Ryan.Wanner@microchip.com> From: Ryan Wanner <Ryan.Wanner@microchip.com> Avoiding detecting finely in-place operations with different scatter lists. Copying the source data for decryption into rctx->lastc regardless if the operation is in-place or not. This allows in-place operations with different scatter lists without affecting other operations. This approach takes less resources than parsing both scatter lists to check if they are equal. Signed-off-by: Ryan Wanner <Ryan.Wanner@microchip.com> --- drivers/crypto/atmel-tdes.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/crypto/atmel-tdes.c b/drivers/crypto/atmel-tdes.c index 8b7bc1076e0d..edf18073516e 100644 --- a/drivers/crypto/atmel-tdes.c +++ b/drivers/crypto/atmel-tdes.c @@ -565,17 +565,12 @@ atmel_tdes_set_iv_as_last_ciphertext_block(struct atmel_tdes_dev *dd) if (req->cryptlen < ivsize) return; - if (rctx->mode & TDES_FLAGS_ENCRYPT) { + if (rctx->mode & TDES_FLAGS_ENCRYPT) scatterwalk_map_and_copy(req->iv, req->dst, req->cryptlen - ivsize, ivsize, 0); - } else { - if (req->src == req->dst) - memcpy(req->iv, rctx->lastc, ivsize); - else - scatterwalk_map_and_copy(req->iv, req->src, - req->cryptlen - ivsize, - ivsize, 0); - } + else + memcpy(req->iv, rctx->lastc, ivsize); + } static void atmel_tdes_finish_req(struct atmel_tdes_dev *dd, int err) @@ -722,7 +717,7 @@ static int atmel_tdes_crypt(struct skcipher_request *req, unsigned long mode) rctx->mode = mode; if ((mode & TDES_FLAGS_OPMODE_MASK) != TDES_FLAGS_ECB && - !(mode & TDES_FLAGS_ENCRYPT) && req->src == req->dst) { + !(mode & TDES_FLAGS_ENCRYPT)) { unsigned int ivsize = crypto_skcipher_ivsize(skcipher); if (req->cryptlen >= ivsize) -- 2.37.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2023-03-28 19:56 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-03-28 19:56 [PATCH 0/4] Atmel crypto engine fixes Ryan.Wanner 2023-03-28 19:56 ` Ryan.Wanner 2023-03-28 19:56 ` [PATCH 1/4] crypto: atmel-sha: Add zero length message digest support for hmac Ryan.Wanner 2023-03-28 19:56 ` Ryan.Wanner 2023-03-28 19:56 ` Ryan.Wanner [this message] 2023-03-28 19:56 ` [PATCH 2/4] crypto: atmel-tdes - Detecting in-place operations with two sg lists Ryan.Wanner 2023-03-28 19:56 ` [PATCH 3/4] crypto: atmel-aes - Detecting in-place operations " Ryan.Wanner 2023-03-28 19:56 ` Ryan.Wanner 2023-03-28 19:56 ` [PATCH 4/4] crypto: atmel-aes - Match cfb block size with generic implementation Ryan.Wanner 2023-03-28 19:56 ` Ryan.Wanner 2023-04-06 8:50 ` [PATCH 0/4] Atmel crypto engine fixes Herbert Xu 2023-04-06 8:50 ` Herbert Xu
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=ad0815e3b8ffcb9d627895fe2464ef15dbb44a56.1680019905.git.Ryan.Wanner@microchip.com \ --to=ryan.wanner@microchip.com \ --cc=alexandre.belloni@bootlin.com \ --cc=claudiu.beznea@microchip.com \ --cc=davem@davemloft.net \ --cc=herbert@gondor.apana.org.au \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-crypto@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=nicolas.ferre@microchip.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.