|
| 1 | +/* |
| 2 | + * Copyright (c) 2019, Arm Limited and affiliates |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +#include "psa/client.h" |
| 19 | +#include "psa_test_partition_ifs.h" |
| 20 | +#include "test_partition_proxy.h" |
| 21 | + |
| 22 | +#define MINOR_VER 1 |
| 23 | + |
| 24 | +static psa_status_t invoke_ipc_call(uint32_t sid, psa_invec *in_vec, size_t in_vec_size, |
| 25 | + psa_outvec *out_vec, size_t out_vec_size) |
| 26 | +{ |
| 27 | + psa_status_t status; |
| 28 | + |
| 29 | + psa_handle_t handle = psa_connect(sid, MINOR_VER); |
| 30 | + if (handle <= 0) { |
| 31 | + return (PSA_ERROR_COMMUNICATION_FAILURE); |
| 32 | + } |
| 33 | + |
| 34 | + status = psa_call(handle, in_vec, in_vec_size, out_vec, out_vec_size); |
| 35 | + psa_close(handle); |
| 36 | + |
| 37 | + if (status < 0) { |
| 38 | + status = PSA_ERROR_COMMUNICATION_FAILURE; |
| 39 | + } |
| 40 | + |
| 41 | + return (status); |
| 42 | +} |
| 43 | + |
| 44 | +psa_status_t test_partition_crypto_create_persistent_key(psa_key_id_t key_id, psa_key_handle_t *key_handle) |
| 45 | +{ |
| 46 | + psa_invec in_vec = { &key_id, sizeof(key_id) }; |
| 47 | + psa_outvec out_vec = { key_handle, sizeof(*key_handle) }; |
| 48 | + psa_status_t status = invoke_ipc_call(CRYPTO_CREATE_PERSISTENT_KEY, &in_vec, 1, &out_vec, 1); |
| 49 | + return (status); |
| 50 | +} |
| 51 | + |
| 52 | +psa_status_t test_partition_crypto_set_key_policy(psa_key_handle_t key_handle, psa_key_usage_t key_usage, |
| 53 | + psa_algorithm_t key_alg) |
| 54 | +{ |
| 55 | + psa_invec in_vec[3] = { |
| 56 | + { &key_handle, sizeof(key_handle) }, |
| 57 | + { &key_usage, sizeof(key_usage) }, |
| 58 | + { &key_alg, sizeof(key_alg) } |
| 59 | + }; |
| 60 | + psa_status_t status = invoke_ipc_call(CRYPTO_SET_KEY_POLICY, in_vec, 3, NULL, 0); |
| 61 | + return (status); |
| 62 | +} |
| 63 | + |
| 64 | +psa_status_t test_partition_crypto_get_key_policy(psa_key_handle_t key_handle, psa_key_usage_t *key_usage, |
| 65 | + psa_algorithm_t *key_alg) |
| 66 | +{ |
| 67 | + psa_invec in_vec = { &key_handle, sizeof(key_handle) }; |
| 68 | + psa_outvec out_vec[2] = { |
| 69 | + { key_usage, sizeof(*key_usage) }, |
| 70 | + { key_alg, sizeof(*key_alg) } |
| 71 | + }; |
| 72 | + psa_status_t status = invoke_ipc_call(CRYPTO_GET_KEY_POLICY, &in_vec, 1, out_vec, 2); |
| 73 | + return (status); |
| 74 | +} |
| 75 | + |
| 76 | +psa_status_t test_partition_crypto_get_key_information(psa_key_handle_t key_handle, psa_key_type_t *key_type, |
| 77 | + size_t *key_bits) |
| 78 | +{ |
| 79 | + psa_invec in_vec = { &key_handle, sizeof(key_handle) }; |
| 80 | + psa_outvec out_vec[2] = { |
| 81 | + { key_type, sizeof(*key_type) }, |
| 82 | + { key_bits, sizeof(*key_bits) } |
| 83 | + }; |
| 84 | + psa_status_t status = invoke_ipc_call(CRYPTO_GET_KEY_INFO, &in_vec, 1, out_vec, 2); |
| 85 | + return (status); |
| 86 | +} |
| 87 | + |
| 88 | +psa_status_t test_partition_crypto_generate_key(psa_key_handle_t key_handle, psa_key_type_t key_type, size_t key_bits) |
| 89 | +{ |
| 90 | + psa_invec in_vec[3] = { |
| 91 | + { &key_handle, sizeof(key_handle) }, |
| 92 | + { &key_type, sizeof(key_type) }, |
| 93 | + { &key_bits, sizeof(key_bits) } |
| 94 | + }; |
| 95 | + psa_status_t status = invoke_ipc_call(CRYPTO_GENERATE_KEY, in_vec, 3, NULL, 0); |
| 96 | + return (status); |
| 97 | +} |
| 98 | + |
| 99 | +psa_status_t test_partition_crypto_open_persistent_key(psa_key_id_t key_id, psa_key_handle_t *key_handle) |
| 100 | +{ |
| 101 | + psa_invec in_vec = { &key_id, sizeof(key_id) }; |
| 102 | + psa_outvec out_vec = { key_handle, sizeof(*key_handle) }; |
| 103 | + psa_status_t status = invoke_ipc_call(CRYPTO_OPEN_PERSISTENT_KEY, &in_vec, 1, &out_vec, 1); |
| 104 | + return (status); |
| 105 | +} |
| 106 | + |
| 107 | +psa_status_t test_partition_crypto_close_key(psa_key_handle_t key_handle) |
| 108 | +{ |
| 109 | + psa_invec in_vec = { &key_handle, sizeof(key_handle) }; |
| 110 | + psa_status_t status = invoke_ipc_call(CRYPTO_CLOSE_KEY, &in_vec, 1, NULL, 0); |
| 111 | + return (status); |
| 112 | +} |
| 113 | + |
| 114 | +psa_status_t test_partition_crypto_destroy_key(psa_key_handle_t key_handle) |
| 115 | +{ |
| 116 | + psa_invec in_vec = { &key_handle, sizeof(key_handle) }; |
| 117 | + psa_status_t status = invoke_ipc_call(CRYPTO_DESTROY_KEY, &in_vec, 1, NULL, 0); |
| 118 | + return (status); |
| 119 | +} |
0 commit comments