SEC: fix first seeding of x917 to be fully deterministic.
authorrasky <rasky@38d2e660-2303-0410-9eaa-f027e97ec537>
Wed, 29 Sep 2010 16:51:03 +0000 (16:51 +0000)
committerrasky <rasky@38d2e660-2303-0410-9eaa-f027e97ec537>
Wed, 29 Sep 2010 16:51:03 +0000 (16:51 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4364 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/sec/prng/x917.c

index 63888c8f3b7ae99bb7f941fc294bc265c3b9b8e2..d2c84f71f1a4ae8d0a5e0b2aab0208e7852188cc 100644 (file)
@@ -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);
+       }
 }
 
 /*********************************************************************/