aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/api.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/api.c')
-rw-r--r--crypto/api.c63
1 files changed, 7 insertions, 56 deletions
diff --git a/crypto/api.c b/crypto/api.c
index 8c446871cd5b..8b80baec853a 100644
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -212,25 +212,6 @@ struct crypto_alg *crypto_alg_mod_lookup(const char *name, u32 type, u32 mask)
212} 212}
213EXPORT_SYMBOL_GPL(crypto_alg_mod_lookup); 213EXPORT_SYMBOL_GPL(crypto_alg_mod_lookup);
214 214
215static int crypto_init_flags(struct crypto_tfm *tfm, u32 flags)
216{
217 tfm->crt_flags = flags & CRYPTO_TFM_REQ_MASK;
218 flags &= ~CRYPTO_TFM_REQ_MASK;
219
220 switch (crypto_tfm_alg_type(tfm)) {
221 case CRYPTO_ALG_TYPE_CIPHER:
222 return crypto_init_cipher_flags(tfm, flags);
223
224 case CRYPTO_ALG_TYPE_DIGEST:
225 return crypto_init_digest_flags(tfm, flags);
226
227 case CRYPTO_ALG_TYPE_COMPRESS:
228 return crypto_init_compress_flags(tfm, flags);
229 }
230
231 return 0;
232}
233
234static int crypto_init_ops(struct crypto_tfm *tfm) 215static int crypto_init_ops(struct crypto_tfm *tfm)
235{ 216{
236 const struct crypto_type *type = tfm->__crt_alg->cra_type; 217 const struct crypto_type *type = tfm->__crt_alg->cra_type;
@@ -285,7 +266,7 @@ static void crypto_exit_ops(struct crypto_tfm *tfm)
285 } 266 }
286} 267}
287 268
288static unsigned int crypto_ctxsize(struct crypto_alg *alg, int flags) 269static unsigned int crypto_ctxsize(struct crypto_alg *alg)
289{ 270{
290 const struct crypto_type *type = alg->cra_type; 271 const struct crypto_type *type = alg->cra_type;
291 unsigned int len; 272 unsigned int len;
@@ -299,15 +280,15 @@ static unsigned int crypto_ctxsize(struct crypto_alg *alg, int flags)
299 BUG(); 280 BUG();
300 281
301 case CRYPTO_ALG_TYPE_CIPHER: 282 case CRYPTO_ALG_TYPE_CIPHER:
302 len += crypto_cipher_ctxsize(alg, flags); 283 len += crypto_cipher_ctxsize(alg);
303 break; 284 break;
304 285
305 case CRYPTO_ALG_TYPE_DIGEST: 286 case CRYPTO_ALG_TYPE_DIGEST:
306 len += crypto_digest_ctxsize(alg, flags); 287 len += crypto_digest_ctxsize(alg);
307 break; 288 break;
308 289
309 case CRYPTO_ALG_TYPE_COMPRESS: 290 case CRYPTO_ALG_TYPE_COMPRESS:
310 len += crypto_compress_ctxsize(alg, flags); 291 len += crypto_compress_ctxsize(alg);
311 break; 292 break;
312 } 293 }
313 294
@@ -322,23 +303,19 @@ void crypto_shoot_alg(struct crypto_alg *alg)
322} 303}
323EXPORT_SYMBOL_GPL(crypto_shoot_alg); 304EXPORT_SYMBOL_GPL(crypto_shoot_alg);
324 305
325struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 flags) 306struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg)
326{ 307{
327 struct crypto_tfm *tfm = NULL; 308 struct crypto_tfm *tfm = NULL;
328 unsigned int tfm_size; 309 unsigned int tfm_size;
329 int err = -ENOMEM; 310 int err = -ENOMEM;
330 311
331 tfm_size = sizeof(*tfm) + crypto_ctxsize(alg, flags); 312 tfm_size = sizeof(*tfm) + crypto_ctxsize(alg);
332 tfm = kzalloc(tfm_size, GFP_KERNEL); 313 tfm = kzalloc(tfm_size, GFP_KERNEL);
333 if (tfm == NULL) 314 if (tfm == NULL)
334 goto out_err; 315 goto out_err;
335 316
336 tfm->__crt_alg = alg; 317 tfm->__crt_alg = alg;
337 318
338 err = crypto_init_flags(tfm, flags);
339 if (err)
340 goto out_free_tfm;
341
342 err = crypto_init_ops(tfm); 319 err = crypto_init_ops(tfm);
343 if (err) 320 if (err)
344 goto out_free_tfm; 321 goto out_free_tfm;
@@ -362,31 +339,6 @@ out:
362} 339}
363EXPORT_SYMBOL_GPL(__crypto_alloc_tfm); 340EXPORT_SYMBOL_GPL(__crypto_alloc_tfm);
364 341
365struct crypto_tfm *crypto_alloc_tfm(const char *name, u32 flags)
366{
367 struct crypto_tfm *tfm = NULL;
368 int err;
369
370 do {
371 struct crypto_alg *alg;
372
373 alg = crypto_alg_mod_lookup(name, 0, CRYPTO_ALG_ASYNC);
374 err = PTR_ERR(alg);
375 if (IS_ERR(alg))
376 continue;
377
378 tfm = __crypto_alloc_tfm(alg, flags);
379 err = 0;
380 if (IS_ERR(tfm)) {
381 crypto_mod_put(alg);
382 err = PTR_ERR(tfm);
383 tfm = NULL;
384 }
385 } while (err == -EAGAIN && !signal_pending(current));
386
387 return tfm;
388}
389
390/* 342/*
391 * crypto_alloc_base - Locate algorithm and allocate transform 343 * crypto_alloc_base - Locate algorithm and allocate transform
392 * @alg_name: Name of algorithm 344 * @alg_name: Name of algorithm
@@ -420,7 +372,7 @@ struct crypto_tfm *crypto_alloc_base(const char *alg_name, u32 type, u32 mask)
420 goto err; 372 goto err;
421 } 373 }
422 374
423 tfm = __crypto_alloc_tfm(alg, 0); 375 tfm = __crypto_alloc_tfm(alg);
424 if (!IS_ERR(tfm)) 376 if (!IS_ERR(tfm))
425 return tfm; 377 return tfm;
426 378
@@ -466,7 +418,6 @@ void crypto_free_tfm(struct crypto_tfm *tfm)
466 kfree(tfm); 418 kfree(tfm);
467} 419}
468 420
469EXPORT_SYMBOL_GPL(crypto_alloc_tfm);
470EXPORT_SYMBOL_GPL(crypto_free_tfm); 421EXPORT_SYMBOL_GPL(crypto_free_tfm);
471 422
472int crypto_has_alg(const char *name, u32 type, u32 mask) 423int crypto_has_alg(const char *name, u32 type, u32 mask)