Example #1
0
static
int test_uninstantiate(void)
{
	u8_t entropy[32] = {0}; /* value not important */
	TCCtrPrng_t ctx;
	size_t words;
	size_t i;
	int rc;

	rc = tc_ctr_prng_init(&ctx, entropy, sizeof(entropy), 0, 0);
	if (rc != TC_CRYPTO_SUCCESS) {
		rc = TC_FAIL;
		goto exit_test;
	}

	tc_ctr_prng_uninstantiate(&ctx);
	/* show that state has been zeroised */
	for (i = 0; i < sizeof(ctx.V); i++) {
		if (ctx.V[i] != 0) {
			rc = TC_FAIL;
			goto exit_test;
		}
	}

	words = sizeof(ctx.key.words) / sizeof(ctx.key.words[0]);
	for (i = 0; i < words; i++) {
		if (ctx.key.words[i] != 0) {
			rc = TC_FAIL;
			goto exit_test;
		}
	}

	if (ctx.reseedCount != 0) {
		rc = TC_FAIL;
		goto exit_test;
	}

	rc = TC_PASS;

exit_test:
	return rc;
}
Example #2
0
static int32_t test_uninstantiate(void)
{
	uint32_t i;
	int32_t result = TC_PASS;
	uint8_t entropy[32U] = {0U}; /* value not important */
	TCCtrPrng_t ctx;

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

	tc_ctr_prng_uninstantiate(&ctx);
	/* show that state has been zeroised */
	for (i = 0U; i < sizeof ctx.V; i++)
	{
		if (0U != ctx.V[i])
		{
			TC_ERROR("CTR PRNG uninstantiate tests failed\n");
			result = TC_FAIL;
			break;
		}
	}

	for (i = 0U; i < sizeof ctx.key.words / sizeof ctx.key.words[0]; i++)
	{
		if (0U != ctx.key.words[i])
		{
			TC_ERROR("CTR PRNG uninstantiate tests failed\n");
			result = TC_FAIL;
			break;
		}
	}

	if (0U != ctx.reseedCount)
	{
		TC_ERROR("CTR PRNG uninstantiate tests failed\n");
		result = TC_FAIL;
	}

	return result;
}
Example #3
0
static
int test_robustness(void)
{
	u8_t entropy[32] = {0}; /* value not important */
	u8_t output[32];
	TCCtrPrng_t ctx;
	int rc;

	/* show that the CTR PRNG is robust to invalid inputs */
	tc_ctr_prng_uninstantiate(0);

	rc = tc_ctr_prng_generate(&ctx, 0, 0, 0, 0);
	if (rc != TC_CRYPTO_FAIL) {
		rc = TC_FAIL;
		goto exit_test;
	}

	rc = tc_ctr_prng_generate(0, 0, 0, output, sizeof(output));
	if (rc != TC_CRYPTO_FAIL) {
		rc = TC_FAIL;
		goto exit_test;
	}

	rc = tc_ctr_prng_generate(0, 0, 0, 0, 0);
	if (rc != TC_CRYPTO_FAIL) {
		rc = TC_FAIL;
		goto exit_test;
	}

	rc = tc_ctr_prng_reseed(&ctx, 0, 0, 0, 0);
	if (rc != TC_CRYPTO_FAIL) {
		rc = TC_FAIL;
		goto exit_test;
	}

	/* too little entropy */
	rc = tc_ctr_prng_reseed(&ctx, entropy, sizeof(entropy) - 1, 0, 0);
	if (rc != TC_CRYPTO_FAIL) {
		rc = TC_FAIL;
		goto exit_test;
	}

	rc = tc_ctr_prng_reseed(0, entropy, sizeof(entropy), 0, 0);
	if (rc != TC_CRYPTO_FAIL) {
		rc = TC_FAIL;
		goto exit_test;
	}

	rc = tc_ctr_prng_reseed(0, 0, 0, 0, 0);
	if (rc != TC_CRYPTO_FAIL) {
		rc = TC_FAIL;
		goto exit_test;
	}

	rc = tc_ctr_prng_init(&ctx, 0, 0, 0, 0);
	if (rc != TC_CRYPTO_FAIL) {
		rc = TC_FAIL;
		goto exit_test;
	}

	/* too little entropy */
	rc = tc_ctr_prng_init(&ctx, entropy, sizeof(entropy) - 1, 0, 0);
	if (rc != TC_CRYPTO_FAIL) {
		rc = TC_FAIL;
		goto exit_test;
	}

	rc = tc_ctr_prng_init(0, entropy, sizeof(entropy), 0, 0);
	if (rc != TC_CRYPTO_FAIL) {
		rc = TC_FAIL;
		goto exit_test;
	}

	rc = tc_ctr_prng_init(0, 0, 0, 0, 0);
	if (rc != TC_CRYPTO_FAIL) {
		rc = TC_FAIL;
		goto exit_test;
	}

	rc = TC_PASS;

exit_test:
	return rc;
}
Example #4
0
static int32_t test_robustness(void)
{
	int32_t result = TC_PASS;
	int32_t ret;
	uint8_t entropy[32U] = {0U}; /* value not important */
	uint8_t output[32];
	TCCtrPrng_t ctx;


	/* show that the CTR PRNG is robust to invalid inputs */
	tc_ctr_prng_uninstantiate(0);

	ret = tc_ctr_prng_generate(&ctx, 0, 0, 0, 0);
	if (0 != ret)
	{
		result = TC_FAIL;
		goto exitTest;
	}

	ret = tc_ctr_prng_generate(0, 0, 0, output, sizeof output);
	if (0 != ret)
	{
		result = TC_FAIL;
		goto exitTest;
	}

	ret = tc_ctr_prng_generate(0, 0, 0, 0, 0);
	if (0 != ret)
	{
		result = TC_FAIL;
		goto exitTest;
	}

	ret = tc_ctr_prng_reseed(&ctx, 0, 0, 0, 0);
	if (0 != ret)
	{
		result = TC_FAIL;
		goto exitTest;
	}

	/* too little entropy */
	ret = tc_ctr_prng_reseed(&ctx, entropy, (sizeof entropy) - 1U, 0, 0);
	if (0 != ret)
	{
		result = TC_FAIL;
		goto exitTest;
	}

	ret = tc_ctr_prng_reseed(0, entropy, sizeof entropy, 0, 0);
	if (0 != ret)
	{
		result = TC_FAIL;
		goto exitTest;
	}

	ret = tc_ctr_prng_reseed(0, 0, 0, 0, 0);
	if (0 != ret)
	{
		result = TC_FAIL;
		goto exitTest;
	}

	ret = tc_ctr_prng_init(&ctx, 0, 0, 0, 0);
	if (0 != ret)
	{
		result = TC_FAIL;
		goto exitTest;
	}

	/* too little entropy */
	ret = tc_ctr_prng_init(&ctx, entropy, (sizeof entropy) - 1U, 0, 0);
	if (0 != ret)
	{
		result = TC_FAIL;
		goto exitTest;
	}

	ret = tc_ctr_prng_init(0, entropy, sizeof entropy, 0, 0);
	if (0 != ret)
	{
		result = TC_FAIL;
		goto exitTest;
	}

	ret = tc_ctr_prng_init(0, 0, 0, 0, 0);
	if (0 != ret)
	{
		result = TC_FAIL;
		goto exitTest;
	}

	exitTest:
	if (TC_FAIL == result)
	{
		TC_ERROR("CTR PRNG reseed tests failed\n");
	}


	return result;
}