Skip to content

Conversation

@SparkiDev
Copy link
Contributor

Description

rep_cnt is count of contiguous bytes with same value.
First ever sample must set count to 1.

Wasn't filling the cache up completely.
Off by one in check for initial fill.

Testing

./configure --disable-shared --enable-entropy-memuse

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@SparkiDev SparkiDev self-assigned this May 29, 2025
@kaleb-himes
Copy link
Contributor

@SparkiDev can you rebase this on master please so you get the updates to the workflow file? There are known issues with Ubuntu mirrors at the moment so the following has been added to the workflow file to update the repositories list after VM creation. Unfortunately your PR workflow file is missing the updates:

LATEST:

 37       - name: install_multilib                                                   
 38         run: |                                                                   
 39           export DEBIAN_FRONTEND=noninteractive                                  
 40           sudo apt-get update                                                    
 41           sudo apt-get install -y gcc-multilib 

Your branch:

37      - name: install_multilib
38        run: sudo apt-get install -y gcc-multilib

@SparkiDev SparkiDev force-pushed the entropy_cont_tests_fix branch from 038de3b to ecba6eb Compare June 2, 2025 22:01
@SparkiDev
Copy link
Contributor Author

rebased and now failing on multi-test that is failing for all PRs.

@SparkiDev SparkiDev force-pushed the entropy_cont_tests_fix branch 2 times, most recently from 88beaec to 2fa7b9b Compare June 5, 2025 00:57
@SparkiDev
Copy link
Contributor Author

retest this please

Copy link
Contributor

@kaleb-himes kaleb-himes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lab assessing the solution has approved of the changes and noted all concerns have been addressed.

@kaleb-himes
Copy link
Contributor

kaleb-himes commented Jun 5, 2025

I did notice a new behavior with this update, one now has to call wolfCrypt_Init() two times, once to "prime the entropy source" and then a second time to get a successful init. The first call seems to fail 100% of the time with ENTROPY_APT_E = -295, /* Entropy Adaptive Proportion Test failed */ at least on the system I am using to gather noise samples.

Do we want to look into that more or is that expected?

@kaleb-himes
Copy link
Contributor

Since we're making a change anyway, now might be a good time to address that longer initial time slice we were seeing during startup sequences due the SHA3-256 Conditional Algorithm Self Test (CAST) on initial priming of the entropy pool, here is a tentitive patch to address that if you care to include it (no obligation):

diff --git a/wolfcrypt/src/random.c b/wolfcrypt/src/random.c
index 822f069f7..650945fc4 100644
--- a/wolfcrypt/src/random.c
+++ b/wolfcrypt/src/random.c
@@ -1086,7 +1086,15 @@ static word64 Entropy_GetSample(void)
     word64 now;
     word64 ret;
 
+    /* If zero we know this is the very first call */
+    if (entropy_last_time == 0) {
+        Entropy_MemUse(); /* do INITIAL work to trigger the CAST in FIPS mode */
+        entropy_last_time = Entropy_TimeHiRes(); /* Exclude CAST time from first
+                                                  * sample */
+    }
+
     /* Use memory such that it will take an unpredictable amount of time. */
+    /* All other times just do 'the work' */
     Entropy_MemUse();

@kaleb-himes kaleb-himes self-requested a review June 6, 2025 15:32
Copy link
Contributor

@kaleb-himes kaleb-himes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upon further testing there is an issue with the solution, seeing a failure in the adaptive proportion test.

1704 setting prop_cnt[12] updated to 3                                                
1705 setting prop_cnt[87] updated to 3                                                
1706 setting prop_cnt[154] updated to 2                                               
1707 setting prop_cnt[140] updated to 3                                               
1708 setting prop_cnt[177] updated to 2                                               
1709 setting prop_cnt[146] updated to 1                                               
1710 setting prop_cnt[200] updated to 2 

