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=-14.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, 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 92430C433FE for ; Sat, 12 Dec 2020 19:49: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 4CDC722257 for ; Sat, 12 Dec 2020 19:49:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4CDC722257 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=EspyZpLUHN2Q/mZ1Bka5347u4w0QMxGcXpYtpKQdihE=; b=KUq8XzNxGcn+rJsVIFRp56wuw uQFaN4UoSzC5eXQQgHN2FjJcCvUoMBoUqDE351Hd2baUTce7jC1S+tflREOTmMSQEBrCKAgpfFdmv jJLUxNCr31/l5+hAUY6vqNcZYLsktMft8bMlb++pJeCNjBsEKxDoZYzWE6OvMnQz4b2FZZG6UgsiP CZ34BPb+tNI0ECLEpfFm6Abvnd6TISTj457Qxpd5uP5nDIgZuhzqk4OeTBDyOeNiG4aHkU3Rgis6J fPom0tSot1GHIPn1KZJMXN9i7p4ai9iOLP3qcOAL3WJV/vqio7TVxERKdM2jAkzIH8ikJoV4KO/ag hB7KbSlKw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1koAsI-0003Ks-GA; Sat, 12 Dec 2020 19:48:14 +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 1koAsF-0003KX-Bn for linux-arm-kernel@lists.infradead.org; Sat, 12 Dec 2020 19:48:12 +0000 Date: Sat, 12 Dec 2020 11:48:08 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1607802489; bh=3aKr4v+i7KrJ+/Nfda/fGXDWB/9VCxMZkwZGpDIuFKY=; h=From:To:Cc:Subject:References:In-Reply-To:From; b=WpFQpG5qolNpv1gtAFkxVPl1ZGnKqa0PxiDR7lnBFMHq4WJxxrXn4+wDLAKroYAlx sHe6tdiopSV/LI4mkthukp9XJ1f2Zx9Tj13vM4HLlsRkliNJYsKo9N6qs362i/sB+r +8vY/dm6Gew0DlA/QUJYWEHmFxeBt8mLPDvAtrcLEcZyjYMYqtyzNXUEk1GrsGrHQc JIquqwX/wLM0VOAjZFqNQFAhspekIF4QTqr1hbFpJn+UHIdjF51e6XFywbywYUHsKF fgzYT61lQZz2SCVi1PW174lDUvq19GtCbPl+zaiKrWl3PT0oYrsyvhCn1u8dZ07y4W Dkg/IjQXKmJtg== 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: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201212_144811_552746_FB1E2762 X-CRM114-Status: GOOD ( 23.39 ) 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 , "Jason A . Donenfeld" , Linux Crypto Mailing List , Linux ARM , Herbert Xu 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 On Sat, Dec 12, 2020 at 08:24:24AM +0100, Ard Biesheuvel wrote: > On Sat, 12 Dec 2020 at 07:43, Eric Biggers wrote: > > > > 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. > > > > Yeah, good point. 'bytes' could be exactly CHACHA_BLOCK_SIZE now, > which wasn't the case before. > > I'll send a fix. > > > 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? > > > > Does your QEMU lack this patch? I found that bug working on this code. > > https://git.qemu.org/?p=qemu.git;a=commitdiff;h=604cef3e57eaeeef77074d78f6cf2eca1be11c62 It doesn't have that patch. That must be the problem then; good to hear that you've already fixed it. - Eric _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel