2011-03-22 23:00:54 +02:00
|
|
|
--- a/src/crypto/random.c
|
|
|
|
+++ b/src/crypto/random.c
|
2012-09-13 15:38:51 +03:00
|
|
|
@@ -33,6 +33,8 @@
|
2011-04-02 22:44:51 +03:00
|
|
|
#include "sha1.h"
|
|
|
|
#include "random.h"
|
|
|
|
|
|
|
|
+#define RANDOM_STAMPFILE "/var/run/.random_available"
|
|
|
|
+
|
|
|
|
#define POOL_WORDS 32
|
|
|
|
#define POOL_WORDS_MASK (POOL_WORDS - 1)
|
|
|
|
#define POOL_TAP1 26
|
2012-09-13 15:38:51 +03:00
|
|
|
@@ -43,6 +45,8 @@
|
2011-03-22 23:00:54 +02:00
|
|
|
#define EXTRACT_LEN 16
|
|
|
|
#define MIN_READY_MARK 2
|
|
|
|
|
|
|
|
+#ifndef CONFIG_NO_RANDOM_POOL
|
|
|
|
+
|
|
|
|
static u32 pool[POOL_WORDS];
|
|
|
|
static unsigned int input_rotate = 0;
|
|
|
|
static unsigned int pool_pos = 0;
|
2012-09-13 15:38:51 +03:00
|
|
|
@@ -123,7 +127,7 @@ static void random_extract(u8 *out)
|
2011-03-22 23:00:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-void random_add_randomness(const void *buf, size_t len)
|
|
|
|
+static void random_pool_add_randomness(const void *buf, size_t len)
|
|
|
|
{
|
|
|
|
struct os_time t;
|
|
|
|
static unsigned int count = 0;
|
2012-09-13 15:38:51 +03:00
|
|
|
@@ -213,16 +217,22 @@ int random_get_bytes(void *buf, size_t l
|
2011-04-02 22:44:51 +03:00
|
|
|
int random_pool_ready(void)
|
|
|
|
{
|
|
|
|
#ifdef __linux__
|
|
|
|
+ struct stat st;
|
|
|
|
int fd;
|
|
|
|
ssize_t res;
|
|
|
|
|
|
|
|
+ if (stat(RANDOM_STAMPFILE, &st) == 0)
|
|
|
|
+ return 1;
|
|
|
|
+
|
|
|
|
/*
|
|
|
|
* Make sure that there is reasonable entropy available before allowing
|
|
|
|
* some key derivation operations to proceed.
|
2011-04-12 20:30:16 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
- if (dummy_key_avail == sizeof(dummy_key))
|
|
|
|
+ if (dummy_key_avail == sizeof(dummy_key)) {
|
|
|
|
+ random_mark_pool_ready();
|
|
|
|
return 1; /* Already initialized - good to continue */
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to fetch some more data from the kernel high quality
|
2012-09-13 15:38:51 +03:00
|
|
|
@@ -257,6 +267,7 @@ int random_pool_ready(void)
|
2011-11-04 03:05:26 +02:00
|
|
|
if (dummy_key_avail == sizeof(dummy_key)) {
|
|
|
|
if (own_pool_ready < MIN_READY_MARK)
|
|
|
|
own_pool_ready = MIN_READY_MARK;
|
2011-04-12 20:30:16 +03:00
|
|
|
+ random_mark_pool_ready();
|
2011-11-04 03:05:26 +02:00
|
|
|
random_write_entropy();
|
2011-04-12 20:30:16 +03:00
|
|
|
return 1;
|
2011-11-04 03:05:26 +02:00
|
|
|
}
|
2012-09-13 15:38:51 +03:00
|
|
|
@@ -269,6 +280,7 @@ int random_pool_ready(void)
|
2011-04-12 20:30:16 +03:00
|
|
|
total_collected + 10 * own_pool_ready > MIN_COLLECT_ENTROPY) {
|
|
|
|
wpa_printf(MSG_INFO, "random: Allow operation to proceed "
|
|
|
|
"based on internal entropy");
|
|
|
|
+ random_mark_pool_ready();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-09-13 15:38:51 +03:00
|
|
|
@@ -284,10 +296,16 @@ int random_pool_ready(void)
|
2011-04-02 22:44:51 +03:00
|
|
|
|
|
|
|
void random_mark_pool_ready(void)
|
|
|
|
{
|
|
|
|
+ int fd;
|
|
|
|
+
|
|
|
|
own_pool_ready++;
|
|
|
|
wpa_printf(MSG_DEBUG, "random: Mark internal entropy pool to be "
|
|
|
|
"ready (count=%u/%u)", own_pool_ready, MIN_READY_MARK);
|
2011-11-04 03:05:26 +02:00
|
|
|
random_write_entropy();
|
2011-04-02 22:44:51 +03:00
|
|
|
+
|
|
|
|
+ fd = open(RANDOM_STAMPFILE, O_CREAT | O_WRONLY | O_EXCL | O_NOFOLLOW, 0600);
|
|
|
|
+ if (fd >= 0)
|
|
|
|
+ close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-13 15:38:51 +03:00
|
|
|
@@ -444,3 +462,22 @@ void random_deinit(void)
|
2011-11-04 03:05:26 +02:00
|
|
|
os_free(random_entropy_file);
|
|
|
|
random_entropy_file = NULL;
|
2011-03-22 23:00:54 +02:00
|
|
|
}
|
|
|
|
+
|
|
|
|
+#endif /* CONFIG_NO_RANDOM_POOL */
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+void random_add_randomness(const void *buf, size_t len)
|
|
|
|
+{
|
|
|
|
+#ifdef __linux__
|
|
|
|
+ int fd;
|
|
|
|
+
|
|
|
|
+ fd = open("/dev/random", O_RDWR);
|
|
|
|
+ if (fd >= 0) {
|
|
|
|
+ write(fd, buf, len);
|
|
|
|
+ close(fd);
|
|
|
|
+ }
|
|
|
|
+#endif
|
|
|
|
+#ifndef CONFIG_NO_RANDOM_POOL
|
|
|
|
+ random_pool_add_randomness(buf, len);
|
|
|
|
+#endif
|
|
|
|
+}
|
|
|
|
--- a/wpa_supplicant/Makefile
|
|
|
|
+++ b/wpa_supplicant/Makefile
|
2012-09-13 15:38:51 +03:00
|
|
|
@@ -1217,9 +1217,8 @@ endif
|
2011-03-22 23:00:54 +02:00
|
|
|
|
|
|
|
ifdef CONFIG_NO_RANDOM_POOL
|
|
|
|
CFLAGS += -DCONFIG_NO_RANDOM_POOL
|
|
|
|
-else
|
|
|
|
-OBJS += ../src/crypto/random.o
|
|
|
|
endif
|
|
|
|
+OBJS += ../src/crypto/random.o
|
|
|
|
|
|
|
|
ifdef CONFIG_CTRL_IFACE
|
|
|
|
ifeq ($(CONFIG_CTRL_IFACE), y)
|
|
|
|
--- a/wpa_supplicant/Android.mk
|
|
|
|
+++ b/wpa_supplicant/Android.mk
|
2012-09-13 15:38:51 +03:00
|
|
|
@@ -1161,9 +1161,8 @@ endif
|
2011-03-22 23:00:54 +02:00
|
|
|
|
|
|
|
ifdef CONFIG_NO_RANDOM_POOL
|
|
|
|
L_CFLAGS += -DCONFIG_NO_RANDOM_POOL
|
|
|
|
-else
|
|
|
|
-OBJS += src/crypto/random.c
|
|
|
|
endif
|
|
|
|
+OBJS += src/crypto/random.c
|
|
|
|
|
|
|
|
ifdef CONFIG_CTRL_IFACE
|
|
|
|
ifeq ($(CONFIG_CTRL_IFACE), y)
|
|
|
|
--- a/hostapd/Android.mk
|
|
|
|
+++ b/hostapd/Android.mk
|
2012-09-13 15:38:51 +03:00
|
|
|
@@ -748,11 +748,11 @@ endif
|
2011-03-22 23:00:54 +02:00
|
|
|
ifdef CONFIG_NO_RANDOM_POOL
|
|
|
|
L_CFLAGS += -DCONFIG_NO_RANDOM_POOL
|
|
|
|
else
|
|
|
|
-OBJS += src/crypto/random.c
|
|
|
|
-HOBJS += src/crypto/random.c
|
|
|
|
HOBJS += $(SHA1OBJS)
|
|
|
|
HOBJS += src/crypto/md5.c
|
|
|
|
endif
|
|
|
|
+OBJS += src/crypto/random.c
|
|
|
|
+HOBJS += src/crypto/random.c
|
|
|
|
|
|
|
|
ifdef CONFIG_RADIUS_SERVER
|
|
|
|
L_CFLAGS += -DRADIUS_SERVER
|
2011-11-04 03:05:26 +02:00
|
|
|
--- a/hostapd/Makefile
|
|
|
|
+++ b/hostapd/Makefile
|
2012-09-13 15:38:51 +03:00
|
|
|
@@ -755,12 +755,12 @@ endif
|
2011-11-04 03:05:26 +02:00
|
|
|
ifdef CONFIG_NO_RANDOM_POOL
|
|
|
|
CFLAGS += -DCONFIG_NO_RANDOM_POOL
|
|
|
|
else
|
|
|
|
-OBJS += ../src/crypto/random.o
|
|
|
|
-HOBJS += ../src/crypto/random.o
|
|
|
|
HOBJS += ../src/utils/eloop.o
|
|
|
|
HOBJS += $(SHA1OBJS)
|
|
|
|
HOBJS += ../src/crypto/md5.o
|
|
|
|
endif
|
|
|
|
+OBJS += ../src/crypto/random.o
|
|
|
|
+HOBJS += ../src/crypto/random.o
|
|
|
|
|
|
|
|
ifdef CONFIG_RADIUS_SERVER
|
|
|
|
CFLAGS += -DRADIUS_SERVER
|