diff options
Diffstat (limited to 'crypto/api.c')
-rw-r--r-- | crypto/api.c | 80 |
1 files changed, 16 insertions, 64 deletions
diff --git a/crypto/api.c b/crypto/api.c index 8c446871cd5b..55af8bb0f050 100644 --- a/crypto/api.c +++ b/crypto/api.c | |||
@@ -212,31 +212,12 @@ struct crypto_alg *crypto_alg_mod_lookup(const char *name, u32 type, u32 mask) | |||
212 | } | 212 | } |
213 | EXPORT_SYMBOL_GPL(crypto_alg_mod_lookup); | 213 | EXPORT_SYMBOL_GPL(crypto_alg_mod_lookup); |
214 | 214 | ||
215 | static int crypto_init_flags(struct crypto_tfm *tfm, u32 flags) | 215 | static int crypto_init_ops(struct crypto_tfm *tfm, u32 type, u32 mask) |
216 | { | 216 | { |
217 | tfm->crt_flags = flags & CRYPTO_TFM_REQ_MASK; | 217 | const struct crypto_type *type_obj = tfm->__crt_alg->cra_type; |
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 | 218 | ||
234 | static int crypto_init_ops(struct crypto_tfm *tfm) | 219 | if (type_obj) |
235 | { | 220 | return type_obj->init(tfm, type, mask); |
236 | const struct crypto_type *type = tfm->__crt_alg->cra_type; | ||
237 | |||
238 | if (type) | ||
239 | return type->init(tfm); | ||
240 | 221 | ||
241 | switch (crypto_tfm_alg_type(tfm)) { | 222 | switch (crypto_tfm_alg_type(tfm)) { |
242 | case CRYPTO_ALG_TYPE_CIPHER: | 223 | case CRYPTO_ALG_TYPE_CIPHER: |
@@ -285,29 +266,29 @@ static void crypto_exit_ops(struct crypto_tfm *tfm) | |||
285 | } | 266 | } |
286 | } | 267 | } |
287 | 268 | ||
288 | static unsigned int crypto_ctxsize(struct crypto_alg *alg, int flags) | 269 | static unsigned int crypto_ctxsize(struct crypto_alg *alg, u32 type, u32 mask) |
289 | { | 270 | { |
290 | const struct crypto_type *type = alg->cra_type; | 271 | const struct crypto_type *type_obj = alg->cra_type; |
291 | unsigned int len; | 272 | unsigned int len; |
292 | 273 | ||
293 | len = alg->cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1); | 274 | len = alg->cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1); |
294 | if (type) | 275 | if (type_obj) |
295 | return len + type->ctxsize(alg); | 276 | return len + type_obj->ctxsize(alg, type, mask); |
296 | 277 | ||
297 | switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) { | 278 | switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) { |
298 | default: | 279 | default: |
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,24 +303,21 @@ void crypto_shoot_alg(struct crypto_alg *alg) | |||
322 | } | 303 | } |
323 | EXPORT_SYMBOL_GPL(crypto_shoot_alg); | 304 | EXPORT_SYMBOL_GPL(crypto_shoot_alg); |
324 | 305 | ||
325 | struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 flags) | 306 | struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type, |
307 | u32 mask) | ||
326 | { | 308 | { |
327 | struct crypto_tfm *tfm = NULL; | 309 | struct crypto_tfm *tfm = NULL; |
328 | unsigned int tfm_size; | 310 | unsigned int tfm_size; |
329 | int err = -ENOMEM; | 311 | int err = -ENOMEM; |
330 | 312 | ||
331 | tfm_size = sizeof(*tfm) + crypto_ctxsize(alg, flags); | 313 | tfm_size = sizeof(*tfm) + crypto_ctxsize(alg, type, mask); |
332 | tfm = kzalloc(tfm_size, GFP_KERNEL); | 314 | tfm = kzalloc(tfm_size, GFP_KERNEL); |
333 | if (tfm == NULL) | 315 | if (tfm == NULL) |
334 | goto out_err; | 316 | goto out_err; |
335 | 317 | ||
336 | tfm->__crt_alg = alg; | 318 | tfm->__crt_alg = alg; |
337 | 319 | ||
338 | err = crypto_init_flags(tfm, flags); | 320 | err = crypto_init_ops(tfm, type, mask); |
339 | if (err) | ||
340 | goto out_free_tfm; | ||
341 | |||
342 | err = crypto_init_ops(tfm); | ||
343 | if (err) | 321 | if (err) |
344 | goto out_free_tfm; | 322 | goto out_free_tfm; |
345 | 323 | ||
@@ -362,31 +340,6 @@ out: | |||
362 | } | 340 | } |
363 | EXPORT_SYMBOL_GPL(__crypto_alloc_tfm); | 341 | EXPORT_SYMBOL_GPL(__crypto_alloc_tfm); |
364 | 342 | ||
365 | struct 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 | /* | 343 | /* |
391 | * crypto_alloc_base - Locate algorithm and allocate transform | 344 | * crypto_alloc_base - Locate algorithm and allocate transform |
392 | * @alg_name: Name of algorithm | 345 | * @alg_name: Name of algorithm |
@@ -420,7 +373,7 @@ struct crypto_tfm *crypto_alloc_base(const char *alg_name, u32 type, u32 mask) | |||
420 | goto err; | 373 | goto err; |
421 | } | 374 | } |
422 | 375 | ||
423 | tfm = __crypto_alloc_tfm(alg, 0); | 376 | tfm = __crypto_alloc_tfm(alg, type, mask); |
424 | if (!IS_ERR(tfm)) | 377 | if (!IS_ERR(tfm)) |
425 | return tfm; | 378 | return tfm; |
426 | 379 | ||
@@ -466,7 +419,6 @@ void crypto_free_tfm(struct crypto_tfm *tfm) | |||
466 | kfree(tfm); | 419 | kfree(tfm); |
467 | } | 420 | } |
468 | 421 | ||
469 | EXPORT_SYMBOL_GPL(crypto_alloc_tfm); | ||
470 | EXPORT_SYMBOL_GPL(crypto_free_tfm); | 422 | EXPORT_SYMBOL_GPL(crypto_free_tfm); |
471 | 423 | ||
472 | int crypto_has_alg(const char *name, u32 type, u32 mask) | 424 | int crypto_has_alg(const char *name, u32 type, u32 mask) |