Skip to content

Commit

Permalink
rtc: wm831x: Feed the write counter into device_add_randomness()
Browse files Browse the repository at this point in the history
commit 9dccf55 upstream.

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>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
  • Loading branch information
Mark Brown authored and Paul Gortmaker committed Aug 17, 2012
1 parent aed22e3 commit 8197604
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion drivers/rtc/rtc-wm831x.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -465,6 +485,8 @@ static int wm831x_rtc_probe(struct platform_device *pdev)
alm_irq, ret);
}

wm831x_rtc_add_randomness(wm831x);

return 0;

err:
Expand Down

0 comments on commit 8197604

Please sign in to comment.