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
@@ -100,25 +112,33 @@ utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
100
112
static void injection_small_good ()
101
113
{
102
114
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);
115
+ validate_entropy_seed_injection (
116
+ MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE, PSA_SUCCESS,
117
+ MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE, PSA_ERROR_NOT_PERMITTED);
104
118
}
105
119
106
120
static void injection_big_good ()
107
121
{
108
122
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);
123
+ validate_entropy_seed_injection (
124
+ MBEDTLS_ENTROPY_MAX_SEED_SIZE, PSA_SUCCESS,
125
+ MBEDTLS_ENTROPY_MAX_SEED_SIZE, PSA_ERROR_NOT_PERMITTED);
110
126
}
111
127
112
128
static void injection_too_small ()
113
129
{
114
130
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);
131
+ validate_entropy_seed_injection (
132
+ (MBEDTLS_ENTROPY_MIN_PLATFORM - 1 ), PSA_ERROR_INVALID_ARGUMENT,
133
+ MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE, PSA_SUCCESS);
116
134
}
117
135
118
136
static void injection_too_big ()
119
137
{
120
138
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);
139
+ validate_entropy_seed_injection (
140
+ (MBEDTLS_ENTROPY_MAX_SEED_SIZE + 1 ), PSA_ERROR_INVALID_ARGUMENT,
141
+ MBEDTLS_ENTROPY_MAX_SEED_SIZE, PSA_SUCCESS);
122
142
}
123
143
124
144
static void injection_and_init_deinit ()
0 commit comments