5060 23,218,41,145,64,143,29,90,125,50,64,206,134,154,6,38,55,                        
5061 157,201,67,81,79,96,0,151,128,67,23,146,148,99,201,32,                           
5062 154,186,192,233,55,111,119,230,52,61,70,175,154,110,233,169,                     
5063 215,157,134,236,209,64,3,250,114,84,218,58,213,189,55,26,                        
5064 47,23,227,128,233,157,241,210,253,157,128,67,32,227,64,55,                       
5065 253,247,32,239,125,186,186,137,87,169,61,87,12,128,166,119,                      
5066 76,61,189,151,239,55,55,201,134,215,250,143,102,139,108,137,                     
5067 177,76,224,32,145,41,113,117,154,253,192,253,210,17,160,186,                     
5068 253,163,105,186,134,157,26,169,116,160,82,43,210,221,137,110,                    
5069 128,221,73,201,250,224,198,20,58,79,134,200,131,178,35,81,                       
5070 9,227,49,93,105,12,87,154,140,177,146,200,47,244,93,131,                         
5071 47,134,116,183,172,169,55,102,238,41,0,41,49,29,181,96,                          
5072 122,186,230,131,186,250,218,175,3,250,253,218,35,23,64,24,                       
5073 145,154,96,163,207,107,213,49,111,81,175,131,136,35,137,23,                      
5074 108,125,55,21,49,15,215,218,47,160,160,148,73,163,218,195,                       
5075 145,204,157,221,20,53,163,235,131,166,154,250,3,32,160,224,                      
5076 128,221,192,166,207,215,204,241,47,55,96,29,23,236,177,201,                      
5077 140,116,23,227,175,253,96,58,119,195,163,198,250,221,245,139,                    
5078 175,113,99,93,32,245,115,190,99,67,192,134,177,79,87,108,                        
5079 61,58,209,35,21,119,209,99,149,148,140,142,125,169,160,6,                        
5080 180,189,82,125,96,145,85,119,241,70,186,184,253,14,79,52,                        
5081 236,230,139,61,112,118,221,236,20,99,160,224,169,169,244,192,                    
5082 90,163,93,41,227,230,58,93,195,110,96,6,236,6,235,18,                            
5083 189,6,244,9,61,154,137,64,189,192,67,203,73,47,81,6,                             
5084 134,58,35,195,55,140,154,81,134,38,157,125,204,157,206,56,                       
5085 218,23,233,87,32,143,49,221,50,20,157,224,111,87,55,32,                          
5086 172,67,75,76,90,108,189,131,119,47,11,0,108,49,21,180,                           
5087 207,40,120,145,160,102,9,206,70,70,119,68,98,241,236,90,                         
5088 239,23,250,218,73,55,128,169,137,90,201,64,55,9,99,183,                          
5089 180,236,163,55,35,73,128,96,122,70,122,134,195,174,64,242,                       
5090 128,43,64,201,186,29,137,87,128,93,105,99,186,204,81,61,                         
5091 73,35,230,90,134,177,149,183,102,218,253,76,203,73,233,

5092 prop_cnt[val]: (65535) 1111 1111 1111 1111                                       
5093 PROP_CUTOFF: (325) 0000 0001 0100 0101                                           
5094 The value 200 appears 65535 times in the window

200 only appears in the window 2 times, not 65535 times. Something is a little off yet, we should re-assess.

@SparkiDev SparkiDev force-pushed the entropy_cont_tests_fix branch 2 times, most recently from 4ac4a5e to eb6cf0c Compare June 11, 2025 01:27
@SparkiDev
Copy link
Contributor Author

Made sure all values are reset.

@SparkiDev
Copy link
Contributor Author

retest this please

rep_cnt is count of contiguous bytes with same value.
First ever sample must set count to 1.

Wasn't filling the cache up completely.
Off by one in check for initial fill.
@SparkiDev SparkiDev force-pushed the entropy_cont_tests_fix branch from eb6cf0c to c724c65 Compare June 17, 2025 22:11
Copy link
Contributor

@kaleb-himes kaleb-himes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @SparkiDev

@kaleb-himes kaleb-himes merged commit 6f78c26 into wolfSSL:master Jun 17, 2025
213 checks passed
@SparkiDev SparkiDev assigned kaleb-himes and unassigned SparkiDev Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants