*
* \brief ISAAC implementation
* \author Giovanni Bajo <rasky@develer.com>
*
* \brief ISAAC implementation
* \author Giovanni Bajo <rasky@develer.com>
*(r++) = b = ind(mm,y>>CONFIG_ISAAC_RANDSIZL) + x; \
}
*(r++) = b = ind(mm,y>>CONFIG_ISAAC_RANDSIZL) + x; \
}
-static void isaac(ISAAC_Context *ctx)
+static void isaac(IsaacContext *ctx)
{
register ub4 a,b,x,y,*m,*mm,*m2,*r,*mend;
mm=ctx->randmem; r=ctx->randrsl;
{
register ub4 a,b,x,y,*m,*mm,*m2,*r,*mend;
mm=ctx->randmem; r=ctx->randrsl;
-static void ISAAC_reseed(PRNG *ctx_, const uint8_t *seed)
+static void isaac_reseed(PRNG *ctx_, const uint8_t *seed)
- ISAAC_Context *ctx = (ISAAC_Context *)ctx_;
+ IsaacContext *ctx = (IsaacContext *)ctx_;
int i;
ub4 a,b,c,d,e,f,g,h;
ub4 *m,*r;
int i;
ub4 a,b,c,d,e,f,g,h;
ub4 *m,*r;
-static void ISAAC_generate(PRNG *ctx_, uint8_t *data, size_t len)
+static void isaac_generate(PRNG *ctx_, uint8_t *data, size_t len)
- ISAAC_Context *ctx = (ISAAC_Context *)ctx_;
+ IsaacContext *ctx = (IsaacContext *)ctx_;
STATIC_ASSERT(sizeof(ctx->randrsl) == CONFIG_ISAAC_RANDSIZ*4);
while (len)
{
ASSERT(ctx->randcnt <= CONFIG_ISAAC_RANDSIZ*4);
STATIC_ASSERT(sizeof(ctx->randrsl) == CONFIG_ISAAC_RANDSIZ*4);
while (len)
{
ASSERT(ctx->randcnt <= CONFIG_ISAAC_RANDSIZ*4);
if (ctx->randcnt == CONFIG_ISAAC_RANDSIZ*4)
{
isaac(ctx);
if (ctx->randcnt == CONFIG_ISAAC_RANDSIZ*4)
{
isaac(ctx);
-
- size_t L = MIN(len, CONFIG_ISAAC_RANDSIZ*4 - (size_t)ctx->randcnt);
+
+ size_t L = MIN(len, CONFIG_ISAAC_RANDSIZ*4 - (size_t)ctx->randcnt);
memcpy(data, (uint8_t*)ctx->randrsl + ctx->randcnt, L);
data += L;
ctx->randcnt += L;
memcpy(data, (uint8_t*)ctx->randrsl + ctx->randcnt, L);
data += L;
ctx->randcnt += L;
/**********************************************************************/
/**********************************************************************/
-void ISAAC_init(ISAAC_Context *ctx)
+void isaac_init(IsaacContext *ctx)
- ctx->prng.reseed = ISAAC_reseed;
- ctx->prng.generate = ISAAC_generate;
+ ctx->prng.reseed = isaac_reseed;
+ ctx->prng.generate = isaac_generate;
ctx->prng.seed_len = sizeof(ctx->randrsl) / 2;
ctx->randcnt = CONFIG_ISAAC_RANDSIZ*4;
ctx->prng.seed_len = sizeof(ctx->randrsl) / 2;
ctx->randcnt = CONFIG_ISAAC_RANDSIZ*4;
*
* \brief ISAAC implementation
* \author Giovanni Bajo <rasky@develer.com>
*
* \brief ISAAC implementation
* \author Giovanni Bajo <rasky@develer.com>
*/
#ifndef SEC_PRNG_ISAAC_H
*/
#ifndef SEC_PRNG_ISAAC_H
/**
* Size of the internal ISAAC state (in 32-bit words).
/**
* 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
* ISAAC is known to generate unbiased data as follows:
* * 3 words: 2^37 unbiased values
* * 4 words: 2^45 unbiased values
* * 6 words: 2^61 unbiased values
* * 7 words: 2^69 unbiased values
* * 8 words: 2^77 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))
* 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 IsaacContext
{
PRNG prng;
uint32_t randcnt;
{
PRNG prng;
uint32_t randcnt;
uint32_t randa;
uint32_t randb;
uint32_t randc;
uint32_t randa;
uint32_t randb;
uint32_t randc;
-void ISAAC_init(ISAAC_Context *ctx);
+void isaac_init(IsaacContext *ctx);
-#define ISAAC_stackinit(...) \
- ({ ISAAC_Context *ctx = alloca(sizeof(ISAAC_Context)); ISAAC_init(ctx , ##__VA_ARGS__); &ctx->prng; })
+#define isaac_stackinit(...) \
+ ({ IsaacContext *ctx = alloca(sizeof(IsaacContext)); isaac_init(ctx , ##__VA_ARGS__); &ctx->prng; })
#endif /* SEC_PRNG_ISAAC_H */
#endif /* SEC_PRNG_ISAAC_H */
#define PRNG_ISAAC 1
#define PRNG_X917 2
#define PRNG_YARROW 3
#define PRNG_ISAAC 1
#define PRNG_X917 2
#define PRNG_YARROW 3
-#define PRNG_NAMEU1 ISAAC
+#define PRNG_NAMEU1 Isaac
#define PRNG_NAMEL1 isaac
#define PRNG_NAMEU2 X917
#define PRNG_NAMEL2 x917
#define PRNG_NAMEL1 isaac
#define PRNG_NAMEU2 X917
#define PRNG_NAMEL2 x917