VM: full munmap
[minix.git] / lib / libsys / get_randomness.c
blob720f674722c1112157ac2de82bc8dc4e628bf586
1 #include <lib.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <minix/profile.h>
6 #include <minix/syslib.h>
7 #include <minix/type.h>
8 #include <minix/minlib.h>
9 #include <minix/sysutil.h>
11 /*===========================================================================*
12 * get_randomness *
13 *===========================================================================*/
14 void get_randomness(rand, source)
15 struct k_randomness *rand;
16 int source;
18 /* Use architecture-dependent high-resolution clock for
19 * raw entropy gathering.
21 int r_next;
22 unsigned long tsc_high, tsc_low;
24 source %= RANDOM_SOURCES;
25 r_next= rand->bin[source].r_next;
26 read_tsc((u32_t *) &tsc_high, (u32_t *) &tsc_low);
27 rand->bin[source].r_buf[r_next] = tsc_low;
28 if (rand->bin[source].r_size < RANDOM_ELEMENTS) {
29 rand->bin[source].r_size ++;
31 rand->bin[source].r_next = (r_next + 1 ) % RANDOM_ELEMENTS;