summaryrefslogtreecommitdiff
path: root/crypto/api.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2005-07-06 13:53:29 -0700
committerDavid S. Miller <davem@davemloft.net>2005-07-06 13:53:29 -0700
commitaaf033a7a6d8b354345e8b558d8723e91420f560 (patch)
treed27e53c50e8b5f93a653348c5ca3560d62455d62 /crypto/api.c
parentf1093620ecc883dbc931b352d1b8138a8c20fdef (diff)
downloadlinux-crypto-aaf033a7a6d8b354345e8b558d8723e91420f560.tar.gz
linux-crypto-aaf033a7a6d8b354345e8b558d8723e91420f560.zip
[CRYPTO] Ensure cit_iv is aligned correctly
This patch ensures that cit_iv is aligned according to cra_alignmask by allocating it as part of the tfm structure. As a side effect the crypto layer will also guarantee that the tfm ctx area has enough space to be aligned by cra_alignmask. This allows us to remove the extra space reservation from the Padlock driver. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'crypto/api.c')
-rw-r--r--crypto/api.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/crypto/api.c b/crypto/api.c
index 0b583d24..2d8d828c 100644
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -125,20 +125,46 @@ static void crypto_exit_ops(struct crypto_tfm *tfm)
}
}
+static unsigned int crypto_ctxsize(struct crypto_alg *alg, int flags)
+{
+ unsigned int len;
+
+ switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) {
+ default:
+ BUG();
+
+ case CRYPTO_ALG_TYPE_CIPHER:
+ len = crypto_cipher_ctxsize(alg, flags);
+ break;
+
+ case CRYPTO_ALG_TYPE_DIGEST:
+ len = crypto_digest_ctxsize(alg, flags);
+ break;
+
+ case CRYPTO_ALG_TYPE_COMPRESS:
+ len = crypto_compress_ctxsize(alg, flags);
+ break;
+ }
+
+ return len + alg->cra_alignmask;
+}
+
struct crypto_tfm *crypto_alloc_tfm(const char *name, u32 flags)
{
struct crypto_tfm *tfm = NULL;
struct crypto_alg *alg;
+ unsigned int tfm_size;
alg = crypto_alg_mod_lookup(name);
if (alg == NULL)
goto out;
-
- tfm = kmalloc(sizeof(*tfm) + alg->cra_ctxsize, GFP_KERNEL);
+
+ tfm_size = sizeof(*tfm) + crypto_ctxsize(alg, flags);
+ tfm = kmalloc(tfm_size, GFP_KERNEL);
if (tfm == NULL)
goto out_put;
- memset(tfm, 0, sizeof(*tfm) + alg->cra_ctxsize);
+ memset(tfm, 0, tfm_size);
tfm->__crt_alg = alg;