Skip to content

Commit f107414

Browse files
committed
add DRBG reseed boundary test
1 parent 8ec3c39 commit f107414

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

tests/api/test_random.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,41 @@ 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+
struct DRBG_internal* drbg;
104+
byte out[32];
105+
#ifdef WORD64_AVAILABLE
106+
word64 startCtr;
107+
#else
108+
word32 startCtr;
109+
#endif
110+
111+
XMEMSET(&rng, 0, sizeof(WC_RNG));
112+
ExpectIntEQ(wc_InitRng(&rng), 0);
113+
114+
drbg = (struct DRBG_internal*)rng.drbg;
115+
if (drbg != NULL && rng.status == WC_DRBG_OK) {
116+
startCtr = drbg->reseedCtr;
117+
ExpectIntEQ(wc_RNG_GenerateBlock(&rng, out, sizeof(out)), 0);
118+
if (drbg->reseedCtr == startCtr + 1) {
119+
drbg->reseedCtr = WC_RESEED_INTERVAL - 1;
120+
ExpectIntEQ(wc_RNG_GenerateBlock(&rng, out, sizeof(out)), 0);
121+
ExpectTrue(drbg->reseedCtr == WC_RESEED_INTERVAL);
122+
ExpectIntEQ(wc_RNG_GenerateBlock(&rng, out, sizeof(out)), 0);
123+
ExpectTrue(drbg->reseedCtr == 2);
124+
}
125+
}
126+
127+
DoExpectIntEQ(wc_FreeRng(&rng), 0);
128+
#endif
129+
return EXPECT_RESULT();
130+
}
131+
97132
int test_wc_RNG_GenerateBlock(void)
98133
{
99134
EXPECT_DECLS;

tests/api/test_random.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
int test_wc_InitRng(void);
2828
int test_wc_RNG_GenerateBlock_Reseed(void);
29+
int test_wc_RNG_ReseedBoundary(void);
2930
int test_wc_RNG_GenerateBlock(void);
3031
int test_wc_RNG_GenerateByte(void);
3132
int test_wc_InitRngNonce(void);
@@ -39,6 +40,7 @@ int test_wc_RNG_HealthTest(void);
3940
#define TEST_RANDOM_DECLS \
4041
TEST_DECL_GROUP("random", test_wc_InitRng), \
4142
TEST_DECL_GROUP("random", test_wc_RNG_GenerateBlock_Reseed), \
43+
TEST_DECL_GROUP("random", test_wc_RNG_ReseedBoundary), \
4244
TEST_DECL_GROUP("random", test_wc_RNG_GenerateBlock), \
4345
TEST_DECL_GROUP("random", test_wc_RNG_GenerateByte), \
4446
TEST_DECL_GROUP("random", test_wc_InitRngNonce), \

0 commit comments

Comments
 (0)