Skip to content
This repository was archived by the owner on Mar 5, 2024. It is now read-only.

Commit 09139db

Browse files
author
hackermnementh
authored
Merge pull request #6 from chris-morrison/fix-ctr-prng-reseed
Fix bug in CTR PRNG reseed function to correctly use the seed material
2 parents a1da379 + 601f6a2 commit 09139db

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

lib/source/ctr_prng.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ int32_t tc_ctr_prng_reseed(TCCtrPrng_t * const ctx,
208208
}
209209

210210
/* 10.2.1.4.1 step 4 */
211-
tc_ctr_prng_update(ctx, entropy);
211+
tc_ctr_prng_update(ctx, seed_material);
212212

213213
/* 10.2.1.4.1 step 5 */
214214
ctx->reseedCount = 1U;

tests/test_ctr_prng.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ static int32_t test_reseed(void)
324324
uint8_t output[32];
325325
TCCtrPrng_t ctx;
326326
int32_t ret;
327+
uint32_t i;
327328

328329
(void)tc_ctr_prng_init(&ctx, entropy, sizeof entropy, 0, 0U);
329330

@@ -362,6 +363,59 @@ static int32_t test_reseed(void)
362363
goto exitTest;
363364
}
364365

366+
/* confirm entropy and additional_input are being used correctly */
367+
/* first, entropy only */
368+
memset(&ctx, 0x0, sizeof ctx);
369+
for (i = 0U; i < sizeof entropy; i++)
370+
{
371+
entropy[i] = i;
372+
}
373+
ret = tc_ctr_prng_reseed(&ctx, entropy, sizeof entropy, 0, 0U);
374+
if (1 != ret)
375+
{
376+
result = TC_FAIL;
377+
goto exitTest;
378+
}
379+
{
380+
uint8_t expectedV[] =
381+
{0x7EU, 0xE3U, 0xA0U, 0xCBU, 0x6DU, 0x5CU, 0x4BU, 0xC2U,
382+
0x4BU, 0x7EU, 0x3CU, 0x48U, 0x88U, 0xC3U, 0x69U, 0x70U};
383+
for (i = 0U; i < sizeof expectedV; i++)
384+
{
385+
if (ctx.V[i] != expectedV[i])
386+
{
387+
result = TC_FAIL;
388+
goto exitTest;
389+
}
390+
}
391+
}
392+
393+
/* now, entropy and additional_input */
394+
memset(&ctx, 0x0, sizeof ctx);
395+
for (i = 0U; i < sizeof additional_input; i++)
396+
{
397+
additional_input[i] = i * 2U;
398+
}
399+
ret = tc_ctr_prng_reseed(&ctx, entropy, sizeof entropy, additional_input, sizeof additional_input);
400+
if (1 != ret)
401+
{
402+
result = TC_FAIL;
403+
goto exitTest;
404+
}
405+
{
406+
uint8_t expectedV[] =
407+
{0x5EU, 0xC1U, 0x84U, 0xEDU, 0x45U, 0x76U, 0x67U, 0xECU,
408+
0x7BU, 0x4CU, 0x08U, 0x7EU, 0xB0U, 0xF9U, 0x55U, 0x4EU};
409+
for (i = 0U; i < sizeof expectedV; i++)
410+
{
411+
if (ctx.V[i] != expectedV[i])
412+
{
413+
result = TC_FAIL;
414+
goto exitTest;
415+
}
416+
}
417+
}
418+
365419
exitTest:
366420
if (TC_FAIL == result)
367421
{

0 commit comments

Comments
 (0)