/* * Just take 2 next blocks as new key */ static void rekey(FState * st) { encrypt_counter(st, st->key); encrypt_counter(st, st->key + CIPH_BLOCK); ciph_init(&st->ciph, st->key, BLOCK); }
/* * generate new key from all the pools */ static void reseed(FState * st) { unsigned k; unsigned n; MD_CTX key_md; unsigned char buf[BLOCK]; /* set pool as empty */ st->pool0_bytes = 0; /* * Both #0 and #1 reseed would use only pool 0. Just skip #0 then. */ n = ++st->reseed_count; /* * The goal: use k-th pool only 1/(2^k) of the time. */ md_init(&key_md); for (k = 0; k < NUM_POOLS; k++) { md_result(&st->pool[k], buf); md_update(&key_md, buf, BLOCK); if (n & 1 || !n) break; n >>= 1; } /* add old key into mix too */ md_update(&key_md, st->key, BLOCK); /* add pid to make output diverse after fork() */ md_update(&key_md, (const unsigned char *)&st->pid, sizeof(st->pid)); /* now we have new key */ md_result(&key_md, st->key); /* use new key */ ciph_init(&st->ciph, st->key, BLOCK); memset(&key_md, 0, sizeof(key_md)); memset(buf, 0, BLOCK); }
/* * generate new key from all the pools */ static void reseed(FState *st) { unsigned k; unsigned n; mdCtx key_md; uint8_t buf[block]; /* set pool as empty */ st->pool0Bytes = 0; /* * Both #0 and #1 reseed would use only pool 0. Just skip #0 then. */ n = ++st->reseedCount; /* * The goal: use k-th pool only 1/(2^k) of the time. */ md_init(&key_md); for (k = 0; k < numPools; k++) { md_result(&st->pool[k], buf); md_update(&key_md, buf, block); if (n & 1 || !n) break; n >>= 1; } /* add old key into mix too */ md_update(&key_md, st->key, block); /* now we have new key */ md_result(&key_md, st->key); /* use new key */ ciph_init(&st->ciph, st->key, block); memset(&key_md, 0, sizeof(key_md)); memset(buf, 0, block); }
/* * Just take 2 next blocks as new key */ static void rekey(FState *st) { encrypt_counter(st, st->key); encrypt_counter(st, st->key + ciphBlock); ciph_init(&st->ciph, st->key, block); }