@@ -94,6 +94,63 @@ 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+ word32 startCtr = drbg -> reseedCtr ;
114+ ExpectIntEQ (wc_RNG_GenerateBlock (& rng , out , sizeof (out )), 0 );
115+ if (drbg -> reseedCtr == startCtr + 1 ) {
116+ drbg -> reseedCtr = WC_RESEED_INTERVAL - 1 ;
117+ ExpectIntEQ (wc_RNG_GenerateBlock (& rng , out , sizeof (out )), 0 );
118+ ExpectTrue (drbg -> reseedCtr == WC_RESEED_INTERVAL );
119+ ExpectIntEQ (wc_RNG_GenerateBlock (& rng , out , sizeof (out )), 0 );
120+ ExpectTrue (drbg -> reseedCtr == 2 );
121+ drbgChecked = 1 ;
122+ }
123+ }
124+ }
125+ #endif
126+ #ifdef WOLFSSL_DRBG_SHA512
127+ if (!drbgChecked && rng .drbgType == WC_DRBG_SHA512 ) {
128+ struct DRBG_SHA512_internal * drbg =
129+ (struct DRBG_SHA512_internal * )rng .drbg512 ;
130+ if (drbg != NULL && rng .status == WC_DRBG_OK ) {
131+ word64 startCtr = drbg -> reseedCtr ;
132+ ExpectIntEQ (wc_RNG_GenerateBlock (& rng , out , sizeof (out )), 0 );
133+ if (drbg -> reseedCtr == startCtr + 1 ) {
134+ drbg -> reseedCtr = WC_RESEED_INTERVAL - 1 ;
135+ ExpectIntEQ (wc_RNG_GenerateBlock (& rng , out , sizeof (out )), 0 );
136+ ExpectTrue (drbg -> reseedCtr == WC_RESEED_INTERVAL );
137+ ExpectIntEQ (wc_RNG_GenerateBlock (& rng , out , sizeof (out )), 0 );
138+ ExpectTrue (drbg -> reseedCtr == 2 );
139+ drbgChecked = 1 ;
140+ }
141+ }
142+ }
143+ #endif
144+ /* Ensure the test actually exercised a DRBG; a silently-skipped body
145+ * (e.g. due to an unrecognised drbgType) would otherwise pass with no
146+ * coverage. */
147+ ExpectIntEQ (drbgChecked , 1 );
148+
149+ DoExpectIntEQ (wc_FreeRng (& rng ), 0 );
150+ #endif
151+ return EXPECT_RESULT ();
152+ }
153+
97154int test_wc_RNG_GenerateBlock (void )
98155{
99156 EXPECT_DECLS ;
0 commit comments