8475ac6234f2e800dd8ef89d6e2a274b8d4cbfc1
[openwrt.git] / package / hostapd / patches / 700-random_pool_add_kernel.patch
1 --- a/src/crypto/random.c
2 +++ b/src/crypto/random.c
3 @@ -48,6 +48,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 @@ -122,7 +124,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 @@ -335,3 +337,22 @@ void random_deinit(void)
22         random_close_fd();
23  #endif /* __linux__ */
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 @@ -18,17 +18,16 @@
105  #ifdef CONFIG_NO_RANDOM_POOL
106  #define random_init() do { } while (0)
107  #define random_deinit() do { } while (0)
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_init(void);
114  void random_deinit(void);
115 -void random_add_randomness(const void *buf, size_t len);
116  int random_get_bytes(void *buf, size_t len);
117  int random_pool_ready(void);
118  void random_mark_pool_ready(void);
119  #endif /* CONFIG_NO_RANDOM_POOL */
120 +void random_add_randomness(const void *buf, size_t len);
121  
122  #endif /* RANDOM_H */