hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/crypto/rng.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Cryptographic API.
34 *
....@@ -5,12 +6,6 @@
56 *
67 * Copyright (c) 2008 Neil Horman <nhorman@tuxdriver.com>
78 * Copyright (c) 2015 Herbert Xu <herbert@gondor.apana.org.au>
8
- *
9
- * This program is free software; you can redistribute it and/or modify it
10
- * under the terms of the GNU General Public License as published by the Free
11
- * Software Foundation; either version 2 of the License, or (at your option)
12
- * any later version.
13
- *
149 */
1510
1611 #include <linux/atomic.h>
....@@ -35,6 +30,7 @@
3530
3631 int crypto_rng_reset(struct crypto_rng *tfm, const u8 *seed, unsigned int slen)
3732 {
33
+ struct crypto_alg *alg = tfm->base.__crt_alg;
3834 u8 *buf = NULL;
3935 int err;
4036
....@@ -49,9 +45,11 @@
4945 seed = buf;
5046 }
5147
48
+ crypto_stats_get(alg);
5249 err = crypto_rng_alg(tfm)->seed(tfm, seed, slen);
50
+ crypto_stats_rng_seed(alg, err);
5351 out:
54
- kzfree(buf);
52
+ kfree_sensitive(buf);
5553 return err;
5654 }
5755 EXPORT_SYMBOL_GPL(crypto_rng_reset);
....@@ -73,17 +71,13 @@
7371 {
7472 struct crypto_report_rng rrng;
7573
76
- strncpy(rrng.type, "rng", sizeof(rrng.type));
74
+ memset(&rrng, 0, sizeof(rrng));
75
+
76
+ strscpy(rrng.type, "rng", sizeof(rrng.type));
7777
7878 rrng.seedsize = seedsize(alg);
7979
80
- if (nla_put(skb, CRYPTOCFGA_REPORT_RNG,
81
- sizeof(struct crypto_report_rng), &rrng))
82
- goto nla_put_failure;
83
- return 0;
84
-
85
-nla_put_failure:
86
- return -EMSGSIZE;
80
+ return nla_put(skb, CRYPTOCFGA_REPORT_RNG, sizeof(rrng), &rrng);
8781 }
8882 #else
8983 static int crypto_rng_report(struct sk_buff *skb, struct crypto_alg *alg)