Skip to content

Commit

Permalink
remove jent_read_entropy_safe
Browse files Browse the repository at this point in the history
  • Loading branch information
smittals2 committed Jan 10, 2025
1 parent 8ff5cce commit 3031228
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 98 deletions.
6 changes: 0 additions & 6 deletions crypto/fipsmodule/rand/cpu_jitter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ TEST(CPUJitterEntropyTest, Basic) {
EXPECT_EQ(jent_read_entropy(jitter_ec.instance,
(char*) data0, data_len), data_len);

// Draw some entropy with the "safe" API to check if it works.
EXPECT_EQ(jent_read_entropy_safe(&jitter_ec.instance,
(char*) data1, data_len), data_len);

// Basic check that the random data is not equal.
EXPECT_NE(Bytes(data0), Bytes(data1));

Expand All @@ -60,8 +56,6 @@ TEST(CPUJitterEntropyTest, Basic) {
// Test drawing entropy from the Jitter object that was reset.
EXPECT_EQ(jent_read_entropy(jitter_ec.instance,
(char*) data0, data_len), data_len);
EXPECT_EQ(jent_read_entropy_safe(&jitter_ec.instance,
(char*) data1, data_len), data_len);

// Verify that the Jitter library version is v3.4.0.
unsigned int jitter_version = 3040000;
Expand Down
89 changes: 0 additions & 89 deletions third_party/jitterentropy/jitterentropy-base.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,95 +242,6 @@ ssize_t jent_read_entropy(struct rand_data *ec, char *data, size_t len)
static struct rand_data *_jent_entropy_collector_alloc(unsigned int osr,
unsigned int flags);

/**
* Entry function: Obtain entropy for the caller.
*
* This is a service function to jent_read_entropy() with the difference
* that it automatically re-allocates the entropy collector if a health
* test failure is observed. Before reallocation, a new power-on health test
* is performed. The allocation of the new entropy collector automatically
* increases the OSR by one. This is done based on the idea that a health
* test failure indicates that the assumed entropy rate is too high.
*
* Note the function returns with an health test error if the OSR is
* getting too large. If an error is returned by this function, the Jitter RNG
* is not safe to be used on the current system.
*
* @ec [in] Reference to entropy collector - this is a double pointer as
* The entropy collector may be freed and reallocated.
* @data [out] pointer to buffer for storing random data -- buffer must
* already exist
* @len [in] size of the buffer, specifying also the requested number of random
* in bytes
*
* @return see jent_read_entropy()
*/
JENT_PRIVATE_STATIC
ssize_t jent_read_entropy_safe(struct rand_data **ec, char *data, size_t len)
{
char *p = data;
size_t orig_len = len;
ssize_t ret = 0;

if (!ec)
return -1;

while (len > 0) {
unsigned int osr, flags, max_mem_set;

ret = jent_read_entropy(*ec, p, len);

switch (ret) {
case -1:
case -4:
return ret;
case -2:
case -3:
case -5:
osr = (*ec)->osr + 1;
flags = (*ec)->flags;
max_mem_set = (*ec)->max_mem_set;

/* generic arbitrary cutoff */
if (osr > 20)
return ret;

/*
* If the caller did not set any specific maximum value
* let the Jitter RNG increase the maximum memory by
* one step.
*/
if (!max_mem_set)
flags = jent_update_memsize(flags);

/*
* re-allocate entropy collector with higher OSR and
* memory size
*/
jent_entropy_collector_free(*ec);

/* Perform new health test with updated OSR */
if (jent_entropy_init_ex(osr, flags))
return -1;

*ec = _jent_entropy_collector_alloc(osr, flags);
if (!*ec)
return -1;

/* Remember whether caller configured memory size */
(*ec)->max_mem_set = !!max_mem_set;

break;

default:
len -= (size_t)ret;
p += (size_t)ret;
}
}

return (ssize_t)orig_len;
}

/***************************************************************************
* Initialization logic
***************************************************************************/
Expand Down
3 changes: 1 addition & 2 deletions third_party/jitterentropy/jitterentropy.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,7 @@ struct rand_data
/* get raw entropy */
JENT_PRIVATE_STATIC
ssize_t jent_read_entropy(struct rand_data *ec, char *data, size_t len);
JENT_PRIVATE_STATIC
ssize_t jent_read_entropy_safe(struct rand_data **ec, char *data, size_t len);

/* initialize an instance of the entropy collector */
JENT_PRIVATE_STATIC
struct rand_data *jent_entropy_collector_alloc(unsigned int osr,
Expand Down
2 changes: 1 addition & 1 deletion tool/speed.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2356,7 +2356,7 @@ static bool SpeedJitter(size_t chunk_size) {

if (!TimeFunction(&results, [&jitter_ec, &input, chunk_size]() -> bool {
size_t bytes =
jent_read_entropy_safe(&jitter_ec, input.get(), chunk_size);
jent_read_entropy(jitter_ec, input.get(), chunk_size);
if (bytes != chunk_size) {
return false;
}
Expand Down

0 comments on commit 3031228

Please sign in to comment.