From a0d687b7edac40d6ebf9537d3c7500848946a179 Mon Sep 17 00:00:00 2001 From: John Denker Date: Tue, 15 Oct 2013 13:01:29 -0700 Subject: things that aren't entropy shouldn't be called entropy --- drivers/char/random.c | 36 +++++++++++++++++++++++------------- include/trace/events/random.h | 6 +++--- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/drivers/char/random.c b/drivers/char/random.c index 254407b..7a06c59 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -833,11 +833,21 @@ void add_disk_randomness(struct gendisk *disk) /********************************************************************* * - * Entropy extraction routines + * Extraction routines. * - *********************************************************************/ + * These routines extract bytes that are "random" in some unspecified + * sense, but may _or may not_ contain any appreciable amount of + * entropy. Therefore, please do not call them "entropy" extraction + * routines. + * + * Specifically, in the case of the PRNG, i.e. the nonblocking pool, + * the extracted bytes may have an entropy density that is vastly less + * than 8 bits per byte, orders of magnitude less. + * + * ********************************************************************/ -static ssize_t extract_entropy(struct entropy_store *r, void *buf, +/* Forward reference */ +static ssize_t extract_rnd(struct entropy_store *r, void *buf, size_t nbytes, int min, int rsvd); /* @@ -913,7 +923,7 @@ static void fill_pool( BIT2BYTE(mybatch), BIT2BYTE(rsvd)); if (txbits < 0) return; /* already full enough */ - actual = extract_entropy(r->pull, tmp, BIT2BYTE(txbits), + actual = extract_rnd(r->pull, tmp, BIT2BYTE(txbits), BIT2BYTE(mybatch), BIT2BYTE(rsvd)); mix_pool_bytes(r, tmp, actual, NULL); credit_entropy_bits(r, actual*8); @@ -1065,7 +1075,7 @@ static void extract_buf(struct entropy_store *r, __u8 *out) * * We return the actual number of bytes extracted. */ -static ssize_t extract_entropy(struct entropy_store *r, void *buf, +static ssize_t extract_rnd(struct entropy_store *r, void *buf, size_t txbytes, int min, int reserved) { ssize_t ret = 0, i; @@ -1078,7 +1088,7 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf, if (!r->last_data_init) { r->last_data_init = true; spin_unlock_irqrestore(&r->lock, flags); - trace_extract_entropy(r->name, EXTRACT_SIZE, + trace_extract_rnd(r->name, EXTRACT_SIZE, r->entropy_count, _RET_IP_); fill_pool(r, EXTRACT_SIZE); extract_buf(r, tmp); @@ -1088,7 +1098,7 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf, spin_unlock_irqrestore(&r->lock, flags); } - trace_extract_entropy(r->name, txbytes, r->entropy_count, _RET_IP_); + trace_extract_rnd(r->name, txbytes, r->entropy_count, _RET_IP_); /* * We want our pool (r) to have enough entropy, if possible. * So pull it up to a level (txbits) that will cover the @@ -1129,13 +1139,13 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf, return ret; } -static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf, +static ssize_t extract_rnd_user(struct entropy_store *r, void __user *buf, size_t nbytes) { ssize_t ret = 0, i; __u8 tmp[EXTRACT_SIZE]; - trace_extract_entropy_user(r->name, nbytes, r->entropy_count, _RET_IP_); + trace_extract_rnd_user(r->name, nbytes, r->entropy_count, _RET_IP_); fill_pool(r, nbytes); /* Debit the estimate, according to the extraction we are about to do: */ @@ -1181,7 +1191,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf, */ void get_random_bytes(void *buf, int nbytes) { - extract_entropy(&nonblocking_pool, buf, nbytes, 0, 0); + extract_rnd(&nonblocking_pool, buf, nbytes, 0, 0); } EXPORT_SYMBOL(get_random_bytes); @@ -1213,7 +1223,7 @@ void get_random_bytes_arch(void *buf, int nbytes) } if (nbytes) - extract_entropy(&nonblocking_pool, p, nbytes, 0, 0); + extract_rnd(&nonblocking_pool, p, nbytes, 0, 0); } EXPORT_SYMBOL(get_random_bytes_arch); @@ -1307,7 +1317,7 @@ random_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) DEBUG_ENT("reading %zu bits\n", n*8); - n = extract_entropy_user(&blocking_pool, buf, n); + n = extract_rnd_user(&blocking_pool, buf, n); if (n < 0) { retval = n; @@ -1352,7 +1362,7 @@ random_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) static ssize_t urandom_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) { - return extract_entropy_user(&nonblocking_pool, buf, nbytes); + return extract_rnd_user(&nonblocking_pool, buf, nbytes); } static unsigned int diff --git a/include/trace/events/random.h b/include/trace/events/random.h index 422df19..2825208 100644 --- a/include/trace/events/random.h +++ b/include/trace/events/random.h @@ -86,7 +86,7 @@ TRACE_EVENT(get_random_bytes, TP_printk("nbytes %d caller %pF", __entry->nbytes, (void *)__entry->IP) ); -DECLARE_EVENT_CLASS(random__extract_entropy, +DECLARE_EVENT_CLASS(random__extract_rnd, TP_PROTO(const char *pool_name, int nbytes, int entropy_count, unsigned long IP), @@ -112,14 +112,14 @@ DECLARE_EVENT_CLASS(random__extract_entropy, ); -DEFINE_EVENT(random__extract_entropy, extract_entropy, +DEFINE_EVENT(random__extract_rnd, extract_rnd, TP_PROTO(const char *pool_name, int nbytes, int entropy_count, unsigned long IP), TP_ARGS(pool_name, nbytes, entropy_count, IP) ); -DEFINE_EVENT(random__extract_entropy, extract_entropy_user, +DEFINE_EVENT(random__extract_rnd, extract_rnd_user, TP_PROTO(const char *pool_name, int nbytes, int entropy_count, unsigned long IP), -- cgit v1.2.3