1 --- a/src/crypto/random.c
2 +++ b/src/crypto/random.c
7 +#define RANDOM_STAMPFILE "/var/run/.random_available"
10 #define POOL_WORDS_MASK (POOL_WORDS - 1)
13 #define EXTRACT_LEN 16
14 #define MIN_READY_MARK 2
16 +#ifndef CONFIG_NO_RANDOM_POOL
18 static u32 pool[POOL_WORDS];
19 static unsigned int input_rotate = 0;
20 static unsigned int pool_pos = 0;
21 @@ -122,7 +126,7 @@ static void random_extract(u8 *out)
25 -void random_add_randomness(const void *buf, size_t len)
26 +static void random_pool_add_randomness(const void *buf, size_t len)
29 static unsigned int count = 0;
30 @@ -191,16 +195,22 @@ int random_get_bytes(void *buf, size_t l
31 int random_pool_ready(void)
38 + if (stat(RANDOM_STAMPFILE, &st) == 0)
42 * Make sure that there is reasonable entropy available before allowing
43 * some key derivation operations to proceed.
46 - if (dummy_key_avail == sizeof(dummy_key))
47 + if (dummy_key_avail == sizeof(dummy_key)) {
48 + random_mark_pool_ready();
49 return 1; /* Already initialized - good to continue */
53 * Try to fetch some more data from the kernel high quality
54 @@ -232,8 +242,10 @@ int random_pool_ready(void)
55 dummy_key_avail += res;
58 - if (dummy_key_avail == sizeof(dummy_key))
59 + if (dummy_key_avail == sizeof(dummy_key)) {
60 + random_mark_pool_ready();
64 wpa_printf(MSG_INFO, "random: Only %u/%u bytes of strong "
65 "random data available from /dev/random",
66 @@ -243,6 +255,7 @@ int random_pool_ready(void)
67 total_collected + 10 * own_pool_ready > MIN_COLLECT_ENTROPY) {
68 wpa_printf(MSG_INFO, "random: Allow operation to proceed "
69 "based on internal entropy");
70 + random_mark_pool_ready();
74 @@ -258,9 +271,15 @@ int random_pool_ready(void)
76 void random_mark_pool_ready(void)
81 wpa_printf(MSG_DEBUG, "random: Mark internal entropy pool to be "
82 "ready (count=%u/%u)", own_pool_ready, MIN_READY_MARK);
84 + fd = open(RANDOM_STAMPFILE, O_CREAT | O_WRONLY | O_EXCL | O_NOFOLLOW, 0600);
90 @@ -335,3 +354,22 @@ void random_deinit(void)
92 #endif /* __linux__ */
95 +#endif /* CONFIG_NO_RANDOM_POOL */
98 +void random_add_randomness(const void *buf, size_t len)
103 + fd = open("/dev/random", O_RDWR);
105 + write(fd, buf, len);
109 +#ifndef CONFIG_NO_RANDOM_POOL
110 + random_pool_add_randomness(buf, len);
113 --- a/hostapd/Makefile
114 +++ b/hostapd/Makefile
115 @@ -698,11 +698,11 @@ endif
116 ifdef CONFIG_NO_RANDOM_POOL
117 CFLAGS += -DCONFIG_NO_RANDOM_POOL
119 -OBJS += ../src/crypto/random.o
120 -HOBJS += ../src/crypto/random.o
122 HOBJS += ../src/crypto/md5.o
124 +OBJS += ../src/crypto/random.o
125 +HOBJS += ../src/crypto/random.o
127 ifdef CONFIG_RADIUS_SERVER
128 CFLAGS += -DRADIUS_SERVER
129 --- a/wpa_supplicant/Makefile
130 +++ b/wpa_supplicant/Makefile
131 @@ -1101,9 +1101,8 @@ endif
133 ifdef CONFIG_NO_RANDOM_POOL
134 CFLAGS += -DCONFIG_NO_RANDOM_POOL
136 -OBJS += ../src/crypto/random.o
138 +OBJS += ../src/crypto/random.o
140 ifdef CONFIG_CTRL_IFACE
141 ifeq ($(CONFIG_CTRL_IFACE), y)
142 --- a/wpa_supplicant/Android.mk
143 +++ b/wpa_supplicant/Android.mk
144 @@ -1102,9 +1102,8 @@ endif
146 ifdef CONFIG_NO_RANDOM_POOL
147 L_CFLAGS += -DCONFIG_NO_RANDOM_POOL
149 -OBJS += src/crypto/random.c
151 +OBJS += src/crypto/random.c
153 ifdef CONFIG_CTRL_IFACE
154 ifeq ($(CONFIG_CTRL_IFACE), y)
155 --- a/hostapd/Android.mk
156 +++ b/hostapd/Android.mk
157 @@ -717,11 +717,11 @@ endif
158 ifdef CONFIG_NO_RANDOM_POOL
159 L_CFLAGS += -DCONFIG_NO_RANDOM_POOL
161 -OBJS += src/crypto/random.c
162 -HOBJS += src/crypto/random.c
164 HOBJS += src/crypto/md5.c
166 +OBJS += src/crypto/random.c
167 +HOBJS += src/crypto/random.c
169 ifdef CONFIG_RADIUS_SERVER
170 L_CFLAGS += -DRADIUS_SERVER
171 --- a/src/crypto/random.h
172 +++ b/src/crypto/random.h
174 #ifdef CONFIG_NO_RANDOM_POOL
175 #define random_init() do { } while (0)
176 #define random_deinit() do { } while (0)
177 -#define random_add_randomness(b, l) do { } while (0)
178 #define random_get_bytes(b, l) os_get_random((b), (l))
179 #define random_pool_ready() 1
180 #define random_mark_pool_ready() do { } while (0)
181 #else /* CONFIG_NO_RANDOM_POOL */
182 void random_init(void);
183 void random_deinit(void);
184 -void random_add_randomness(const void *buf, size_t len);
185 int random_get_bytes(void *buf, size_t len);
186 int random_pool_ready(void);
187 void random_mark_pool_ready(void);
188 #endif /* CONFIG_NO_RANDOM_POOL */
189 +void random_add_randomness(const void *buf, size_t len);
191 #endif /* RANDOM_H */