Remove unneeded ifdef.
[bertos.git] / bertos / sec / prng / isaac.c
index 4e031c0be5d9a36d234088b8a39cd460a8a721d1..86c162700369b8f7b99366ccef5913c8c6601d45 100644 (file)
@@ -48,6 +48,7 @@ MODIFIED:
 
 #include "isaac.h"
 #include <sec/prng.h>
+#include <sec/util.h>
 #include <cfg/compiler.h>
 #include <cfg/macros.h>
 #include <string.h>
@@ -56,7 +57,7 @@ typedef uint32_t ub4;
 typedef uint16_t ub2;
 typedef uint8_t ub1;
 
-#define ind(mm,x)  (*(ub4 *)((ub1 *)(mm) + ((x) & ((CONFIG_ISAAC_RANDSIZ-1)<<2))))
+#define ind(mm,x)  (*(ub4 *)((size_t)(mm) + ((x) & ((CONFIG_ISAAC_RANDSIZ-1)<<2))))
 #define rngstep(mix,a,b,mm,m,m2,r,x) \
 { \
   x = *m;  \
@@ -107,9 +108,9 @@ static void isaac_reseed(PRNG *ctx_, const uint8_t *seed)
        ub4 a,b,c,d,e,f,g,h;
        ub4 *m,*r;
 
-       // Copy seed over half of randrsl, to reuse half of last-generated
-       // data as seed.
-       memcpy(ctx->randrsl, seed, sizeof(ctx->randrsl)/2);
+       // XOR the new seed over the current state, so to depend on
+       // the previously-generated output.
+       xor_block(ctx->randrsl, ctx->randrsl, seed, sizeof(ctx->randrsl));
 
        ctx->randa = ctx->randb = ctx->randc = 0;
        m=ctx->randmem;
@@ -172,7 +173,7 @@ void isaac_init(IsaacContext *ctx)
 {
        ctx->prng.reseed = isaac_reseed;
        ctx->prng.generate = isaac_generate;
-       ctx->prng.seed_len = sizeof(ctx->randrsl) / 2;
+       ctx->prng.seed_len = sizeof(ctx->randrsl);
        ctx->prng.seeded = 0;
 
        ctx->randcnt = CONFIG_ISAAC_RANDSIZ*4;