Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/random/randomdev.c
Show First 20 Lines • Show All 160 Lines • ▼ Show 20 Lines | if (error == 0) { | ||||
read_rate_increment((uio->uio_resid + sizeof(uint32_t))/sizeof(uint32_t)); | read_rate_increment((uio->uio_resid + sizeof(uint32_t))/sizeof(uint32_t)); | ||||
total_read = 0; | total_read = 0; | ||||
while (uio->uio_resid && !error) { | while (uio->uio_resid && !error) { | ||||
read_len = uio->uio_resid; | read_len = uio->uio_resid; | ||||
/* | /* | ||||
* Belt-and-braces. | * Belt-and-braces. | ||||
* Round up the read length to a crypto block size multiple, | * Round up the read length to a crypto block size multiple, | ||||
* which is what the underlying generator is expecting. | * which is what the underlying generator is expecting. | ||||
* See the random_buf size requirements in the Yarrow/Fortuna code. | * See the random_buf size requirements in the Fortuna code. | ||||
*/ | */ | ||||
read_len = roundup(read_len, RANDOM_BLOCKSIZE); | read_len = roundup(read_len, RANDOM_BLOCKSIZE); | ||||
/* Work in chunks page-sized or less */ | /* Work in chunks page-sized or less */ | ||||
read_len = MIN(read_len, PAGE_SIZE); | read_len = MIN(read_len, PAGE_SIZE); | ||||
p_random_alg_context->ra_read(random_buf, read_len); | p_random_alg_context->ra_read(random_buf, read_len); | ||||
c = MIN(uio->uio_resid, read_len); | c = MIN(uio->uio_resid, read_len); | ||||
/* | /* | ||||
* uiomove() may yield the CPU before each 'c' bytes | * uiomove() may yield the CPU before each 'c' bytes | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | randomdev_accumulate(uint8_t *buf, u_int count) | ||||
randomdev_hash_iterate(&hash, buf, count); | randomdev_hash_iterate(&hash, buf, count); | ||||
timestamp = (uint32_t)get_cyclecount(); | timestamp = (uint32_t)get_cyclecount(); | ||||
randomdev_hash_iterate(&hash, ×tamp, sizeof(timestamp)); | randomdev_hash_iterate(&hash, ×tamp, sizeof(timestamp)); | ||||
randomdev_hash_finish(&hash, entropy_data); | randomdev_hash_finish(&hash, entropy_data); | ||||
explicit_bzero(&hash, sizeof(hash)); | explicit_bzero(&hash, sizeof(hash)); | ||||
for (i = 0; i < RANDOM_KEYSIZE_WORDS; i += sizeof(event.he_entropy)/sizeof(event.he_entropy[0])) { | for (i = 0; i < RANDOM_KEYSIZE_WORDS; i += sizeof(event.he_entropy)/sizeof(event.he_entropy[0])) { | ||||
event.he_somecounter = (uint32_t)get_cyclecount(); | event.he_somecounter = (uint32_t)get_cyclecount(); | ||||
event.he_size = sizeof(event.he_entropy); | event.he_size = sizeof(event.he_entropy); | ||||
event.he_bits = event.he_size/8; | |||||
event.he_source = RANDOM_CACHED; | event.he_source = RANDOM_CACHED; | ||||
event.he_destination = destination++; /* Harmless cheating */ | event.he_destination = destination++; /* Harmless cheating */ | ||||
memcpy(event.he_entropy, entropy_data + i, sizeof(event.he_entropy)); | memcpy(event.he_entropy, entropy_data + i, sizeof(event.he_entropy)); | ||||
p_random_alg_context->ra_event_processor(&event); | p_random_alg_context->ra_event_processor(&event); | ||||
} | } | ||||
explicit_bzero(entropy_data, sizeof(entropy_data)); | explicit_bzero(entropy_data, sizeof(entropy_data)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 161 Lines • Show Last 20 Lines |