1 --- a/src/crypto/random.c
2 +++ b/src/crypto/random.c
4 #include "utils/includes.h"
10 #include "utils/common.h"
15 +#define RANDOM_STAMPFILE "/var/run/.random_available"
18 #define POOL_WORDS_MASK (POOL_WORDS - 1)
21 #define EXTRACT_LEN 16
22 #define MIN_READY_MARK 2
24 +#ifndef CONFIG_NO_RANDOM_POOL
26 static u32 pool[POOL_WORDS];
27 static unsigned int input_rotate = 0;
28 static unsigned int pool_pos = 0;
29 @@ -123,7 +128,7 @@ static void random_extract(u8 *out)
33 -void random_add_randomness(const void *buf, size_t len)
34 +static void random_pool_add_randomness(const void *buf, size_t len)
37 static unsigned int count = 0;
38 @@ -213,16 +218,22 @@ int random_get_bytes(void *buf, size_t l
39 int random_pool_ready(void)
46 + if (stat(RANDOM_STAMPFILE, &st) == 0)
50 * Make sure that there is reasonable entropy available before allowing
51 * some key derivation operations to proceed.
54 - if (dummy_key_avail == sizeof(dummy_key))
55 + if (dummy_key_avail == sizeof(dummy_key)) {
56 + random_mark_pool_ready();
57 return 1; /* Already initialized - good to continue */
61 * Try to fetch some more data from the kernel high quality
62 @@ -257,6 +268,7 @@ int random_pool_ready(void)
63 if (dummy_key_avail == sizeof(dummy_key)) {
64 if (own_pool_ready < MIN_READY_MARK)
65 own_pool_ready = MIN_READY_MARK;
66 + random_mark_pool_ready();
67 random_write_entropy();
70 @@ -269,6 +281,7 @@ int random_pool_ready(void)
71 total_collected + 10 * own_pool_ready > MIN_COLLECT_ENTROPY) {
72 wpa_printf(MSG_INFO, "random: Allow operation to proceed "
73 "based on internal entropy");
74 + random_mark_pool_ready();
78 @@ -284,10 +297,16 @@ int random_pool_ready(void)
80 void random_mark_pool_ready(void)
85 wpa_printf(MSG_DEBUG, "random: Mark internal entropy pool to be "
86 "ready (count=%u/%u)", own_pool_ready, MIN_READY_MARK);
87 random_write_entropy();
89 + fd = open(RANDOM_STAMPFILE, O_CREAT | O_WRONLY | O_EXCL | O_NOFOLLOW, 0600);
95 @@ -444,3 +463,22 @@ void random_deinit(void)
96 os_free(random_entropy_file);
97 random_entropy_file = NULL;
100 +#endif /* CONFIG_NO_RANDOM_POOL */
103 +void random_add_randomness(const void *buf, size_t len)
108 + fd = open("/dev/random", O_RDWR);
110 + write(fd, buf, len);
114 +#ifndef CONFIG_NO_RANDOM_POOL
115 + random_pool_add_randomness(buf, len);
118 --- a/wpa_supplicant/Makefile
119 +++ b/wpa_supplicant/Makefile
120 @@ -1222,9 +1222,8 @@ endif
122 ifdef CONFIG_NO_RANDOM_POOL
123 CFLAGS += -DCONFIG_NO_RANDOM_POOL
125 -OBJS += ../src/crypto/random.o
127 +OBJS += ../src/crypto/random.o
129 ifdef CONFIG_CTRL_IFACE
130 ifeq ($(CONFIG_CTRL_IFACE), y)
131 --- a/wpa_supplicant/Android.mk
132 +++ b/wpa_supplicant/Android.mk
133 @@ -1192,9 +1192,8 @@ endif
135 ifdef CONFIG_NO_RANDOM_POOL
136 L_CFLAGS += -DCONFIG_NO_RANDOM_POOL
138 -OBJS += src/crypto/random.c
140 +OBJS += src/crypto/random.c
142 ifdef CONFIG_CTRL_IFACE
143 ifeq ($(CONFIG_CTRL_IFACE), y)
144 --- a/hostapd/Android.mk
145 +++ b/hostapd/Android.mk
146 @@ -778,12 +778,12 @@ endif
147 ifdef CONFIG_NO_RANDOM_POOL
148 L_CFLAGS += -DCONFIG_NO_RANDOM_POOL
150 -OBJS += src/crypto/random.c
151 -HOBJS += src/crypto/random.c
152 HOBJS += src/utils/eloop.c
154 HOBJS += src/crypto/md5.c
156 +OBJS += src/crypto/random.c
157 +HOBJS += src/crypto/random.c
159 ifdef CONFIG_RADIUS_SERVER
160 L_CFLAGS += -DRADIUS_SERVER
161 --- a/hostapd/Makefile
162 +++ b/hostapd/Makefile
163 @@ -748,12 +748,12 @@ endif
164 ifdef CONFIG_NO_RANDOM_POOL
165 CFLAGS += -DCONFIG_NO_RANDOM_POOL
167 -OBJS += ../src/crypto/random.o
168 -HOBJS += ../src/crypto/random.o
169 HOBJS += ../src/utils/eloop.o
171 HOBJS += ../src/crypto/md5.o
173 +OBJS += ../src/crypto/random.o
174 +HOBJS += ../src/crypto/random.o
176 ifdef CONFIG_RADIUS_SERVER
177 CFLAGS += -DRADIUS_SERVER