aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/api.c
diff options
context:
space:
mode:
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 0b583d24f7fa..2d8d828c0ca2 100644
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -125,20 +125,46 @@ static void crypto_exit_ops(struct crypto_tfm *tfm)
125 } 125 }
126} 126}
127 127
128static unsigned int crypto_ctxsize(struct crypto_alg *alg, int flags)
129{
130 unsigned int len;
131
132 switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) {
133 default:
134 BUG();
135
136 case CRYPTO_ALG_TYPE_CIPHER:
137 len = crypto_cipher_ctxsize(alg, flags);
138 break;
139
140 case CRYPTO_ALG_TYPE_DIGEST:
141 len = crypto_digest_ctxsize(alg, flags);
142 break;
143
144 case CRYPTO_ALG_TYPE_COMPRESS:
145 len = crypto_compress_ctxsize(alg, flags);
146 break;
147 }
148
149 return len + alg->cra_alignmask;
150}
151
128struct crypto_tfm *crypto_alloc_tfm(const char *name, u32 flags) 152struct crypto_tfm *crypto_alloc_tfm(const char *name, u32 flags)
129{ 153{
130 struct crypto_tfm *tfm = NULL; 154 struct crypto_tfm *tfm = NULL;
131 struct crypto_alg *alg; 155 struct crypto_alg *alg;
156 unsigned int tfm_size;
132 157
133 alg = crypto_alg_mod_lookup(name); 158 alg = crypto_alg_mod_lookup(name);
134 if (alg == NULL) 159 if (alg == NULL)
135 goto out; 160 goto out;
136 161
137 tfm = kmalloc(sizeof(*tfm) + alg->cra_ctxsize, GFP_KERNEL); 162 tfm_size = sizeof(*tfm) + crypto_ctxsize(alg, flags);
163 tfm = kmalloc(tfm_size, GFP_KERNEL);
138 if (tfm == NULL) 164 if (tfm == NULL)
139 goto out_put; 165 goto out_put;
140 166
141 memset(tfm, 0, sizeof(*tfm) + alg->cra_ctxsize); 167 memset(tfm, 0, tfm_size);
142 168
143 tfm->__crt_alg = alg; 169 tfm->__crt_alg = alg;
144 170