From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF805C2BB48 for ; Mon, 14 Dec 2020 20:04:33 +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 9FC77207A2 for ; Mon, 14 Dec 2020 20:04:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9FC77207A2 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+linux-arm-kernel=archiver.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=udr0yjmrspqK9UQ5QzrfLHbDvKXpfwopNvS8iBrPCCg=; b=NOZFNi7ugDzh9wBXvyTFkcii+K aGDwXgK5XJoWchKvQisgTKW8/BgKB2lWx68Zq73LL8Zcjk+75q/kxfzqoqsX/psDSLoU+SMx8v1wd yb/Xroz8XucD9Bb+Eq8TjusWfZSIIvEFEiIqWrLA8EU7/AZO4xmuqSfBFTF9X2KkzbAQW2pejMDNl 7aOnDROY4wTjoKHcK7JoJuLLhjpGrr8T2dTlo59DR9QMHP0gVb55sbDuUChceTdzym2CtoIELnOGe f19rYeuhZwmsHlVJahC3IyLX3rzd773NpVUHXOOaT9M6ybK5Zi4dl31vKfBaKD7DDFDOhpqos4XFe 1v9sU8yA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kou3v-0007QQ-Pu; Mon, 14 Dec 2020 20:03:15 +0000 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kou3r-0007P8-RY for linux-arm-kernel@lists.infradead.org; Mon, 14 Dec 2020 20:03:13 +0000 Received: by mail-pj1-x1043.google.com with SMTP id b5so7348187pjl.0 for ; Mon, 14 Dec 2020 12:03:11 -0800 (PST) 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=mhauqzte4SJbuo85PM/RZAliMy73/eGjDvxrpH1oQU4=; b=l9xgQyB5zjgkCGjyqAVgK6gxKFbynKpwdZlSE6VMtp0Ch6cMS4ZsJBmrItSuYyXFNq /Gp9X1j8UHNFm2juKHYalJ5aZT0wb+T++K52CaecvviwslaHIkL4iH3CUPVe+ggV3KUT Um1SUlUVGCY4GJxGsMA9OA30UiMmTMT4ypJ8LNSYR4QzmgR1cY7RA7nkRrxUekRleFQq eBQ5h91fT3Pf6mB0k9RVpM3WozqV10YxtdEermLD2WCz1ZYTny+FLFL/1UvJN+ipjTzw ZsUU92hzfUruPFSp/RXA+OxB4TeAzj9NgYxD//7mN4Dmi7VQQLVvZOW8bNCerEH0wAVW 8CTg== 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=mhauqzte4SJbuo85PM/RZAliMy73/eGjDvxrpH1oQU4=; b=co53XdyWX3ZueWRxJ/Xs5BQk1+9vqgUHQRByj0LdlfZxvYFlZIwuOhgAZcJ+73EMEx Z04I7c7t0QWHDjVX8ADhhFwl/1/iFaBoOj3UKQ4YVRrLfrNQ4nITkAGVQkSGXh2ywBZU lApI9ULzR3/L1yUPSLVLPBJ6Nlze2utQqas7tEprSRqdjdrK56E1CO154CxLKfWWbCQv HEIAJHuwO5OAo2uWoMyANygie07iqtJG1rThoAc8xKDq+3t2LupFhLE80YGQpRHOkexw D6tEDbeXuTts+c5+54GvaOxw5heShy+3y7tgid0yHRghSONzBV+sxb1/rPmd8sBIEDjL CsEQ== X-Gm-Message-State: AOAM533x9jhqzmZmGyD//KQmY5+futp1HL/DT+KbzsLpFrYJ3fl5hQkz lqSW1MUmylEod93jqT26x6L4R7vPwfBdtg== X-Google-Smtp-Source: ABdhPJy/trSmJp3u3Ah+OXevgu0p8lTfXgL2QEj3S7UmptY3EDmKUPahfnHf5Luy82j4ghyIoSFWHw== X-Received: by 2002:a17:90b:2317:: with SMTP id mt23mr27087120pjb.2.1607976189937; Mon, 14 Dec 2020 12:03:09 -0800 (PST) Received: from localhost.localdomain ([163.172.76.58]) by smtp.googlemail.com with ESMTPSA id js9sm22434109pjb.2.2020.12.14.12.03.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Dec 2020 12:03:08 -0800 (PST) From: Corentin Labbe To: arnd@arndb.de, davem@davemloft.net, herbert@gondor.apana.org.au, jernej.skrabec@siol.net, mripard@kernel.org, wens@csie.org Subject: [PATCH v4 3/8] crypto: sun4i-ss: IV register does not work on A10 and A13 Date: Mon, 14 Dec 2020 20:02:27 +0000 Message-Id: <20201214200232.17357-4-clabbe@baylibre.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201214200232.17357-1-clabbe@baylibre.com> References: <20201214200232.17357-1-clabbe@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201214_150311_930194_1705825C X-CRM114-Status: GOOD ( 17.96 ) 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.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 f49797588329..c7bf731dad7b 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 */ unsigned int ob = 0; /* offset in buf */ @@ -202,6 +214,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) @@ -322,9 +341,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); } } -- 2.26.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel