secondary cache feature in vm.
[minix.git] / lib / libsys / get_randomness.c
blobd603735b9cd0aaea3bee5fc77bff33480c636356
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/sysutil.h>
10 /*===========================================================================*
11 * get_randomness *
12 *===========================================================================*/
13 PUBLIC void get_randomness(rand, source)
14 struct k_randomness *rand;
15 int source;
17 /* Use architecture-dependent high-resolution clock for
18 * raw entropy gathering.
20 int r_next;
21 unsigned long tsc_high, tsc_low;
23 source %= RANDOM_SOURCES;
24 r_next= rand->bin[source].r_next;
25 read_tsc(&tsc_high, &tsc_low);
26 rand->bin[source].r_buf[r_next] = tsc_low;
27 if (rand->bin[source].r_size < RANDOM_ELEMENTS) {
28 rand->bin[source].r_size ++;
30 rand->bin[source].r_next = (r_next + 1 ) % RANDOM_ELEMENTS;