Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
[sfrench/cifs-2.6.git] / crypto / ghash-generic.c
index 6425b9cd718e6a69e3074b011acedef2deaa0271..dad9e1f91a783f66f6cfcaf9521de45c6f57ba32 100644 (file)
@@ -31,6 +31,7 @@ static int ghash_setkey(struct crypto_shash *tfm,
                        const u8 *key, unsigned int keylen)
 {
        struct ghash_ctx *ctx = crypto_shash_ctx(tfm);
+       be128 k;
 
        if (keylen != GHASH_BLOCK_SIZE) {
                crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
@@ -39,7 +40,12 @@ static int ghash_setkey(struct crypto_shash *tfm,
 
        if (ctx->gf128)
                gf128mul_free_4k(ctx->gf128);
-       ctx->gf128 = gf128mul_init_4k_lle((be128 *)key);
+
+       BUILD_BUG_ON(sizeof(k) != GHASH_BLOCK_SIZE);
+       memcpy(&k, key, GHASH_BLOCK_SIZE); /* avoid violating alignment rules */
+       ctx->gf128 = gf128mul_init_4k_lle(&k);
+       memzero_explicit(&k, GHASH_BLOCK_SIZE);
+
        if (!ctx->gf128)
                return -ENOMEM;