summaryrefslogtreecommitdiffstats
path: root/sys/dev/random
diff options
context:
space:
mode:
authormarkm <markm@FreeBSD.org>2003-11-02 10:55:16 +0000
committermarkm <markm@FreeBSD.org>2003-11-02 10:55:16 +0000
commita3bf188d5b14acb242cc0a64b6bbfe2797f04d04 (patch)
treef8cbc8e96eb57c0a8f38852165f7e17ba12c50de /sys/dev/random
parent315c0ec426935ae53905eb509b87fc3e5f7b11af (diff)
downloadFreeBSD-src-a3bf188d5b14acb242cc0a64b6bbfe2797f04d04.zip
FreeBSD-src-a3bf188d5b14acb242cc0a64b6bbfe2797f04d04.tar.gz
Make sure we get all user-written input. This simplifies the
code considerably. Submitted by: (forgotten) [I'll happily acknowledge the submitter if he owns up!]
Diffstat (limited to 'sys/dev/random')
-rw-r--r--sys/dev/random/randomdev.c19
1 files changed, 5 insertions, 14 deletions
diff --git a/sys/dev/random/randomdev.c b/sys/dev/random/randomdev.c
index 57bb54c..6bbe200 100644
--- a/sys/dev/random/randomdev.c
+++ b/sys/dev/random/randomdev.c
@@ -406,27 +406,18 @@ static void
random_write_internal(void *buf, int count)
{
int i;
+ u_int chunk;
/* Break the input up into HARVESTSIZE chunks.
* The writer has too much control here, so "estimate" the
* the entropy as zero.
*/
for (i = 0; i < count; i += HARVESTSIZE) {
+ chunk = HARVESTSIZE;
+ if (i + chunk >= count)
+ chunk = (u_int)(count - i);
random_harvest_internal(get_cyclecount(), (char *)buf + i,
- HARVESTSIZE, 0, 0, RANDOM_WRITE);
- }
-
- /* Maybe the loop iterated at least once */
- if (i > count)
- i -= HARVESTSIZE;
-
- /* Get the last bytes even if the input length is not
- * a multiple of HARVESTSIZE.
- */
- count %= HARVESTSIZE;
- if (count) {
- random_harvest_internal(get_cyclecount(), (char *)buf + i,
- (u_int)count, 0, 0, RANDOM_WRITE);
+ chunk, 0, 0, RANDOM_WRITE);
}
}
OpenPOWER on IntegriCloud