summaryrefslogtreecommitdiff
path: root/drivers/char
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2013-10-15 13:01:29 -0700
committerJohn Denker <jsd@av8n.com>2013-10-18 05:33:22 -0700
commita0d687b7edac40d6ebf9537d3c7500848946a179 (patch)
treed19314dfd408c0e2f36196bdd83bcdfaebfba65e /drivers/char
parent8dc7be5e5db5532dfe28aa5329a91939c823e37a (diff)
things that aren't entropy shouldn't be called entropy
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/random.c36
1 files changed, 23 insertions, 13 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