linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/8] drivers/char/random: Split out __get_random_int
@ 2011-03-14  0:57 George Spelvin
  2011-03-16  3:03 ` Matt Mackall
  0 siblings, 1 reply; 7+ messages in thread
From: George Spelvin @ 2011-03-14  0:57 UTC (permalink / raw)
  To: penberg, herbert, mpm; +Cc: linux-mm, linux-kernel, linux

The unlocked function is needed for following work.
No API change.

(Minor functional change while messing with code: all 64 bits of
the cycles counter is used.  No API change.)
---
 drivers/char/random.c |   27 +++++++++++++++++----------
 1 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 4bcc4f2..fdbf7b6 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1621,22 +1621,29 @@ EXPORT_SYMBOL(secure_dccp_sequence_number);
 /*
  * Get a random word for internal kernel use only. Similar to urandom but
  * with the goal of minimal entropy pool depletion. As a result, the random
- * value is not cryptographically secure but for several uses the cost of
- * depleting entropy is too high
+ * value is not strongly cryptographically secure, but for several uses the
+ * cost of depleting entropy is too high.
  */
 DEFINE_PER_CPU(__u32 [4], get_random_int_hash);
-unsigned int get_random_int(void)
+static u32 __get_random_int(u32 *hash)
 {
-	struct keydata *keyptr;
-	__u32 *hash = get_cpu_var(get_random_int_hash);
-	int ret;
+	struct keydata const *keyptr = get_keyptr();
+	cycles_t c = get_cycles();
 
-	keyptr = get_keyptr();
-	hash[0] += current->pid + jiffies + get_cycles();
+	/* Throw in some extra seed material */
+	hash[0] += (__u32)c;
+	hash[1] += (__u32)(c>>16>>16); /* Safe if cycles_it is 32 bits. */
+	hash[2] += current->pid + jiffies;
 
-	ret = half_md4_transform(hash, keyptr->secret);
-	put_cpu_var(get_random_int_hash);
+	return half_md4_transform(hash, keyptr->secret);
+}
 
+unsigned int get_random_int(void)
+{
+	u32 *hash = get_cpu_var(get_random_int_hash);
+	u32 ret = __get_random_int(hash);
+
+	put_cpu_var(get_random_int_hash);
 	return ret;
 }
 
-- 
1.7.4.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-03-16 20:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-14  0:57 [PATCH 2/8] drivers/char/random: Split out __get_random_int George Spelvin
2011-03-16  3:03 ` Matt Mackall
2011-03-16  4:24   ` George Spelvin
2011-03-16  6:27     ` Pekka Enberg
2011-03-16 14:24     ` Matt Mackall
2011-03-16 18:35       ` George Spelvin
2011-03-16 20:35         ` Matt Mackall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).