Changeset View
Changeset View
Standalone View
Standalone View
head/sys/dev/random/fortuna.c
Show First 20 Lines • Show All 302 Lines • ▼ Show 20 Lines | |||||
/*- | /*- | ||||
* FS&K - GenerateBlocks() | * FS&K - GenerateBlocks() | ||||
* Generate a number of complete blocks of random output. | * Generate a number of complete blocks of random output. | ||||
*/ | */ | ||||
static __inline void | static __inline void | ||||
random_fortuna_genblocks(uint8_t *buf, u_int blockcount) | random_fortuna_genblocks(uint8_t *buf, u_int blockcount) | ||||
{ | { | ||||
u_int i; | |||||
RANDOM_RESEED_ASSERT_LOCK_OWNED(); | RANDOM_RESEED_ASSERT_LOCK_OWNED(); | ||||
KASSERT(!uint128_is_zero(fortuna_state.fs_counter), ("FS&K: C != 0")); | KASSERT(!uint128_is_zero(fortuna_state.fs_counter), ("FS&K: C != 0")); | ||||
for (i = 0; i < blockcount; i++) { | /* | ||||
/*- | * Fills buf with RANDOM_BLOCKSIZE * blockcount bytes of keystream. | ||||
* FS&K - r = r|E(K,C) | * Increments fs_counter as it goes. | ||||
* - C = C + 1 | |||||
*/ | */ | ||||
randomdev_encrypt(&fortuna_state.fs_key, &fortuna_state.fs_counter, buf, RANDOM_BLOCKSIZE); | randomdev_keystream(&fortuna_state.fs_key, &fortuna_state.fs_counter, | ||||
buf += RANDOM_BLOCKSIZE; | buf, blockcount); | ||||
uint128_increment(&fortuna_state.fs_counter); | |||||
} | |||||
} | } | ||||
/*- | /*- | ||||
* FS&K - PseudoRandomData() | * FS&K - PseudoRandomData() | ||||
* This generates no more than 2^20 bytes of data, and cleans up its | * This generates no more than 2^20 bytes of data, and cleans up its | ||||
* internal state when finished. It is assumed that a whole number of | * internal state when finished. It is assumed that a whole number of | ||||
* blocks are available for writing; any excess generated will be | * blocks are available for writing; any excess generated will be | ||||
* ignored. | * ignored. | ||||
▲ Show 20 Lines • Show All 135 Lines • Show Last 20 Lines |