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 | |
| 55 | |
| 56 | __tfm_secure_gateway_attributes__ |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame^] | 57 | enum tfm_crypto_err_t tfm_crypto_veneer_cipher_set_iv( |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 58 | psa_cipher_operation_t *operation, |
| 59 | const unsigned char *iv, |
| 60 | size_t iv_length) |
| 61 | { |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame^] | 62 | 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] | 63 | operation, iv, iv_length, 0); |
| 64 | } |
| 65 | |
| 66 | __tfm_secure_gateway_attributes__ |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame^] | 67 | enum tfm_crypto_err_t tfm_crypto_veneer_cipher_encrypt_setup( |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 68 | psa_cipher_operation_t *operation, |
| 69 | psa_key_slot_t key, |
| 70 | psa_algorithm_t alg) |
| 71 | { |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame^] | 72 | 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] | 73 | operation, key, alg, 0); |
| 74 | } |
| 75 | |
| 76 | __tfm_secure_gateway_attributes__ |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame^] | 77 | enum tfm_crypto_err_t tfm_crypto_veneer_cipher_decrypt_setup( |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 78 | psa_cipher_operation_t *operation, |
| 79 | psa_key_slot_t key, |
| 80 | psa_algorithm_t alg) |
| 81 | { |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame^] | 82 | 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] | 83 | operation, key, alg, 0); |
| 84 | } |
| 85 | |
| 86 | __tfm_secure_gateway_attributes__ |
| 87 | enum tfm_crypto_err_t tfm_crypto_veneer_cipher_update( |
| 88 | psa_cipher_operation_t *operation, |
| 89 | struct psa_cipher_update_input *input_s, |
| 90 | struct psa_cipher_update_output *output_s) |
| 91 | { |
| 92 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_cipher_update_wrapper, |
| 93 | operation, input_s, output_s, 0); |
| 94 | } |
| 95 | |
| 96 | __tfm_secure_gateway_attributes__ |
| 97 | enum tfm_crypto_err_t tfm_crypto_veneer_cipher_abort( |
| 98 | psa_cipher_operation_t *operation) |
| 99 | { |
| 100 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_cipher_abort, |
| 101 | operation, 0, 0, 0); |
| 102 | } |
| 103 | |
| 104 | __tfm_secure_gateway_attributes__ |
| 105 | enum tfm_crypto_err_t tfm_crypto_veneer_cipher_finish( |
| 106 | psa_cipher_operation_t *operation, |
| 107 | uint8_t *output, |
| 108 | size_t output_size, |
| 109 | size_t *output_length) |
| 110 | { |
| 111 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_cipher_finish, |
| 112 | operation, output, output_size, output_length); |
| 113 | } |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 114 | |
| 115 | __tfm_secure_gateway_attributes__ |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame^] | 116 | enum tfm_crypto_err_t tfm_crypto_veneer_hash_setup( |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 117 | psa_hash_operation_t *operation, |
| 118 | psa_algorithm_t alg) |
| 119 | { |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame^] | 120 | 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] | 121 | operation, alg, 0, 0); |
| 122 | } |
| 123 | |
| 124 | __tfm_secure_gateway_attributes__ |
| 125 | enum tfm_crypto_err_t tfm_crypto_veneer_hash_update( |
| 126 | psa_hash_operation_t *operation, |
| 127 | const uint8_t *input, |
| 128 | size_t input_length) |
| 129 | { |
| 130 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_hash_update, |
| 131 | operation, input, input_length, 0); |
| 132 | } |
| 133 | |
| 134 | __tfm_secure_gateway_attributes__ |
| 135 | enum tfm_crypto_err_t tfm_crypto_veneer_hash_finish( |
| 136 | psa_hash_operation_t *operation, |
| 137 | uint8_t *hash, |
| 138 | size_t hash_size, |
| 139 | size_t *hash_length) |
| 140 | { |
| 141 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_hash_finish, |
| 142 | operation, hash, hash_size, hash_length); |
| 143 | } |
| 144 | |
| 145 | __tfm_secure_gateway_attributes__ |
| 146 | enum tfm_crypto_err_t tfm_crypto_veneer_hash_verify( |
| 147 | psa_hash_operation_t *operation, |
| 148 | const uint8_t *hash, |
| 149 | size_t hash_length) |
| 150 | { |
| 151 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_hash_verify, |
| 152 | operation, hash, hash_length, 0); |
| 153 | } |
| 154 | |
| 155 | __tfm_secure_gateway_attributes__ |
| 156 | enum tfm_crypto_err_t tfm_crypto_veneer_hash_abort( |
| 157 | psa_hash_operation_t *operation) |
| 158 | { |
| 159 | TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_hash_abort, |
| 160 | operation, 0, 0, 0); |
| 161 | } |