From patchwork Fri Sep 13 09:11:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomas Paukrt X-Patchwork-Id: 13803182 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D8C4DFA3734 for ; Fri, 13 Sep 2024 09:15:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:Mime-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=g4vwlwy5O7TMlld+y4YtQP4hezQIvov6mjtXb2jroRk=; b=va6Fc9YxAVcTyK71zB+u+Z5LF/ bGAwIM3AMmPlB8AtAeJnWGxHU+cLNJA1BMB4iNODf9V5JmAEc3ncfCpkh6DZJA0wtmf3nZMYMHatM 9mKLOfKF/rW7ujuCyDlAOpA1bKaVb5+e/OXzKqAMi8ijvESnGjGw/x0qWOZE+wb+CVYcrsMw3TpEB 7dfGAarkJs1m7eYBqgIfbmFbPMSPHD4NtfOuPGjtkQa6Q6IwtuvRPB/5veWh8evD0kwZk2qNVDy1D hJ7Btex/yIrkKEJBI3FhajlD9n7/7x08DcwiH9ksEP87/LBX+azeIys6ERBAIqfpcN+NGiqaGE4Vb S2Hl9FpA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sp2OV-0000000FSGg-3JER; Fri, 13 Sep 2024 09:15:11 +0000 Received: from mxc-2-460.seznam.cz ([2a02:598:64:8a00::1000:460]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sp2NQ-0000000FSCR-42RC for linux-arm-kernel@lists.infradead.org; Fri, 13 Sep 2024 09:14:07 +0000 Received: from email.seznam.cz by smtpc-mxc-58959dfbcf-mrxrj (smtpc-mxc-58959dfbcf-mrxrj [2a02:598:64:8a00::1000:460]) id 34e24eddca16fc77346cc0c5; Fri, 13 Sep 2024 11:11:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=email.cz; s=szn20221014; t=1726218708; bh=g4vwlwy5O7TMlld+y4YtQP4hezQIvov6mjtXb2jroRk=; h=Received:From:To:Cc:Subject:Date:Message-Id:Mime-Version:X-Mailer: Content-Type:Content-Transfer-Encoding; b=ABTide6vKVoFNrVunr8ULeqy0dJJzoZvvLdW4CQuHeUvgvMENkXT1pYKjf42Z4BdI W78a7hW/o+XRTsiiIQDWt10YMdP4psdsFGD3q7BsLbCGCs6A1ch35AOB1UTjsQsLYf 5wV/XQlLIOyQxKV6YU9odYJ6uq+dkOxoTrXSRkuuqT5V1s7qzDQaSe7p8l3FKRSHSL cXcW+XONp/uQKYmQAHDs/hzetw0iHohI2c4vf5+JlbeYobzOKLNt9d8adfTGdpI7a6 TwBnzh0gIfmM8qcG+sGjLqIlVMz6FhwPhybgYticGIlyrj0T2+vOSqcC4x7nBBfowc XTh3FZ2WqHdFg== Received: from 184-143.ktuo.cz (184-143.ktuo.cz [82.144.143.184]) by email.seznam.cz (szn-ebox-5.0.189) with HTTP; Fri, 13 Sep 2024 11:11:43 +0200 (CEST) From: "Tomas Paukrt" To: Cc: "Herbert Xu" , "David S. Miller" , "Shawn Guo" , "Sascha Hauer" , "Pengutronix Kernel Team" , "Fabio Estevam" , , Subject: [PATCH] crypto: mxs-dcp: Fix AES-CBC with hardware-bound keys Date: Fri, 13 Sep 2024 11:11:43 +0200 (CEST) Message-Id: <1Wx.Zci3.5c7{vqn25ku.1cv07F@seznam.cz> Mime-Version: 1.0 (szn-mime-2.1.61) X-Mailer: szn-ebox-5.0.189 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240913_021405_753741_5B7DD999 X-CRM114-Status: UNSURE ( 8.56 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Fix passing an initialization vector in the payload field which is necessary for AES in CBC mode even with hardware-bound keys. Fixes: 3d16af0b4cfa ("crypto: mxs-dcp: Add support for hardware-bound keys") Signed-off-by: Tomas Paukrt --- drivers/crypto/mxs-dcp.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/crypto/mxs-dcp.c b/drivers/crypto/mxs-dcp.c index c82775d..77a6301 100644 --- a/drivers/crypto/mxs-dcp.c +++ b/drivers/crypto/mxs-dcp.c @@ -225,21 +225,22 @@ static int mxs_dcp_start_dma(struct dcp_async_ctx *actx) static int mxs_dcp_run_aes(struct dcp_async_ctx *actx, struct skcipher_request *req, int init) { - dma_addr_t key_phys = 0; - dma_addr_t src_phys, dst_phys; + dma_addr_t key_phys, src_phys, dst_phys; struct dcp *sdcp = global_sdcp; struct dcp_dma_desc *desc = &sdcp->coh->desc[actx->chan]; struct dcp_aes_req_ctx *rctx = skcipher_request_ctx(req); bool key_referenced = actx->key_referenced; int ret; - if (!key_referenced) { + if (key_referenced) + key_phys = dma_map_single(sdcp->dev, sdcp->coh->aes_key + AES_KEYSIZE_128, + AES_KEYSIZE_128, DMA_TO_DEVICE); + else key_phys = dma_map_single(sdcp->dev, sdcp->coh->aes_key, 2 * AES_KEYSIZE_128, DMA_TO_DEVICE); - ret = dma_mapping_error(sdcp->dev, key_phys); - if (ret) - return ret; - } + ret = dma_mapping_error(sdcp->dev, key_phys); + if (ret) + return ret; src_phys = dma_map_single(sdcp->dev, sdcp->coh->aes_in_buf, DCP_BUF_SZ, DMA_TO_DEVICE); @@ -300,7 +301,10 @@ static int mxs_dcp_run_aes(struct dcp_async_ctx *actx, err_dst: dma_unmap_single(sdcp->dev, src_phys, DCP_BUF_SZ, DMA_TO_DEVICE); err_src: - if (!key_referenced) + if (key_referenced) + dma_unmap_single(sdcp->dev, key_phys, AES_KEYSIZE_128, + DMA_TO_DEVICE); + else dma_unmap_single(sdcp->dev, key_phys, 2 * AES_KEYSIZE_128, DMA_TO_DEVICE); return ret;