public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rtc: wm831x: Feed the write counter into device_add_randomness()
@ 2012-07-05 20:19 Mark Brown
  2012-07-06 21:23 ` Theodore Ts'o
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Brown @ 2012-07-05 20:19 UTC (permalink / raw)
  To: Theodore Ts'o, Alessandro Zummo, Andrew Morton
  Cc: linux-kernel, patches, rtc-linux, Mark Brown

The tamper evident features of the RTC include the "write counter" which
is a pseudo-random number regenerated whenever we set the RTC. Since this
value is unpredictable it should provide some useful seeding to the random
number generator.

Only do this on boot since the goal is to seed the pool rather than add
useful entropy.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
---

add_device_randomness() has only just been added in -next, this will
need to either wait until after the merge window or be merged along with
the patch adding it.

 drivers/rtc/rtc-wm831x.c |   24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-wm831x.c b/drivers/rtc/rtc-wm831x.c
index 59c6245..ea5c6f8 100644
--- a/drivers/rtc/rtc-wm831x.c
+++ b/drivers/rtc/rtc-wm831x.c
@@ -24,7 +24,7 @@
 #include <linux/mfd/wm831x/core.h>
 #include <linux/delay.h>
 #include <linux/platform_device.h>
-
+#include <linux/random.h>
 
 /*
  * R16416 (0x4020) - RTC Write Counter
@@ -96,6 +96,26 @@ struct wm831x_rtc {
 	unsigned int alarm_enabled:1;
 };
 
+static void wm831x_rtc_add_randomness(struct wm831x *wm831x)
+{
+	int ret;
+	u16 reg;
+
+	/*
+	 * The write counter contains a pseudo-random number which is
+	 * regenerated every time we set the RTC so it should be a
+	 * useful per-system source of entropy.
+	 */
+	ret = wm831x_reg_read(wm831x, WM831X_RTC_WRITE_COUNTER);
+	if (ret >= 0) {
+		reg = ret;
+		add_device_randomness(&reg, sizeof(reg));
+	} else {
+		dev_warn(wm831x->dev, "Failed to read RTC write counter: %d\n",
+			 ret);
+	}
+}
+
 /*
  * Read current time and date in RTC
  */
@@ -431,6 +451,8 @@ static int wm831x_rtc_probe(struct platform_device *pdev)
 			alm_irq, ret);
 	}
 
+	wm831x_rtc_add_randomness(wm831x);
+
 	return 0;
 
 err:
-- 
1.7.10


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

* Re: rtc: wm831x: Feed the write counter into device_add_randomness()
  2012-07-05 20:19 [PATCH] rtc: wm831x: Feed the write counter into device_add_randomness() Mark Brown
@ 2012-07-06 21:23 ` Theodore Ts'o
  0 siblings, 0 replies; 2+ messages in thread
From: Theodore Ts'o @ 2012-07-06 21:23 UTC (permalink / raw)
  To: Mark Brown
  Cc: Alessandro Zummo, Andrew Morton, linux-kernel, patches, rtc-linux

On Thu, Jul 05, 2012 at 08:19:17PM -0000, Mark Brown wrote:
> The tamper evident features of the RTC include the "write counter" which
> is a pseudo-random number regenerated whenever we set the RTC. Since this
> value is unpredictable it should provide some useful seeding to the random
> number generator.
> 
> Only do this on boot since the goal is to seed the pool rather than add
> useful entropy.
> 
> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>

> add_device_randomness() has only just been added in -next, this will
> need to either wait until after the merge window or be merged along with
> the patch adding it.

Thanks, I've added this to the /dev/random git tree.

	     	   	       		   - Ted


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

end of thread, other threads:[~2012-07-06 21:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-05 20:19 [PATCH] rtc: wm831x: Feed the write counter into device_add_randomness() Mark Brown
2012-07-06 21:23 ` Theodore Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox