hostapd: make entropy collection contribute to the kernel pool
[openwrt.git] / package / hostapd / patches / 700-random_pool_add_kernel.patch
1 --- a/src/crypto/random.c
2 +++ b/src/crypto/random.c
3 @@ -47,6 +47,8 @@
4 #define EXTRACT_LEN 16
5 #define MIN_READY_MARK 2
6
7 +#ifndef CONFIG_NO_RANDOM_POOL
8 +
9 static u32 pool[POOL_WORDS];
10 static unsigned int input_rotate = 0;
11 static unsigned int pool_pos = 0;
12 @@ -120,7 +122,7 @@ static void random_extract(u8 *out)
13 }
14
15
16 -void random_add_randomness(const void *buf, size_t len)
17 +static void random_pool_add_randomness(const void *buf, size_t len)
18 {
19 struct os_time t;
20 static unsigned int count = 0;
21 @@ -260,3 +262,22 @@ void random_mark_pool_ready(void)
22 wpa_printf(MSG_DEBUG, "random: Mark internal entropy pool to be "
23 "ready (count=%u/%u)", own_pool_ready, MIN_READY_MARK);
24 }
25 +
26 +#endif /* CONFIG_NO_RANDOM_POOL */
27 +
28 +
29 +void random_add_randomness(const void *buf, size_t len)
30 +{
31 +#ifdef __linux__
32 + int fd;
33 +
34 + fd = open("/dev/random", O_RDWR);
35 + if (fd >= 0) {
36 + write(fd, buf, len);
37 + close(fd);
38 + }
39 +#endif
40 +#ifndef CONFIG_NO_RANDOM_POOL
41 + random_pool_add_randomness(buf, len);
42 +#endif
43 +}
44 --- a/hostapd/Makefile
45 +++ b/hostapd/Makefile
46 @@ -698,11 +698,11 @@ endif
47 ifdef CONFIG_NO_RANDOM_POOL
48 CFLAGS += -DCONFIG_NO_RANDOM_POOL
49 else
50 -OBJS += ../src/crypto/random.o
51 -HOBJS += ../src/crypto/random.o
52 HOBJS += $(SHA1OBJS)
53 HOBJS += ../src/crypto/md5.o
54 endif
55 +OBJS += ../src/crypto/random.o
56 +HOBJS += ../src/crypto/random.o
57
58 ifdef CONFIG_RADIUS_SERVER
59 CFLAGS += -DRADIUS_SERVER
60 --- a/wpa_supplicant/Makefile
61 +++ b/wpa_supplicant/Makefile
62 @@ -1101,9 +1101,8 @@ endif
63
64 ifdef CONFIG_NO_RANDOM_POOL
65 CFLAGS += -DCONFIG_NO_RANDOM_POOL
66 -else
67 -OBJS += ../src/crypto/random.o
68 endif
69 +OBJS += ../src/crypto/random.o
70
71 ifdef CONFIG_CTRL_IFACE
72 ifeq ($(CONFIG_CTRL_IFACE), y)
73 --- a/wpa_supplicant/Android.mk
74 +++ b/wpa_supplicant/Android.mk
75 @@ -1102,9 +1102,8 @@ endif
76
77 ifdef CONFIG_NO_RANDOM_POOL
78 L_CFLAGS += -DCONFIG_NO_RANDOM_POOL
79 -else
80 -OBJS += src/crypto/random.c
81 endif
82 +OBJS += src/crypto/random.c
83
84 ifdef CONFIG_CTRL_IFACE
85 ifeq ($(CONFIG_CTRL_IFACE), y)
86 --- a/hostapd/Android.mk
87 +++ b/hostapd/Android.mk
88 @@ -717,11 +717,11 @@ endif
89 ifdef CONFIG_NO_RANDOM_POOL
90 L_CFLAGS += -DCONFIG_NO_RANDOM_POOL
91 else
92 -OBJS += src/crypto/random.c
93 -HOBJS += src/crypto/random.c
94 HOBJS += $(SHA1OBJS)
95 HOBJS += src/crypto/md5.c
96 endif
97 +OBJS += src/crypto/random.c
98 +HOBJS += src/crypto/random.c
99
100 ifdef CONFIG_RADIUS_SERVER
101 L_CFLAGS += -DRADIUS_SERVER
102 --- a/src/crypto/random.h
103 +++ b/src/crypto/random.h
104 @@ -16,15 +16,14 @@
105 #define RANDOM_H
106
107 #ifdef CONFIG_NO_RANDOM_POOL
108 -#define random_add_randomness(b, l) do { } while (0)
109 #define random_get_bytes(b, l) os_get_random((b), (l))
110 #define random_pool_ready() 1
111 #define random_mark_pool_ready() do { } while (0)
112 #else /* CONFIG_NO_RANDOM_POOL */
113 -void random_add_randomness(const void *buf, size_t len);
114 int random_get_bytes(void *buf, size_t len);
115 int random_pool_ready(void);
116 void random_mark_pool_ready(void);
117 #endif /* CONFIG_NO_RANDOM_POOL */
118 +void random_add_randomness(const void *buf, size_t len);
119
120 #endif /* RANDOM_H */
This page took 0.054832 seconds and 5 git commands to generate.