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,9 +195,13 @@ 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.
44 @@ -258,9 +266,15 @@ int random_pool_ready(void)
46 void random_mark_pool_ready(void)
51 wpa_printf(MSG_DEBUG, "random: Mark internal entropy pool to be "
52 "ready (count=%u/%u)", own_pool_ready, MIN_READY_MARK);
54 + fd = open(RANDOM_STAMPFILE, O_CREAT | O_WRONLY | O_EXCL | O_NOFOLLOW, 0600);
60 @@ -335,3 +349,22 @@ void random_deinit(void)
62 #endif /* __linux__ */
65 +#endif /* CONFIG_NO_RANDOM_POOL */
68 +void random_add_randomness(const void *buf, size_t len)
73 + fd = open("/dev/random", O_RDWR);
75 + write(fd, buf, len);
79 +#ifndef CONFIG_NO_RANDOM_POOL
80 + random_pool_add_randomness(buf, len);
83 --- a/hostapd/Makefile
84 +++ b/hostapd/Makefile
85 @@ -698,11 +698,11 @@ endif
86 ifdef CONFIG_NO_RANDOM_POOL
87 CFLAGS += -DCONFIG_NO_RANDOM_POOL
89 -OBJS += ../src/crypto/random.o
90 -HOBJS += ../src/crypto/random.o
92 HOBJS += ../src/crypto/md5.o
94 +OBJS += ../src/crypto/random.o
95 +HOBJS += ../src/crypto/random.o
97 ifdef CONFIG_RADIUS_SERVER
98 CFLAGS += -DRADIUS_SERVER
99 --- a/wpa_supplicant/Makefile
100 +++ b/wpa_supplicant/Makefile
101 @@ -1101,9 +1101,8 @@ endif
103 ifdef CONFIG_NO_RANDOM_POOL
104 CFLAGS += -DCONFIG_NO_RANDOM_POOL
106 -OBJS += ../src/crypto/random.o
108 +OBJS += ../src/crypto/random.o
110 ifdef CONFIG_CTRL_IFACE
111 ifeq ($(CONFIG_CTRL_IFACE), y)
112 --- a/wpa_supplicant/Android.mk
113 +++ b/wpa_supplicant/Android.mk
114 @@ -1102,9 +1102,8 @@ endif
116 ifdef CONFIG_NO_RANDOM_POOL
117 L_CFLAGS += -DCONFIG_NO_RANDOM_POOL
119 -OBJS += src/crypto/random.c
121 +OBJS += src/crypto/random.c
123 ifdef CONFIG_CTRL_IFACE
124 ifeq ($(CONFIG_CTRL_IFACE), y)
125 --- a/hostapd/Android.mk
126 +++ b/hostapd/Android.mk
127 @@ -717,11 +717,11 @@ endif
128 ifdef CONFIG_NO_RANDOM_POOL
129 L_CFLAGS += -DCONFIG_NO_RANDOM_POOL
131 -OBJS += src/crypto/random.c
132 -HOBJS += src/crypto/random.c
134 HOBJS += src/crypto/md5.c
136 +OBJS += src/crypto/random.c
137 +HOBJS += src/crypto/random.c
139 ifdef CONFIG_RADIUS_SERVER
140 L_CFLAGS += -DRADIUS_SERVER
141 --- a/src/crypto/random.h
142 +++ b/src/crypto/random.h
144 #ifdef CONFIG_NO_RANDOM_POOL
145 #define random_init() do { } while (0)
146 #define random_deinit() do { } while (0)
147 -#define random_add_randomness(b, l) do { } while (0)
148 #define random_get_bytes(b, l) os_get_random((b), (l))
149 #define random_pool_ready() 1
150 #define random_mark_pool_ready() do { } while (0)
151 #else /* CONFIG_NO_RANDOM_POOL */
152 void random_init(void);
153 void random_deinit(void);
154 -void random_add_randomness(const void *buf, size_t len);
155 int random_get_bytes(void *buf, size_t len);
156 int random_pool_ready(void);
157 void random_mark_pool_ready(void);
158 #endif /* CONFIG_NO_RANDOM_POOL */
159 +void random_add_randomness(const void *buf, size_t len);
161 #endif /* RANDOM_H */