static void yarrow_fast_reseed(struct yarrow256_ctx *ctx) { quint8 digest[SHA256_DIGEST_SIZE]; unsigned i; #if YARROW_DEBUG fprintf(stderr, "yarrow_fast_reseed\n"); #endif /* We feed two block of output using the current key into the pool * before emptying it. */ if (ctx->seeded) { quint8 blocks[AES_BLOCK_SIZE * 2]; yarrow_generate_block(ctx, blocks); yarrow_generate_block(ctx, blocks + AES_BLOCK_SIZE); sha256_update(&ctx->pools[YARROW_FAST],blocks,sizeof(blocks)); } sha256_finish(&ctx->pools[YARROW_FAST],digest); /* Iterate */ yarrow_iterate(digest); aes_encrypt_key256(digest,&ctx->key); /* Derive new counter value */ memset(ctx->counter, 0, sizeof(ctx->counter)); //aes_encrypt(&ctx->key, sizeof(ctx->counter), ctx->counter, ctx->counter); aes_ecb_encrypt(ctx->counter,ctx->counter,sizeof(ctx->counter),&ctx->key); /* Reset estimates. */ for (i = 0; i<ctx->nsources; i++) ctx->sources[i].estimate[YARROW_FAST] = 0; /* New seed file. */ /* FIXME: Extract this into a function of its own. */ for (i = 0; i < sizeof(ctx->seed_file); i+= AES_BLOCK_SIZE) yarrow_generate_block(ctx, ctx->seed_file + i); yarrow_gate(ctx); }
void yarrow256_fast_reseed(struct yarrow256_ctx *ctx) { uint8_t digest[SHA256_DIGEST_SIZE]; unsigned i; #if YARROW_DEBUG fprintf(stderr, "yarrow256_fast_reseed\n"); #endif /* We feed two block of output using the current key into the pool * before emptying it. */ if (ctx->seeded) { uint8_t blocks[AES_BLOCK_SIZE * 2]; yarrow_generate_block(ctx, blocks); yarrow_generate_block(ctx, blocks + AES_BLOCK_SIZE); sha256_update(&ctx->pools[YARROW_FAST], sizeof(blocks), blocks); } sha256_digest(&ctx->pools[YARROW_FAST], sizeof(digest), digest); /* Iterate */ yarrow_iterate(digest); aes256_set_encrypt_key(&ctx->key, digest); ctx->seeded = 1; /* Derive new counter value */ memset(ctx->counter, 0, sizeof(ctx->counter)); aes256_encrypt(&ctx->key, sizeof(ctx->counter), ctx->counter, ctx->counter); /* Reset estimates. */ for (i = 0; i<ctx->nsources; i++) ctx->sources[i].estimate[YARROW_FAST] = 0; }