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=-9.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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 C0C25C433FE for ; Sat, 12 Dec 2020 06:45:26 +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 744992311A for ; Sat, 12 Dec 2020 06:45:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 744992311A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org 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:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=81tWZ3HraCBvLu+bkBUbuEr/6Djx9tO16Zw0y/0qKZ4=; b=g2u/SQSCq9+PkN1+M3qgYcClF C+8eDiTeqfPHxWifcfL3Ip2HG16/7qRTE8ZubZUJ1m3AVqqq3LcPe4qyF71zz/tSP7OB0WaFPvyfi UHifZbi4R+wY/yn7pvh+XcIvejM0n0zzGmGZ/vTB4oK5dr2imxIDb9nj8RDnWbxQMFmlE5jzKPgAv VBbOHLTaXvIuKNnwsY69dDmPg1lCF2kytq2ZWHMPQgHa35WG1+flaLZDRU+spuxsyDsTjKLG4QfED WTgsTctthSJYIUZRcYF4Q1BA+7IeR2p2Q6cOybEeT7L8AVZVD97r8U+hDa7dWJnZJ23rtcLGme7Jj 0+8gDyIzg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1knyd7-0004fZ-8e; Sat, 12 Dec 2020 06:43:45 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1knycz-0004fD-F6 for linux-arm-kernel@lists.infradead.org; Sat, 12 Dec 2020 06:43:38 +0000 Date: Fri, 11 Dec 2020 22:43:33 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1607755416; bh=BKe3RqZftxgWgdo4mwyE9tnxQC7zlNP7NcNvP7TPzvE=; h=From:To:Cc:Subject:References:In-Reply-To:From; b=aF3+08tB4biUWZmUuNEQVmTAEYpzFjCY9FGeh4mJLe5arcieKvnJ8dx4cKptqd6wI 9Ye/zJ5dQo0qpo4YE4fkFqk3FgqiaAkF7srv4pVq5nmu3N4GGq9LNyEmcRy/bOMuT6 +kq+TMjmVfp7i7UNMfkuca/tzzgkhJqRH7acmvJXqxu+xspEr929BAak6ad0uxKZsJ AkKrnFTn2maCd3Fxv2YKFcHFjR39Zz/PG9Hsi42uBqbXUmuCJA5BbOXDDvKwouZ5c7 WyjjVKgVMd4nPFxY/nBaWTfnNgHtUXl57dNMvB19+I3nOYhaLqe5Yyqf/Y9tYW9/Wu hBOw7FdFf4Q7g== From: Eric Biggers To: Ard Biesheuvel Subject: Re: [PATCH v2] crypto: arm/chacha-neon - optimize for non-block size multiples Message-ID: References: <20201103162809.28167-1-ardb@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201103162809.28167-1-ardb@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201212_014337_588033_560398CB X-CRM114-Status: GOOD ( 15.28 ) 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: andre.przywara@arm.com, "Jason A . Donenfeld" , linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, herbert@gondor.apana.org.au 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 Hi Ard, On Tue, Nov 03, 2020 at 05:28:09PM +0100, Ard Biesheuvel wrote: > @@ -42,24 +42,24 @@ static void chacha_doneon(u32 *state, u8 *dst, const u8 *src, > { > u8 buf[CHACHA_BLOCK_SIZE]; > > - while (bytes >= CHACHA_BLOCK_SIZE * 4) { > - chacha_4block_xor_neon(state, dst, src, nrounds); > - bytes -= CHACHA_BLOCK_SIZE * 4; > - src += CHACHA_BLOCK_SIZE * 4; > - dst += CHACHA_BLOCK_SIZE * 4; > - state[12] += 4; > - } > - while (bytes >= CHACHA_BLOCK_SIZE) { > - chacha_block_xor_neon(state, dst, src, nrounds); > - bytes -= CHACHA_BLOCK_SIZE; > - src += CHACHA_BLOCK_SIZE; > - dst += CHACHA_BLOCK_SIZE; > - state[12]++; > + while (bytes > CHACHA_BLOCK_SIZE) { > + unsigned int l = min(bytes, CHACHA_BLOCK_SIZE * 4U); > + > + chacha_4block_xor_neon(state, dst, src, nrounds, l); > + bytes -= l; > + src += l; > + dst += l; > + state[12] += DIV_ROUND_UP(l, CHACHA_BLOCK_SIZE); > } > if (bytes) { > - memcpy(buf, src, bytes); > - chacha_block_xor_neon(state, buf, buf, nrounds); > - memcpy(dst, buf, bytes); > + const u8 *s = src; > + u8 *d = dst; > + > + if (bytes != CHACHA_BLOCK_SIZE) > + s = d = memcpy(buf, src, bytes); > + chacha_block_xor_neon(state, d, s, nrounds); > + if (d != dst) > + memcpy(dst, buf, bytes); > } > } > Shouldn't this be incrementing the block counter after chacha_block_xor_neon()? It might be needed by the library API. Also, even with that fixed, this patch is causing the self-tests (both the chacha20poly1305_selftest(), and the crypto API tests for chacha20-neon, xchacha20-neon, and xchacha12-neon) to fail when I boot a kernel in QEMU. This doesn't happen on real hardware (Raspberry Pi 2), and I don't see any other bugs in this patch, so I'm not sure what the problem is. Did you run the self-tests on every platform you tested this on? - Eric _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel