Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ee756416 authored by Herbert Xu's avatar Herbert Xu
Browse files

[CRYPTO] digest: Store temporary digest in tfm



When the final result location is unaligned, we store the digest in a
temporary buffer before copying it to the final location.  Currently
that buffer sits on the stack.  This patch moves it to an area in the
tfm, just like the CBC IV buffer.

Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 560c06ae
Loading
Loading
Loading
Loading
+10 −6
Original line number Original line Diff line number Diff line
@@ -66,14 +66,18 @@ static void update(struct crypto_tfm *tfm,
static void final(struct crypto_tfm *tfm, u8 *out)
static void final(struct crypto_tfm *tfm, u8 *out)
{
{
	unsigned long alignmask = crypto_tfm_alg_alignmask(tfm);
	unsigned long alignmask = crypto_tfm_alg_alignmask(tfm);
	struct digest_alg *digest = &tfm->__crt_alg->cra_digest;

	if (unlikely((unsigned long)out & alignmask)) {
	if (unlikely((unsigned long)out & alignmask)) {
		unsigned int size = crypto_tfm_alg_digestsize(tfm);
		unsigned long align = alignmask + 1;
		u8 buffer[size + alignmask];
		unsigned long addr = (unsigned long)crypto_tfm_ctx(tfm);
		u8 *dst = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
		u8 *dst = (u8 *)ALIGN(addr, align) +
		tfm->__crt_alg->cra_digest.dia_final(tfm, dst);
			  ALIGN(tfm->__crt_alg->cra_ctxsize, align);
		memcpy(out, dst, size);

		digest->dia_final(tfm, dst);
		memcpy(out, dst, digest->dia_digestsize);
	} else
	} else
		tfm->__crt_alg->cra_digest.dia_final(tfm, out);
		digest->dia_final(tfm, out);
}
}


static int nosetkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
static int nosetkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
+8 −1
Original line number Original line Diff line number Diff line
@@ -99,7 +99,14 @@ static inline void crypto_exit_proc(void)
static inline unsigned int crypto_digest_ctxsize(struct crypto_alg *alg,
static inline unsigned int crypto_digest_ctxsize(struct crypto_alg *alg,
						 int flags)
						 int flags)
{
{
	return alg->cra_ctxsize;
	unsigned int len = alg->cra_ctxsize;

	if (alg->cra_alignmask) {
		len = ALIGN(len, (unsigned long)alg->cra_alignmask + 1);
		len += alg->cra_digest.dia_digestsize;
	}

	return len;
}
}


static inline unsigned int crypto_cipher_ctxsize(struct crypto_alg *alg,
static inline unsigned int crypto_cipher_ctxsize(struct crypto_alg *alg,