tinycrypt: Update CTR PRNG test case
This commit updates the TinyCrypt CTR PRNG test application. See: https://github.com/01org/tinycrypt/ Commit: 601f6a26ab4505ac82a2fb13ae4757c2b8d3eba8 Change-Id: I9f5d92b9abbcf9608065992b05f114667a768c76 Signed-off-by: Flavio Santes <flavio.santes@intel.com>
This commit is contained in:
parent
f73c86d096
commit
da5dd09875
1 changed files with 44 additions and 2 deletions
|
@ -354,10 +354,15 @@ exit_test:
|
|||
static
|
||||
int test_reseed(void)
|
||||
{
|
||||
uint8_t expectedV1[] = {0x7E, 0xE3, 0xA0, 0xCB, 0x6D, 0x5C, 0x4B, 0xC2,
|
||||
0x4B, 0x7E, 0x3C, 0x48, 0x88, 0xC3, 0x69, 0x70};
|
||||
uint8_t expectedV2[] = {0x5E, 0xC1, 0x84, 0xED, 0x45, 0x76, 0x67, 0xEC,
|
||||
0x7B, 0x4C, 0x08, 0x7E, 0xB0, 0xF9, 0x55, 0x4E};
|
||||
uint8_t extra_input[32] = {0};
|
||||
uint8_t entropy[32] = {0}; /* value not important */
|
||||
uint8_t output[32];
|
||||
TCCtrPrng_t ctx;
|
||||
uint32_t i;
|
||||
int rc;
|
||||
|
||||
rc = tc_ctr_prng_init(&ctx, entropy, sizeof(entropy), 0, 0U);
|
||||
|
@ -382,8 +387,8 @@ int test_reseed(void)
|
|||
goto exit_test;
|
||||
}
|
||||
|
||||
/* reseed and confirm generate works again */
|
||||
/* make entropy different from original value - not really important
|
||||
/* reseed and confirm generate works again
|
||||
* make entropy different from original value - not really important
|
||||
* for the purpose of this test
|
||||
*/
|
||||
memset(entropy, 0xFF, sizeof(entropy));
|
||||
|
@ -400,6 +405,43 @@ int test_reseed(void)
|
|||
goto exit_test;
|
||||
}
|
||||
|
||||
/* confirm entropy and additional_input are being used correctly
|
||||
* first, entropy only
|
||||
*/
|
||||
memset(&ctx, 0x0, sizeof(ctx));
|
||||
for (i = 0; i < sizeof(entropy); i++) {
|
||||
entropy[i] = i;
|
||||
}
|
||||
|
||||
rc = tc_ctr_prng_reseed(&ctx, entropy, sizeof(entropy), 0, 0);
|
||||
if (rc != 1) {
|
||||
rc = TC_FAIL;
|
||||
goto exit_test;
|
||||
}
|
||||
|
||||
if (memcmp(ctx.V, expectedV1, sizeof(expectedV1))) {
|
||||
rc = TC_FAIL;
|
||||
goto exit_test;
|
||||
}
|
||||
|
||||
/* now, entropy and additional_input */
|
||||
memset(&ctx, 0x00, sizeof(ctx));
|
||||
for (i = 0; i < sizeof(extra_input); i++) {
|
||||
extra_input[i] = i * 2;
|
||||
}
|
||||
|
||||
rc = tc_ctr_prng_reseed(&ctx, entropy, sizeof(entropy),
|
||||
extra_input, sizeof(extra_input));
|
||||
if (rc != 1) {
|
||||
rc = TC_FAIL;
|
||||
goto exit_test;
|
||||
}
|
||||
|
||||
if (memcmp(ctx.V, expectedV2, sizeof(expectedV2))) {
|
||||
rc = TC_FAIL;
|
||||
goto exit_test;
|
||||
}
|
||||
|
||||
rc = TC_PASS;
|
||||
|
||||
exit_test:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue