To support the LRNG operation which uses the Jitter RNG separately
from the kernel crypto API, at a time where potentially the regular
memory management is not yet initialized, the Jitter RNG needs to
provide a state whose memory is defined at compile time. As only once
instance will ever be needed by the LRNG, define once static memory
block which is solely to be used by the LRNG.

CC: Torsten Duwe <d...@lst.de>
CC: "Eric W. Biederman" <ebied...@xmission.com>
CC: "Alexander E. Patrakov" <patra...@gmail.com>
CC: "Ahmed S. Darwish" <darwish...@gmail.com>
CC: "Theodore Y. Ts'o" <ty...@mit.edu>
CC: Willy Tarreau <w...@1wt.eu>
CC: Matthew Garrett <mj...@srcf.ucam.org>
CC: Vito Caputo <vcap...@pengaru.com>
CC: Andreas Dilger <adilger.ker...@dilger.ca>
CC: Jan Kara <j...@suse.cz>
CC: Ray Strode <rstr...@redhat.com>
CC: William Jon McCann <mcc...@jhu.edu>
CC: zhangjs <zach...@baishancloud.com>
CC: Andy Lutomirski <l...@kernel.org>
CC: Florian Weimer <fwei...@redhat.com>
CC: Lennart Poettering <mzxre...@0pointer.de>
CC: Nicolai Stange <nsta...@suse.de>
Reviewed-by: Roman Drahtmueller <dr...@schaltsekun.de>
Tested-by: Roman Drahtmüller <dr...@schaltsekun.de>
Tested-by: Marcelo Henrique Cerri <marcelo.ce...@canonical.com>
Tested-by: Neil Horman <nhor...@redhat.com>
Signed-off-by: Stephan Mueller <smuel...@chronox.de>
---
 crypto/jitterentropy-kcapi.c                  |  3 +-
 crypto/jitterentropy.c                        | 31 ++++++++++++++++++-
 .../crypto/internal}/jitterentropy.h          |  3 ++
 3 files changed, 34 insertions(+), 3 deletions(-)
 rename {crypto => include/crypto/internal}/jitterentropy.h (84%)

diff --git a/crypto/jitterentropy-kcapi.c b/crypto/jitterentropy-kcapi.c
index e8a4165a1874..c90e60910827 100644
--- a/crypto/jitterentropy-kcapi.c
+++ b/crypto/jitterentropy-kcapi.c
@@ -43,8 +43,7 @@
 #include <linux/fips.h>
 #include <linux/time.h>
 #include <crypto/internal/rng.h>
-
-#include "jitterentropy.h"
+#include <crypto/internal/jitterentropy.h>
 
 /***************************************************************************
  * Helper function
diff --git a/crypto/jitterentropy.c b/crypto/jitterentropy.c
index 6e147c43fc18..fa1459f09b01 100644
--- a/crypto/jitterentropy.c
+++ b/crypto/jitterentropy.c
@@ -117,7 +117,7 @@ struct rand_data {
 #define JENT_EHEALTH           9 /* Health test failed during initialization */
 #define JENT_ERCT              10 /* RCT failed during initialization */
 
-#include "jitterentropy.h"
+#include <crypto/internal/jitterentropy.h>
 
 /***************************************************************************
  * Adaptive Proportion Test
@@ -854,3 +854,32 @@ int jent_entropy_init(void)
 
        return 0;
 }
+
+struct rand_data *jent_lrng_entropy_collector(void)
+{
+       static unsigned char lrng_jent_mem[JENT_MEMORY_SIZE];
+       static struct rand_data lrng_jent_state = {
+               .data           = 0,
+               .old_data       = 0,
+               .prev_time      = 0,
+               .last_delta     = 0,
+               .last_delta2    = 0,
+               .osr            = 1,
+               .mem            = lrng_jent_mem,
+               .memlocation    = 0,
+               .memblocks      = JENT_MEMORY_BLOCKSIZE,
+               .memblocksize   = JENT_MEMORY_BLOCKS,
+               .memaccessloops = JENT_MEMORY_ACCESSLOOPS,
+               .rct_count      = 0,
+               .apt_observations = 0,
+               .apt_count      = 0,
+               .apt_base       = 0,
+               .apt_base_set   = 0,
+               .health_failure = 0
+       };
+
+       if (jent_entropy_init())
+               return NULL;
+
+       return &lrng_jent_state;
+}
diff --git a/crypto/jitterentropy.h b/include/crypto/internal/jitterentropy.h
similarity index 84%
rename from crypto/jitterentropy.h
rename to include/crypto/internal/jitterentropy.h
index c83fff32d130..6e07d86eac82 100644
--- a/crypto/jitterentropy.h
+++ b/include/crypto/internal/jitterentropy.h
@@ -15,3 +15,6 @@ extern int jent_read_entropy(struct rand_data *ec, unsigned 
char *data,
 extern struct rand_data *jent_entropy_collector_alloc(unsigned int osr,
                                                      unsigned int flags);
 extern void jent_entropy_collector_free(struct rand_data *entropy_collector);
+
+/* Access to statically allocated Jitter RNG instance */
+extern struct rand_data *jent_lrng_entropy_collector(void);
-- 
2.29.2




Reply via email to