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