Skip to content

Commit a9149a3

Browse files
Ard BiesheuvelJiri Slaby
authored andcommitted
crypto: ghash-clmulni-intel - use C implementation for setkey()
commit 8ceee72 upstream. The GHASH setkey() function uses SSE registers but fails to call kernel_fpu_begin()/kernel_fpu_end(). Instead of adding these calls, and then having to deal with the restriction that they cannot be called from interrupt context, move the setkey() implementation to the C domain. Note that setkey() does not use any particular SSE features and is not expected to become a performance bottleneck. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Acked-by: H. Peter Anvin <hpa@linux.intel.com> Fixes: 0e1227d (crypto: ghash - Add PCLMULQDQ accelerated implementation) Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
1 parent 9fc22da commit a9149a3

2 files changed

Lines changed: 11 additions & 32 deletions

File tree

‎arch/x86/crypto/ghash-clmulni-intel_asm.S‎

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
.align 16
2525
.Lbswap_mask:
2626
.octa 0x000102030405060708090a0b0c0d0e0f
27-
.Lpoly:
28-
.octa 0xc2000000000000000000000000000001
29-
.Ltwo_one:
30-
.octa 0x00000001000000000000000000000001
3127

3228
#define DATA %xmm0
3329
#define SHASH %xmm1
@@ -134,28 +130,3 @@ ENTRY(clmul_ghash_update)
134130
.Lupdate_just_ret:
135131
ret
136132
ENDPROC(clmul_ghash_update)
137-
138-
/*
139-
* void clmul_ghash_setkey(be128 *shash, const u8 *key);
140-
*
141-
* Calculate hash_key << 1 mod poly
142-
*/
143-
ENTRY(clmul_ghash_setkey)
144-
movaps .Lbswap_mask, BSWAP
145-
movups (%rsi), %xmm0
146-
PSHUFB_XMM BSWAP %xmm0
147-
movaps %xmm0, %xmm1
148-
psllq $1, %xmm0
149-
psrlq $63, %xmm1
150-
movaps %xmm1, %xmm2
151-
pslldq $8, %xmm1
152-
psrldq $8, %xmm2
153-
por %xmm1, %xmm0
154-
# reduction
155-
pshufd $0b00100100, %xmm2, %xmm1
156-
pcmpeqd .Ltwo_one, %xmm1
157-
pand .Lpoly, %xmm1
158-
pxor %xmm1, %xmm0
159-
movups %xmm0, (%rdi)
160-
ret
161-
ENDPROC(clmul_ghash_setkey)

‎arch/x86/crypto/ghash-clmulni-intel_glue.c‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ void clmul_ghash_mul(char *dst, const be128 *shash);
3030
void clmul_ghash_update(char *dst, const char *src, unsigned int srclen,
3131
const be128 *shash);
3232

33-
void clmul_ghash_setkey(be128 *shash, const u8 *key);
34-
3533
struct ghash_async_ctx {
3634
struct cryptd_ahash *cryptd_tfm;
3735
};
@@ -58,13 +56,23 @@ static int ghash_setkey(struct crypto_shash *tfm,
5856
const u8 *key, unsigned int keylen)
5957
{
6058
struct ghash_ctx *ctx = crypto_shash_ctx(tfm);
59+
be128 *x = (be128 *)key;
60+
u64 a, b;
6161

6262
if (keylen != GHASH_BLOCK_SIZE) {
6363
crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
6464
return -EINVAL;
6565
}
6666

67-
clmul_ghash_setkey(&ctx->shash, key);
67+
/* perform multiplication by 'x' in GF(2^128) */
68+
a = be64_to_cpu(x->a);
69+
b = be64_to_cpu(x->b);
70+
71+
ctx->shash.a = (__be64)((b << 1) | (a >> 63));
72+
ctx->shash.b = (__be64)((a << 1) | (b >> 63));
73+
74+
if (a >> 63)
75+
ctx->shash.b ^= cpu_to_be64(0xc2);
6876

6977
return 0;
7078
}

0 commit comments

Comments
 (0)