summaryrefslogtreecommitdiff
path: root/crypto/digest.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2006-07-09 14:49:42 +1000
committerHerbert Xu <herbert@gondor.apana.org.au>2006-09-21 11:41:02 +1000
commit6747dd4093f7bac44c55c994048bb7e8a64b5600 (patch)
tree9ea354906c6abf913d89997e1c02c2e08885f77c /crypto/digest.c
parentbb21071e97b5cda4d8c7ba3a58a6faaf9e663ea6 (diff)
downloadlinux-crypto-6747dd4093f7bac44c55c994048bb7e8a64b5600.tar.gz
linux-crypto-6747dd4093f7bac44c55c994048bb7e8a64b5600.zip
[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: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/digest.c')
-rw-r--r--crypto/digest.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/crypto/digest.c b/crypto/digest.c
index 0df7f392..19e75563 100644
--- a/crypto/digest.c
+++ b/crypto/digest.c
@@ -66,14 +66,18 @@ static void update(struct crypto_tfm *tfm,
static void final(struct crypto_tfm *tfm, u8 *out)
{
unsigned long alignmask = crypto_tfm_alg_alignmask(tfm);
+ struct digest_alg *digest = &tfm->__crt_alg->cra_digest;
+
if (unlikely((unsigned long)out & alignmask)) {
- unsigned int size = crypto_tfm_alg_digestsize(tfm);
- u8 buffer[size + alignmask];
- u8 *dst = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
- tfm->__crt_alg->cra_digest.dia_final(tfm, dst);
- memcpy(out, dst, size);
+ unsigned long align = alignmask + 1;
+ unsigned long addr = (unsigned long)crypto_tfm_ctx(tfm);
+ u8 *dst = (u8 *)ALIGN(addr, align) +
+ ALIGN(tfm->__crt_alg->cra_ctxsize, align);
+
+ digest->dia_final(tfm, dst);
+ memcpy(out, dst, digest->dia_digestsize);
} 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)