blob: 4d3480148fdfe07aa37af9cf09f3a64490f250fe [file] [log] [blame]
Antonio de Angelisa6f72162018-09-05 11:00:37 +01001/*
Antonio de Angelis04debbd2019-10-14 12:12:52 +01002 * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
Antonio de Angelisa6f72162018-09-05 11:00:37 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
Jamie Fox0e54ebc2019-04-09 14:21:04 +01008#include <stddef.h>
9#include <stdint.h>
Antonio de Angelisa6f72162018-09-05 11:00:37 +010010
Jamie Fox0e54ebc2019-04-09 14:21:04 +010011#include "tfm_mbedcrypto_include.h"
Antonio de Angelis4743e672019-04-11 11:38:48 +010012
Jamie Fox0e54ebc2019-04-09 14:21:04 +010013#include "tfm_crypto_api.h"
14#include "tfm_crypto_defs.h"
Soby Mathewd8abdfd2020-10-14 10:28:01 +010015#include "tfm_crypto_private.h"
Jamie Fox0ff04ba2019-02-05 14:19:07 +000016
Antonio de Angelisa6f72162018-09-05 11:00:37 +010017/*!
18 * \defgroup public_psa Public functions, PSA
19 *
20 */
21
22/*!@{*/
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000023psa_status_t tfm_crypto_hash_setup(psa_invec in_vec[],
24 size_t in_len,
25 psa_outvec out_vec[],
26 size_t out_len)
Antonio de Angelisa6f72162018-09-05 11:00:37 +010027{
Kevin Peng96f802e2019-12-26 16:10:25 +080028#ifdef TFM_CRYPTO_HASH_MODULE_DISABLED
Antonio de Angelis7740b382019-07-16 10:59:25 +010029 return PSA_ERROR_NOT_SUPPORTED;
30#else
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010031 psa_status_t status = PSA_SUCCESS;
Jamie Fox0e54ebc2019-04-09 14:21:04 +010032 psa_hash_operation_t *operation = NULL;
Antonio de Angelisa6f72162018-09-05 11:00:37 +010033
Soby Mathewd8abdfd2020-10-14 10:28:01 +010034 CRYPTO_IN_OUT_LEN_VALIDATE(in_len, 1, 1, out_len, 1, 1);
Antonio de Angelisa6f72162018-09-05 11:00:37 +010035
Antonio de Angelis4743e672019-04-11 11:38:48 +010036 if ((out_vec[0].len != sizeof(uint32_t)) ||
37 (in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec))) {
Soby Mathewc6e89362020-10-19 16:55:16 +010038 return PSA_ERROR_PROGRAMMER_ERROR;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000039 }
Antonio de Angelis4743e672019-04-11 11:38:48 +010040 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
Jamie Fox0e54ebc2019-04-09 14:21:04 +010041 uint32_t handle = iov->op_handle;
Antonio de Angelis4743e672019-04-11 11:38:48 +010042 uint32_t *handle_out = out_vec[0].base;
43 psa_algorithm_t alg = iov->alg;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000044
Antonio de Angelis4743e672019-04-11 11:38:48 +010045 /* Init the handle in the operation with the one passed from the iov */
Jamie Fox0e54ebc2019-04-09 14:21:04 +010046 *handle_out = iov->op_handle;
Antonio de Angelisa6f72162018-09-05 11:00:37 +010047
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010048 /* Allocate the operation context in the secure world */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000049 status = tfm_crypto_operation_alloc(TFM_CRYPTO_HASH_OPERATION,
Antonio de Angelis4743e672019-04-11 11:38:48 +010050 &handle,
Jamie Fox0e54ebc2019-04-09 14:21:04 +010051 (void **)&operation);
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000052 if (status != PSA_SUCCESS) {
53 return status;
Antonio de Angelisa6f72162018-09-05 11:00:37 +010054 }
55
Antonio de Angelis4743e672019-04-11 11:38:48 +010056 *handle_out = handle;
57
Jamie Fox0e54ebc2019-04-09 14:21:04 +010058 status = psa_hash_setup(operation, alg);
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010059 if (status != PSA_SUCCESS) {
Hugues de Valon8b442442019-02-19 14:30:52 +000060 /* Release the operation context, ignore if the operation fails. */
Jamie Fox0e54ebc2019-04-09 14:21:04 +010061 (void)tfm_crypto_operation_release(handle_out);
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000062 return status;
Antonio de Angelisa6f72162018-09-05 11:00:37 +010063 }
64
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000065 return PSA_SUCCESS;
Antonio de Angelis7740b382019-07-16 10:59:25 +010066#endif /* TFM_CRYPTO_HASH_MODULE_DISABLED */
Antonio de Angelisa6f72162018-09-05 11:00:37 +010067}
68
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000069psa_status_t tfm_crypto_hash_update(psa_invec in_vec[],
70 size_t in_len,
71 psa_outvec out_vec[],
72 size_t out_len)
Antonio de Angelisa6f72162018-09-05 11:00:37 +010073{
Kevin Peng96f802e2019-12-26 16:10:25 +080074#ifdef TFM_CRYPTO_HASH_MODULE_DISABLED
Antonio de Angelis7740b382019-07-16 10:59:25 +010075 return PSA_ERROR_NOT_SUPPORTED;
76#else
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010077 psa_status_t status = PSA_SUCCESS;
Jamie Fox0e54ebc2019-04-09 14:21:04 +010078 psa_hash_operation_t *operation = NULL;
Antonio de Angelisa6f72162018-09-05 11:00:37 +010079
Soby Mathewd8abdfd2020-10-14 10:28:01 +010080 CRYPTO_IN_OUT_LEN_VALIDATE(in_len, 1, 2, out_len, 1, 1);
Antonio de Angelisa6f72162018-09-05 11:00:37 +010081
Antonio de Angelis4743e672019-04-11 11:38:48 +010082 if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) ||
83 (out_vec[0].len != sizeof(uint32_t))) {
Soby Mathewc6e89362020-10-19 16:55:16 +010084 return PSA_ERROR_PROGRAMMER_ERROR;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000085 }
Antonio de Angelis4743e672019-04-11 11:38:48 +010086 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
Jamie Fox0e54ebc2019-04-09 14:21:04 +010087 uint32_t handle = iov->op_handle;
Antonio de Angelis4743e672019-04-11 11:38:48 +010088 uint32_t *handle_out = out_vec[0].base;
89 const uint8_t *input = in_vec[1].base;
90 size_t input_length = in_vec[1].len;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000091
Antonio de Angelis4743e672019-04-11 11:38:48 +010092 /* Init the handle in the operation with the one passed from the iov */
Jamie Fox0e54ebc2019-04-09 14:21:04 +010093 *handle_out = iov->op_handle;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000094
Antonio de Angelisa6f72162018-09-05 11:00:37 +010095 /* Look up the corresponding operation context */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000096 status = tfm_crypto_operation_lookup(TFM_CRYPTO_HASH_OPERATION,
Antonio de Angelis4743e672019-04-11 11:38:48 +010097 handle,
Jamie Fox0e54ebc2019-04-09 14:21:04 +010098 (void **)&operation);
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000099 if (status != PSA_SUCCESS) {
100 return status;
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100101 }
102
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100103 status = psa_hash_update(operation, input, input_length);
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100104 if (status != PSA_SUCCESS) {
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100105 /* Release the operation context, ignore if the operation fails. */
106 (void)tfm_crypto_operation_release(handle_out);
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000107 return status;
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100108 }
109
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000110 return PSA_SUCCESS;
Antonio de Angelis7740b382019-07-16 10:59:25 +0100111#endif /* TFM_CRYPTO_HASH_MODULE_DISABLED */
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100112}
113
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000114psa_status_t tfm_crypto_hash_finish(psa_invec in_vec[],
115 size_t in_len,
116 psa_outvec out_vec[],
117 size_t out_len)
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100118{
Kevin Peng96f802e2019-12-26 16:10:25 +0800119#ifdef TFM_CRYPTO_HASH_MODULE_DISABLED
Antonio de Angelis7740b382019-07-16 10:59:25 +0100120 return PSA_ERROR_NOT_SUPPORTED;
121#else
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100122 psa_status_t status = PSA_SUCCESS;
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100123 psa_hash_operation_t *operation = NULL;
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100124
Soby Mathewd8abdfd2020-10-14 10:28:01 +0100125 CRYPTO_IN_OUT_LEN_VALIDATE(in_len, 1, 1, out_len, 1, 2);
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100126
Antonio de Angelis4743e672019-04-11 11:38:48 +0100127 if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) ||
128 (out_vec[0].len != sizeof(uint32_t))) {
Soby Mathewc6e89362020-10-19 16:55:16 +0100129 return PSA_ERROR_PROGRAMMER_ERROR;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000130 }
Antonio de Angelis4743e672019-04-11 11:38:48 +0100131 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100132 uint32_t handle = iov->op_handle;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100133 uint32_t *handle_out = out_vec[0].base;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000134 uint8_t *hash = out_vec[1].base;
135 size_t hash_size = out_vec[1].len;
136
Antonio de Angelis4743e672019-04-11 11:38:48 +0100137 /* Init the handle in the operation with the one passed from the iov */
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100138 *handle_out = iov->op_handle;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100139
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000140 /* Initialise hash_length to zero */
141 out_vec[1].len = 0;
142
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100143 /* Look up the corresponding operation context */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000144 status = tfm_crypto_operation_lookup(TFM_CRYPTO_HASH_OPERATION,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100145 handle,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100146 (void **)&operation);
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000147 if (status != PSA_SUCCESS) {
148 return status;
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100149 }
150
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100151 status = psa_hash_finish(operation, hash, hash_size, &out_vec[1].len);
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100152 if (status != PSA_SUCCESS) {
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100153 /* Release the operation context, ignore if the operation fails. */
154 (void)tfm_crypto_operation_release(handle_out);
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000155 return status;
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100156 }
157
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100158 status = tfm_crypto_operation_release(handle_out);
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000159
160 return status;
Antonio de Angelis7740b382019-07-16 10:59:25 +0100161#endif /* TFM_CRYPTO_HASH_MODULE_DISABLED */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000162}
163
164psa_status_t tfm_crypto_hash_verify(psa_invec in_vec[],
165 size_t in_len,
166 psa_outvec out_vec[],
167 size_t out_len)
168{
Kevin Peng96f802e2019-12-26 16:10:25 +0800169#ifdef TFM_CRYPTO_HASH_MODULE_DISABLED
Antonio de Angelis7740b382019-07-16 10:59:25 +0100170 return PSA_ERROR_NOT_SUPPORTED;
171#else
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000172 psa_status_t status = PSA_SUCCESS;
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100173 psa_hash_operation_t *operation = NULL;
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100174
Soby Mathewd8abdfd2020-10-14 10:28:01 +0100175 CRYPTO_IN_OUT_LEN_VALIDATE(in_len, 1, 2, out_len, 1, 1);
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100176
Antonio de Angelis4743e672019-04-11 11:38:48 +0100177 if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) ||
178 (out_vec[0].len != sizeof(uint32_t))) {
Soby Mathewc6e89362020-10-19 16:55:16 +0100179 return PSA_ERROR_PROGRAMMER_ERROR;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000180 }
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100181 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
182 uint32_t handle = iov->op_handle;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100183 uint32_t *handle_out = out_vec[0].base;
184 const uint8_t *hash = in_vec[1].base;
185 size_t hash_length = in_vec[1].len;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000186
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100187 /* Init the handle in the operation with the one passed from the iov */
188 *handle_out = iov->op_handle;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000189
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100190 /* Look up the corresponding operation context */
191 status = tfm_crypto_operation_lookup(TFM_CRYPTO_HASH_OPERATION,
192 handle,
193 (void **)&operation);
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000194 if (status != PSA_SUCCESS) {
195 return status;
196 }
197
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100198 status = psa_hash_verify(operation, hash, hash_length);
199 if (status != PSA_SUCCESS) {
200 /* Release the operation context, ignore if the operation fails. */
201 (void)tfm_crypto_operation_release(handle_out);
202 return status;
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100203 }
204
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100205 status = tfm_crypto_operation_release(handle_out);
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100206
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100207 return status;
Antonio de Angelis7740b382019-07-16 10:59:25 +0100208#endif /* TFM_CRYPTO_HASH_MODULE_DISABLED */
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100209}
210
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000211psa_status_t tfm_crypto_hash_abort(psa_invec in_vec[],
212 size_t in_len,
213 psa_outvec out_vec[],
214 size_t out_len)
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100215{
Kevin Peng96f802e2019-12-26 16:10:25 +0800216#ifdef TFM_CRYPTO_HASH_MODULE_DISABLED
Antonio de Angelis7740b382019-07-16 10:59:25 +0100217 return PSA_ERROR_NOT_SUPPORTED;
218#else
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000219 psa_status_t status = PSA_SUCCESS;
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100220 psa_hash_operation_t *operation = NULL;
Antonio de Angelis377a1552018-11-22 17:02:40 +0000221
Soby Mathewd8abdfd2020-10-14 10:28:01 +0100222 CRYPTO_IN_OUT_LEN_VALIDATE(in_len, 1, 1, out_len, 1, 1);
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100223
Antonio de Angelis4743e672019-04-11 11:38:48 +0100224 if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) ||
225 (out_vec[0].len != sizeof(uint32_t))) {
Soby Mathewc6e89362020-10-19 16:55:16 +0100226 return PSA_ERROR_PROGRAMMER_ERROR;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000227 }
Antonio de Angelis4743e672019-04-11 11:38:48 +0100228 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100229 uint32_t handle = iov->op_handle;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100230 uint32_t *handle_out = out_vec[0].base;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000231
Antonio de Angelis4743e672019-04-11 11:38:48 +0100232 /* Init the handle in the operation with the one passed from the iov */
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100233 *handle_out = iov->op_handle;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000234
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100235 /* Look up the corresponding operation context */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000236 status = tfm_crypto_operation_lookup(TFM_CRYPTO_HASH_OPERATION,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100237 handle,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100238 (void **)&operation);
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000239 if (status != PSA_SUCCESS) {
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100240 /* Operation does not exist, so abort has no effect */
241 return PSA_SUCCESS;
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100242 }
243
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100244 status = psa_hash_abort(operation);
245 if (status != PSA_SUCCESS) {
246 /* Release the operation context, ignore if the operation fails. */
247 (void)tfm_crypto_operation_release(handle_out);
248 return status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100249 }
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100250
251 status = tfm_crypto_operation_release(handle_out);
252
Antonio de Angelis4743e672019-04-11 11:38:48 +0100253 return status;
Antonio de Angelis7740b382019-07-16 10:59:25 +0100254#endif /* TFM_CRYPTO_HASH_MODULE_DISABLED */
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100255}
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100256
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100257psa_status_t tfm_crypto_hash_clone(psa_invec in_vec[],
258 size_t in_len,
259 psa_outvec out_vec[],
260 size_t out_len)
261{
Kevin Peng96f802e2019-12-26 16:10:25 +0800262#ifdef TFM_CRYPTO_HASH_MODULE_DISABLED
Antonio de Angelis7740b382019-07-16 10:59:25 +0100263 return PSA_ERROR_NOT_SUPPORTED;
264#else
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100265 psa_status_t status = PSA_SUCCESS;
266 psa_hash_operation_t *source_operation = NULL;
267 psa_hash_operation_t *target_operation = NULL;
268
Soby Mathewd8abdfd2020-10-14 10:28:01 +0100269 CRYPTO_IN_OUT_LEN_VALIDATE(in_len, 1, 1, out_len, 1, 1);
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100270
271 if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) ||
272 (out_vec[0].len != sizeof(uint32_t))) {
Soby Mathewc6e89362020-10-19 16:55:16 +0100273 return PSA_ERROR_PROGRAMMER_ERROR;
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100274 }
275 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
276 uint32_t source_handle = iov->op_handle;
277 uint32_t *target_handle = out_vec[0].base;
278
279 /* Look up the corresponding source operation context */
280 status = tfm_crypto_operation_lookup(TFM_CRYPTO_HASH_OPERATION,
281 source_handle,
282 (void **)&source_operation);
283 if (status != PSA_SUCCESS) {
284 return status;
285 }
286
287 /* Allocate the target operation context in the secure world */
288 status = tfm_crypto_operation_alloc(TFM_CRYPTO_HASH_OPERATION,
289 target_handle,
290 (void **)&target_operation);
291 if (status != PSA_SUCCESS) {
292 return status;
293 }
294
295 status = psa_hash_clone(source_operation, target_operation);
296 if (status != PSA_SUCCESS) {
297 /* Release the target operation context, ignore if it fails. */
298 (void)tfm_crypto_operation_release(target_handle);
299 return status;
300 }
301
302 return status;
Antonio de Angelis7740b382019-07-16 10:59:25 +0100303#endif /* TFM_CRYPTO_HASH_MODULE_DISABLED */
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100304}
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100305
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100306psa_status_t tfm_crypto_hash_compute(psa_invec in_vec[],
307 size_t in_len,
308 psa_outvec out_vec[],
309 size_t out_len)
310{
Soby Mathew07ef6e42020-07-20 21:09:23 +0100311#ifdef TFM_CRYPTO_HASH_MODULE_DISABLED
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100312 return PSA_ERROR_NOT_SUPPORTED;
Soby Mathew07ef6e42020-07-20 21:09:23 +0100313#else
Soby Mathewd8abdfd2020-10-14 10:28:01 +0100314
315 CRYPTO_IN_OUT_LEN_VALIDATE(in_len, 1, 2, out_len, 0, 1);
Soby Mathew07ef6e42020-07-20 21:09:23 +0100316
317 if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec))) {
Soby Mathewc6e89362020-10-19 16:55:16 +0100318 return PSA_ERROR_PROGRAMMER_ERROR;
Soby Mathew07ef6e42020-07-20 21:09:23 +0100319 }
320
321 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
322 psa_algorithm_t alg = iov->alg;
323 const uint8_t *input = in_vec[1].base;
324 size_t input_length = in_vec[1].len;
325 uint8_t *hash = out_vec[0].base;
326 size_t hash_size = out_vec[0].len;
327
328 /* Initialize hash_length to zero */
329 out_vec[0].len = 0;
330 return psa_hash_compute(alg, input, input_length, hash, hash_size,
331 &out_vec[0].len);
332#endif /* TFM_CRYPTO_HASH_MODULE_DISABLED */
333}
334
335psa_status_t tfm_crypto_hash_compare(psa_invec in_vec[],
336 size_t in_len,
337 psa_outvec out_vec[],
338 size_t out_len)
339{
340#ifdef TFM_CRYPTO_HASH_MODULE_DISABLED
341 return PSA_ERROR_NOT_SUPPORTED;
342#else
Soby Mathewd8abdfd2020-10-14 10:28:01 +0100343
344 CRYPTO_IN_OUT_LEN_VALIDATE(in_len, 1, 3, out_len, 0, 0);
Soby Mathew07ef6e42020-07-20 21:09:23 +0100345
346 if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec))) {
Soby Mathewc6e89362020-10-19 16:55:16 +0100347 return PSA_ERROR_PROGRAMMER_ERROR;
Soby Mathew07ef6e42020-07-20 21:09:23 +0100348 }
349
350 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
351 psa_algorithm_t alg = iov->alg;
352 const uint8_t *input = in_vec[1].base;
353 size_t input_length = in_vec[1].len;
354 const uint8_t *hash = in_vec[2].base;
355 size_t hash_length = in_vec[2].len;
356
357 return psa_hash_compare(alg, input, input_length, hash, hash_length);
358#endif /* TFM_CRYPTO_HASH_MODULE_DISABLED */
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100359}
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100360/*!@}*/