Commit 36f87a4a authored by Steffen Klassert's avatar Steffen Klassert Committed by Herbert Xu

crypto: xcbc - Fix alignment calculation of xcbc_tfm_ctx

The alignment calculation of xcbc_tfm_ctx uses alg->cra_alignmask
and not alg->cra_alignmask + 1 as it should. This led to frequent
crashes during the selftest of xcbc(aes-asm) on x86_64
machines. This patch fixes this. Also we use the alignmask
of xcbc and not the alignmask of the underlying algorithm
for the alignmnent calculation in xcbc_create now.
Signed-off-by: default avatarSteffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 4e4ed83b
...@@ -199,6 +199,7 @@ static int xcbc_create(struct crypto_template *tmpl, struct rtattr **tb) ...@@ -199,6 +199,7 @@ static int xcbc_create(struct crypto_template *tmpl, struct rtattr **tb)
{ {
struct shash_instance *inst; struct shash_instance *inst;
struct crypto_alg *alg; struct crypto_alg *alg;
unsigned long alignmask;
int err; int err;
err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SHASH); err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SHASH);
...@@ -228,19 +229,20 @@ static int xcbc_create(struct crypto_template *tmpl, struct rtattr **tb) ...@@ -228,19 +229,20 @@ static int xcbc_create(struct crypto_template *tmpl, struct rtattr **tb)
if (err) if (err)
goto out_free_inst; goto out_free_inst;
alignmask = alg->cra_alignmask | 3;
inst->alg.base.cra_alignmask = alignmask;
inst->alg.base.cra_priority = alg->cra_priority; inst->alg.base.cra_priority = alg->cra_priority;
inst->alg.base.cra_blocksize = alg->cra_blocksize; inst->alg.base.cra_blocksize = alg->cra_blocksize;
inst->alg.base.cra_alignmask = alg->cra_alignmask | 3;
inst->alg.digestsize = alg->cra_blocksize; inst->alg.digestsize = alg->cra_blocksize;
inst->alg.descsize = ALIGN(sizeof(struct xcbc_desc_ctx), inst->alg.descsize = ALIGN(sizeof(struct xcbc_desc_ctx),
crypto_tfm_ctx_alignment()) + crypto_tfm_ctx_alignment()) +
(alg->cra_alignmask & (alignmask &
~(crypto_tfm_ctx_alignment() - 1)) + ~(crypto_tfm_ctx_alignment() - 1)) +
alg->cra_blocksize * 2; alg->cra_blocksize * 2;
inst->alg.base.cra_ctxsize = ALIGN(sizeof(struct xcbc_tfm_ctx), inst->alg.base.cra_ctxsize = ALIGN(sizeof(struct xcbc_tfm_ctx),
alg->cra_alignmask) + alignmask + 1) +
alg->cra_blocksize * 2; alg->cra_blocksize * 2;
inst->alg.base.cra_init = xcbc_init_tfm; inst->alg.base.cra_init = xcbc_init_tfm;
inst->alg.base.cra_exit = xcbc_exit_tfm; inst->alg.base.cra_exit = xcbc_exit_tfm;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment