aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crypto/api.c2
-rw-r--r--drivers/crypto/padlock-aes.c6
-rw-r--r--include/linux/crypto.h10
3 files changed, 15 insertions, 3 deletions
diff --git a/crypto/api.c b/crypto/api.c
index e26156f7183..34e02caffc2 100644
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -165,7 +165,7 @@ static unsigned int crypto_ctxsize(struct crypto_alg *alg, int flags)
break;
}
- return len + alg->cra_alignmask;
+ return len + (alg->cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1));
}
struct crypto_tfm *crypto_alloc_tfm(const char *name, u32 flags)
diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c
index 0c08c58252b..5158a9db4bc 100644
--- a/drivers/crypto/padlock-aes.c
+++ b/drivers/crypto/padlock-aes.c
@@ -284,7 +284,11 @@ aes_hw_extkey_available(uint8_t key_len)
static inline struct aes_ctx *aes_ctx(void *ctx)
{
- return (struct aes_ctx *)ALIGN((unsigned long)ctx, PADLOCK_ALIGNMENT);
+ unsigned long align = PADLOCK_ALIGNMENT;
+
+ if (align <= crypto_tfm_ctx_alignment())
+ align = 1;
+ return (struct aes_ctx *)ALIGN((unsigned long)ctx, align);
}
static int
diff --git a/include/linux/crypto.h b/include/linux/crypto.h
index d88bf8aa8b4..0ab1bc1152c 100644
--- a/include/linux/crypto.h
+++ b/include/linux/crypto.h
@@ -229,6 +229,8 @@ struct crypto_tfm {
} crt_u;
struct crypto_alg *__crt_alg;
+
+ char __crt_ctx[] __attribute__ ((__aligned__));
};
/*
@@ -301,7 +303,13 @@ static inline unsigned int crypto_tfm_alg_alignmask(struct crypto_tfm *tfm)
static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm)
{
- return (void *)&tfm[1];
+ return tfm->__crt_ctx;
+}
+
+static inline unsigned int crypto_tfm_ctx_alignment(void)
+{
+ struct crypto_tfm *tfm;
+ return __alignof__(tfm->__crt_ctx);
}
/*