Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 1 | /* |
Antonio de Angelis | 04debbd | 2019-10-14 12:12:52 +0100 | [diff] [blame^] | 2 | * Copyright (c) 2019-2020, Arm Limited. All rights reserved. |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | #include <stdint.h> |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 10 | |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 11 | /* FixMe: Use PSA_ERROR_CONNECTION_REFUSED when performing parameter |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 12 | * integrity checks but this will have to be revised |
| 13 | * when the full set of error codes mandated by PSA FF |
| 14 | * is available. |
| 15 | */ |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 16 | #include "tfm_mbedcrypto_include.h" |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 17 | |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 18 | #include "tfm_crypto_api.h" |
| 19 | #include "tfm_crypto_defs.h" |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 20 | |
| 21 | /*! |
| 22 | * \defgroup public_psa Public functions, PSA |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | /*!@{*/ |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 27 | psa_status_t tfm_crypto_mac_sign_setup(psa_invec in_vec[], |
| 28 | size_t in_len, |
| 29 | psa_outvec out_vec[], |
| 30 | size_t out_len) |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 31 | { |
Kevin Peng | 96f802e | 2019-12-26 16:10:25 +0800 | [diff] [blame] | 32 | #ifdef TFM_CRYPTO_MAC_MODULE_DISABLED |
Antonio de Angelis | 7740b38 | 2019-07-16 10:59:25 +0100 | [diff] [blame] | 33 | return PSA_ERROR_NOT_SUPPORTED; |
| 34 | #else |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 35 | psa_status_t status = PSA_SUCCESS; |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 36 | psa_mac_operation_t *operation = NULL; |
| 37 | |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 38 | if ((in_len != 1) || (out_len != 1)) { |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 39 | return PSA_ERROR_CONNECTION_REFUSED; |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 42 | if ((out_vec[0].len != sizeof(uint32_t)) || |
| 43 | (in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec))) { |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 44 | return PSA_ERROR_CONNECTION_REFUSED; |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 45 | } |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 46 | const struct tfm_crypto_pack_iovec *iov = in_vec[0].base; |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 47 | uint32_t handle = iov->op_handle; |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 48 | uint32_t *handle_out = out_vec[0].base; |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 49 | psa_key_handle_t key_handle = iov->key_handle; |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 50 | psa_algorithm_t alg = iov->alg; |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 51 | |
Antonio de Angelis | 60a6fe6 | 2019-06-18 15:27:34 +0100 | [diff] [blame] | 52 | status = tfm_crypto_check_handle_owner(key_handle, NULL); |
| 53 | if (status != PSA_SUCCESS) { |
| 54 | return status; |
| 55 | } |
| 56 | |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 57 | /* Init the handle in the operation with the one passed from the iov */ |
| 58 | *handle_out = iov->op_handle; |
| 59 | |
| 60 | /* Allocate the operation context in the secure world */ |
| 61 | status = tfm_crypto_operation_alloc(TFM_CRYPTO_MAC_OPERATION, |
| 62 | &handle, |
| 63 | (void **)&operation); |
| 64 | if (status != PSA_SUCCESS) { |
| 65 | return status; |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 66 | } |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 67 | |
| 68 | *handle_out = handle; |
| 69 | |
| 70 | status = psa_mac_sign_setup(operation, key_handle, alg); |
| 71 | if (status != PSA_SUCCESS) { |
| 72 | /* Release the operation context, ignore if the operation fails. */ |
| 73 | (void)tfm_crypto_operation_release(handle_out); |
| 74 | return status; |
| 75 | } |
| 76 | |
| 77 | return PSA_SUCCESS; |
Antonio de Angelis | 7740b38 | 2019-07-16 10:59:25 +0100 | [diff] [blame] | 78 | #endif /* TFM_CRYPTO_MAC_MODULE_DISABLED */ |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 79 | } |
| 80 | |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 81 | psa_status_t tfm_crypto_mac_verify_setup(psa_invec in_vec[], |
| 82 | size_t in_len, |
| 83 | psa_outvec out_vec[], |
| 84 | size_t out_len) |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 85 | { |
Kevin Peng | 96f802e | 2019-12-26 16:10:25 +0800 | [diff] [blame] | 86 | #ifdef TFM_CRYPTO_MAC_MODULE_DISABLED |
Antonio de Angelis | 7740b38 | 2019-07-16 10:59:25 +0100 | [diff] [blame] | 87 | return PSA_ERROR_NOT_SUPPORTED; |
| 88 | #else |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 89 | psa_status_t status = PSA_SUCCESS; |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 90 | psa_mac_operation_t *operation = NULL; |
| 91 | |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 92 | if ((in_len != 1) || (out_len != 1)) { |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 93 | return PSA_ERROR_CONNECTION_REFUSED; |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 96 | if ((out_vec[0].len != sizeof(uint32_t)) || |
| 97 | (in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec))) { |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 98 | return PSA_ERROR_CONNECTION_REFUSED; |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 99 | } |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 100 | const struct tfm_crypto_pack_iovec *iov = in_vec[0].base; |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 101 | uint32_t handle = iov->op_handle; |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 102 | uint32_t *handle_out = out_vec[0].base; |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 103 | psa_key_handle_t key_handle = iov->key_handle; |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 104 | psa_algorithm_t alg = iov->alg; |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 105 | |
Antonio de Angelis | 60a6fe6 | 2019-06-18 15:27:34 +0100 | [diff] [blame] | 106 | status = tfm_crypto_check_handle_owner(key_handle, NULL); |
| 107 | if (status != PSA_SUCCESS) { |
| 108 | return status; |
| 109 | } |
| 110 | |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 111 | /* Init the handle in the operation with the one passed from the iov */ |
| 112 | *handle_out = iov->op_handle; |
| 113 | |
| 114 | /* Allocate the operation context in the secure world */ |
| 115 | status = tfm_crypto_operation_alloc(TFM_CRYPTO_MAC_OPERATION, |
| 116 | &handle, |
| 117 | (void **)&operation); |
| 118 | if (status != PSA_SUCCESS) { |
| 119 | return status; |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 120 | } |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 121 | |
| 122 | *handle_out = handle; |
| 123 | |
| 124 | status = psa_mac_verify_setup(operation, key_handle, alg); |
| 125 | if (status != PSA_SUCCESS) { |
| 126 | /* Release the operation context, ignore if the operation fails. */ |
| 127 | (void)tfm_crypto_operation_release(handle_out); |
| 128 | return status; |
| 129 | } |
| 130 | |
| 131 | return PSA_SUCCESS; |
Antonio de Angelis | 7740b38 | 2019-07-16 10:59:25 +0100 | [diff] [blame] | 132 | #endif /* TFM_CRYPTO_MAC_MODULE_DISABLED */ |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 133 | } |
| 134 | |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 135 | psa_status_t tfm_crypto_mac_update(psa_invec in_vec[], |
| 136 | size_t in_len, |
| 137 | psa_outvec out_vec[], |
| 138 | size_t out_len) |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 139 | { |
Kevin Peng | 96f802e | 2019-12-26 16:10:25 +0800 | [diff] [blame] | 140 | #ifdef TFM_CRYPTO_MAC_MODULE_DISABLED |
Antonio de Angelis | 7740b38 | 2019-07-16 10:59:25 +0100 | [diff] [blame] | 141 | return PSA_ERROR_NOT_SUPPORTED; |
| 142 | #else |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 143 | psa_status_t status = PSA_SUCCESS; |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 144 | psa_mac_operation_t *operation = NULL; |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 145 | |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 146 | if ((in_len != 2) || (out_len != 1)) { |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 147 | return PSA_ERROR_CONNECTION_REFUSED; |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 148 | } |
| 149 | |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 150 | if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) || |
| 151 | (out_vec[0].len != sizeof(uint32_t))) { |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 152 | return PSA_ERROR_CONNECTION_REFUSED; |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 153 | } |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 154 | const struct tfm_crypto_pack_iovec *iov = in_vec[0].base; |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 155 | uint32_t handle = iov->op_handle; |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 156 | uint32_t *handle_out = out_vec[0].base; |
| 157 | const uint8_t *input = in_vec[1].base; |
| 158 | size_t input_length = in_vec[1].len; |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 159 | |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 160 | /* Init the handle in the operation with the one passed from the iov */ |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 161 | *handle_out = iov->op_handle; |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 162 | |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 163 | /* Look up the corresponding operation context */ |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 164 | status = tfm_crypto_operation_lookup(TFM_CRYPTO_MAC_OPERATION, |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 165 | handle, |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 166 | (void **)&operation); |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 167 | if (status != PSA_SUCCESS) { |
| 168 | return status; |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 169 | } |
| 170 | |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 171 | status = psa_mac_update(operation, input, input_length); |
| 172 | if (status != PSA_SUCCESS) { |
| 173 | /* Release the operation context, ignore if the operation fails. */ |
| 174 | (void)tfm_crypto_operation_release(handle_out); |
| 175 | return status; |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 176 | } |
| 177 | |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 178 | return PSA_SUCCESS; |
Antonio de Angelis | 7740b38 | 2019-07-16 10:59:25 +0100 | [diff] [blame] | 179 | #endif /* TFM_CRYPTO_MAC_MODULE_DISABLED */ |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 180 | } |
| 181 | |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 182 | psa_status_t tfm_crypto_mac_sign_finish(psa_invec in_vec[], |
| 183 | size_t in_len, |
| 184 | psa_outvec out_vec[], |
| 185 | size_t out_len) |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 186 | { |
Kevin Peng | 96f802e | 2019-12-26 16:10:25 +0800 | [diff] [blame] | 187 | #ifdef TFM_CRYPTO_MAC_MODULE_DISABLED |
Antonio de Angelis | 7740b38 | 2019-07-16 10:59:25 +0100 | [diff] [blame] | 188 | return PSA_ERROR_NOT_SUPPORTED; |
| 189 | #else |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 190 | psa_status_t status = PSA_SUCCESS; |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 191 | psa_mac_operation_t *operation = NULL; |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 192 | |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 193 | if ((in_len != 1) || (out_len != 2)) { |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 194 | return PSA_ERROR_CONNECTION_REFUSED; |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 197 | if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) || |
| 198 | (out_vec[0].len != sizeof(uint32_t))) { |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 199 | return PSA_ERROR_CONNECTION_REFUSED; |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 200 | } |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 201 | const struct tfm_crypto_pack_iovec *iov = in_vec[0].base; |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 202 | uint32_t handle = iov->op_handle; |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 203 | uint32_t *handle_out = out_vec[0].base; |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 204 | uint8_t *mac = out_vec[1].base; |
| 205 | size_t mac_size = out_vec[1].len; |
| 206 | |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 207 | /* Init the handle in the operation with the one passed from the iov */ |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 208 | *handle_out = iov->op_handle; |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 209 | |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 210 | /* Initialise mac_length to zero */ |
| 211 | out_vec[1].len = 0; |
| 212 | |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 213 | /* Look up the corresponding operation context */ |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 214 | status = tfm_crypto_operation_lookup(TFM_CRYPTO_MAC_OPERATION, |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 215 | handle, |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 216 | (void **)&operation); |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 217 | if (status != PSA_SUCCESS) { |
| 218 | return status; |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 219 | } |
| 220 | |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 221 | status = psa_mac_sign_finish(operation, mac, mac_size, &out_vec[1].len); |
| 222 | if (status != PSA_SUCCESS) { |
| 223 | /* Release the operation context, ignore if the operation fails. */ |
| 224 | (void)tfm_crypto_operation_release(handle_out); |
| 225 | return status; |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 226 | } |
| 227 | |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 228 | status = tfm_crypto_operation_release(handle_out); |
| 229 | |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 230 | return status; |
Antonio de Angelis | 7740b38 | 2019-07-16 10:59:25 +0100 | [diff] [blame] | 231 | #endif /* TFM_CRYPTO_MAC_MODULE_DISABLED */ |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 232 | } |
| 233 | |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 234 | psa_status_t tfm_crypto_mac_verify_finish(psa_invec in_vec[], |
| 235 | size_t in_len, |
| 236 | psa_outvec out_vec[], |
| 237 | size_t out_len) |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 238 | { |
Kevin Peng | 96f802e | 2019-12-26 16:10:25 +0800 | [diff] [blame] | 239 | #ifdef TFM_CRYPTO_MAC_MODULE_DISABLED |
Antonio de Angelis | 7740b38 | 2019-07-16 10:59:25 +0100 | [diff] [blame] | 240 | return PSA_ERROR_NOT_SUPPORTED; |
| 241 | #else |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 242 | psa_status_t status = PSA_SUCCESS; |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 243 | psa_mac_operation_t *operation = NULL; |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 244 | |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 245 | if ((in_len != 2) || (out_len != 1)) { |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 246 | return PSA_ERROR_CONNECTION_REFUSED; |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 247 | } |
| 248 | |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 249 | if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) || |
| 250 | (out_vec[0].len != sizeof(uint32_t))) { |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 251 | return PSA_ERROR_CONNECTION_REFUSED; |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 252 | } |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 253 | const struct tfm_crypto_pack_iovec *iov = in_vec[0].base; |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 254 | uint32_t handle = iov->op_handle; |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 255 | uint32_t *handle_out = out_vec[0].base; |
| 256 | const uint8_t *mac = in_vec[1].base; |
| 257 | size_t mac_length = in_vec[1].len; |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 258 | |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 259 | /* Init the handle in the operation with the one passed from the iov */ |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 260 | *handle_out = iov->op_handle; |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 261 | |
| 262 | /* Look up the corresponding operation context */ |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 263 | status = tfm_crypto_operation_lookup(TFM_CRYPTO_MAC_OPERATION, |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 264 | handle, |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 265 | (void **)&operation); |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 266 | if (status != PSA_SUCCESS) { |
| 267 | return status; |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 268 | } |
| 269 | |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 270 | status = psa_mac_verify_finish(operation, mac, mac_length); |
| 271 | if (status != PSA_SUCCESS) { |
| 272 | /* Release the operation context, ignore if the operation fails. */ |
| 273 | (void)tfm_crypto_operation_release(handle_out); |
| 274 | return status; |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 275 | } |
| 276 | |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 277 | status = tfm_crypto_operation_release(handle_out); |
| 278 | |
| 279 | return status; |
Antonio de Angelis | 7740b38 | 2019-07-16 10:59:25 +0100 | [diff] [blame] | 280 | #endif /* TFM_CRYPTO_MAC_MODULE_DISABLED */ |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 281 | } |
| 282 | |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 283 | psa_status_t tfm_crypto_mac_abort(psa_invec in_vec[], |
| 284 | size_t in_len, |
| 285 | psa_outvec out_vec[], |
| 286 | size_t out_len) |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 287 | { |
Kevin Peng | 96f802e | 2019-12-26 16:10:25 +0800 | [diff] [blame] | 288 | #ifdef TFM_CRYPTO_MAC_MODULE_DISABLED |
Antonio de Angelis | 7740b38 | 2019-07-16 10:59:25 +0100 | [diff] [blame] | 289 | return PSA_ERROR_NOT_SUPPORTED; |
| 290 | #else |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 291 | psa_status_t status = PSA_SUCCESS; |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 292 | psa_mac_operation_t *operation = NULL; |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 293 | |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 294 | if ((in_len != 1) || (out_len != 1)) { |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 295 | return PSA_ERROR_CONNECTION_REFUSED; |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 296 | } |
| 297 | |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 298 | if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) || |
| 299 | (out_vec[0].len != sizeof(uint32_t))) { |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 300 | return PSA_ERROR_CONNECTION_REFUSED; |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 301 | } |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 302 | const struct tfm_crypto_pack_iovec *iov = in_vec[0].base; |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 303 | uint32_t handle = iov->op_handle; |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 304 | uint32_t *handle_out = out_vec[0].base; |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 305 | |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 306 | /* Init the handle in the operation with the one passed from the iov */ |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 307 | *handle_out = iov->op_handle; |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 308 | |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 309 | /* Look up the corresponding operation context */ |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 310 | status = tfm_crypto_operation_lookup(TFM_CRYPTO_MAC_OPERATION, |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 311 | handle, |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 312 | (void **)&operation); |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 313 | if (status != PSA_SUCCESS) { |
Antonio de Angelis | 25e2b2d | 2019-04-25 14:49:50 +0100 | [diff] [blame] | 314 | /* Operation does not exist, so abort has no effect */ |
| 315 | return PSA_SUCCESS; |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 316 | } |
| 317 | |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 318 | status = psa_mac_abort(operation); |
| 319 | |
| 320 | if (status != PSA_SUCCESS) { |
| 321 | /* Release the operation context, ignore if the operation fails. */ |
| 322 | (void)tfm_crypto_operation_release(handle_out); |
| 323 | return status; |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 324 | } |
| 325 | |
Jamie Fox | 0e54ebc | 2019-04-09 14:21:04 +0100 | [diff] [blame] | 326 | status = tfm_crypto_operation_release(handle_out); |
| 327 | |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 328 | return status; |
Antonio de Angelis | 7740b38 | 2019-07-16 10:59:25 +0100 | [diff] [blame] | 329 | #endif /* TFM_CRYPTO_MAC_MODULE_DISABLED */ |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 330 | } |
Antonio de Angelis | 04debbd | 2019-10-14 12:12:52 +0100 | [diff] [blame^] | 331 | |
| 332 | psa_status_t tfm_crypto_mac_compute(psa_invec in_vec[], |
| 333 | size_t in_len, |
| 334 | psa_outvec out_vec[], |
| 335 | size_t out_len) |
| 336 | { |
| 337 | /* FixMe: To be implemented */ |
| 338 | return PSA_ERROR_NOT_SUPPORTED; |
| 339 | } |
| 340 | |
| 341 | psa_status_t tfm_crypto_mac_verify(psa_invec in_vec[], |
| 342 | size_t in_len, |
| 343 | psa_outvec out_vec[], |
| 344 | size_t out_len) |
| 345 | { |
| 346 | /* FixMe: To be implemented */ |
| 347 | return PSA_ERROR_NOT_SUPPORTED; |
| 348 | } |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 349 | /*!@}*/ |