From patchwork Tue Mar 28 19:56:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan.Wanner@microchip.com X-Patchwork-Id: 76244 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2480354vqo; Tue, 28 Mar 2023 13:17:38 -0700 (PDT) X-Google-Smtp-Source: AKy350YDdTYlfhpX1t7ByMUwbSMDzuAqkBhhCHph6y6uFOCOaEb9mGejJgnQTFSIU5rY85K1luxe X-Received: by 2002:a17:907:a50f:b0:8e6:bcb6:469e with SMTP id vr15-20020a170907a50f00b008e6bcb6469emr18940020ejc.0.1680034658315; Tue, 28 Mar 2023 13:17:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680034658; cv=none; d=google.com; s=arc-20160816; b=yW5ntFXPkkHSmgUlUosKdnYGWNsp3PHeHzcUZh8KbltX58YxxTbso2hCZt3NXsSsuj doSBPmrRg65lZq09pz93qmAvZVeT9uVUyx9FHwNKzxMkua2u0gB8h6Yzf/iDs8J2qKd1 uCM9cQsnsCcl66w6Waiml5AyfVukV0vwMPQf+dMvWZUeGCMesGcPvWbDh4/Uskq2QX9e mp9UPvRgEKiptSrplyfqpjc+pI2n2FoaKMzvC481qeJpxJO8PU5RkpQKPjYZya+JKIhg 1CwVxGyIkmzxvfOGfaCg4F/9hQvDKjQ3IlzaUkLDexl6+ymJ2YB/Rt+aJKWwhB/WbTcj ++ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ipt6LaneDhuoFrZgGh12GQT4ValhWULo9BO0MNE+N6A=; b=WL/HKyUI2hVeJhO68HqriolqhnKK1vaOv60bh4HG6Z1Zoc79Tz3P8ylLm9GGqPnTno b+0mLjC7++nyRBR5DI9elOHM8QhgoZ/NcFzXFdvLJrXpR9vHvqh1qSVb65FyxPGC7nAP 94jA2nGWSU/2GDn0LjxYli2UfzH4fuwGb5piNz36trNJH4syN3fQ1cf0ZZHOaqa2bzda OPnBTUYiBTuxs+M/IEBSouMkgvEJmmWYlgaCpLLquK893HOo/heK+/x/wk+9X/k4YOqb 3bGNw0iYvq64eyKo+C4OXqj5s0DNBhYCSXibSv2Ivs6XwZLlCphpFJDR4Hs7nYmF+CDa c2Ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=DwT6Q2Xv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r22-20020aa7d156000000b00502030dd391si16291213edo.46.2023.03.28.13.16.22; Tue, 28 Mar 2023 13:17:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=DwT6Q2Xv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229730AbjC1T43 (ORCPT + 99 others); Tue, 28 Mar 2023 15:56:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229460AbjC1T40 (ORCPT ); Tue, 28 Mar 2023 15:56:26 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 175AD1BE1; Tue, 28 Mar 2023 12:56:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1680033385; x=1711569385; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3pNleVDsOKO+SQXxRv8CZk7/1rEyCdwTx0A5JZpAvdk=; b=DwT6Q2XvK9Lmli2/QoHwmFU8zQHquGP7TvUBc5resLBrCGsaHoMRqdoi gQ9K7p2DsXN1YKhGsqVZC6xqwEitWLq6d0JkG7MqQSwgdH0Xd6zceRBWT FjyLlsLhIVpNvZqvSIeOKahyRvBe0akU2MwUM8SX24157rGIStZA7FI2S 8QCz16WX+expsjGs1Z20WwDfTF43bl3fdGd/iptxbMxEzbgZKlSCDmKDc P2Z0hMHACPC7warATC1AFMN6HrDKNsgbo3jx+TBvZPD3xZ6Y2yDOnBF3k nGB5FmhXw58rmN/rn7m4nPY2h14Ggl81lA26q1pVsGgNxYNM6mkAm7gMm w==; X-IronPort-AV: E=Sophos;i="5.98,297,1673938800"; d="scan'208";a="144351914" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 28 Mar 2023 12:56:24 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Tue, 28 Mar 2023 12:56:22 -0700 Received: from ryan-Precision-3630-Tower.microchip.com (10.10.115.15) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2507.21 via Frontend Transport; Tue, 28 Mar 2023 12:56:22 -0700 From: To: , , , , CC: , , , Ryan Wanner Subject: [PATCH 2/4] crypto: atmel-tdes - Detecting in-place operations with two sg lists Date: Tue, 28 Mar 2023 12:56:27 -0700 Message-ID: X-Mailer: git-send-email 2.37.2 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761644021487748346?= X-GMAIL-MSGID: =?utf-8?q?1761644021487748346?= From: Ryan Wanner 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 --- 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)