From 30312284cb220445700160dcd19fed2bb50d85ed Mon Sep 17 00:00:00 2001 From: Shubham Mittal Date: Fri, 10 Jan 2025 13:29:08 -0800 Subject: [PATCH] remove jent_read_entropy_safe --- crypto/fipsmodule/rand/cpu_jitter_test.cc | 6 -- .../jitterentropy/jitterentropy-base.c | 89 ------------------- third_party/jitterentropy/jitterentropy.h | 3 +- tool/speed.cc | 2 +- 4 files changed, 2 insertions(+), 98 deletions(-) diff --git a/crypto/fipsmodule/rand/cpu_jitter_test.cc b/crypto/fipsmodule/rand/cpu_jitter_test.cc index 1ac0f9eb4f..2327daba92 100644 --- a/crypto/fipsmodule/rand/cpu_jitter_test.cc +++ b/crypto/fipsmodule/rand/cpu_jitter_test.cc @@ -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)); @@ -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; diff --git a/third_party/jitterentropy/jitterentropy-base.c b/third_party/jitterentropy/jitterentropy-base.c index f2e79bd4ec..a306167f15 100644 --- a/third_party/jitterentropy/jitterentropy-base.c +++ b/third_party/jitterentropy/jitterentropy-base.c @@ -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 ***************************************************************************/ diff --git a/third_party/jitterentropy/jitterentropy.h b/third_party/jitterentropy/jitterentropy.h index 8e9372c792..a2ce9fce85 100644 --- a/third_party/jitterentropy/jitterentropy.h +++ b/third_party/jitterentropy/jitterentropy.h @@ -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, diff --git a/tool/speed.cc b/tool/speed.cc index 543b304963..b07dd45014 100644 --- a/tool/speed.cc +++ b/tool/speed.cc @@ -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; }