X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;ds=sidebyside;f=bertos%2Fsec%2Fprng%2Fisaac.c;h=86c162700369b8f7b99366ccef5913c8c6601d45;hb=4d8a6a97c6c0e15296b51d5f02674079bede1aa0;hp=4e031c0be5d9a36d234088b8a39cd460a8a721d1;hpb=f2108fe515132a85c7e84e588789f482f8feb750;p=bertos.git diff --git a/bertos/sec/prng/isaac.c b/bertos/sec/prng/isaac.c index 4e031c0b..86c16270 100644 --- a/bertos/sec/prng/isaac.c +++ b/bertos/sec/prng/isaac.c @@ -48,6 +48,7 @@ MODIFIED: #include "isaac.h" #include +#include #include #include #include @@ -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;