Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: x86/ghash - add comment and fix broken link

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@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Eric Biggers and committed by
Herbert Xu
750426d6 f1740751

+24 -5
+1 -1
arch/x86/crypto/ghash-clmulni-intel_asm.S
··· 4 4 * instructions. This file contains accelerated part of ghash 5 5 * implementation. More information about PCLMULQDQ can be found at: 6 6 * 7 - * http://software.intel.com/en-us/articles/carry-less-multiplication-and-its-usage-for-computing-the-gcm-mode/ 7 + * https://www.intel.com/content/dam/develop/external/us/en/documents/clmul-wp-rev-2-02-2014-04-20.pdf 8 8 * 9 9 * Copyright (c) 2009 Intel Corp. 10 10 * Author: Huang Ying <ying.huang@intel.com>
+23 -4
arch/x86/crypto/ghash-clmulni-intel_glue.c
··· 60 60 if (keylen != GHASH_BLOCK_SIZE) 61 61 return -EINVAL; 62 62 63 - /* perform multiplication by 'x' in GF(2^128) */ 63 + /* 64 + * GHASH maps bits to polynomial coefficients backwards, which makes it 65 + * hard to implement. But it can be shown that the GHASH multiplication 66 + * 67 + * D * K (mod x^128 + x^7 + x^2 + x + 1) 68 + * 69 + * (where D is a data block and K is the key) is equivalent to: 70 + * 71 + * bitreflect(D) * bitreflect(K) * x^(-127) 72 + * (mod x^128 + x^127 + x^126 + x^121 + 1) 73 + * 74 + * So, the code below precomputes: 75 + * 76 + * bitreflect(K) * x^(-127) (mod x^128 + x^127 + x^126 + x^121 + 1) 77 + * 78 + * ... but in Montgomery form (so that Montgomery multiplication can be 79 + * used), i.e. with an extra x^128 factor, which means actually: 80 + * 81 + * bitreflect(K) * x (mod x^128 + x^127 + x^126 + x^121 + 1) 82 + * 83 + * The within-a-byte part of bitreflect() cancels out GHASH's built-in 84 + * reflection, and thus bitreflect() is actually a byteswap. 85 + */ 64 86 a = get_unaligned_be64(key); 65 87 b = get_unaligned_be64(key + 8); 66 - 67 88 ctx->shash.a = cpu_to_le64((a << 1) | (b >> 63)); 68 89 ctx->shash.b = cpu_to_le64((b << 1) | (a >> 63)); 69 - 70 90 if (a >> 63) 71 91 ctx->shash.a ^= cpu_to_le64((u64)0xc2 << 56); 72 - 73 92 return 0; 74 93 } 75 94