@@ -120,6 +120,10 @@ static psa_status_t psa_mac_setup(psa_mac_operation_t *operation,
120
120
psa_algorithm_t alg ,
121
121
psa_sec_function_t func )
122
122
{
123
+ if (operation -> handle != PSA_NULL_HANDLE ) {
124
+ return (PSA_ERROR_BAD_STATE );
125
+ }
126
+
123
127
psa_crypto_ipc_t psa_crypto_ipc = {
124
128
.func = func ,
125
129
.handle = key_handle ,
@@ -133,6 +137,9 @@ static psa_status_t psa_mac_setup(psa_mac_operation_t *operation,
133
137
return (status );
134
138
}
135
139
status = ipc_call (& operation -> handle , & in_vec , 1 , NULL , 0 , false);
140
+ if (status != PSA_SUCCESS ) {
141
+ ipc_close (& operation -> handle );
142
+ }
136
143
return (status );
137
144
}
138
145
@@ -168,6 +175,9 @@ psa_status_t psa_mac_update(psa_mac_operation_t *operation,
168
175
};
169
176
170
177
psa_status_t status = ipc_call (& operation -> handle , in_vec , 2 , NULL , 0 , false);
178
+ if (status != PSA_SUCCESS ) {
179
+ ipc_close (& operation -> handle );
180
+ }
171
181
return (status );
172
182
}
173
183
@@ -240,6 +250,10 @@ psa_status_t psa_hash_abort(psa_hash_operation_t *operation)
240
250
psa_status_t psa_hash_setup (psa_hash_operation_t * operation ,
241
251
psa_algorithm_t alg )
242
252
{
253
+ if (operation -> handle != PSA_NULL_HANDLE ) {
254
+ return (PSA_ERROR_BAD_STATE );
255
+ }
256
+
243
257
psa_crypto_ipc_t psa_crypto_ipc = {
244
258
.func = PSA_HASH_SETUP ,
245
259
.handle = 0 ,
@@ -253,6 +267,9 @@ psa_status_t psa_hash_setup(psa_hash_operation_t *operation,
253
267
return (status );
254
268
}
255
269
status = ipc_call (& operation -> handle , & in_vec , 1 , NULL , 0 , false);
270
+ if (status != PSA_SUCCESS ) {
271
+ ipc_close (& operation -> handle );
272
+ }
256
273
return (status );
257
274
}
258
275
@@ -272,6 +289,9 @@ psa_status_t psa_hash_update(psa_hash_operation_t *operation,
272
289
};
273
290
274
291
psa_status_t status = ipc_call (& operation -> handle , in_vec , 2 , NULL , 0 , false);
292
+ if (status != PSA_SUCCESS ) {
293
+ ipc_close (& operation -> handle );
294
+ }
275
295
return (status );
276
296
}
277
297
@@ -986,6 +1006,10 @@ psa_status_t psa_key_derivation(psa_crypto_generator_t *generator,
986
1006
size_t label_length ,
987
1007
size_t capacity )
988
1008
{
1009
+ if (generator -> handle != PSA_NULL_HANDLE ) {
1010
+ return (PSA_ERROR_BAD_STATE );
1011
+ }
1012
+
989
1013
psa_crypto_derivation_ipc_t psa_crypto_ipc = {
990
1014
.func = PSA_KEY_DERIVATION ,
991
1015
.handle = key_handle ,
@@ -1004,6 +1028,9 @@ psa_status_t psa_key_derivation(psa_crypto_generator_t *generator,
1004
1028
return (status );
1005
1029
}
1006
1030
status = ipc_call (& generator -> handle , in_vec , 3 , NULL , 0 , false);
1031
+ if (status != PSA_SUCCESS ) {
1032
+ ipc_close (& generator -> handle );
1033
+ }
1007
1034
return (status );
1008
1035
}
1009
1036
@@ -1013,6 +1040,10 @@ psa_status_t psa_key_agreement(psa_crypto_generator_t *generator,
1013
1040
size_t peer_key_length ,
1014
1041
psa_algorithm_t alg )
1015
1042
{
1043
+ if (generator -> handle != PSA_NULL_HANDLE ) {
1044
+ return (PSA_ERROR_BAD_STATE );
1045
+ }
1046
+
1016
1047
psa_crypto_derivation_ipc_t psa_crypto_ipc = {
1017
1048
.func = PSA_KEY_AGREEMENT ,
1018
1049
.handle = private_key_handle ,
@@ -1030,6 +1061,9 @@ psa_status_t psa_key_agreement(psa_crypto_generator_t *generator,
1030
1061
return (status );
1031
1062
}
1032
1063
status = ipc_call (& generator -> handle , in_vec , 2 , NULL , 0 , false);
1064
+ if (status != PSA_SUCCESS ) {
1065
+ ipc_close (& generator -> handle );
1066
+ }
1033
1067
return (status );
1034
1068
}
1035
1069
@@ -1055,12 +1089,17 @@ psa_status_t psa_generator_abort(psa_crypto_generator_t *generator)
1055
1089
/****************************************************************/
1056
1090
/* SYMMETRIC */
1057
1091
/****************************************************************/
1058
- psa_status_t psa_cipher_encrypt_setup (psa_cipher_operation_t * operation ,
1059
- psa_key_handle_t key_handle ,
1060
- psa_algorithm_t alg )
1092
+ static psa_status_t psa_cipher_setup (psa_cipher_operation_t * operation ,
1093
+ psa_key_handle_t key_handle ,
1094
+ psa_algorithm_t alg ,
1095
+ psa_sec_function_t func )
1061
1096
{
1097
+ if (operation -> handle != PSA_NULL_HANDLE ) {
1098
+ return (PSA_ERROR_BAD_STATE );
1099
+ }
1100
+
1062
1101
psa_crypto_ipc_t psa_crypto_ipc = {
1063
- .func = PSA_CIPHER_ENCRYPT_SETUP ,
1102
+ .func = func ,
1064
1103
.handle = key_handle ,
1065
1104
.alg = alg
1066
1105
};
@@ -1072,26 +1111,25 @@ psa_status_t psa_cipher_encrypt_setup(psa_cipher_operation_t *operation,
1072
1111
return (status );
1073
1112
}
1074
1113
status = ipc_call (& operation -> handle , & in_vec , 1 , NULL , 0 , false);
1114
+ if (status != PSA_SUCCESS ) {
1115
+ ipc_close (& operation -> handle );
1116
+ }
1075
1117
return (status );
1076
1118
}
1077
1119
1078
- psa_status_t psa_cipher_decrypt_setup (psa_cipher_operation_t * operation ,
1120
+ psa_status_t psa_cipher_encrypt_setup (psa_cipher_operation_t * operation ,
1079
1121
psa_key_handle_t key_handle ,
1080
1122
psa_algorithm_t alg )
1081
1123
{
1082
- psa_crypto_ipc_t psa_crypto_ipc = {
1083
- .func = PSA_CIPHER_DECRYPT_SETUP ,
1084
- .handle = key_handle ,
1085
- .alg = alg
1086
- };
1087
-
1088
- psa_invec in_vec = { & psa_crypto_ipc , sizeof (psa_crypto_ipc ) };
1124
+ psa_status_t status = psa_cipher_setup (operation , key_handle , alg , PSA_CIPHER_ENCRYPT_SETUP );
1125
+ return (status );
1126
+ }
1089
1127
1090
- psa_status_t status = ipc_connect ( PSA_SYMMETRIC_ID , & operation -> handle );
1091
- if ( status != PSA_SUCCESS ) {
1092
- return ( status );
1093
- }
1094
- status = ipc_call ( & operation -> handle , & in_vec , 1 , NULL , 0 , false );
1128
+ psa_status_t psa_cipher_decrypt_setup ( psa_cipher_operation_t * operation ,
1129
+ psa_key_handle_t key_handle ,
1130
+ psa_algorithm_t alg )
1131
+ {
1132
+ psa_status_t status = psa_cipher_setup ( operation , key_handle , alg , PSA_CIPHER_DECRYPT_SETUP );
1095
1133
return (status );
1096
1134
}
1097
1135
@@ -1114,6 +1152,9 @@ psa_status_t psa_cipher_generate_iv(psa_cipher_operation_t *operation,
1114
1152
};
1115
1153
1116
1154
psa_status_t status = ipc_call (& operation -> handle , & in_vec , 1 , out_vec , 2 , false);
1155
+ if (status != PSA_SUCCESS ) {
1156
+ ipc_close (& operation -> handle );
1157
+ }
1117
1158
return (status );
1118
1159
}
1119
1160
@@ -1133,6 +1174,9 @@ psa_status_t psa_cipher_set_iv(psa_cipher_operation_t *operation,
1133
1174
};
1134
1175
1135
1176
psa_status_t status = ipc_call (& operation -> handle , in_vec , 2 , NULL , 0 , false);
1177
+ if (status != PSA_SUCCESS ) {
1178
+ ipc_close (& operation -> handle );
1179
+ }
1136
1180
return (status );
1137
1181
}
1138
1182
@@ -1160,6 +1204,9 @@ psa_status_t psa_cipher_update(psa_cipher_operation_t *operation,
1160
1204
};
1161
1205
1162
1206
psa_status_t status = ipc_call (& operation -> handle , in_vec , 2 , out_vec , 2 , false);
1207
+ if (status != PSA_SUCCESS ) {
1208
+ ipc_close (& operation -> handle );
1209
+ }
1163
1210
return (status );
1164
1211
}
1165
1212
0 commit comments