blob: 0a7f9e9d5c9ed209f1590b6ba8482d535053d48c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#include <lib.h>
#include <stdlib.h>
#include <string.h>
#include <minix/profile.h>
#include <minix/syslib.h>
#include <minix/type.h>
#include <minix/minlib.h>
#include <minix/sysutil.h>
/*===========================================================================*
* get_randomness *
*===========================================================================*/
void get_randomness(rand, source)
struct k_randomness *rand;
int source;
{
/* Use architecture-dependent high-resolution clock for
* raw entropy gathering.
*/
int r_next;
unsigned long tsc_high, tsc_low;
source %= RANDOM_SOURCES;
if (rand->bin[source].r_size >= RANDOM_ELEMENTS) return;
r_next= rand->bin[source].r_next;
read_tsc((u32_t *) &tsc_high, (u32_t *) &tsc_low);
rand->bin[source].r_buf[r_next] = tsc_low;
if (rand->bin[source].r_size < RANDOM_ELEMENTS) {
rand->bin[source].r_size ++;
}
rand->bin[source].r_next = (r_next + 1 ) % RANDOM_ELEMENTS;
}
|