27
27
#include " psa/lifecycle.h"
28
28
#include " entropy.h"
29
29
#include " entropy_poll.h"
30
- #include " crypto.h"
30
+ #include " psa/ crypto.h"
31
31
32
32
/* MAX value support macro */
33
33
#if !defined(MAX)
@@ -51,31 +51,43 @@ void validate_entropy_seed_injection(int seed_length_a,
51
51
psa_status_t status;
52
52
uint8_t output[32 ] = { 0 };
53
53
uint8_t zeros[32 ] = { 0 };
54
+ int memcmp_res = 0 ;
54
55
status = mbedtls_psa_inject_entropy (seed, seed_length_a);
55
- TEST_ASSERT (status == expected_status_a);
56
+ TEST_ASSERT_EQUAL_INT (expected_status_a, status);
57
+
56
58
status = mbedtls_psa_inject_entropy (seed, seed_length_b);
57
- TEST_ASSERT (status == expected_status_b);
58
- TEST_ASSERT (psa_crypto_init () == PSA_SUCCESS);
59
- TEST_ASSERT (psa_generate_random (output, sizeof (output)) == PSA_SUCCESS);
60
- TEST_ASSERT (memcmp (output, zeros, sizeof (output)) != 0 );
59
+ TEST_ASSERT_EQUAL_INT (expected_status_b, status);
60
+
61
+ status = psa_crypto_init ();
62
+ TEST_ASSERT_EQUAL_INT (PSA_SUCCESS, status);
63
+
64
+ status = psa_generate_random (output, sizeof (output));
65
+ TEST_ASSERT_EQUAL_INT (PSA_SUCCESS, status);
66
+
67
+ memcmp_res = memcmp (output, zeros, sizeof (output));
68
+ TEST_ASSERT_NOT_EQUAL (0 , memcmp_res);
61
69
}
62
70
63
71
void run_entropy_inject_with_crypto_init ()
64
72
{
65
73
psa_its_status_t its_status;
66
74
psa_status_t status;
67
75
status = psa_crypto_init ();
68
- TEST_ASSERT (status == PSA_ERROR_INSUFFICIENT_ENTROPY);
76
+ TEST_ASSERT_EQUAL_INT (PSA_ERROR_INSUFFICIENT_ENTROPY, status);
77
+
69
78
status = mbedtls_psa_inject_entropy (seed, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE);
70
- TEST_ASSERT (status == PSA_SUCCESS);
79
+ TEST_ASSERT_EQUAL_INT (PSA_SUCCESS, status);
80
+
71
81
status = psa_crypto_init ();
72
- TEST_ASSERT (status == PSA_SUCCESS);
82
+ TEST_ASSERT_EQUAL_INT (PSA_SUCCESS, status);
83
+
73
84
status = mbedtls_psa_inject_entropy (seed, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE);
74
- TEST_ASSERT (status == PSA_ERROR_NOT_PERMITTED);
85
+ TEST_ASSERT_EQUAL_INT (PSA_ERROR_NOT_PERMITTED, status);
86
+
75
87
mbedtls_psa_crypto_free ();
76
88
/* The seed is written by nv_seed callback functions therefore the injection will fail */
77
89
status = mbedtls_psa_inject_entropy (seed, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE);
78
- TEST_ASSERT (status == PSA_ERROR_NOT_PERMITTED);
90
+ TEST_ASSERT_EQUAL_INT ( PSA_ERROR_NOT_PERMITTED, status );
79
91
}
80
92
81
93
@@ -90,6 +102,9 @@ utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
90
102
seed[i] = i;
91
103
}
92
104
105
+ psa_status_t status = mbed_psa_reboot_and_request_new_security_state (PSA_LIFECYCLE_ASSEMBLY_AND_TEST);
106
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, status);
107
+
93
108
if (mbedtls_psa_inject_entropy (seed, MBEDTLS_ENTROPY_MAX_SEED_SIZE) == PSA_ERROR_NOT_SUPPORTED) {
94
109
skip_tests = true ;
95
110
}
@@ -100,25 +115,33 @@ utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
100
115
static void injection_small_good ()
101
116
{
102
117
TEST_SKIP_UNLESS (!skip_tests);
103
- validate_entropy_seed_injection (MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE, PSA_SUCCESS, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE, PSA_ERROR_NOT_PERMITTED);
118
+ validate_entropy_seed_injection (
119
+ MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE, PSA_SUCCESS,
120
+ MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE, PSA_ERROR_NOT_PERMITTED);
104
121
}
105
122
106
123
static void injection_big_good ()
107
124
{
108
125
TEST_SKIP_UNLESS (!skip_tests);
109
- validate_entropy_seed_injection (MBEDTLS_ENTROPY_MAX_SEED_SIZE, PSA_SUCCESS, MBEDTLS_ENTROPY_MAX_SEED_SIZE, PSA_ERROR_NOT_PERMITTED);
126
+ validate_entropy_seed_injection (
127
+ MBEDTLS_ENTROPY_MAX_SEED_SIZE, PSA_SUCCESS,
128
+ MBEDTLS_ENTROPY_MAX_SEED_SIZE, PSA_ERROR_NOT_PERMITTED);
110
129
}
111
130
112
131
static void injection_too_small ()
113
132
{
114
133
TEST_SKIP_UNLESS (!skip_tests);
115
- validate_entropy_seed_injection ((MBEDTLS_ENTROPY_MIN_PLATFORM - 1 ), PSA_ERROR_INVALID_ARGUMENT, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE, PSA_SUCCESS);
134
+ validate_entropy_seed_injection (
135
+ (MBEDTLS_ENTROPY_MIN_PLATFORM - 1 ), PSA_ERROR_INVALID_ARGUMENT,
136
+ MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE, PSA_SUCCESS);
116
137
}
117
138
118
139
static void injection_too_big ()
119
140
{
120
141
TEST_SKIP_UNLESS (!skip_tests);
121
- validate_entropy_seed_injection ((MBEDTLS_ENTROPY_MAX_SEED_SIZE + 1 ), PSA_ERROR_INVALID_ARGUMENT, MBEDTLS_ENTROPY_MAX_SEED_SIZE, PSA_SUCCESS);
142
+ validate_entropy_seed_injection (
143
+ (MBEDTLS_ENTROPY_MAX_SEED_SIZE + 1 ), PSA_ERROR_INVALID_ARGUMENT,
144
+ MBEDTLS_ENTROPY_MAX_SEED_SIZE, PSA_SUCCESS);
122
145
}
123
146
124
147
static void injection_and_init_deinit ()
0 commit comments