@@ -98,6 +98,7 @@ static psa_status_t psa_mac_setup( psa_mac_operation_t *operation,
98
98
psa_invec_t in_vec = { & psa_crypto_ipc , sizeof ( psa_crypto_ipc ) };
99
99
100
100
operation -> handle = psa_connect ( PSA_MAC_ID , MINOR_VER );
101
+
101
102
if ( operation -> handle <= 0 )
102
103
return ( PSA_ERROR_COMMUNICATION_FAILURE );
103
104
@@ -140,6 +141,9 @@ psa_status_t psa_mac_update( psa_mac_operation_t *operation,
140
141
psa_invec_t in_vec [2 ] = { { & psa_crypto_ipc , sizeof ( psa_crypto_ipc ) },
141
142
{ input , input_length } };
142
143
144
+ if ( operation -> handle <= 0 )
145
+ return ( PSA_ERROR_INVALID_ARGUMENT );
146
+
143
147
err = psa_call ( operation -> handle , in_vec , 2 , NULL , 0 );
144
148
if ( err < 0 )
145
149
err = PSA_ERROR_COMMUNICATION_FAILURE ;
@@ -161,6 +165,9 @@ psa_status_t psa_mac_sign_finish( psa_mac_operation_t *operation,
161
165
{ & mac_size , sizeof ( mac_size ) } };
162
166
psa_outvec_t out_vec [2 ] = { { mac , mac_size }, { mac_length , sizeof ( * mac_length ) } };
163
167
168
+ if ( operation -> handle <= 0 )
169
+ return ( PSA_ERROR_INVALID_ARGUMENT );
170
+
164
171
err_call = psa_call ( operation -> handle , in_vec , 2 , out_vec , 2 );
165
172
psa_close ( operation -> handle );
166
173
operation -> handle = PSA_NULL_HANDLE ;
@@ -184,6 +191,9 @@ psa_status_t psa_mac_verify_finish( psa_mac_operation_t *operation,
184
191
{ & mac_length , sizeof ( mac_length ) },
185
192
{ mac , mac_length } };
186
193
194
+ if ( operation -> handle <= 0 )
195
+ return ( PSA_ERROR_INVALID_ARGUMENT );
196
+
187
197
err_call = psa_call ( operation -> handle , in_vec , 3 , NULL , 0 );
188
198
psa_close ( operation -> handle );
189
199
operation -> handle = PSA_NULL_HANDLE ;
@@ -255,6 +265,9 @@ psa_status_t psa_hash_update( psa_hash_operation_t *operation,
255
265
psa_invec_t in_vec [2 ] = { {& psa_crypto_ipc , sizeof ( psa_crypto_ipc ) },
256
266
{ input , input_length } };
257
267
268
+ if ( operation -> handle <= 0 )
269
+ return ( PSA_ERROR_INVALID_ARGUMENT );
270
+
258
271
err = psa_call ( operation -> handle , in_vec , 2 , NULL , 0 );
259
272
if ( err < 0 )
260
273
err = PSA_ERROR_COMMUNICATION_FAILURE ;
@@ -277,6 +290,9 @@ psa_status_t psa_hash_finish( psa_hash_operation_t *operation,
277
290
psa_outvec_t out_vec [2 ] = { { hash , hash_size },
278
291
{ hash_length , sizeof ( * hash_length ) } };
279
292
293
+ if ( operation -> handle <= 0 )
294
+ return ( PSA_ERROR_INVALID_ARGUMENT );
295
+
280
296
err_call = psa_call ( operation -> handle , in_vec , 2 , out_vec , 2 );
281
297
psa_close ( operation -> handle );
282
298
operation -> handle = PSA_NULL_HANDLE ;
@@ -300,6 +316,9 @@ psa_status_t psa_hash_verify( psa_hash_operation_t *operation,
300
316
{ & hash_length , sizeof ( hash_length ) },
301
317
{ hash , hash_length } };
302
318
319
+ if ( operation -> handle <= 0 )
320
+ return ( PSA_ERROR_INVALID_ARGUMENT );
321
+
303
322
err_call = psa_call ( operation -> handle , in_vec , 3 , NULL , 0 );
304
323
psa_close ( operation -> handle );
305
324
operation -> handle = PSA_NULL_HANDLE ;
@@ -1117,6 +1136,7 @@ psa_status_t psa_cipher_decrypt_setup( psa_cipher_operation_t *operation,
1117
1136
in_vec = ( psa_invec_t ){ & psa_crypto_ipc , sizeof ( psa_crypto_ipc ) };
1118
1137
1119
1138
operation -> handle = psa_connect ( PSA_SYMMETRIC_ID , MINOR_VER );
1139
+
1120
1140
if ( operation -> handle <= 0 )
1121
1141
return ( PSA_ERROR_COMMUNICATION_FAILURE );
1122
1142
@@ -1143,6 +1163,9 @@ psa_status_t psa_cipher_generate_iv( psa_cipher_operation_t *operation,
1143
1163
out_vec [0 ] = ( psa_outvec_t ){ iv , iv_size };
1144
1164
out_vec [1 ] = ( psa_outvec_t ){ iv_length , sizeof ( * iv_length ) };
1145
1165
1166
+ if ( operation -> handle <= 0 )
1167
+ return ( PSA_ERROR_INVALID_ARGUMENT );
1168
+
1146
1169
err = psa_call ( operation -> handle , & in_vec , 1 , out_vec , 2 );
1147
1170
if ( err < 0 )
1148
1171
err = ( psa_error_t ) PSA_ERROR_COMMUNICATION_FAILURE ;
@@ -1162,6 +1185,9 @@ psa_status_t psa_cipher_set_iv( psa_cipher_operation_t *operation,
1162
1185
in_vec [0 ] = ( psa_invec_t ){ & psa_crypto_ipc , sizeof ( psa_crypto_ipc ) };
1163
1186
in_vec [1 ] = ( psa_invec_t ){ iv , iv_length };
1164
1187
1188
+ if ( operation -> handle <= 0 )
1189
+ return ( PSA_ERROR_INVALID_ARGUMENT );
1190
+
1165
1191
err = psa_call ( operation -> handle , in_vec , 2 , NULL , 0 );
1166
1192
if ( err < 0 )
1167
1193
err = ( psa_error_t ) PSA_ERROR_COMMUNICATION_FAILURE ;
@@ -1189,6 +1215,9 @@ psa_status_t psa_cipher_update( psa_cipher_operation_t *operation,
1189
1215
out_vec [1 ] = ( psa_outvec_t ){ output_length , ( output_length == NULL ? 0 :
1190
1216
sizeof ( * output_length ) ) };
1191
1217
1218
+ if ( operation -> handle <= 0 )
1219
+ return ( PSA_ERROR_INVALID_ARGUMENT );
1220
+
1192
1221
err = psa_call ( operation -> handle , in_vec , 2 , out_vec , 2 );
1193
1222
if ( err < 0 )
1194
1223
err = ( psa_error_t ) PSA_ERROR_COMMUNICATION_FAILURE ;
@@ -1213,6 +1242,9 @@ psa_status_t psa_cipher_finish( psa_cipher_operation_t *operation,
1213
1242
out_vec [1 ] = ( psa_outvec_t ){ output_length , ( output_length == NULL ? 0 :
1214
1243
sizeof ( * output_length ) ) };
1215
1244
1245
+ if ( operation -> handle <= 0 )
1246
+ return ( PSA_ERROR_INVALID_ARGUMENT );
1247
+
1216
1248
err_call = psa_call ( operation -> handle , & in_vec , 1 , out_vec , 2 );
1217
1249
psa_close ( operation -> handle );
1218
1250
operation -> handle = PSA_NULL_HANDLE ;
0 commit comments