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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D8FCC4332F for ; Tue, 20 Dec 2022 10:09:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC2E08E0003; Tue, 20 Dec 2022 05:09:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D4B5D8E0001; Tue, 20 Dec 2022 05:09:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BEC0C8E0003; Tue, 20 Dec 2022 05:09:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A7C6F8E0001 for ; Tue, 20 Dec 2022 05:09:30 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 6A770AAC76 for ; Tue, 20 Dec 2022 10:09:30 +0000 (UTC) X-FDA: 80262262500.23.8662DB0 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf29.hostedemail.com (Postfix) with ESMTP id DC588120010 for ; Tue, 20 Dec 2022 10:09:28 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=mifUTTsP; dmarc=none; spf=none (imf29.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671530969; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mQoXx7ooWzXAgLu3DbAl3UCLnz1vvc6S+1s5Rvnq/UI=; b=qKyH5XtknWNBsPT/IoNFKTQ4Yezg2mzvliquEShwse6hYsGDnYMf3adE+XqdaNCwI6h71o 3V0OiLeC3b7x9/zg8J5UQYTSDwsZEOF0ssaxGHObowbquH8hlguA7mq2/YrGYudklTUVIt eaEmaVcR6MpzUUK8ubYgLne6z0bkKa4= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=mifUTTsP; dmarc=none; spf=none (imf29.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671530969; a=rsa-sha256; cv=none; b=6BCgt8wqLuvA+6DukFSPvtoKwg4X3iJkSalt1MkmnQ0lyb68SjuCc509D1urP2/5FBvH7i pzmVQ5RsMXjB5GK+rq5/J3yxi4mlGzmac5rhlRQtkjk+/PnAxTqt6nzRHmfpjxIz1NCshP vF7nVoDovC8Bk5jQDgztWg2rMyycpjg= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=mQoXx7ooWzXAgLu3DbAl3UCLnz1vvc6S+1s5Rvnq/UI=; b=mifUTTsP8pp/47e91n+1G5oAGl Sytj5m/XMsUymJR6hl/wNCZLxJsqkWKZXV+2zQ9MuvryuM7nKDKoAqAQ47XIXHOwTkmCnuAIWfLzy kvCyAKW+BmJSyHpcIlgvM9T9OjzbLtAmUKFjsenj43QJM2fi5Xma65xF7N16RYVY+HIBbMM/xNj8m NKKtjqtohqpqRmTU/UMIe6VUfhSD3zdYZD+48z3UOu2A8I28cV3h4WcSCrs4PMqs35w3gh9dWKGpE lNnqsH4LvQIcWKg375a/JZouT1oGuIk24Gb0pp6Tk1QK1kw2Is+yw2SAYC4ayabXxOXP9bj1K0vvl 6nEPcutQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1p7ZYt-001gUJ-QB; Tue, 20 Dec 2022 10:09:27 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 237DC300023; Tue, 20 Dec 2022 11:09:17 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id DF1E6200AB1CE; Tue, 20 Dec 2022 11:09:16 +0100 (CET) Date: Tue, 20 Dec 2022 11:09:16 +0100 From: Peter Zijlstra To: Eric Biggers Cc: linux-crypto@vger.kernel.org, corbet@lwn.net, will@kernel.org, boqun.feng@gmail.com, mark.rutland@arm.com, catalin.marinas@arm.com, dennis@kernel.org, tj@kernel.org, cl@linux.com, hca@linux.ibm.com, gor@linux.ibm.com, agordeev@linux.ibm.com, borntraeger@linux.ibm.com, svens@linux.ibm.com, Herbert Xu , davem@davemloft.net, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, joro@8bytes.org, suravee.suthikulpanit@amd.com, robin.murphy@arm.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, Arnd Bergmann , penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, Andrew Morton , vbabka@suse.cz, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-s390@vger.kernel.org, iommu@lists.linux.dev, linux-arch@vger.kernel.org Subject: Re: [PATCH 3/3] crypto: x86/ghash - add comment and fix broken link Message-ID: References: <20221220054042.188537-1-ebiggers@kernel.org> <20221220054042.188537-4-ebiggers@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221220054042.188537-4-ebiggers@kernel.org> X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: DC588120010 X-Stat-Signature: 6dfnybg1u5466tp7dgc37bwojshg8win X-HE-Tag: 1671530968-630077 X-HE-Meta: U2FsdGVkX1+qTqKgY3jF8d1on7vYE94xUUvVklWy+tu1BN0RGiQszGVp7BUjzDq6nuNWPz2UpxQEaYj42aZKeoQrMxxfEPYF1hBQBuvW+6CKkrjJqbvBWeDcBSa7XbYR/25JjKXOwZ5/UxuNbUSQYrFCppnzKjL7X89AgEVng4aNJ4P3XlvSY/9dgIHgyKLtfpCLH6c7X3GBGtD7lAKiqVHmU5JtMqveFnErqY2UGqMKH4I9y3S0aaB/DqFq3BLIKEKY+0U0VZ7nLqqTX7LA0ROKlLLjpAB4jX+uUNREYcaObM4Dhx9kDhYTeUq9iXdEhxlZiqXpPftROSD02E6ObaqENLI8s1mS8Mf3udx0auWRdBnd4oM48cBgEf3kCIEaoPm3aklvjcQIriuiTzaTUmGCQeJnBsmQAU8ArTkssK9bRkkSGQBI/EI/UHpP6yMeBLaIL0S4fXVneT7ASHh7z9gbKMBnFyurTpHK6NWBi5d1i0jFftFFM4/eq7QtTcZOI4tO7Bm0TiJJkqv/XaJVEztCARamOgD7lpLGoh/HE/pQwmnGzi8k6DjEOO+PsFY3dIN1YjpydtCzCWF1whF8ZRNrwBJWak0Dp/uiiGXNuQZkqj9+u6yhNzFKwXY5fUdPgadfYrjO7tjptAYE6Vyp2PNSE83uUaIFLp9WoWKE0kNQrq69CIll+P304TQlZk784BLU9Cxp5vtKistd9/LSpSyoQIKOMZECLmauEHwTdG0j+waDeXB1wQEjqSy1EjsqP9dm9iTEP1zCkfa0vr0y2G1gQM5aF3p5v23A8QtcLUXO1P213f2/M1bJpYEAsZuahyRYhTsNY4euZsiPaKJns07Ad+pM6F0UdabjJAxoU18M9F86cg/kA26DD3sIKixTSZ6c0LaevPWgk4oynxEPaMXH8uuKHaffiY/iYovNxfk= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Dec 19, 2022 at 09:40:42PM -0800, Eric Biggers wrote: > From: Eric Biggers > > Add a comment that explains what ghash_setkey() is doing, as it's hard > to understand otherwise. Also fix a broken hyperlink. > > Signed-off-by: Eric Biggers > --- > arch/x86/crypto/ghash-clmulni-intel_asm.S | 2 +- > arch/x86/crypto/ghash-clmulni-intel_glue.c | 27 ++++++++++++++++++---- > 2 files changed, 24 insertions(+), 5 deletions(-) > > diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S > index 9dfeb4d31b92..257ed9446f3e 100644 > --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S > +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S > @@ -4,7 +4,7 @@ > * instructions. This file contains accelerated part of ghash > * implementation. More information about PCLMULQDQ can be found at: > * > - * http://software.intel.com/en-us/articles/carry-less-multiplication-and-its-usage-for-computing-the-gcm-mode/ > + * https://www.intel.com/content/dam/develop/external/us/en/documents/clmul-wp-rev-2-02-2014-04-20.pdf Since these things have a habbit if changing, we tend to prefer to host a copy on kernel.org somewhere (used to be bugzilla, but perhaps there's a better places these days). > * > * Copyright (c) 2009 Intel Corp. > * Author: Huang Ying > diff --git a/arch/x86/crypto/ghash-clmulni-intel_glue.c b/arch/x86/crypto/ghash-clmulni-intel_glue.c > index 9453b094bb3b..700ecaee9a08 100644 > --- a/arch/x86/crypto/ghash-clmulni-intel_glue.c > +++ b/arch/x86/crypto/ghash-clmulni-intel_glue.c > @@ -60,16 +60,35 @@ static int ghash_setkey(struct crypto_shash *tfm, > if (keylen != GHASH_BLOCK_SIZE) > return -EINVAL; > > - /* perform multiplication by 'x' in GF(2^128) */ > + /* > + * GHASH maps bits to polynomial coefficients backwards, which makes it > + * hard to implement. But it can be shown that the GHASH multiplication > + * > + * D * K (mod x^128 + x^7 + x^2 + x + 1) > + * > + * (where D is a data block and K is the key) is equivalent to: > + * > + * bitreflect(D) * bitreflect(K) * x^(-127) > + * (mod x^128 + x^127 + x^126 + x^121 + 1) > + * > + * So, the code below precomputes: > + * > + * bitreflect(K) * x^(-127) (mod x^128 + x^127 + x^126 + x^121 + 1) > + * > + * ... but in Montgomery form (so that Montgomery multiplication can be > + * used), i.e. with an extra x^128 factor, which means actually: > + * > + * bitreflect(K) * x (mod x^128 + x^127 + x^126 + x^121 + 1) > + * > + * The within-a-byte part of bitreflect() cancels out GHASH's built-in > + * reflection, and thus bitreflect() is actually a byteswap. > + */ Whee, thanks, that was indeed entirely non-obvious.