X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fsec%2Fprng.h;h=d0d21b454c29f590c30bbbc3825cd25e79adca77;hb=f2108fe515132a85c7e84e588789f482f8feb750;hp=7b39f5fac3c0659cf95fac44ce14ce38bdfe1db9;hpb=d1a9a6eb1d3014b7708b0f0ddf6e85b783d21639;p=bertos.git diff --git a/bertos/sec/prng.h b/bertos/sec/prng.h index 7b39f5fa..d0d21b45 100644 --- a/bertos/sec/prng.h +++ b/bertos/sec/prng.h @@ -32,7 +32,7 @@ * * \brief Generic interface for cryptographically-secure pseudo-RNG * \author Giovanni Bajo - * + * */ #ifndef SEC_PRNG_H @@ -42,15 +42,16 @@ #include typedef struct PRNG -{ +{ void (*reseed)(struct PRNG *ctx, const uint8_t *seed); void (*generate)(struct PRNG *ctx, uint8_t *data, size_t len); - size_t seed_len; + uint8_t seed_len; + uint8_t seeded; } PRNG; /** * Feed a new seed into the PRNG. - * + * * \note: Being a cryptographically-secure PRNG, the seed will be * mixed to the current state of the generator, so it is NOT possible * to generate the same sequence simply by using the same seed. If you @@ -60,6 +61,7 @@ INLINE void prng_reseed(PRNG *ctx, const uint8_t *seed) { ASSERT(ctx->reseed); ctx->reseed(ctx, seed); + ctx->seeded = 1; } /** @@ -77,6 +79,7 @@ INLINE size_t prng_seed_len(PRNG *ctx) INLINE void prng_generate(PRNG *ctx, uint8_t *data, size_t len) { ASSERT(ctx->generate); + ASSERT(ctx->seeded); ctx->generate(ctx, data, len); }