use smaller integers for random cache state
This commit is contained in:
parent
1fed72a9c3
commit
943a81fbeb
4
random.c
4
random.c
@ -56,7 +56,7 @@ static void refill(struct random_state *state) {
|
|||||||
|
|
||||||
u16 get_random_u16(struct random_state *state) {
|
u16 get_random_u16(struct random_state *state) {
|
||||||
u16 value;
|
u16 value;
|
||||||
size_t remaining = RANDOM_CACHE_SIZE - state->index;
|
unsigned remaining = RANDOM_CACHE_SIZE - state->index;
|
||||||
if (remaining < sizeof(value)) {
|
if (remaining < sizeof(value)) {
|
||||||
refill(state);
|
refill(state);
|
||||||
}
|
}
|
||||||
@ -83,7 +83,7 @@ u16 get_random_u16_uniform(struct random_state *state, u16 bound) {
|
|||||||
|
|
||||||
u64 get_random_u64(struct random_state *state) {
|
u64 get_random_u64(struct random_state *state) {
|
||||||
u64 value;
|
u64 value;
|
||||||
size_t remaining = RANDOM_CACHE_SIZE - state->index;
|
unsigned remaining = RANDOM_CACHE_SIZE - state->index;
|
||||||
if (remaining < sizeof(value)) {
|
if (remaining < sizeof(value)) {
|
||||||
refill(state);
|
refill(state);
|
||||||
}
|
}
|
||||||
|
8
random.h
8
random.h
@ -4,12 +4,12 @@
|
|||||||
#include "chacha.h"
|
#include "chacha.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#define RANDOM_CACHE_SIZE 256ULL
|
#define RANDOM_CACHE_SIZE 256U
|
||||||
#define RANDOM_RESEED_SIZE 256ULL * 1024
|
#define RANDOM_RESEED_SIZE (256U * 1024)
|
||||||
|
|
||||||
struct random_state {
|
struct random_state {
|
||||||
size_t index;
|
unsigned index;
|
||||||
size_t reseed;
|
unsigned reseed;
|
||||||
chacha_ctx ctx;
|
chacha_ctx ctx;
|
||||||
u8 cache[RANDOM_CACHE_SIZE];
|
u8 cache[RANDOM_CACHE_SIZE];
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user