hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/crypto/api.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Scatterlist Cryptographic API.
34 *
....@@ -7,12 +8,6 @@
78 *
89 * Portions derived from Cryptoapi, by Alexander Kjeldaas <astor@fast.no>
910 * 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
- *
1611 */
1712
1813 #include <linux/err.h>
....@@ -102,7 +97,7 @@
10297 struct crypto_larval *larval = (void *)alg;
10398
10499 BUG_ON(!crypto_is_larval(alg));
105
- if (larval->adult)
100
+ if (!IS_ERR_OR_NULL(larval->adult))
106101 crypto_mod_put(larval->adult);
107102 kfree(larval);
108103 }
....@@ -183,6 +178,8 @@
183178 alg = ERR_PTR(-ETIMEDOUT);
184179 else if (!alg)
185180 alg = ERR_PTR(-ENOENT);
181
+ else if (IS_ERR(alg))
182
+ ;
186183 else if (crypto_is_test_larval(larval) &&
187184 !(alg->cra_flags & CRYPTO_ALG_TESTED))
188185 alg = ERR_PTR(-EAGAIN);
....@@ -300,20 +297,7 @@
300297
301298 if (type_obj)
302299 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;
317301 }
318302
319303 static void crypto_exit_ops(struct crypto_tfm *tfm)
....@@ -349,12 +333,13 @@
349333 return len;
350334 }
351335
352
-static void crypto_shoot_alg(struct crypto_alg *alg)
336
+void crypto_shoot_alg(struct crypto_alg *alg)
353337 {
354338 down_write(&crypto_alg_sem);
355339 alg->cra_flags |= CRYPTO_ALG_DYING;
356340 up_write(&crypto_alg_sem);
357341 }
342
+EXPORT_SYMBOL_GPL(crypto_shoot_alg);
358343
359344 struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type,
360345 u32 mask)
....@@ -410,7 +395,7 @@
410395 *
411396 * The returned transform is of a non-determinate type. Most people
412397 * should use one of the more specific allocation functions such as
413
- * crypto_alloc_blkcipher.
398
+ * crypto_alloc_skcipher().
414399 *
415400 * In case of error the return value is an error pointer.
416401 */
....@@ -448,8 +433,9 @@
448433 }
449434 EXPORT_SYMBOL_GPL(crypto_alloc_base);
450435
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)
453439 {
454440 char *mem;
455441 struct crypto_tfm *tfm = NULL;
....@@ -460,12 +446,13 @@
460446 tfmsize = frontend->tfmsize;
461447 total = tfmsize + sizeof(*tfm) + frontend->extsize(alg);
462448
463
- mem = kzalloc(total, GFP_KERNEL);
449
+ mem = kzalloc_node(total, GFP_KERNEL, node);
464450 if (mem == NULL)
465451 goto out_err;
466452
467453 tfm = (struct crypto_tfm *)(mem + tfmsize);
468454 tfm->__crt_alg = alg;
455
+ tfm->node = node;
469456
470457 err = frontend->init_tfm(tfm);
471458 if (err)
....@@ -487,7 +474,7 @@
487474 out:
488475 return mem;
489476 }
490
-EXPORT_SYMBOL_GPL(crypto_create_tfm);
477
+EXPORT_SYMBOL_GPL(crypto_create_tfm_node);
491478
492479 struct crypto_alg *crypto_find_alg(const char *alg_name,
493480 const struct crypto_type *frontend,
....@@ -505,11 +492,13 @@
505492 EXPORT_SYMBOL_GPL(crypto_find_alg);
506493
507494 /*
508
- * crypto_alloc_tfm - Locate algorithm and allocate transform
495
+ * crypto_alloc_tfm_node - Locate algorithm and allocate transform
509496 * @alg_name: Name of algorithm
510497 * @frontend: Frontend algorithm type
511498 * @type: Type of algorithm
512499 * @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.
513502 *
514503 * crypto_alloc_tfm() will first attempt to locate an already loaded
515504 * algorithm. If that fails and the kernel supports dynamically loadable
....@@ -520,12 +509,14 @@
520509 *
521510 * The returned transform is of a non-determinate type. Most people
522511 * should use one of the more specific allocation functions such as
523
- * crypto_alloc_blkcipher.
512
+ * crypto_alloc_skcipher().
524513 *
525514 * In case of error the return value is an error pointer.
526515 */
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)
529520 {
530521 void *tfm;
531522 int err;
....@@ -539,7 +530,7 @@
539530 goto err;
540531 }
541532
542
- tfm = crypto_create_tfm(alg, frontend);
533
+ tfm = crypto_create_tfm_node(alg, frontend, node);
543534 if (!IS_ERR(tfm))
544535 return tfm;
545536
....@@ -557,7 +548,7 @@
557548
558549 return ERR_PTR(err);
559550 }
560
-EXPORT_SYMBOL_GPL(crypto_alloc_tfm);
551
+EXPORT_SYMBOL_GPL(crypto_alloc_tfm_node);
561552
562553 /*
563554 * crypto_destroy_tfm - Free crypto transform
....@@ -580,7 +571,7 @@
580571 alg->cra_exit(tfm);
581572 crypto_exit_ops(tfm);
582573 crypto_mod_put(alg);
583
- kzfree(mem);
574
+ kfree_sensitive(mem);
584575 }
585576 EXPORT_SYMBOL_GPL(crypto_destroy_tfm);
586577