History

kern/posix: remove srandom()/random() code for entropy gathering, will always use /dev/[u]random

cinap_lenrek committed 10 years ago

Commit bc73cba1 parent 62ab8e71 file · +1 −13Browse files

Unified · Split

kern/posix.c+1−13
@@ -162,37 +162,25 @@ procwakeup(Proc *p) · 161 unmodified lines
162 pthread_mutex_unlock(&op->mutex);162 pthread_mutex_unlock(&op->mutex);
163}163}
164 164
165int randfd;165static int randfd;
166#undef open166#undef open
167void167void
168randominit(void)168randominit(void)
169{169{
170#ifdef USE_RANDOM
171 srandom(getpid()+fastticks(nil)+ticks());
172#else
173 if((randfd = open("/dev/urandom", OREAD)) < 0)170 if((randfd = open("/dev/urandom", OREAD)) < 0)
174 if((randfd = open("/dev/random", OREAD)) < 0)171 if((randfd = open("/dev/random", OREAD)) < 0)
175 panic("open /dev/random: %r");172 panic("open /dev/random: %r");
176#endif
177}173}
178 174
179#undef read175#undef read
180ulong176ulong
181randomread(void *v, ulong n)177randomread(void *v, ulong n)
182{178{
183#ifdef USE_RANDOM
184 int i;
185
186 for(i=0; i<n; i++)
187 ((uchar*)v)[i] = random();
188 return n;
189#else
190 int m;179 int m;
191 180
192 if((m = read(randfd, v, n)) != n)181 if((m = read(randfd, v, n)) != n)
193 panic("short read from /dev/random: %d but %d", n, m);182 panic("short read from /dev/random: %d but %d", n, m);
194 return m;183 return m;
195#endif
196}184}
197 185
198#undef time186#undef time

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t