mirror of https://github.com/ARMmbed/mbed-os.git
Refactor psa entropy inject test
Replace TEST_ASSERT with more specific assertionspull/9701/head
parent
709e6ff795
commit
6bb0894c47
|
@ -27,7 +27,7 @@
|
|||
#include "psa/lifecycle.h"
|
||||
#include "entropy.h"
|
||||
#include "entropy_poll.h"
|
||||
#include "crypto.h"
|
||||
#include "psa/crypto.h"
|
||||
|
||||
/* MAX value support macro */
|
||||
#if !defined(MAX)
|
||||
|
@ -51,13 +51,21 @@ void validate_entropy_seed_injection(int seed_length_a,
|
|||
psa_status_t status;
|
||||
uint8_t output[32] = { 0 };
|
||||
uint8_t zeros[32] = { 0 };
|
||||
int memcmp_res = 0;
|
||||
status = mbedtls_psa_inject_entropy(seed, seed_length_a);
|
||||
TEST_ASSERT(status == expected_status_a);
|
||||
TEST_ASSERT_EQUAL_INT(expected_status_a, status);
|
||||
|
||||
status = mbedtls_psa_inject_entropy(seed, seed_length_b);
|
||||
TEST_ASSERT(status == expected_status_b);
|
||||
TEST_ASSERT(psa_crypto_init() == PSA_SUCCESS);
|
||||
TEST_ASSERT(psa_generate_random(output, sizeof(output)) == PSA_SUCCESS);
|
||||
TEST_ASSERT(memcmp(output, zeros, sizeof(output)) != 0);
|
||||
TEST_ASSERT_EQUAL_INT(expected_status_b, status);
|
||||
|
||||
status = psa_crypto_init();
|
||||
TEST_ASSERT_EQUAL_INT(PSA_SUCCESS, status);
|
||||
|
||||
status = psa_generate_random(output, sizeof(output));
|
||||
TEST_ASSERT_EQUAL_INT(PSA_SUCCESS, status);
|
||||
|
||||
memcmp_res = memcmp(output, zeros, sizeof(output));
|
||||
TEST_ASSERT_NOT_EQUAL(0, memcmp_res);
|
||||
}
|
||||
|
||||
void run_entropy_inject_with_crypto_init()
|
||||
|
@ -65,17 +73,21 @@ void run_entropy_inject_with_crypto_init()
|
|||
psa_its_status_t its_status;
|
||||
psa_status_t status;
|
||||
status = psa_crypto_init();
|
||||
TEST_ASSERT(status == PSA_ERROR_INSUFFICIENT_ENTROPY);
|
||||
TEST_ASSERT_EQUAL_INT(PSA_ERROR_INSUFFICIENT_ENTROPY, status);
|
||||
|
||||
status = mbedtls_psa_inject_entropy(seed, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE);
|
||||
TEST_ASSERT(status == PSA_SUCCESS);
|
||||
TEST_ASSERT_EQUAL_INT(PSA_SUCCESS, status);
|
||||
|
||||
status = psa_crypto_init();
|
||||
TEST_ASSERT(status == PSA_SUCCESS);
|
||||
TEST_ASSERT_EQUAL_INT(PSA_SUCCESS, status);
|
||||
|
||||
status = mbedtls_psa_inject_entropy(seed, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE);
|
||||
TEST_ASSERT(status == PSA_ERROR_NOT_PERMITTED);
|
||||
TEST_ASSERT_EQUAL_INT(PSA_ERROR_NOT_PERMITTED, status);
|
||||
|
||||
mbedtls_psa_crypto_free();
|
||||
/* The seed is written by nv_seed callback functions therefore the injection will fail */
|
||||
status = mbedtls_psa_inject_entropy(seed, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE);
|
||||
TEST_ASSERT(status == PSA_ERROR_NOT_PERMITTED);
|
||||
TEST_ASSERT_EQUAL_INT(PSA_ERROR_NOT_PERMITTED, status);
|
||||
}
|
||||
|
||||
|
||||
|
@ -100,25 +112,33 @@ utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
|
|||
static void injection_small_good()
|
||||
{
|
||||
TEST_SKIP_UNLESS(!skip_tests);
|
||||
validate_entropy_seed_injection(MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE, PSA_SUCCESS, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE, PSA_ERROR_NOT_PERMITTED);
|
||||
validate_entropy_seed_injection(
|
||||
MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE, PSA_SUCCESS,
|
||||
MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE, PSA_ERROR_NOT_PERMITTED);
|
||||
}
|
||||
|
||||
static void injection_big_good()
|
||||
{
|
||||
TEST_SKIP_UNLESS(!skip_tests);
|
||||
validate_entropy_seed_injection(MBEDTLS_ENTROPY_MAX_SEED_SIZE, PSA_SUCCESS, MBEDTLS_ENTROPY_MAX_SEED_SIZE, PSA_ERROR_NOT_PERMITTED);
|
||||
validate_entropy_seed_injection(
|
||||
MBEDTLS_ENTROPY_MAX_SEED_SIZE, PSA_SUCCESS,
|
||||
MBEDTLS_ENTROPY_MAX_SEED_SIZE, PSA_ERROR_NOT_PERMITTED);
|
||||
}
|
||||
|
||||
static void injection_too_small()
|
||||
{
|
||||
TEST_SKIP_UNLESS(!skip_tests);
|
||||
validate_entropy_seed_injection((MBEDTLS_ENTROPY_MIN_PLATFORM - 1), PSA_ERROR_INVALID_ARGUMENT, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE, PSA_SUCCESS);
|
||||
validate_entropy_seed_injection(
|
||||
(MBEDTLS_ENTROPY_MIN_PLATFORM - 1), PSA_ERROR_INVALID_ARGUMENT,
|
||||
MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE, PSA_SUCCESS);
|
||||
}
|
||||
|
||||
static void injection_too_big()
|
||||
{
|
||||
TEST_SKIP_UNLESS(!skip_tests);
|
||||
validate_entropy_seed_injection((MBEDTLS_ENTROPY_MAX_SEED_SIZE + 1), PSA_ERROR_INVALID_ARGUMENT, MBEDTLS_ENTROPY_MAX_SEED_SIZE, PSA_SUCCESS);
|
||||
validate_entropy_seed_injection(
|
||||
(MBEDTLS_ENTROPY_MAX_SEED_SIZE + 1), PSA_ERROR_INVALID_ARGUMENT,
|
||||
MBEDTLS_ENTROPY_MAX_SEED_SIZE, PSA_SUCCESS);
|
||||
}
|
||||
|
||||
static void injection_and_init_deinit()
|
||||
|
|
Loading…
Reference in New Issue