mirror of
https://git.yoctoproject.org/meta-ti
synced 2026-07-16 22:38:04 +00:00
df420fe6fd
Signed-off-by: Koen Kooi <koen@dominion.thruhere.net> Signed-off-by: Denys Dmytriyenko <denys@ti.com> Signed-off-by: Denys Dmytriyenko <denis@denix.org>
96 lines
3.3 KiB
Diff
96 lines
3.3 KiB
Diff
From 6ce374197d352474ff8514805efb43436c9cf87b Mon Sep 17 00:00:00 2001
|
|
From: Theodore Ts'o <tytso@mit.edu>
|
|
Date: Thu, 5 Jul 2012 10:35:23 -0400
|
|
Subject: [PATCH 20/70] random: add new get_random_bytes_arch() function
|
|
|
|
commit c2557a303ab6712bb6e09447df828c557c710ac9 upstream.
|
|
|
|
Create a new function, get_random_bytes_arch() which will use the
|
|
architecture-specific hardware random number generator if it is
|
|
present. Change get_random_bytes() to not use the HW RNG, even if it
|
|
is avaiable.
|
|
|
|
The reason for this is that the hw random number generator is fast (if
|
|
it is present), but it requires that we trust the hardware
|
|
manufacturer to have not put in a back door. (For example, an
|
|
increasing counter encrypted by an AES key known to the NSA.)
|
|
|
|
It's unlikely that Intel (for example) was paid off by the US
|
|
Government to do this, but it's impossible for them to prove otherwise
|
|
---
|
|
drivers/char/random.c | 29 ++++++++++++++++++++++++-----
|
|
include/linux/random.h | 1 +
|
|
2 files changed, 25 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/drivers/char/random.c b/drivers/char/random.c
|
|
index 4a83220..f3200bf 100644
|
|
--- a/drivers/char/random.c
|
|
+++ b/drivers/char/random.c
|
|
@@ -1038,17 +1038,34 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
|
|
|
|
/*
|
|
* This function is the exported kernel interface. It returns some
|
|
- * number of good random numbers, suitable for seeding TCP sequence
|
|
- * numbers, etc.
|
|
+ * number of good random numbers, suitable for key generation, seeding
|
|
+ * TCP sequence numbers, etc. It does not use the hw random number
|
|
+ * generator, if available; use get_random_bytes_arch() for that.
|
|
*/
|
|
void get_random_bytes(void *buf, int nbytes)
|
|
{
|
|
+ extract_entropy(&nonblocking_pool, buf, nbytes, 0, 0);
|
|
+}
|
|
+EXPORT_SYMBOL(get_random_bytes);
|
|
+
|
|
+/*
|
|
+ * This function will use the architecture-specific hardware random
|
|
+ * number generator if it is available. The arch-specific hw RNG will
|
|
+ * almost certainly be faster than what we can do in software, but it
|
|
+ * is impossible to verify that it is implemented securely (as
|
|
+ * opposed, to, say, the AES encryption of a sequence number using a
|
|
+ * key known by the NSA). So it's useful if we need the speed, but
|
|
+ * only if we're willing to trust the hardware manufacturer not to
|
|
+ * have put in a back door.
|
|
+ */
|
|
+void get_random_bytes_arch(void *buf, int nbytes)
|
|
+{
|
|
char *p = buf;
|
|
|
|
while (nbytes) {
|
|
unsigned long v;
|
|
int chunk = min(nbytes, (int)sizeof(unsigned long));
|
|
-
|
|
+
|
|
if (!arch_get_random_long(&v))
|
|
break;
|
|
|
|
@@ -1057,9 +1074,11 @@ void get_random_bytes(void *buf, int nbytes)
|
|
nbytes -= chunk;
|
|
}
|
|
|
|
- extract_entropy(&nonblocking_pool, p, nbytes, 0, 0);
|
|
+ if (nbytes)
|
|
+ extract_entropy(&nonblocking_pool, p, nbytes, 0, 0);
|
|
}
|
|
-EXPORT_SYMBOL(get_random_bytes);
|
|
+EXPORT_SYMBOL(get_random_bytes_arch);
|
|
+
|
|
|
|
/*
|
|
* init_std_data - initialize pool with system data
|
|
diff --git a/include/linux/random.h b/include/linux/random.h
|
|
index e14b438..29e217a 100644
|
|
--- a/include/linux/random.h
|
|
+++ b/include/linux/random.h
|
|
@@ -56,6 +56,7 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
|
|
extern void add_interrupt_randomness(int irq, int irq_flags);
|
|
|
|
extern void get_random_bytes(void *buf, int nbytes);
|
|
+extern void get_random_bytes_arch(void *buf, int nbytes);
|
|
void generate_random_uuid(unsigned char uuid_out[16]);
|
|
|
|
#ifndef MODULE
|
|
--
|
|
1.7.7.6
|
|
|