moved type and constants for random data to include file;
added consistency check in random; added source of randomness internal to random using timing; only retrieve random bins that are full.
This commit is contained in:
@@ -10,6 +10,7 @@ libsys_FILES=" \
|
||||
kprintf.c \
|
||||
kputc.c \
|
||||
tickdelay.c \
|
||||
get_randomness.c \
|
||||
getuptime.c \
|
||||
getuptime2.c \
|
||||
env_get_prm.c \
|
||||
|
||||
34
lib/sysutil/get_randomness.c
Normal file
34
lib/sysutil/get_randomness.c
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <lib.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <minix/profile.h>
|
||||
#include <minix/syslib.h>
|
||||
#include <minix/type.h>
|
||||
#include <minix/sysutil.h>
|
||||
|
||||
/*===========================================================================*
|
||||
* get_randomness *
|
||||
*===========================================================================*/
|
||||
PUBLIC 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;
|
||||
r_next= rand->bin[source].r_next;
|
||||
read_tsc(&tsc_high, &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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user