Merge pull request #10232 from itayzafrir/crypto-service-multipart-operation-abort-fix

PSA Crypto Service - multipart operation memory fixes
pull/10378/head
Martin Kojtal 2019-04-11 11:51:18 +01:00 committed by GitHub
commit c6b917327b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 541 additions and 448 deletions

View File

@ -120,6 +120,10 @@ static psa_status_t psa_mac_setup(psa_mac_operation_t *operation,
psa_algorithm_t alg,
psa_sec_function_t func)
{
if (operation->handle != PSA_NULL_HANDLE) {
return (PSA_ERROR_BAD_STATE);
}
psa_crypto_ipc_t psa_crypto_ipc = {
.func = func,
.handle = key_handle,
@ -133,6 +137,9 @@ static psa_status_t psa_mac_setup(psa_mac_operation_t *operation,
return (status);
}
status = ipc_call(&operation->handle, &in_vec, 1, NULL, 0, false);
if (status != PSA_SUCCESS) {
ipc_close(&operation->handle);
}
return (status);
}
@ -168,6 +175,9 @@ psa_status_t psa_mac_update(psa_mac_operation_t *operation,
};
psa_status_t status = ipc_call(&operation->handle, in_vec, 2, NULL, 0, false);
if (status != PSA_SUCCESS) {
ipc_close(&operation->handle);
}
return (status);
}
@ -240,6 +250,10 @@ psa_status_t psa_hash_abort(psa_hash_operation_t *operation)
psa_status_t psa_hash_setup(psa_hash_operation_t *operation,
psa_algorithm_t alg)
{
if (operation->handle != PSA_NULL_HANDLE) {
return (PSA_ERROR_BAD_STATE);
}
psa_crypto_ipc_t psa_crypto_ipc = {
.func = PSA_HASH_SETUP,
.handle = 0,
@ -253,6 +267,9 @@ psa_status_t psa_hash_setup(psa_hash_operation_t *operation,
return (status);
}
status = ipc_call(&operation->handle, &in_vec, 1, NULL, 0, false);
if (status != PSA_SUCCESS) {
ipc_close(&operation->handle);
}
return (status);
}
@ -272,6 +289,9 @@ psa_status_t psa_hash_update(psa_hash_operation_t *operation,
};
psa_status_t status = ipc_call(&operation->handle, in_vec, 2, NULL, 0, false);
if (status != PSA_SUCCESS) {
ipc_close(&operation->handle);
}
return (status);
}
@ -986,6 +1006,10 @@ psa_status_t psa_key_derivation(psa_crypto_generator_t *generator,
size_t label_length,
size_t capacity)
{
if (generator->handle != PSA_NULL_HANDLE) {
return (PSA_ERROR_BAD_STATE);
}
psa_crypto_derivation_ipc_t psa_crypto_ipc = {
.func = PSA_KEY_DERIVATION,
.handle = key_handle,
@ -1004,6 +1028,9 @@ psa_status_t psa_key_derivation(psa_crypto_generator_t *generator,
return (status);
}
status = ipc_call(&generator->handle, in_vec, 3, NULL, 0, false);
if (status != PSA_SUCCESS) {
ipc_close(&generator->handle);
}
return (status);
}
@ -1013,6 +1040,10 @@ psa_status_t psa_key_agreement(psa_crypto_generator_t *generator,
size_t peer_key_length,
psa_algorithm_t alg)
{
if (generator->handle != PSA_NULL_HANDLE) {
return (PSA_ERROR_BAD_STATE);
}
psa_crypto_derivation_ipc_t psa_crypto_ipc = {
.func = PSA_KEY_AGREEMENT,
.handle = private_key_handle,
@ -1030,6 +1061,9 @@ psa_status_t psa_key_agreement(psa_crypto_generator_t *generator,
return (status);
}
status = ipc_call(&generator->handle, in_vec, 2, NULL, 0, false);
if (status != PSA_SUCCESS) {
ipc_close(&generator->handle);
}
return (status);
}
@ -1055,12 +1089,17 @@ psa_status_t psa_generator_abort(psa_crypto_generator_t *generator)
/****************************************************************/
/* SYMMETRIC */
/****************************************************************/
psa_status_t psa_cipher_encrypt_setup(psa_cipher_operation_t *operation,
psa_key_handle_t key_handle,
psa_algorithm_t alg)
static psa_status_t psa_cipher_setup(psa_cipher_operation_t *operation,
psa_key_handle_t key_handle,
psa_algorithm_t alg,
psa_sec_function_t func)
{
if (operation->handle != PSA_NULL_HANDLE) {
return (PSA_ERROR_BAD_STATE);
}
psa_crypto_ipc_t psa_crypto_ipc = {
.func = PSA_CIPHER_ENCRYPT_SETUP,
.func = func,
.handle = key_handle,
.alg = alg
};
@ -1072,6 +1111,17 @@ psa_status_t psa_cipher_encrypt_setup(psa_cipher_operation_t *operation,
return (status);
}
status = ipc_call(&operation->handle, &in_vec, 1, NULL, 0, false);
if (status != PSA_SUCCESS) {
ipc_close(&operation->handle);
}
return (status);
}
psa_status_t psa_cipher_encrypt_setup(psa_cipher_operation_t *operation,
psa_key_handle_t key_handle,
psa_algorithm_t alg)
{
psa_status_t status = psa_cipher_setup(operation, key_handle, alg, PSA_CIPHER_ENCRYPT_SETUP);
return (status);
}
@ -1079,19 +1129,7 @@ psa_status_t psa_cipher_decrypt_setup(psa_cipher_operation_t *operation,
psa_key_handle_t key_handle,
psa_algorithm_t alg)
{
psa_crypto_ipc_t psa_crypto_ipc = {
.func = PSA_CIPHER_DECRYPT_SETUP,
.handle = key_handle,
.alg = alg
};
psa_invec in_vec = { &psa_crypto_ipc, sizeof(psa_crypto_ipc) };
psa_status_t status = ipc_connect(PSA_SYMMETRIC_ID, &operation->handle);
if (status != PSA_SUCCESS) {
return (status);
}
status = ipc_call(&operation->handle, &in_vec, 1, NULL, 0, false);
psa_status_t status = psa_cipher_setup(operation, key_handle, alg, PSA_CIPHER_DECRYPT_SETUP);
return (status);
}
@ -1114,6 +1152,9 @@ psa_status_t psa_cipher_generate_iv(psa_cipher_operation_t *operation,
};
psa_status_t status = ipc_call(&operation->handle, &in_vec, 1, out_vec, 2, false);
if (status != PSA_SUCCESS) {
ipc_close(&operation->handle);
}
return (status);
}
@ -1133,6 +1174,9 @@ psa_status_t psa_cipher_set_iv(psa_cipher_operation_t *operation,
};
psa_status_t status = ipc_call(&operation->handle, in_vec, 2, NULL, 0, false);
if (status != PSA_SUCCESS) {
ipc_close(&operation->handle);
}
return (status);
}
@ -1160,6 +1204,9 @@ psa_status_t psa_cipher_update(psa_cipher_operation_t *operation,
};
psa_status_t status = ipc_call(&operation->handle, in_vec, 2, out_vec, 2, false);
if (status != PSA_SUCCESS) {
ipc_close(&operation->handle);
}
return (status);
}