X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;ds=inline;f=bertos%2Fsec%2Fprng%2Fisaac.h;fp=bertos%2Fsec%2Fprng%2Fisaac.h;h=c9f9663e4a076c20d2c568dcdfadc50506817107;hb=0483b8dfa8dc9dc01b6c2451bfd90867b1114f9f;hp=0000000000000000000000000000000000000000;hpb=add74b1ad71f92ce018532c6d0614881ca47517e;p=bertos.git diff --git a/bertos/sec/prng/isaac.h b/bertos/sec/prng/isaac.h new file mode 100644 index 00000000..c9f9663e --- /dev/null +++ b/bertos/sec/prng/isaac.h @@ -0,0 +1,77 @@ +/** + * \file + * + * + * \brief ISAAC implementation + * \author Giovanni Bajo + * + */ + +#ifndef SEC_PRNG_ISAAC_H +#define SEC_PRNG_ISAAC_H + +#include + +/** + * Size of the internal ISAAC state (in 32-bit words). + * + * ISAAC is known to generate unbiased data as follows: + * * 3 words: 2^37 unbiased values + * * 4 words: 2^45 unbiased values + * * 5 words: 2^53 unbiased values + * * 6 words: 2^61 unbiased values + * * 7 words: 2^69 unbiased values + * * 8 words: 2^77 unbiased values + * + * The period of the generator is usually much longer, but it is + * obviously uninteresting for a CSPRNG. + */ +#define CONFIG_ISAAC_RANDSIZL (3) +#define CONFIG_ISAAC_RANDSIZ (1<<(CONFIG_ISAAC_RANDSIZL)) + +typedef struct +{ + PRNG prng; + uint32_t randcnt; + uint32_t randrsl[CONFIG_ISAAC_RANDSIZ]; + uint32_t randmem[CONFIG_ISAAC_RANDSIZ]; + uint32_t randa; + uint32_t randb; + uint32_t randc; +} ISAAC_Context; + +void ISAAC_init(ISAAC_Context *ctx); + +#define ISAAC_stackinit(...) \ + ({ ISAAC_Context *ctx = alloca(sizeof(ISAAC_Context)); ISAAC_init(ctx , ##__VA_ARGS__); &ctx->prng; }) + + +#endif /* SEC_PRNG_ISAAC_H */