@@ -165,7 +165,7 @@ static int exercise_cipher_key( psa_key_handle_t handle,
165
165
psa_key_usage_t usage,
166
166
psa_algorithm_t alg )
167
167
{
168
- psa_cipher_operation_t operation;
168
+ psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT ;
169
169
unsigned char iv[16] = {0};
170
170
size_t iv_length = sizeof( iv );
171
171
const unsigned char plaintext[16] = "Hello, world...";
@@ -1153,7 +1153,7 @@ void cipher_with_no_key_activity( )
1153
1153
psa_key_handle_t handle = 0;
1154
1154
psa_status_t status;
1155
1155
psa_key_policy_t policy = PSA_KEY_POLICY_INIT;
1156
- psa_cipher_operation_t operation;
1156
+ psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT ;
1157
1157
int exercise_alg = PSA_ALG_CTR;
1158
1158
1159
1159
PSA_ASSERT( psa_crypto_init( ) );
@@ -1210,7 +1210,7 @@ void cipher_after_import_failure( data_t *data, int type_arg,
1210
1210
int expected_import_status_arg )
1211
1211
{
1212
1212
psa_key_handle_t handle = 0;
1213
- psa_cipher_operation_t operation;
1213
+ psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT ;
1214
1214
psa_key_type_t type = type_arg;
1215
1215
psa_status_t status;
1216
1216
psa_status_t expected_import_status = expected_import_status_arg;
@@ -1492,7 +1492,7 @@ void cipher_key_policy( int policy_usage,
1492
1492
{
1493
1493
psa_key_handle_t handle = 0;
1494
1494
psa_key_policy_t policy = PSA_KEY_POLICY_INIT;
1495
- psa_cipher_operation_t operation;
1495
+ psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT ;
1496
1496
psa_status_t status;
1497
1497
1498
1498
PSA_ASSERT( psa_crypto_init( ) );
@@ -2082,6 +2082,31 @@ exit:
2082
2082
}
2083
2083
/* END_CASE */
2084
2084
2085
+ /* BEGIN_CASE */
2086
+ void cipher_operation_init( )
2087
+ {
2088
+ /* Test each valid way of initializing the object, except for `= {0}`, as
2089
+ * Clang 5 complains when `-Wmissing-field-initializers` is used, even
2090
+ * though it's OK by the C standard. We could test for this, but we'd need
2091
+ * to supress the Clang warning for the test. */
2092
+ psa_cipher_operation_t func = psa_cipher_operation_init( );
2093
+ psa_cipher_operation_t init = PSA_CIPHER_OPERATION_INIT;
2094
+ psa_cipher_operation_t zero;
2095
+
2096
+ memset( &zero, 0, sizeof( zero ) );
2097
+
2098
+ /* Although not technically guaranteed by the C standard nor the PSA Crypto
2099
+ * specification, we test that all valid ways of initializing the object
2100
+ * have the same bit pattern. This is a stronger requirement that may not
2101
+ * be valid on all platforms or PSA Crypto implementations, but implies the
2102
+ * weaker actual requirement is met: that a freshly initialized object, no
2103
+ * matter how it was initialized, acts the same as any other valid
2104
+ * initialization. */
2105
+ TEST_EQUAL( memcmp( &func, &zero, sizeof( zero ) ), 0 );
2106
+ TEST_EQUAL( memcmp( &init, &zero, sizeof( zero ) ), 0 );
2107
+ }
2108
+ /* END_CASE */
2109
+
2085
2110
/* BEGIN_CASE */
2086
2111
void cipher_setup( int key_type_arg,
2087
2112
data_t *key,
@@ -2092,7 +2117,7 @@ void cipher_setup( int key_type_arg,
2092
2117
psa_key_type_t key_type = key_type_arg;
2093
2118
psa_algorithm_t alg = alg_arg;
2094
2119
psa_status_t expected_status = expected_status_arg;
2095
- psa_cipher_operation_t operation;
2120
+ psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT ;
2096
2121
psa_key_policy_t policy = PSA_KEY_POLICY_INIT;
2097
2122
psa_status_t status;
2098
2123
@@ -2133,7 +2158,7 @@ void cipher_encrypt( int alg_arg, int key_type_arg,
2133
2158
size_t output_buffer_size = 0;
2134
2159
size_t function_output_length = 0;
2135
2160
size_t total_output_length = 0;
2136
- psa_cipher_operation_t operation;
2161
+ psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT ;
2137
2162
psa_key_policy_t policy = PSA_KEY_POLICY_INIT;
2138
2163
2139
2164
iv_size = PSA_BLOCK_CIPHER_BLOCK_SIZE( key_type );
@@ -2200,7 +2225,7 @@ void cipher_encrypt_multipart( int alg_arg, int key_type_arg,
2200
2225
size_t output_buffer_size = 0;
2201
2226
size_t function_output_length = 0;
2202
2227
size_t total_output_length = 0;
2203
- psa_cipher_operation_t operation;
2228
+ psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT ;
2204
2229
psa_key_policy_t policy = PSA_KEY_POLICY_INIT;
2205
2230
2206
2231
iv_size = PSA_BLOCK_CIPHER_BLOCK_SIZE( key_type );
@@ -2270,7 +2295,7 @@ void cipher_decrypt_multipart( int alg_arg, int key_type_arg,
2270
2295
size_t output_buffer_size = 0;
2271
2296
size_t function_output_length = 0;
2272
2297
size_t total_output_length = 0;
2273
- psa_cipher_operation_t operation;
2298
+ psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT ;
2274
2299
psa_key_policy_t policy = PSA_KEY_POLICY_INIT;
2275
2300
2276
2301
iv_size = PSA_BLOCK_CIPHER_BLOCK_SIZE( key_type );
@@ -2342,7 +2367,7 @@ void cipher_decrypt( int alg_arg, int key_type_arg,
2342
2367
size_t output_buffer_size = 0;
2343
2368
size_t function_output_length = 0;
2344
2369
size_t total_output_length = 0;
2345
- psa_cipher_operation_t operation;
2370
+ psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT ;
2346
2371
psa_key_policy_t policy = PSA_KEY_POLICY_INIT;
2347
2372
2348
2373
iv_size = PSA_BLOCK_CIPHER_BLOCK_SIZE( key_type );
@@ -2412,8 +2437,8 @@ void cipher_verify_output( int alg_arg, int key_type_arg,
2412
2437
size_t output2_size = 0;
2413
2438
size_t output2_length = 0;
2414
2439
size_t function_output_length = 0;
2415
- psa_cipher_operation_t operation1;
2416
- psa_cipher_operation_t operation2;
2440
+ psa_cipher_operation_t operation1 = PSA_CIPHER_OPERATION_INIT ;
2441
+ psa_cipher_operation_t operation2 = PSA_CIPHER_OPERATION_INIT ;
2417
2442
psa_key_policy_t policy = PSA_KEY_POLICY_INIT;
2418
2443
2419
2444
PSA_ASSERT( psa_crypto_init( ) );
@@ -2497,8 +2522,8 @@ void cipher_verify_output_multipart( int alg_arg,
2497
2522
size_t output2_buffer_size = 0;
2498
2523
size_t output2_length = 0;
2499
2524
size_t function_output_length;
2500
- psa_cipher_operation_t operation1;
2501
- psa_cipher_operation_t operation2;
2525
+ psa_cipher_operation_t operation1 = PSA_CIPHER_OPERATION_INIT ;
2526
+ psa_cipher_operation_t operation2 = PSA_CIPHER_OPERATION_INIT ;
2502
2527
psa_key_policy_t policy = PSA_KEY_POLICY_INIT;
2503
2528
2504
2529
PSA_ASSERT( psa_crypto_init( ) );
0 commit comments