diff options
author | Chris Morrison <[email protected]> | 2016-10-15 05:30:24 -0700 |
---|---|---|
committer | Chris Morrison <[email protected]> | 2016-10-15 05:30:24 -0700 |
commit | 601f6a26ab4505ac82a2fb13ae4757c2b8d3eba8 (patch) | |
tree | 935e8a7ee8ca767dd3671b5b5a0a660ee502ed0a | |
parent | a1da379b394856e69ccef91281831f615d3ee5ef (diff) |
Fix bug in CTR PRNG reseed function to correctly use the seed material
-rw-r--r-- | lib/source/ctr_prng.c | 2 | ||||
-rw-r--r-- | tests/test_ctr_prng.c | 54 |
2 files changed, 55 insertions, 1 deletions
diff --git a/lib/source/ctr_prng.c b/lib/source/ctr_prng.c index 92fc629..bac81d8 100644 --- a/lib/source/ctr_prng.c +++ b/lib/source/ctr_prng.c @@ -208,7 +208,7 @@ int32_t tc_ctr_prng_reseed(TCCtrPrng_t * const ctx, } /* 10.2.1.4.1 step 4 */ - tc_ctr_prng_update(ctx, entropy); + tc_ctr_prng_update(ctx, seed_material); /* 10.2.1.4.1 step 5 */ ctx->reseedCount = 1U; diff --git a/tests/test_ctr_prng.c b/tests/test_ctr_prng.c index 01ee578..b429670 100644 --- a/tests/test_ctr_prng.c +++ b/tests/test_ctr_prng.c @@ -324,6 +324,7 @@ static int32_t test_reseed(void) uint8_t output[32]; TCCtrPrng_t ctx; int32_t ret; + uint32_t i; (void)tc_ctr_prng_init(&ctx, entropy, sizeof entropy, 0, 0U); @@ -362,6 +363,59 @@ static int32_t test_reseed(void) goto exitTest; } + /* confirm entropy and additional_input are being used correctly */ + /* first, entropy only */ + memset(&ctx, 0x0, sizeof ctx); + for (i = 0U; i < sizeof entropy; i++) + { + entropy[i] = i; + } + ret = tc_ctr_prng_reseed(&ctx, entropy, sizeof entropy, 0, 0U); + if (1 != ret) + { + result = TC_FAIL; + goto exitTest; + } + { + uint8_t expectedV[] = + {0x7EU, 0xE3U, 0xA0U, 0xCBU, 0x6DU, 0x5CU, 0x4BU, 0xC2U, + 0x4BU, 0x7EU, 0x3CU, 0x48U, 0x88U, 0xC3U, 0x69U, 0x70U}; + for (i = 0U; i < sizeof expectedV; i++) + { + if (ctx.V[i] != expectedV[i]) + { + result = TC_FAIL; + goto exitTest; + } + } + } + + /* now, entropy and additional_input */ + memset(&ctx, 0x0, sizeof ctx); + for (i = 0U; i < sizeof additional_input; i++) + { + additional_input[i] = i * 2U; + } + ret = tc_ctr_prng_reseed(&ctx, entropy, sizeof entropy, additional_input, sizeof additional_input); + if (1 != ret) + { + result = TC_FAIL; + goto exitTest; + } + { + uint8_t expectedV[] = + {0x5EU, 0xC1U, 0x84U, 0xEDU, 0x45U, 0x76U, 0x67U, 0xECU, + 0x7BU, 0x4CU, 0x08U, 0x7EU, 0xB0U, 0xF9U, 0x55U, 0x4EU}; + for (i = 0U; i < sizeof expectedV; i++) + { + if (ctx.V[i] != expectedV[i]) + { + result = TC_FAIL; + goto exitTest; + } + } + } + exitTest: if (TC_FAIL == result) { |