From 943a81fbebb6c8644ae3cee7d151c1f71426d6e6 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Sun, 4 Nov 2018 14:23:12 -0500 Subject: [PATCH] use smaller integers for random cache state --- random.c | 4 ++-- random.h | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/random.c b/random.c index e5a61a8..f58740e 100644 --- a/random.c +++ b/random.c @@ -56,7 +56,7 @@ static void refill(struct random_state *state) { u16 get_random_u16(struct random_state *state) { u16 value; - size_t remaining = RANDOM_CACHE_SIZE - state->index; + unsigned remaining = RANDOM_CACHE_SIZE - state->index; if (remaining < sizeof(value)) { 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 value; - size_t remaining = RANDOM_CACHE_SIZE - state->index; + unsigned remaining = RANDOM_CACHE_SIZE - state->index; if (remaining < sizeof(value)) { refill(state); } diff --git a/random.h b/random.h index 30672d4..420797d 100644 --- a/random.h +++ b/random.h @@ -4,12 +4,12 @@ #include "chacha.h" #include "util.h" -#define RANDOM_CACHE_SIZE 256ULL -#define RANDOM_RESEED_SIZE 256ULL * 1024 +#define RANDOM_CACHE_SIZE 256U +#define RANDOM_RESEED_SIZE (256U * 1024) struct random_state { - size_t index; - size_t reseed; + unsigned index; + unsigned reseed; chacha_ctx ctx; u8 cache[RANDOM_CACHE_SIZE]; };