2018-08-22 00:53:22 +05:30
|
|
|
#ifndef RANDOM_H
|
|
|
|
#define RANDOM_H
|
|
|
|
|
2018-08-26 08:30:00 +05:30
|
|
|
#include "chacha.h"
|
2018-10-04 23:55:16 +05:30
|
|
|
#include "util.h"
|
2018-08-26 08:30:00 +05:30
|
|
|
|
2018-11-05 00:53:12 +05:30
|
|
|
#define RANDOM_CACHE_SIZE 256U
|
|
|
|
#define RANDOM_RESEED_SIZE (256U * 1024)
|
2018-08-24 02:00:44 +05:30
|
|
|
|
2018-08-22 00:53:22 +05:30
|
|
|
struct random_state {
|
2018-11-05 00:53:12 +05:30
|
|
|
unsigned index;
|
|
|
|
unsigned reseed;
|
2018-08-26 08:30:00 +05:30
|
|
|
chacha_ctx ctx;
|
2018-10-04 23:55:16 +05:30
|
|
|
u8 cache[RANDOM_CACHE_SIZE];
|
2018-08-22 00:53:22 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
void random_state_init(struct random_state *state);
|
2018-10-04 23:55:16 +05:30
|
|
|
u16 get_random_u16(struct random_state *state);
|
|
|
|
u16 get_random_u16_uniform(struct random_state *state, u16 bound);
|
|
|
|
u64 get_random_u64(struct random_state *state);
|
|
|
|
u64 get_random_u64_uniform(struct random_state *state, u64 bound);
|
2018-08-22 00:53:22 +05:30
|
|
|
|
|
|
|
#endif
|