Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 1 | /* |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2019, Arm Limited. All rights reserved. |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #include "tfm_crypto_veneers.h" |
| 9 | #include "secure_fw/services/crypto/tfm_crypto_api.h" |
| 10 | #include "tfm_secure_api.h" |
| 11 | #include "tfm_api.h" |
| 12 | #include "spm_api.h" |
| 13 | |
| 14 | #include "psa_crypto.h" |
| 15 | |
| 16 | #include "crypto_psa_wrappers.h" |
| 17 | |
| 18 | __tfm_secure_gateway_attributes__ |
| 19 | enum tfm_crypto_err_t tfm_crypto_veneer_import_key(psa_key_slot_t key, |
| 20 | psa_key_type_t type, |
| 21 | const uint8_t *data, |
| 22 | size_t data_length) |
| 23 | { |
| 24 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_import_key, |
| 25 | key, type, data, data_length); |
| 26 | } |
| 27 | |
| 28 | __tfm_secure_gateway_attributes__ |
| 29 | enum tfm_crypto_err_t tfm_crypto_veneer_destroy_key(psa_key_slot_t key) |
| 30 | { |
| 31 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_destroy_key, |
| 32 | key, 0, 0, 0); |
| 33 | } |
| 34 | |
| 35 | __tfm_secure_gateway_attributes__ |
| 36 | enum tfm_crypto_err_t tfm_crypto_veneer_get_key_information( |
| 37 | psa_key_slot_t key, |
| 38 | psa_key_type_t *type, |
| 39 | size_t *bits) |
| 40 | { |
| 41 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_get_key_information, |
| 42 | key, type, bits, 0); |
| 43 | } |
| 44 | |
| 45 | __tfm_secure_gateway_attributes__ |
| 46 | enum tfm_crypto_err_t tfm_crypto_veneer_export_key(psa_key_slot_t key, |
| 47 | uint8_t *data, |
| 48 | size_t data_size, |
| 49 | size_t *data_length) |
| 50 | { |
| 51 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_export_key, |
| 52 | key, data, data_size, data_length); |
| 53 | } |
| 54 | |
Jamie Fox | efd8273 | 2018-11-26 10:34:32 +0000 | [diff] [blame] | 55 | __tfm_secure_gateway_attributes__ |
| 56 | enum tfm_crypto_err_t tfm_crypto_veneer_key_policy_init( |
| 57 | psa_key_policy_t *policy) |
| 58 | { |
| 59 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_key_policy_init, |
| 60 | policy, 0, 0, 0); |
| 61 | } |
| 62 | |
| 63 | __tfm_secure_gateway_attributes__ |
| 64 | enum tfm_crypto_err_t tfm_crypto_veneer_key_policy_set_usage( |
| 65 | psa_key_policy_t *policy, |
| 66 | psa_key_usage_t usage, |
| 67 | psa_algorithm_t alg) |
| 68 | { |
| 69 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_key_policy_set_usage, |
| 70 | policy, usage, alg, 0); |
| 71 | } |
| 72 | |
| 73 | __tfm_secure_gateway_attributes__ |
| 74 | enum tfm_crypto_err_t tfm_crypto_veneer_key_policy_get_usage( |
| 75 | const psa_key_policy_t *policy, |
| 76 | psa_key_usage_t *usage) |
| 77 | { |
| 78 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_key_policy_get_usage, |
| 79 | policy, usage, 0, 0); |
| 80 | } |
| 81 | |
| 82 | __tfm_secure_gateway_attributes__ |
| 83 | enum tfm_crypto_err_t tfm_crypto_veneer_key_policy_get_algorithm( |
| 84 | const psa_key_policy_t *policy, |
| 85 | psa_algorithm_t *alg) |
| 86 | { |
| 87 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_key_policy_get_algorithm, |
| 88 | policy, alg, 0, 0); |
| 89 | } |
| 90 | |
| 91 | __tfm_secure_gateway_attributes__ |
| 92 | enum tfm_crypto_err_t tfm_crypto_veneer_set_key_policy( |
| 93 | psa_key_slot_t key, |
| 94 | const psa_key_policy_t *policy) |
| 95 | { |
| 96 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_set_key_policy, |
| 97 | key, policy, 0, 0); |
| 98 | } |
| 99 | |
| 100 | __tfm_secure_gateway_attributes__ |
| 101 | enum tfm_crypto_err_t tfm_crypto_veneer_get_key_policy(psa_key_slot_t key, |
| 102 | psa_key_policy_t *policy) |
| 103 | { |
| 104 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_get_key_policy, |
| 105 | key, policy, 0, 0); |
| 106 | } |
| 107 | |
| 108 | __tfm_secure_gateway_attributes__ |
| 109 | enum tfm_crypto_err_t tfm_crypto_veneer_set_key_lifetime( |
| 110 | psa_key_slot_t key, |
| 111 | psa_key_lifetime_t lifetime) |
| 112 | { |
| 113 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_set_key_lifetime, |
| 114 | key, lifetime, 0, 0); |
| 115 | } |
| 116 | |
| 117 | __tfm_secure_gateway_attributes__ |
| 118 | enum tfm_crypto_err_t tfm_crypto_veneer_get_key_lifetime( |
| 119 | psa_key_slot_t key, |
| 120 | psa_key_lifetime_t *lifetime) |
| 121 | { |
| 122 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_get_key_lifetime, |
| 123 | key, lifetime, 0, 0); |
| 124 | } |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 125 | |
| 126 | __tfm_secure_gateway_attributes__ |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame] | 127 | enum tfm_crypto_err_t tfm_crypto_veneer_cipher_set_iv( |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 128 | psa_cipher_operation_t *operation, |
| 129 | const unsigned char *iv, |
| 130 | size_t iv_length) |
| 131 | { |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame] | 132 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_cipher_set_iv, |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 133 | operation, iv, iv_length, 0); |
| 134 | } |
| 135 | |
| 136 | __tfm_secure_gateway_attributes__ |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame] | 137 | enum tfm_crypto_err_t tfm_crypto_veneer_cipher_encrypt_setup( |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 138 | psa_cipher_operation_t *operation, |
| 139 | psa_key_slot_t key, |
| 140 | psa_algorithm_t alg) |
| 141 | { |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame] | 142 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_cipher_encrypt_setup, |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 143 | operation, key, alg, 0); |
| 144 | } |
| 145 | |
| 146 | __tfm_secure_gateway_attributes__ |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame] | 147 | enum tfm_crypto_err_t tfm_crypto_veneer_cipher_decrypt_setup( |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 148 | psa_cipher_operation_t *operation, |
| 149 | psa_key_slot_t key, |
| 150 | psa_algorithm_t alg) |
| 151 | { |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame] | 152 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_cipher_decrypt_setup, |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 153 | operation, key, alg, 0); |
| 154 | } |
| 155 | |
| 156 | __tfm_secure_gateway_attributes__ |
| 157 | enum tfm_crypto_err_t tfm_crypto_veneer_cipher_update( |
| 158 | psa_cipher_operation_t *operation, |
| 159 | struct psa_cipher_update_input *input_s, |
| 160 | struct psa_cipher_update_output *output_s) |
| 161 | { |
| 162 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_cipher_update_wrapper, |
| 163 | operation, input_s, output_s, 0); |
| 164 | } |
| 165 | |
| 166 | __tfm_secure_gateway_attributes__ |
| 167 | enum tfm_crypto_err_t tfm_crypto_veneer_cipher_abort( |
| 168 | psa_cipher_operation_t *operation) |
| 169 | { |
| 170 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_cipher_abort, |
| 171 | operation, 0, 0, 0); |
| 172 | } |
| 173 | |
| 174 | __tfm_secure_gateway_attributes__ |
| 175 | enum tfm_crypto_err_t tfm_crypto_veneer_cipher_finish( |
| 176 | psa_cipher_operation_t *operation, |
| 177 | uint8_t *output, |
| 178 | size_t output_size, |
| 179 | size_t *output_length) |
| 180 | { |
| 181 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_cipher_finish, |
| 182 | operation, output, output_size, output_length); |
| 183 | } |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 184 | |
| 185 | __tfm_secure_gateway_attributes__ |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame] | 186 | enum tfm_crypto_err_t tfm_crypto_veneer_hash_setup( |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 187 | psa_hash_operation_t *operation, |
| 188 | psa_algorithm_t alg) |
| 189 | { |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame] | 190 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_hash_setup, |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 191 | operation, alg, 0, 0); |
| 192 | } |
| 193 | |
| 194 | __tfm_secure_gateway_attributes__ |
| 195 | enum tfm_crypto_err_t tfm_crypto_veneer_hash_update( |
| 196 | psa_hash_operation_t *operation, |
| 197 | const uint8_t *input, |
| 198 | size_t input_length) |
| 199 | { |
| 200 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_hash_update, |
| 201 | operation, input, input_length, 0); |
| 202 | } |
| 203 | |
| 204 | __tfm_secure_gateway_attributes__ |
| 205 | enum tfm_crypto_err_t tfm_crypto_veneer_hash_finish( |
| 206 | psa_hash_operation_t *operation, |
| 207 | uint8_t *hash, |
| 208 | size_t hash_size, |
| 209 | size_t *hash_length) |
| 210 | { |
| 211 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_hash_finish, |
| 212 | operation, hash, hash_size, hash_length); |
| 213 | } |
| 214 | |
| 215 | __tfm_secure_gateway_attributes__ |
| 216 | enum tfm_crypto_err_t tfm_crypto_veneer_hash_verify( |
| 217 | psa_hash_operation_t *operation, |
| 218 | const uint8_t *hash, |
| 219 | size_t hash_length) |
| 220 | { |
| 221 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_hash_verify, |
| 222 | operation, hash, hash_length, 0); |
| 223 | } |
| 224 | |
| 225 | __tfm_secure_gateway_attributes__ |
| 226 | enum tfm_crypto_err_t tfm_crypto_veneer_hash_abort( |
| 227 | psa_hash_operation_t *operation) |
| 228 | { |
| 229 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_hash_abort, |
| 230 | operation, 0, 0, 0); |
| 231 | } |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 232 | |
| 233 | __tfm_secure_gateway_attributes__ |
| 234 | enum tfm_crypto_err_t tfm_crypto_veneer_mac_sign_setup( |
| 235 | psa_mac_operation_t *operation, |
| 236 | psa_key_slot_t key, |
| 237 | psa_algorithm_t alg) |
| 238 | { |
| 239 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_mac_sign_setup, |
| 240 | operation, key, alg, 0); |
| 241 | } |
| 242 | |
| 243 | __tfm_secure_gateway_attributes__ |
| 244 | enum tfm_crypto_err_t tfm_crypto_veneer_mac_verify_setup( |
| 245 | psa_mac_operation_t *operation, |
| 246 | psa_key_slot_t key, |
| 247 | psa_algorithm_t alg) |
| 248 | { |
| 249 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_mac_verify_setup, |
| 250 | operation, key, alg, 0); |
| 251 | } |
| 252 | |
| 253 | __tfm_secure_gateway_attributes__ |
| 254 | enum tfm_crypto_err_t tfm_crypto_veneer_mac_update( |
| 255 | psa_mac_operation_t *operation, |
| 256 | const uint8_t *input, |
| 257 | size_t input_length) |
| 258 | { |
| 259 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_mac_update, |
| 260 | operation, input, input_length, 0); |
| 261 | } |
| 262 | |
| 263 | __tfm_secure_gateway_attributes__ |
| 264 | enum tfm_crypto_err_t tfm_crypto_veneer_mac_sign_finish( |
| 265 | psa_mac_operation_t *operation, |
| 266 | uint8_t *mac, |
| 267 | size_t mac_size, |
| 268 | size_t *mac_length) |
| 269 | { |
| 270 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_mac_sign_finish, |
| 271 | operation, mac, mac_size, mac_length); |
| 272 | } |
| 273 | |
| 274 | __tfm_secure_gateway_attributes__ |
| 275 | enum tfm_crypto_err_t tfm_crypto_veneer_mac_verify_finish( |
| 276 | psa_mac_operation_t *operation, |
| 277 | const uint8_t *mac, |
| 278 | size_t mac_length) |
| 279 | { |
| 280 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_mac_verify_finish, |
| 281 | operation, mac, mac_length, 0); |
| 282 | } |
| 283 | |
| 284 | __tfm_secure_gateway_attributes__ |
| 285 | enum tfm_crypto_err_t tfm_crypto_veneer_mac_abort( |
| 286 | psa_mac_operation_t *operation) |
| 287 | { |
| 288 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_mac_abort, |
| 289 | operation, 0, 0, 0); |
| 290 | } |
Antonio de Angelis | 3a48099 | 2018-11-07 11:53:28 +0000 | [diff] [blame] | 291 | |
| 292 | __tfm_secure_gateway_attributes__ |
| 293 | enum tfm_crypto_err_t tfm_crypto_veneer_aead_encrypt( |
| 294 | struct psa_aead_encrypt_input *input_s, |
| 295 | struct psa_aead_encrypt_output *output_s) |
| 296 | { |
| 297 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_aead_encrypt_wrapper, |
| 298 | input_s, output_s, 0, 0); |
| 299 | } |
| 300 | |
| 301 | __tfm_secure_gateway_attributes__ |
| 302 | enum tfm_crypto_err_t tfm_crypto_veneer_aead_decrypt( |
| 303 | struct psa_aead_decrypt_input *input_s, |
| 304 | struct psa_aead_decrypt_output *output_s) |
| 305 | { |
| 306 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_aead_decrypt_wrapper, |
| 307 | input_s, output_s, 0, 0); |
| 308 | } |