@@ -94,6 +94,67 @@ int test_wc_RNG_GenerateBlock_Reseed(void)
9494 return EXPECT_RESULT ();
9595}
9696
97+ int test_wc_RNG_ReseedBoundary (void )
98+ {
99+ EXPECT_DECLS ;
100+ #if defined(HAVE_HASHDRBG ) && !defined(CUSTOM_RAND_GENERATE_BLOCK ) && \
101+ !defined(HAVE_FIPS ) && !defined(HAVE_SELFTEST )
102+ WC_RNG rng ;
103+ byte out [32 ];
104+ int drbgChecked = 0 ;
105+
106+ XMEMSET (& rng , 0 , sizeof (WC_RNG ));
107+ ExpectIntEQ (wc_InitRng (& rng ), 0 );
108+
109+ #ifndef NO_SHA256
110+ if (rng .drbgType == WC_DRBG_SHA256 ) {
111+ struct DRBG_internal * drbg = (struct DRBG_internal * )rng .drbg ;
112+ if (drbg != NULL && rng .status == WC_DRBG_OK ) {
113+ #ifdef WORD64_AVAILABLE
114+ word64 startCtr = drbg -> reseedCtr ;
115+ #else
116+ word32 startCtr = drbg -> reseedCtr ;
117+ #endif
118+ ExpectIntEQ (wc_RNG_GenerateBlock (& rng , out , sizeof (out )), 0 );
119+ if (drbg -> reseedCtr == startCtr + 1 ) {
120+ drbg -> reseedCtr = WC_RESEED_INTERVAL - 1 ;
121+ ExpectIntEQ (wc_RNG_GenerateBlock (& rng , out , sizeof (out )), 0 );
122+ ExpectTrue (drbg -> reseedCtr == WC_RESEED_INTERVAL );
123+ ExpectIntEQ (wc_RNG_GenerateBlock (& rng , out , sizeof (out )), 0 );
124+ ExpectTrue (drbg -> reseedCtr == 2 );
125+ drbgChecked = 1 ;
126+ }
127+ }
128+ }
129+ #endif
130+ #ifdef WOLFSSL_DRBG_SHA512
131+ if (!drbgChecked && rng .drbgType == WC_DRBG_SHA512 ) {
132+ struct DRBG_SHA512_internal * drbg =
133+ (struct DRBG_SHA512_internal * )rng .drbg512 ;
134+ if (drbg != NULL && rng .status == WC_DRBG_OK ) {
135+ word64 startCtr = drbg -> reseedCtr ;
136+ ExpectIntEQ (wc_RNG_GenerateBlock (& rng , out , sizeof (out )), 0 );
137+ if (drbg -> reseedCtr == startCtr + 1 ) {
138+ drbg -> reseedCtr = WC_RESEED_INTERVAL - 1 ;
139+ ExpectIntEQ (wc_RNG_GenerateBlock (& rng , out , sizeof (out )), 0 );
140+ ExpectTrue (drbg -> reseedCtr == WC_RESEED_INTERVAL );
141+ ExpectIntEQ (wc_RNG_GenerateBlock (& rng , out , sizeof (out )), 0 );
142+ ExpectTrue (drbg -> reseedCtr == 2 );
143+ drbgChecked = 1 ;
144+ }
145+ }
146+ }
147+ #endif
148+ /* Ensure the test actually exercised a DRBG; a silently-skipped body
149+ * (e.g. due to an unrecognised drbgType) would otherwise pass with no
150+ * coverage. */
151+ ExpectIntEQ (drbgChecked , 1 );
152+
153+ DoExpectIntEQ (wc_FreeRng (& rng ), 0 );
154+ #endif
155+ return EXPECT_RESULT ();
156+ }
157+
97158int test_wc_RNG_GenerateBlock (void )
98159{
99160 EXPECT_DECLS ;
0 commit comments