From patchwork Sun Sep 20 18:37:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 11788085 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 20E9D6CB for ; Sun, 20 Sep 2020 18:37:56 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E0FFE207BB for ; Sun, 20 Sep 2020 18:37:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Bk7wHklw"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="NJyb9kIF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E0FFE207BB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:To: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ltfFPPl0kjgzf7wpUnAOJQsXHzJY4AC2kIfaoFWEflo=; b=Bk7wHklwrFixmoRYHX5fwVAlWC cnAllTdPyaMxfYHx6x0+5eFcbKvollfe+s9SttwSrwZO8MOyDGaU9bYp5UcTZegBWMxopCV6uruCI M6eITimY8iShtJNx71Ex5b5e1kFQ/wl+tHt7Jpv9QUlHB4S5k3FmbsToGm3ghx/TMV4FYnwPbgshS 6IMRx5i+8sXJDEU+SzEqb7g3yaZvLQtZETS45TUVHxWWT56Lsb/TKGetwlleIsdVaClEr7PSH0zEm cdXZD28wKAG6Hqw1AZMGtIcv1XnMWB50lZrSfFKZLz+7qLoRDUC/+v+h0zLkDuqOk+euT2AWtfACU fTEwmTMw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kK4DW-0006r6-K8; Sun, 20 Sep 2020 18:37:42 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kK4DI-0006nd-D8 for linux-arm-kernel@lists.infradead.org; Sun, 20 Sep 2020 18:37:29 +0000 Received: by mail-wm1-x342.google.com with SMTP id b79so10361871wmb.4 for ; Sun, 20 Sep 2020 11:37:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=huiz4hWuEDAzBaczeTBJaesBVDz4VU4ls/AvOgJWeOk=; b=NJyb9kIFE/CthzhB4unI7Fmylr/83s0udqDUg2mdWAjKOkkMxeZcaiuYQNanTBeUJB GdfMBRs/1TR5EI7Fw7Spdcz6XKGxReckwGNC+dM5iviTrjJja2r5dGsaKCIS+BJli/BK QP1A8RsAko1XFRDsQE6TtGErG85J7k3ZHlf956ywSzC+huS0B8AQL+WmQL67SwCy0K9T PUv+Xq277PgRT4gKtsLqxjc58rynv0Ero3znor32MPMMcpLPezUJYXuxJ1/DDie4/AlS rT5jM4X1IFvqjIG1MdKk7E24u4X3klqR7C1G/t710ZHP+DkmX4sFmNCP4H8ZE4LKE3mJ uBsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=huiz4hWuEDAzBaczeTBJaesBVDz4VU4ls/AvOgJWeOk=; b=gjJgAFREPV6LVZaW8MIeI05WOKZnzNNjE+zp3OnMrRSmtSvKh+VtyvxGu5aE0fGqVs gTwkbCzlHcWT4j4F8IDAioBxmRHnntRPsdkmkvtCIL6wE14uL6h6c/nVBPEXHwq4qXr7 T1FqpNhVikWJnqwO3PFJr9pQ+TibhMtN6I0gzFRoos+LNo+R1CR1IQP93jxh1sk/IKN9 7xqyJ3qnjbUVvP2p4ebAum4WrIuuio+Yy/7iLTdXbyaeuyjAvh+MDYw0C/Jq+HUITW2S v+CWBEIsLT18Yu0ElKotMBSrh58WTz90HtYZDS0Pf3OsJqxL1j8szj4IscJ6NtYQHSfB cGtg== X-Gm-Message-State: AOAM5329AaUkvsJ/071F4sOQi5j3Y/LQGrnc77xnWvfW9IqSHyaS+dYj /3nEvnZcx8ffhtMcnHDqMh31LQ== X-Google-Smtp-Source: ABdhPJxlW7YndNuMU5bTLBRvti9rCp3LJ0Og/iDwJDuLz/GP8bWpCiL+y6oZwC3+DzIN4Mq+kjfm2g== X-Received: by 2002:a1c:23c8:: with SMTP id j191mr25370500wmj.64.1600627047323; Sun, 20 Sep 2020 11:37:27 -0700 (PDT) Received: from localhost.localdomain ([51.15.160.169]) by smtp.googlemail.com with ESMTPSA id e18sm16419841wrx.50.2020.09.20.11.37.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Sep 2020 11:37:26 -0700 (PDT) From: Corentin Labbe To: arnd@arndb.de, davem@davemloft.net, herbert@gondor.apana.org.au, mripard@kernel.org, wens@csie.org Subject: [PATCH v2 3/7] crypto: sun4i-ss: IV register does not work on A10 and A13 Date: Sun, 20 Sep 2020 18:37:14 +0000 Message-Id: <1600627038-40000-4-git-send-email-clabbe@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1600627038-40000-1-git-send-email-clabbe@baylibre.com> References: <1600627038-40000-1-git-send-email-clabbe@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200920_143728_465827_C77D2F63 X-CRM114-Status: GOOD ( 18.94 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:342 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, linux-sunxi@googlegroups.com, Corentin Labbe , linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Allwinner A10 and A13 SoC have a version of the SS which produce invalid IV in IVx register. Instead of adding a variant for those, let's convert SS to produce IV directly from data. Fixes: 6298e948215f2 ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator") Cc: Signed-off-by: Corentin Labbe --- .../allwinner/sun4i-ss/sun4i-ss-cipher.c | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c index 2614640231dc..c6c25204780d 100644 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c @@ -20,6 +20,7 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct skcipher_request *areq) unsigned int ivsize = crypto_skcipher_ivsize(tfm); struct sun4i_cipher_req_ctx *ctx = skcipher_request_ctx(areq); u32 mode = ctx->mode; + void *backup_iv = NULL; /* when activating SS, the default FIFO space is SS_RX_DEFAULT(32) */ u32 rx_cnt = SS_RX_DEFAULT; u32 tx_cnt = 0; @@ -42,6 +43,13 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct skcipher_request *areq) return -EINVAL; } + if (areq->iv && ivsize > 0 && mode & SS_DECRYPTION) { + backup_iv = kzalloc(ivsize, GFP_KERNEL); + if (!backup_iv) + return -ENOMEM; + scatterwalk_map_and_copy(backup_iv, areq->src, areq->cryptlen - ivsize, ivsize, 0); + } + spin_lock_irqsave(&ss->slock, flags); for (i = 0; i < op->keylen; i += 4) @@ -102,9 +110,12 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct skcipher_request *areq) } while (oleft); if (areq->iv) { - for (i = 0; i < 4 && i < ivsize / 4; i++) { - v = readl(ss->base + SS_IV0 + i * 4); - *(u32 *)(areq->iv + i * 4) = v; + if (mode & SS_DECRYPTION) { + memcpy(areq->iv, backup_iv, ivsize); + kfree_sensitive(backup_iv); + } else { + scatterwalk_map_and_copy(areq->iv, areq->dst, areq->cryptlen - ivsize, + ivsize, 0); } } @@ -161,6 +172,7 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) unsigned int ileft = areq->cryptlen; unsigned int oleft = areq->cryptlen; unsigned int todo; + void *backup_iv = NULL; struct sg_mapping_iter mi, mo; unsigned int oi, oo; /* offset for in and out */ char buf[4 * SS_RX_MAX];/* buffer for linearize SG src */ @@ -204,6 +216,13 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) if (need_fallback) return sun4i_ss_cipher_poll_fallback(areq); + if (areq->iv && ivsize > 0 && mode & SS_DECRYPTION) { + backup_iv = kzalloc(ivsize, GFP_KERNEL); + if (!backup_iv) + return -ENOMEM; + scatterwalk_map_and_copy(backup_iv, areq->src, areq->cryptlen - ivsize, ivsize, 0); + } + spin_lock_irqsave(&ss->slock, flags); for (i = 0; i < op->keylen; i += 4) @@ -324,9 +343,12 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq) } } if (areq->iv) { - for (i = 0; i < 4 && i < ivsize / 4; i++) { - v = readl(ss->base + SS_IV0 + i * 4); - *(u32 *)(areq->iv + i * 4) = v; + if (mode & SS_DECRYPTION) { + memcpy(areq->iv, backup_iv, ivsize); + kfree_sensitive(backup_iv); + } else { + scatterwalk_map_and_copy(areq->iv, areq->dst, areq->cryptlen - ivsize, + ivsize, 0); } }