X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fsec%2Fprng%2Fx917.c;h=d2c84f71f1a4ae8d0a5e0b2aab0208e7852188cc;hb=1bb0ad8f023538906d593d44a872cf4c091499c9;hp=63888c8f3b7ae99bb7f941fc294bc265c3b9b8e2;hpb=0e8d3b095f4b5ba3ac5c080c0e9edb5226c38bad;p=bertos.git diff --git a/bertos/sec/prng/x917.c b/bertos/sec/prng/x917.c index 63888c8f..d2c84f71 100644 --- a/bertos/sec/prng/x917.c +++ b/bertos/sec/prng/x917.c @@ -103,17 +103,24 @@ static void x917_reseed(PRNG *ctx_, const uint8_t *seed) // of the seed, and use the result as new seed. // * Generate and throw away a block to update the state. X917Context *ctx = (X917Context *)ctx_; + const size_t klen = sizeof(ctx->key); + const size_t blen = sizeof(ctx->state); - size_t klen = sizeof(ctx->key); - size_t blen = sizeof(ctx->state); - - uint8_t buf[klen]; - x917_generate(ctx_, buf, klen); + if (!ctx->rng.seeded) + { + memcpy(ctx->key, seed, klen); + memcpy(ctx->state, seed+klen, blen); + } + else + { + uint8_t buf[klen]; + x917_generate(ctx_, buf, klen); - xor_block(ctx->key, buf, seed, klen); - xor_block(ctx->state, ctx->state, seed+klen, blen); + xor_block(ctx->key, buf, seed, klen); + xor_block(ctx->state, ctx->state, seed+klen, blen); - PURGE(buf); + PURGE(buf); + } } /*********************************************************************/