Skip to content

Commit

Permalink
char/lrng: add power-on and runtime self-tests
Browse files Browse the repository at this point in the history
Parts of the LRNG are already covered by self-tests, including:

* Self-test of SP800-90A DRBG provided by the Linux kernel crypto API.

* Self-test of the PRNG provided by the Linux kernel crypto API.

* Raw noise source data testing including SP800-90B compliant
  tests when enabling CONFIG_LRNG_HEALTH_TESTS

This patch adds the self-tests for the remaining critical functions of
the LRNG that are essential to maintain entropy and provide
cryptographic strong random numbers. The following self-tests are
implemented:

* Self-test of the time array maintenance. This test verifies whether
the time stamp array management to store multiple values in one integer
implements a concatenation of the data.

* Self-test of the software hash implementation ensures that this
function operates compliant to the FIPS 180-4 specification. The
self-test performs a hash operation of a zeroized per-CPU data array.

* Self-test of the ChaCha20 DRNG is based on the self-tests that are
already present and implemented with the stand-alone user space
ChaCha20 DRNG implementation available at [1]. The self-tests cover
different use cases of the DRNG seeded with known seed data.

The status of the LRNG self-tests is provided with the selftest_status
SysFS file. If the file contains a zero, the self-tests passed. The
value 0xffffffff means that the self-tests were not executed. Any other
value indicates a self-test failure.

The self-test may be compiled to panic the system if the self-test
fails.

All self-tests operate on private state data structures. This implies
that none of the self-tests have any impact on the regular LRNG
operations. This allows the self-tests to be repeated at runtime by
writing anything into the selftest_status SysFS file.

[1] https://www.chronox.de/chacha20.html

CC: Torsten Duwe <duwe@lst.de>
CC: "Eric W. Biederman" <ebiederm@xmission.com>
CC: "Alexander E. Patrakov" <patrakov@gmail.com>
CC: "Ahmed S. Darwish" <darwish.07@gmail.com>
CC: "Theodore Y. Ts'o" <tytso@mit.edu>
CC: Willy Tarreau <w@1wt.eu>
CC: Matthew Garrett <mjg59@srcf.ucam.org>
CC: Vito Caputo <vcaputo@pengaru.com>
CC: Andreas Dilger <adilger.kernel@dilger.ca>
CC: Jan Kara <jack@suse.cz>
CC: Ray Strode <rstrode@redhat.com>
CC: William Jon McCann <mccann@jhu.edu>
CC: zhangjs <zachary@baishancloud.com>
CC: Andy Lutomirski <luto@kernel.org>
CC: Florian Weimer <fweimer@redhat.com>
CC: Lennart Poettering <mzxreary@0pointer.de>
CC: Nicolai Stange <nstange@suse.de>
CC: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
CC: Neil Horman <nhorman@redhat.com>
Reviewed-by: Alexander Lobakin <alobakin@pm.me>
Tested-by: Alexander Lobakin <alobakin@pm.me>
Signed-off-by: Stephan Mueller <smueller@chronox.de>
  • Loading branch information
smuellerDD authored and xanmod committed Oct 17, 2021
1 parent 9dc02cd commit 6ae8c67
Show file tree
Hide file tree
Showing 3 changed files with 405 additions and 8 deletions.
43 changes: 35 additions & 8 deletions drivers/char/lrng/Kconfig
Expand Up @@ -165,15 +165,16 @@ config LRNG_COLLECTION_SIZE
default 8192 if LRNG_COLLECTION_SIZE_8192

config LRNG_HEALTH_TESTS
bool "Enable noise source online health tests"
bool "Enable interrupt entropy source online health tests"
help
The online health tests validate the noise source at
runtime for fatal errors. These tests include SP800-90B
compliant tests which are invoked if the system is booted
with fips=1. In case of fatal errors during active
SP800-90B tests, the issue is logged and the noise
data is discarded. These tests are required for full
compliance with SP800-90B.
The online health tests applied to the interrupt entropy
source validate the noise source at runtime for fatal
errors. These tests include SP800-90B compliant tests
which are invoked if the system is booted with fips=1.
In case of fatal errors during active SP800-90B tests,
the issue is logged and the noise data is discarded.
These tests are required for full compliance of the
interrupt entropy source with SP800-90B.

If unsure, say Y.

Expand Down Expand Up @@ -493,4 +494,30 @@ config LRNG_TESTING

endif #LRNG_TESTING_MENU

config LRNG_SELFTEST
bool "Enable power-on and on-demand self-tests"
help
The power-on self-tests are executed during boot time
covering the ChaCha20 DRNG, the hash operation used for
processing the entropy pools and the auxiliary pool, and
the time stamp management of the LRNG.

The on-demand self-tests are triggered by writing any
value into the SysFS file selftest_status. At the same
time, when reading this file, the test status is
returned. A zero indicates that all tests were executed
successfully.

If unsure, say Y.

if LRNG_SELFTEST

config LRNG_SELFTEST_PANIC
bool "Panic the kernel upon self-test failure"
help
If the option is enabled, the kernel is terminated if an
LRNG power-on self-test failure is detected.

endif # LRNG_SELFTEST

endif # LRNG
1 change: 1 addition & 0 deletions drivers/char/lrng/Makefile
Expand Up @@ -17,3 +17,4 @@ obj-$(CONFIG_LRNG_KCAPI) += lrng_kcapi.o
obj-$(CONFIG_LRNG_JENT) += lrng_es_jent.o
obj-$(CONFIG_LRNG_HEALTH_TESTS) += lrng_health.o
obj-$(CONFIG_LRNG_TESTING) += lrng_testing.o
obj-$(CONFIG_LRNG_SELFTEST) += lrng_selftest.o

0 comments on commit 6ae8c67

Please sign in to comment.