diff mbox series

[RFC,33/41] random: make health_test_process() maintain the get_cycles() delta

Message ID 20200921075857.4424-34-nstange@suse.de (mailing list archive)
State Not Applicable
Delegated to: Herbert Xu
Headers show
Series random: possible ways towards NIST SP800-90B compliance | expand

Commit Message

Nicolai Stange Sept. 21, 2020, 7:58 a.m. UTC
The min-entropy estimate has been made for the lower eight bits of the
deltas between cycle counter values from successive IRQ events and thus,
the upcoming health tests should actually be run on these deltas.

Introduce a new field ->previous_sample to struct health_test for storing
the previous get_cycles() value. Make health_test_process() maintain it
and also calculate the delta between the current and the previous value
at this point already in preparation to passing it to the upcoming health
tests. Note that ->previous_sample is deliberately not touched from
health_test_reset() in order to maintain a steady flow of correctly
calculated deltas across health test resets.

Signed-off-by: Nicolai Stange <nstange@suse.de>
---
 drivers/char/random.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/char/random.c b/drivers/char/random.c
index cb6441b96b8e..33f9b7b59f92 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -879,7 +879,9 @@  static void discard_queued_entropy(struct entropy_store *r,
 	spin_unlock_irqrestore(&r->lock, flags);
 }
 
-struct health_test {};
+struct health_test {
+	u8 previous_sample;
+};
 
 enum health_result {
 	health_none,
@@ -895,6 +897,16 @@  static enum health_result
 health_test_process(struct health_test *h, unsigned int event_entropy_shift,
 		    u8 sample)
 {
+	u8 sample_delta;
+
+	/*
+	 * The min-entropy estimate has been made for the lower eight
+	 * bits of the deltas between cycle counter values from
+	 * successive IRQ events.
+	 */
+	sample_delta = sample - h->previous_sample;
+	h->previous_sample = sample;
+
 	return health_none;
 }