From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephan =?ISO-8859-1?Q?M=FCller?= Subject: [PATCH v29 08/12] crypto: provide access to a static Jitter RNG state Date: Sun, 19 Jan 2020 22:17:33 +0100 Message-ID: <3163301.oFKfPMb7QI@positron.chronox.de> References: <6157374.ptSnyUpaCn@positron.chronox.de> <5951792.lmNsirYsPE@positron.chronox.de> <1967138.dxe05VgvIB@positron.chronox.de> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <1967138.dxe05VgvIB@positron.chronox.de> Sender: linux-kernel-owner@vger.kernel.org To: Arnd Bergmann Cc: Greg Kroah-Hartman , linux-crypto@vger.kernel.org, LKML , linux-api@vger.kernel.org, "Eric W. Biederman" , "Alexander E. Patrakov" , "Ahmed S. Darwish" , "Theodore Y. Ts'o" , Willy Tarreau , Matthew Garrett , Vito Caputo , Andreas Dilger , Jan Kara , Ray Strode , William Jon McCann , zhangjs , Andy Lutomirski , Florian Weimer , Lennart Poettering , Nicolai Stange , "Peter, Matthias" List-Id: linux-api@vger.kernel.org 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: "Eric W. Biederman" CC: "Alexander E. Patrakov" CC: "Ahmed S. Darwish" CC: "Theodore Y. Ts'o" CC: Willy Tarreau CC: Matthew Garrett CC: Vito Caputo CC: Andreas Dilger CC: Jan Kara CC: Ray Strode CC: William Jon McCann CC: zhangjs CC: Andy Lutomirski CC: Florian Weimer CC: Lennart Poettering CC: Nicolai Stange Reviewed-by: Roman Drahtmueller Tested-by: Roman Drahtm=FCller Tested-by: Marcelo Henrique Cerri Tested-by: Neil Horman Signed-off-by: Stephan Mueller =2D-- crypto/jitterentropy-kcapi.c | 3 +-- crypto/jitterentropy.c | 25 ++++++++++++++++++- .../crypto/internal}/jitterentropy.h | 3 +++ 3 files changed, 28 insertions(+), 3 deletions(-) rename {crypto =3D> include/crypto/internal}/jitterentropy.h (84%) diff --git a/crypto/jitterentropy-kcapi.c b/crypto/jitterentropy-kcapi.c index a5ce8f96790f..11b00e9f37f3 100644 =2D-- a/crypto/jitterentropy-kcapi.c +++ b/crypto/jitterentropy-kcapi.c @@ -43,8 +43,7 @@ #include #include #include =2D =2D#include "jitterentropy.h" +#include =20 /*************************************************************************= ** * Helper function diff --git a/crypto/jitterentropy.c b/crypto/jitterentropy.c index 042157f0d28b..529c9db13e64 100644 =2D-- a/crypto/jitterentropy.c +++ b/crypto/jitterentropy.c @@ -103,7 +103,7 @@ struct rand_data { * Helper functions *************************************************************************= **/ =20 =2D#include "jitterentropy.h" +#include =20 /** * Update of the loop count used for the next round of @@ -639,3 +639,26 @@ int jent_entropy_init(void) =20 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 =3D { + .data =3D 0, + .old_data =3D 0, + .prev_time =3D 0, + .last_delta =3D 0, + .last_delta2 =3D 0, + .osr =3D 1, + .mem =3D lrng_jent_mem, + .memlocation =3D 0, + .memblocks =3D JENT_MEMORY_BLOCKSIZE, + .memblocksize =3D JENT_MEMORY_BLOCKS, + .memaccessloops =3D JENT_MEMORY_ACCESSLOOPS, + }; + + if (jent_entropy_init()) + return NULL; + + return &lrng_jent_state; +} diff --git a/crypto/jitterentropy.h b/include/crypto/internal/jitterentropy= =2Eh similarity index 84% rename from crypto/jitterentropy.h rename to include/crypto/internal/jitterentropy.h index c83fff32d130..6e07d86eac82 100644 =2D-- a/crypto/jitterentropy.h +++ b/include/crypto/internal/jitterentropy.h @@ -15,3 +15,6 @@ extern int jent_read_entropy(struct rand_data *ec, unsign= ed 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_collecto= r); + +/* Access to statically allocated Jitter RNG instance */ +extern struct rand_data *jent_lrng_entropy_collector(void); =2D-=20 2.24.1