lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y6GJzD9PLKj+Ocr2@hirez.programming.kicks-ass.net>
Date:   Tue, 20 Dec 2022 11:09:16 +0100
From:   Peter Zijlstra <peterz@...radead.org>
To:     Eric Biggers <ebiggers@...nel.org>
Cc:     linux-crypto@...r.kernel.org, corbet@....net, will@...nel.org,
        boqun.feng@...il.com, mark.rutland@....com,
        catalin.marinas@....com, dennis@...nel.org, tj@...nel.org,
        cl@...ux.com, hca@...ux.ibm.com, gor@...ux.ibm.com,
        agordeev@...ux.ibm.com, borntraeger@...ux.ibm.com,
        svens@...ux.ibm.com, Herbert Xu <herbert@...dor.apana.org.au>,
        davem@...emloft.net, tglx@...utronix.de, mingo@...hat.com,
        bp@...en8.de, dave.hansen@...ux.intel.com, x86@...nel.org,
        hpa@...or.com, joro@...tes.org, suravee.suthikulpanit@....com,
        robin.murphy@....com, dwmw2@...radead.org,
        baolu.lu@...ux.intel.com, Arnd Bergmann <arnd@...db.de>,
        penberg@...nel.org, rientjes@...gle.com, iamjoonsoo.kim@....com,
        Andrew Morton <akpm@...ux-foundation.org>, vbabka@...e.cz,
        roman.gushchin@...ux.dev, 42.hyeyoo@...il.com,
        linux-doc@...r.kernel.org, linux-kernel@...r.kernel.org,
        linux-mm@...ck.org, linux-s390@...r.kernel.org,
        iommu@...ts.linux.dev, linux-arch@...r.kernel.org
Subject: Re: [PATCH 3/3] crypto: x86/ghash - add comment and fix broken link

On Mon, Dec 19, 2022 at 09:40:42PM -0800, Eric Biggers wrote:
> From: Eric Biggers <ebiggers@...gle.com>
> 
> 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 <ebiggers@...gle.com>
> ---
>  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 <ying.huang@...el.com>
> 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.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