Skip to content

Commit

Permalink
crypto: provide access to a static Jitter RNG state
Browse files Browse the repository at this point in the history
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 <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: Alexander Lobakin <alobakin@mailbox.org>
Reviewed-by: Roman Drahtmueller <draht@schaltsekun.de>
Tested-by: Roman Drahtmüller <draht@schaltsekun.de>
Tested-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
Tested-by: Neil Horman <nhorman@redhat.com>
Signed-off-by: Stephan Mueller <smueller@chronox.de>
  • Loading branch information
smuellerDD authored and xanmod committed Jul 20, 2021
1 parent 0e6b8b1 commit 5fc04fe
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
3 changes: 1 addition & 2 deletions crypto/jitterentropy-kcapi.c
Expand Up @@ -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
Expand Down
31 changes: 30 additions & 1 deletion crypto/jitterentropy.c
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Up @@ -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);

0 comments on commit 5fc04fe

Please sign in to comment.