| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Scatterlist Cryptographic API. |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 7 | 8 | * |
|---|
| 8 | 9 | * Portions derived from Cryptoapi, by Alexander Kjeldaas <astor@fast.no> |
|---|
| 9 | 10 | * and Nettle, by Niels Möller. |
|---|
| 10 | | - * |
|---|
| 11 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 12 | | - * under the terms of the GNU General Public License as published by the Free |
|---|
| 13 | | - * Software Foundation; either version 2 of the License, or (at your option) |
|---|
| 14 | | - * any later version. |
|---|
| 15 | | - * |
|---|
| 16 | 11 | */ |
|---|
| 17 | 12 | |
|---|
| 18 | 13 | #include <linux/err.h> |
|---|
| .. | .. |
|---|
| 102 | 97 | struct crypto_larval *larval = (void *)alg; |
|---|
| 103 | 98 | |
|---|
| 104 | 99 | BUG_ON(!crypto_is_larval(alg)); |
|---|
| 105 | | - if (larval->adult) |
|---|
| 100 | + if (!IS_ERR_OR_NULL(larval->adult)) |
|---|
| 106 | 101 | crypto_mod_put(larval->adult); |
|---|
| 107 | 102 | kfree(larval); |
|---|
| 108 | 103 | } |
|---|
| .. | .. |
|---|
| 183 | 178 | alg = ERR_PTR(-ETIMEDOUT); |
|---|
| 184 | 179 | else if (!alg) |
|---|
| 185 | 180 | alg = ERR_PTR(-ENOENT); |
|---|
| 181 | + else if (IS_ERR(alg)) |
|---|
| 182 | + ; |
|---|
| 186 | 183 | else if (crypto_is_test_larval(larval) && |
|---|
| 187 | 184 | !(alg->cra_flags & CRYPTO_ALG_TESTED)) |
|---|
| 188 | 185 | alg = ERR_PTR(-EAGAIN); |
|---|
| .. | .. |
|---|
| 300 | 297 | |
|---|
| 301 | 298 | if (type_obj) |
|---|
| 302 | 299 | return type_obj->init(tfm, type, mask); |
|---|
| 303 | | - |
|---|
| 304 | | - switch (crypto_tfm_alg_type(tfm)) { |
|---|
| 305 | | - case CRYPTO_ALG_TYPE_CIPHER: |
|---|
| 306 | | - return crypto_init_cipher_ops(tfm); |
|---|
| 307 | | - |
|---|
| 308 | | - case CRYPTO_ALG_TYPE_COMPRESS: |
|---|
| 309 | | - return crypto_init_compress_ops(tfm); |
|---|
| 310 | | - |
|---|
| 311 | | - default: |
|---|
| 312 | | - break; |
|---|
| 313 | | - } |
|---|
| 314 | | - |
|---|
| 315 | | - BUG(); |
|---|
| 316 | | - return -EINVAL; |
|---|
| 300 | + return 0; |
|---|
| 317 | 301 | } |
|---|
| 318 | 302 | |
|---|
| 319 | 303 | static void crypto_exit_ops(struct crypto_tfm *tfm) |
|---|
| .. | .. |
|---|
| 349 | 333 | return len; |
|---|
| 350 | 334 | } |
|---|
| 351 | 335 | |
|---|
| 352 | | -static void crypto_shoot_alg(struct crypto_alg *alg) |
|---|
| 336 | +void crypto_shoot_alg(struct crypto_alg *alg) |
|---|
| 353 | 337 | { |
|---|
| 354 | 338 | down_write(&crypto_alg_sem); |
|---|
| 355 | 339 | alg->cra_flags |= CRYPTO_ALG_DYING; |
|---|
| 356 | 340 | up_write(&crypto_alg_sem); |
|---|
| 357 | 341 | } |
|---|
| 342 | +EXPORT_SYMBOL_GPL(crypto_shoot_alg); |
|---|
| 358 | 343 | |
|---|
| 359 | 344 | struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type, |
|---|
| 360 | 345 | u32 mask) |
|---|
| .. | .. |
|---|
| 410 | 395 | * |
|---|
| 411 | 396 | * The returned transform is of a non-determinate type. Most people |
|---|
| 412 | 397 | * should use one of the more specific allocation functions such as |
|---|
| 413 | | - * crypto_alloc_blkcipher. |
|---|
| 398 | + * crypto_alloc_skcipher(). |
|---|
| 414 | 399 | * |
|---|
| 415 | 400 | * In case of error the return value is an error pointer. |
|---|
| 416 | 401 | */ |
|---|
| .. | .. |
|---|
| 448 | 433 | } |
|---|
| 449 | 434 | EXPORT_SYMBOL_GPL(crypto_alloc_base); |
|---|
| 450 | 435 | |
|---|
| 451 | | -void *crypto_create_tfm(struct crypto_alg *alg, |
|---|
| 452 | | - const struct crypto_type *frontend) |
|---|
| 436 | +void *crypto_create_tfm_node(struct crypto_alg *alg, |
|---|
| 437 | + const struct crypto_type *frontend, |
|---|
| 438 | + int node) |
|---|
| 453 | 439 | { |
|---|
| 454 | 440 | char *mem; |
|---|
| 455 | 441 | struct crypto_tfm *tfm = NULL; |
|---|
| .. | .. |
|---|
| 460 | 446 | tfmsize = frontend->tfmsize; |
|---|
| 461 | 447 | total = tfmsize + sizeof(*tfm) + frontend->extsize(alg); |
|---|
| 462 | 448 | |
|---|
| 463 | | - mem = kzalloc(total, GFP_KERNEL); |
|---|
| 449 | + mem = kzalloc_node(total, GFP_KERNEL, node); |
|---|
| 464 | 450 | if (mem == NULL) |
|---|
| 465 | 451 | goto out_err; |
|---|
| 466 | 452 | |
|---|
| 467 | 453 | tfm = (struct crypto_tfm *)(mem + tfmsize); |
|---|
| 468 | 454 | tfm->__crt_alg = alg; |
|---|
| 455 | + tfm->node = node; |
|---|
| 469 | 456 | |
|---|
| 470 | 457 | err = frontend->init_tfm(tfm); |
|---|
| 471 | 458 | if (err) |
|---|
| .. | .. |
|---|
| 487 | 474 | out: |
|---|
| 488 | 475 | return mem; |
|---|
| 489 | 476 | } |
|---|
| 490 | | -EXPORT_SYMBOL_GPL(crypto_create_tfm); |
|---|
| 477 | +EXPORT_SYMBOL_GPL(crypto_create_tfm_node); |
|---|
| 491 | 478 | |
|---|
| 492 | 479 | struct crypto_alg *crypto_find_alg(const char *alg_name, |
|---|
| 493 | 480 | const struct crypto_type *frontend, |
|---|
| .. | .. |
|---|
| 505 | 492 | EXPORT_SYMBOL_GPL(crypto_find_alg); |
|---|
| 506 | 493 | |
|---|
| 507 | 494 | /* |
|---|
| 508 | | - * crypto_alloc_tfm - Locate algorithm and allocate transform |
|---|
| 495 | + * crypto_alloc_tfm_node - Locate algorithm and allocate transform |
|---|
| 509 | 496 | * @alg_name: Name of algorithm |
|---|
| 510 | 497 | * @frontend: Frontend algorithm type |
|---|
| 511 | 498 | * @type: Type of algorithm |
|---|
| 512 | 499 | * @mask: Mask for type comparison |
|---|
| 500 | + * @node: NUMA node in which users desire to put requests, if node is |
|---|
| 501 | + * NUMA_NO_NODE, it means users have no special requirement. |
|---|
| 513 | 502 | * |
|---|
| 514 | 503 | * crypto_alloc_tfm() will first attempt to locate an already loaded |
|---|
| 515 | 504 | * algorithm. If that fails and the kernel supports dynamically loadable |
|---|
| .. | .. |
|---|
| 520 | 509 | * |
|---|
| 521 | 510 | * The returned transform is of a non-determinate type. Most people |
|---|
| 522 | 511 | * should use one of the more specific allocation functions such as |
|---|
| 523 | | - * crypto_alloc_blkcipher. |
|---|
| 512 | + * crypto_alloc_skcipher(). |
|---|
| 524 | 513 | * |
|---|
| 525 | 514 | * In case of error the return value is an error pointer. |
|---|
| 526 | 515 | */ |
|---|
| 527 | | -void *crypto_alloc_tfm(const char *alg_name, |
|---|
| 528 | | - const struct crypto_type *frontend, u32 type, u32 mask) |
|---|
| 516 | + |
|---|
| 517 | +void *crypto_alloc_tfm_node(const char *alg_name, |
|---|
| 518 | + const struct crypto_type *frontend, u32 type, u32 mask, |
|---|
| 519 | + int node) |
|---|
| 529 | 520 | { |
|---|
| 530 | 521 | void *tfm; |
|---|
| 531 | 522 | int err; |
|---|
| .. | .. |
|---|
| 539 | 530 | goto err; |
|---|
| 540 | 531 | } |
|---|
| 541 | 532 | |
|---|
| 542 | | - tfm = crypto_create_tfm(alg, frontend); |
|---|
| 533 | + tfm = crypto_create_tfm_node(alg, frontend, node); |
|---|
| 543 | 534 | if (!IS_ERR(tfm)) |
|---|
| 544 | 535 | return tfm; |
|---|
| 545 | 536 | |
|---|
| .. | .. |
|---|
| 557 | 548 | |
|---|
| 558 | 549 | return ERR_PTR(err); |
|---|
| 559 | 550 | } |
|---|
| 560 | | -EXPORT_SYMBOL_GPL(crypto_alloc_tfm); |
|---|
| 551 | +EXPORT_SYMBOL_GPL(crypto_alloc_tfm_node); |
|---|
| 561 | 552 | |
|---|
| 562 | 553 | /* |
|---|
| 563 | 554 | * crypto_destroy_tfm - Free crypto transform |
|---|
| .. | .. |
|---|
| 580 | 571 | alg->cra_exit(tfm); |
|---|
| 581 | 572 | crypto_exit_ops(tfm); |
|---|
| 582 | 573 | crypto_mod_put(alg); |
|---|
| 583 | | - kzfree(mem); |
|---|
| 574 | + kfree_sensitive(mem); |
|---|
| 584 | 575 | } |
|---|
| 585 | 576 | EXPORT_SYMBOL_GPL(crypto_destroy_tfm); |
|---|
| 586 | 577 | |
|---|