crypto: x86/ghash - fix unaligned access in ghash_setkey()
[ Upstream commit 116db2704c193fff6d73ea6c2219625f0c9bdfc8 ]
The key can be unaligned, so use the unaligned memory access helpers.
Fixes: 8ceee72808
("crypto: ghash-clmulni-intel - use C implementation for setkey()")
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
f6e429cde9
commit
6e43b2d9d1
@@ -19,6 +19,7 @@
|
|||||||
#include <crypto/internal/simd.h>
|
#include <crypto/internal/simd.h>
|
||||||
#include <asm/cpu_device_id.h>
|
#include <asm/cpu_device_id.h>
|
||||||
#include <asm/simd.h>
|
#include <asm/simd.h>
|
||||||
|
#include <asm/unaligned.h>
|
||||||
|
|
||||||
#define GHASH_BLOCK_SIZE 16
|
#define GHASH_BLOCK_SIZE 16
|
||||||
#define GHASH_DIGEST_SIZE 16
|
#define GHASH_DIGEST_SIZE 16
|
||||||
@@ -54,15 +55,14 @@ static int ghash_setkey(struct crypto_shash *tfm,
|
|||||||
const u8 *key, unsigned int keylen)
|
const u8 *key, unsigned int keylen)
|
||||||
{
|
{
|
||||||
struct ghash_ctx *ctx = crypto_shash_ctx(tfm);
|
struct ghash_ctx *ctx = crypto_shash_ctx(tfm);
|
||||||
be128 *x = (be128 *)key;
|
|
||||||
u64 a, b;
|
u64 a, b;
|
||||||
|
|
||||||
if (keylen != GHASH_BLOCK_SIZE)
|
if (keylen != GHASH_BLOCK_SIZE)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
/* perform multiplication by 'x' in GF(2^128) */
|
/* perform multiplication by 'x' in GF(2^128) */
|
||||||
a = be64_to_cpu(x->a);
|
a = get_unaligned_be64(key);
|
||||||
b = be64_to_cpu(x->b);
|
b = get_unaligned_be64(key + 8);
|
||||||
|
|
||||||
ctx->shash.a = (b << 1) | (a >> 63);
|
ctx->shash.a = (b << 1) | (a >> 63);
|
||||||
ctx->shash.b = (a << 1) | (b >> 63);
|
ctx->shash.b = (a << 1) | (b >> 63);
|
||||||
|
Reference in New Issue
Block a user