hostapd: update to latest trunk version (merge r26414, r26415)
[openwrt-10.03/.git] / package / hostapd / patches / 700-random_pool_add_kernel.patch
1 --- a/src/crypto/random.c
2 +++ b/src/crypto/random.c
3 @@ -38,6 +38,8 @@
4  #include "sha1.h"
5  #include "random.h"
6  
7 +#define RANDOM_STAMPFILE "/var/run/.random_available"
8 +
9  #define POOL_WORDS 32
10  #define POOL_WORDS_MASK (POOL_WORDS - 1)
11  #define POOL_TAP1 26
12 @@ -48,6 +50,8 @@
13  #define EXTRACT_LEN 16
14  #define MIN_READY_MARK 2
15  
16 +#ifndef CONFIG_NO_RANDOM_POOL
17 +
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)
22  }
23  
24  
25 -void random_add_randomness(const void *buf, size_t len)
26 +static void random_pool_add_randomness(const void *buf, size_t len)
27  {
28         struct os_time t;
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)
32  {
33  #ifdef __linux__
34 +       struct stat st;
35         int fd;
36         ssize_t res;
37  
38 +       if (stat(RANDOM_STAMPFILE, &st) == 0)
39 +               return 1;
40 +
41         /*
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)
45  
46  void random_mark_pool_ready(void)
47  {
48 +       int fd;
49 +
50         own_pool_ready++;
51         wpa_printf(MSG_DEBUG, "random: Mark internal entropy pool to be "
52                    "ready (count=%u/%u)", own_pool_ready, MIN_READY_MARK);
53 +
54 +       fd = open(RANDOM_STAMPFILE, O_CREAT | O_WRONLY | O_EXCL | O_NOFOLLOW, 0600);
55 +       if (fd >= 0)
56 +               close(fd);
57  }
58  
59  
60 @@ -335,3 +349,22 @@ void random_deinit(void)
61         random_close_fd();
62  #endif /* __linux__ */
63  }
64 +
65 +#endif /* CONFIG_NO_RANDOM_POOL */
66 +
67 +
68 +void random_add_randomness(const void *buf, size_t len)
69 +{
70 +#ifdef __linux__
71 +       int fd;
72 +
73 +       fd = open("/dev/random", O_RDWR);
74 +       if (fd >= 0) {
75 +               write(fd, buf, len);
76 +               close(fd);
77 +       }
78 +#endif
79 +#ifndef CONFIG_NO_RANDOM_POOL
80 +       random_pool_add_randomness(buf, len);
81 +#endif
82 +}
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
88  else
89 -OBJS += ../src/crypto/random.o
90 -HOBJS += ../src/crypto/random.o
91  HOBJS += $(SHA1OBJS)
92  HOBJS += ../src/crypto/md5.o
93  endif
94 +OBJS += ../src/crypto/random.o
95 +HOBJS += ../src/crypto/random.o
96  
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
102  
103  ifdef CONFIG_NO_RANDOM_POOL
104  CFLAGS += -DCONFIG_NO_RANDOM_POOL
105 -else
106 -OBJS += ../src/crypto/random.o
107  endif
108 +OBJS += ../src/crypto/random.o
109  
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
115  
116  ifdef CONFIG_NO_RANDOM_POOL
117  L_CFLAGS += -DCONFIG_NO_RANDOM_POOL
118 -else
119 -OBJS += src/crypto/random.c
120  endif
121 +OBJS += src/crypto/random.c
122  
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
130  else
131 -OBJS += src/crypto/random.c
132 -HOBJS += src/crypto/random.c
133  HOBJS += $(SHA1OBJS)
134  HOBJS += src/crypto/md5.c
135  endif
136 +OBJS += src/crypto/random.c
137 +HOBJS += src/crypto/random.c
138  
139  ifdef CONFIG_RADIUS_SERVER
140  L_CFLAGS += -DRADIUS_SERVER
141 --- a/src/crypto/random.h
142 +++ b/src/crypto/random.h
143 @@ -18,17 +18,16 @@
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);
160  
161  #endif /* RANDOM_H */