From: rasky Date: Wed, 29 Sep 2010 16:51:03 +0000 (+0000) Subject: SEC: fix first seeding of x917 to be fully deterministic. X-Git-Tag: 2.6.0~37 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=1bb0ad8f023538906d593d44a872cf4c091499c9;p=bertos.git SEC: fix first seeding of x917 to be fully deterministic. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4364 38d2e660-2303-0410-9eaa-f027e97ec537 --- 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); + } } /*********************************************************************/