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 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 61942C433F5 for ; Mon, 18 Apr 2022 19:30:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc: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=K6HcXgDJe897J8bK9ek8FANmxZxLws379Tm4ufAeEWo=; b=vFCRw6nwxQuo9I 4B50nqZdMLEcJnp06JG6C1vwTt01xj6JSQI+AHXap16WpdjpS7IHBy0h1lJl0//eaRZ+ciabALPXp s+5i7xrspXQs2svrrOFHqG7cnSPctYmJZ/kgLelSGcVesHfQoKf/+iyYtb5MG24zcEBedTIrcNpYs yHtdI9TCp0/Cb2QcRb4vVnWNC9DdbPHyTI+4dK2AyLsR/gpA9M5+vFN+guxbiHmU59xGSwmCMWF4L +sSJdNamC+iiWaXCk7KNfyO2SNAPWrdVdbjlmeDVJ5vWQlndlb+2vDoI4yNEfJlPKEwbkXeSsm4wT D+YpzSHN4ivw3foRu2Dw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ngWzy-000RxL-Ek; Mon, 18 Apr 2022 19:25:22 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ngWzu-000Rwx-Jb for linux-arm-kernel@lists.infradead.org; Mon, 18 Apr 2022 19:25:20 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E9813B8108B; Mon, 18 Apr 2022 19:25:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E3A8C385A7; Mon, 18 Apr 2022 19:25:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1650309915; bh=o6iVkFHcSfJOiTVdyReysKo15hofwoteSZoJNDuK3ms=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=K2GnLYyyWnPh5ZQmFUavbjRjNhqSRDEtuIyk7UJ0a/mkqEgzjIXv7p+5IRwryzefH D2w0dd+yjod2znUKU7SO3ysB0j5+wLH7dIUUsP+aKU20e8CRTbZW4f2dUSFaRhwKw5 K3LybEf7hivxkA0gslolkzwEohc66hqXccZR6FhE6SmhTN3+i45aubVMhGzb0Mq/ts DV4d6tGBVH8ccZUAwJKAiIvk7jLAw7yqQPQE4CrZscy/7pndM4IJWzJ/1ITlfRzgdg fLLdIDHq08Q6pBLMxh6DcYD421qqO4HFL9gsahH87hjhWWFTFtZO/Pukb1Zp0TJrRL jjx7z22ukQQbg== Date: Mon, 18 Apr 2022 12:25:13 -0700 From: Eric Biggers To: Nathan Huckleberry Cc: linux-crypto@vger.kernel.org, Herbert Xu , "David S. Miller" , linux-arm-kernel@lists.infradead.org, Paul Crowley , Sami Tolvanen , Ard Biesheuvel Subject: Re: [PATCH v4 2/8] crypto: polyval - Add POLYVAL support Message-ID: References: <20220412172816.917723-1-nhuck@google.com> <20220412172816.917723-3-nhuck@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220412172816.917723-3-nhuck@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220418_122518_990245_9E507F40 X-CRM114-Status: GOOD ( 14.33 ) 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: , 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 A couple more nits: On Tue, Apr 12, 2022 at 05:28:10PM +0000, Nathan Huckleberry wrote: > +static int polyval_init(struct shash_desc *desc) [...] > +static int polyval_setkey(struct crypto_shash *tfm, As I mentioned on the x86 patch, setkey() is the first step, before init(). People sometimes mix this up, e.g. see https://git.kernel.org/linus/f3aefb6a7066e24b. Putting the definitions in their natural order might be helpful: 1. polyval_setkey() 2. polyval_init() 3. polyval_update() 4. polyval_final() > +static void reverse_block(u8 block[POLYVAL_BLOCK_SIZE]) > +{ > + u64 *p1 = (u64 *)block; > + u64 *p2 = (u64 *)&block[8]; > + u64 a = get_unaligned(p1); > + u64 b = get_unaligned(p2); > + > + put_unaligned(swab64(a), p2); > + put_unaligned(swab64(b), p1); > +} This is always paired with a memcpy() of the block, so consider making this helper function handle the copy too. E.g. diff --git a/crypto/polyval-generic.c b/crypto/polyval-generic.c index 1399af125b937..b50db5dd51fd1 100644 --- a/crypto/polyval-generic.c +++ b/crypto/polyval-generic.c @@ -75,15 +75,14 @@ static int polyval_init(struct shash_desc *desc) return 0; } -static void reverse_block(u8 block[POLYVAL_BLOCK_SIZE]) +static void copy_and_reverse(u8 dst[POLYVAL_BLOCK_SIZE], + const u8 src[POLYVAL_BLOCK_SIZE]) { - u64 *p1 = (u64 *)block; - u64 *p2 = (u64 *)&block[8]; - u64 a = get_unaligned(p1); - u64 b = get_unaligned(p2); + u64 a = get_unaligned((const u64 *)&src[0]); + u64 b = get_unaligned((const u64 *)&src[8]); - put_unaligned(swab64(a), p2); - put_unaligned(swab64(b), p1); + put_unaligned(swab64(a), (u64 *)&dst[8]); + put_unaligned(swab64(b), (u64 *)&dst[0]); } static int polyval_setkey(struct crypto_shash *tfm, @@ -98,10 +97,7 @@ static int polyval_setkey(struct crypto_shash *tfm, gf128mul_free_4k(ctx->gf128); BUILD_BUG_ON(sizeof(k) != POLYVAL_BLOCK_SIZE); - // avoid violating alignment rules - memcpy(&k, key, POLYVAL_BLOCK_SIZE); - - reverse_block((u8 *)&k); + copy_and_reverse((u8 *)&k, key); gf128mul_x_lle(&k, &k); ctx->gf128 = gf128mul_init_4k_lle(&k); @@ -137,8 +133,7 @@ static int polyval_update(struct shash_desc *desc, } while (srclen >= POLYVAL_BLOCK_SIZE) { - memcpy(tmp, src, POLYVAL_BLOCK_SIZE); - reverse_block(tmp); + copy_and_reverse(tmp, src); crypto_xor(dctx->buffer, tmp, POLYVAL_BLOCK_SIZE); gf128mul_4k_lle(&dctx->buffer128, ctx->gf128); src += POLYVAL_BLOCK_SIZE; @@ -162,11 +157,7 @@ static int polyval_final(struct shash_desc *desc, u8 *dst) if (dctx->bytes) gf128mul_4k_lle(&dctx->buffer128, ctx->gf128); - dctx->bytes = 0; - - reverse_block(dctx->buffer); - memcpy(dst, dctx->buffer, POLYVAL_BLOCK_SIZE); - + copy_and_reverse(dst, dctx->buffer); return 0; } _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel