blob: 6c2d27aa7095b5844b6bdea2e6ed2042dcb12ee2 [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 Angelisa6f72162018-09-05 11:00:37 +010062 }
63
David Hu7e2e5232021-04-21 16:52:07 +080064 return status;
Antonio de Angelis7740b382019-07-16 10:59:25 +010065#endif /* TFM_CRYPTO_HASH_MODULE_DISABLED */
Antonio de Angelisa6f72162018-09-05 11:00:37 +010066}
67
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000068psa_status_t tfm_crypto_hash_update(psa_invec in_vec[],
69 size_t in_len,
70 psa_outvec out_vec[],
71 size_t out_len)
Antonio de Angelisa6f72162018-09-05 11:00:37 +010072{
Kevin Peng96f802e2019-12-26 16:10:25 +080073#ifdef TFM_CRYPTO_HASH_MODULE_DISABLED
Antonio de Angelis7740b382019-07-16 10:59:25 +010074 return PSA_ERROR_NOT_SUPPORTED;
75#else
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010076 psa_status_t status = PSA_SUCCESS;
Jamie Fox0e54ebc2019-04-09 14:21:04 +010077 psa_hash_operation_t *operation = NULL;
Antonio de Angelisa6f72162018-09-05 11:00:37 +010078
Soby Mathewd8abdfd2020-10-14 10:28:01 +010079 CRYPTO_IN_OUT_LEN_VALIDATE(in_len, 1, 2, out_len, 1, 1);
Antonio de Angelisa6f72162018-09-05 11:00:37 +010080
Antonio de Angelis4743e672019-04-11 11:38:48 +010081 if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) ||
82 (out_vec[0].len != sizeof(uint32_t))) {
Soby Mathewc6e89362020-10-19 16:55:16 +010083 return PSA_ERROR_PROGRAMMER_ERROR;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000084 }
Antonio de Angelis4743e672019-04-11 11:38:48 +010085 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
Jamie Fox0e54ebc2019-04-09 14:21:04 +010086 uint32_t handle = iov->op_handle;
Antonio de Angelis4743e672019-04-11 11:38:48 +010087 uint32_t *handle_out = out_vec[0].base;
88 const uint8_t *input = in_vec[1].base;
89 size_t input_length = in_vec[1].len;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000090
Antonio de Angelis4743e672019-04-11 11:38:48 +010091 /* Init the handle in the operation with the one passed from the iov */
Jamie Fox0e54ebc2019-04-09 14:21:04 +010092 *handle_out = iov->op_handle;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000093
Antonio de Angelisa6f72162018-09-05 11:00:37 +010094 /* Look up the corresponding operation context */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000095 status = tfm_crypto_operation_lookup(TFM_CRYPTO_HASH_OPERATION,
Antonio de Angelis4743e672019-04-11 11:38:48 +010096 handle,
Jamie Fox0e54ebc2019-04-09 14:21:04 +010097 (void **)&operation);
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000098 if (status != PSA_SUCCESS) {
99 return status;
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100100 }
101
David Hu7e2e5232021-04-21 16:52:07 +0800102 return psa_hash_update(operation, input, input_length);
Antonio de Angelis7740b382019-07-16 10:59:25 +0100103#endif /* TFM_CRYPTO_HASH_MODULE_DISABLED */
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100104}
105
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000106psa_status_t tfm_crypto_hash_finish(psa_invec in_vec[],
107 size_t in_len,
108 psa_outvec out_vec[],
109 size_t out_len)
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100110{
Kevin Peng96f802e2019-12-26 16:10:25 +0800111#ifdef TFM_CRYPTO_HASH_MODULE_DISABLED
Antonio de Angelis7740b382019-07-16 10:59:25 +0100112 return PSA_ERROR_NOT_SUPPORTED;
113#else
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100114 psa_status_t status = PSA_SUCCESS;
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100115 psa_hash_operation_t *operation = NULL;
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100116
Soby Mathewd8abdfd2020-10-14 10:28:01 +0100117 CRYPTO_IN_OUT_LEN_VALIDATE(in_len, 1, 1, out_len, 1, 2);
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100118
Antonio de Angelis4743e672019-04-11 11:38:48 +0100119 if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) ||
120 (out_vec[0].len != sizeof(uint32_t))) {
Soby Mathewc6e89362020-10-19 16:55:16 +0100121 return PSA_ERROR_PROGRAMMER_ERROR;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000122 }
Antonio de Angelis4743e672019-04-11 11:38:48 +0100123 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100124 uint32_t handle = iov->op_handle;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100125 uint32_t *handle_out = out_vec[0].base;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000126 uint8_t *hash = out_vec[1].base;
127 size_t hash_size = out_vec[1].len;
128
Antonio de Angelis4743e672019-04-11 11:38:48 +0100129 /* Init the handle in the operation with the one passed from the iov */
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100130 *handle_out = iov->op_handle;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100131
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000132 /* Initialise hash_length to zero */
133 out_vec[1].len = 0;
134
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100135 /* Look up the corresponding operation context */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000136 status = tfm_crypto_operation_lookup(TFM_CRYPTO_HASH_OPERATION,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100137 handle,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100138 (void **)&operation);
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000139 if (status != PSA_SUCCESS) {
140 return status;
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100141 }
142
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100143 status = psa_hash_finish(operation, hash, hash_size, &out_vec[1].len);
David Hu7e2e5232021-04-21 16:52:07 +0800144 if (status == PSA_SUCCESS) {
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100145 /* Release the operation context, ignore if the operation fails. */
146 (void)tfm_crypto_operation_release(handle_out);
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100147 }
148
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000149 return status;
Antonio de Angelis7740b382019-07-16 10:59:25 +0100150#endif /* TFM_CRYPTO_HASH_MODULE_DISABLED */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000151}
152
153psa_status_t tfm_crypto_hash_verify(psa_invec in_vec[],
154 size_t in_len,
155 psa_outvec out_vec[],
156 size_t out_len)
157{
Kevin Peng96f802e2019-12-26 16:10:25 +0800158#ifdef TFM_CRYPTO_HASH_MODULE_DISABLED
Antonio de Angelis7740b382019-07-16 10:59:25 +0100159 return PSA_ERROR_NOT_SUPPORTED;
160#else
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000161 psa_status_t status = PSA_SUCCESS;
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100162 psa_hash_operation_t *operation = NULL;
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100163
Soby Mathewd8abdfd2020-10-14 10:28:01 +0100164 CRYPTO_IN_OUT_LEN_VALIDATE(in_len, 1, 2, out_len, 1, 1);
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100165
Antonio de Angelis4743e672019-04-11 11:38:48 +0100166 if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) ||
167 (out_vec[0].len != sizeof(uint32_t))) {
Soby Mathewc6e89362020-10-19 16:55:16 +0100168 return PSA_ERROR_PROGRAMMER_ERROR;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000169 }
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100170 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
171 uint32_t handle = iov->op_handle;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100172 uint32_t *handle_out = out_vec[0].base;
173 const uint8_t *hash = in_vec[1].base;
174 size_t hash_length = in_vec[1].len;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000175
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100176 /* Init the handle in the operation with the one passed from the iov */
177 *handle_out = iov->op_handle;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000178
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100179 /* Look up the corresponding operation context */
180 status = tfm_crypto_operation_lookup(TFM_CRYPTO_HASH_OPERATION,
181 handle,
182 (void **)&operation);
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000183 if (status != PSA_SUCCESS) {
184 return status;
185 }
186
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100187 status = psa_hash_verify(operation, hash, hash_length);
David Hu7e2e5232021-04-21 16:52:07 +0800188 if (status == PSA_SUCCESS) {
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100189 /* Release the operation context, ignore if the operation fails. */
190 (void)tfm_crypto_operation_release(handle_out);
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100191 }
192
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100193 return status;
Antonio de Angelis7740b382019-07-16 10:59:25 +0100194#endif /* TFM_CRYPTO_HASH_MODULE_DISABLED */
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100195}
196
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000197psa_status_t tfm_crypto_hash_abort(psa_invec in_vec[],
198 size_t in_len,
199 psa_outvec out_vec[],
200 size_t out_len)
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100201{
Kevin Peng96f802e2019-12-26 16:10:25 +0800202#ifdef TFM_CRYPTO_HASH_MODULE_DISABLED
Antonio de Angelis7740b382019-07-16 10:59:25 +0100203 return PSA_ERROR_NOT_SUPPORTED;
204#else
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000205 psa_status_t status = PSA_SUCCESS;
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100206 psa_hash_operation_t *operation = NULL;
Antonio de Angelis377a1552018-11-22 17:02:40 +0000207
Soby Mathewd8abdfd2020-10-14 10:28:01 +0100208 CRYPTO_IN_OUT_LEN_VALIDATE(in_len, 1, 1, out_len, 1, 1);
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100209
Antonio de Angelis4743e672019-04-11 11:38:48 +0100210 if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) ||
211 (out_vec[0].len != sizeof(uint32_t))) {
Soby Mathewc6e89362020-10-19 16:55:16 +0100212 return PSA_ERROR_PROGRAMMER_ERROR;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000213 }
Antonio de Angelis4743e672019-04-11 11:38:48 +0100214 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100215 uint32_t handle = iov->op_handle;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100216 uint32_t *handle_out = out_vec[0].base;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000217
Antonio de Angelis4743e672019-04-11 11:38:48 +0100218 /* Init the handle in the operation with the one passed from the iov */
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100219 *handle_out = iov->op_handle;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000220
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100221 /* Look up the corresponding operation context */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000222 status = tfm_crypto_operation_lookup(TFM_CRYPTO_HASH_OPERATION,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100223 handle,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100224 (void **)&operation);
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000225 if (status != PSA_SUCCESS) {
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100226 /* Operation does not exist, so abort has no effect */
227 return PSA_SUCCESS;
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100228 }
229
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100230 status = psa_hash_abort(operation);
231 if (status != PSA_SUCCESS) {
232 /* Release the operation context, ignore if the operation fails. */
233 (void)tfm_crypto_operation_release(handle_out);
234 return status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100235 }
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100236
David Hu7e2e5232021-04-21 16:52:07 +0800237 return tfm_crypto_operation_release(handle_out);
Antonio de Angelis7740b382019-07-16 10:59:25 +0100238#endif /* TFM_CRYPTO_HASH_MODULE_DISABLED */
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100239}
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100240
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100241psa_status_t tfm_crypto_hash_clone(psa_invec in_vec[],
242 size_t in_len,
243 psa_outvec out_vec[],
244 size_t out_len)
245{
Kevin Peng96f802e2019-12-26 16:10:25 +0800246#ifdef TFM_CRYPTO_HASH_MODULE_DISABLED
Antonio de Angelis7740b382019-07-16 10:59:25 +0100247 return PSA_ERROR_NOT_SUPPORTED;
248#else
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100249 psa_status_t status = PSA_SUCCESS;
250 psa_hash_operation_t *source_operation = NULL;
251 psa_hash_operation_t *target_operation = NULL;
252
Soby Mathewd8abdfd2020-10-14 10:28:01 +0100253 CRYPTO_IN_OUT_LEN_VALIDATE(in_len, 1, 1, out_len, 1, 1);
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100254
255 if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) ||
256 (out_vec[0].len != sizeof(uint32_t))) {
Soby Mathewc6e89362020-10-19 16:55:16 +0100257 return PSA_ERROR_PROGRAMMER_ERROR;
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100258 }
259 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
260 uint32_t source_handle = iov->op_handle;
261 uint32_t *target_handle = out_vec[0].base;
262
263 /* Look up the corresponding source operation context */
264 status = tfm_crypto_operation_lookup(TFM_CRYPTO_HASH_OPERATION,
265 source_handle,
266 (void **)&source_operation);
267 if (status != PSA_SUCCESS) {
268 return status;
269 }
270
271 /* Allocate the target operation context in the secure world */
272 status = tfm_crypto_operation_alloc(TFM_CRYPTO_HASH_OPERATION,
273 target_handle,
274 (void **)&target_operation);
275 if (status != PSA_SUCCESS) {
276 return status;
277 }
278
David Hu7e2e5232021-04-21 16:52:07 +0800279 return psa_hash_clone(source_operation, target_operation);
Antonio de Angelis7740b382019-07-16 10:59:25 +0100280#endif /* TFM_CRYPTO_HASH_MODULE_DISABLED */
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100281}
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100282
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100283psa_status_t tfm_crypto_hash_compute(psa_invec in_vec[],
284 size_t in_len,
285 psa_outvec out_vec[],
286 size_t out_len)
287{
Soby Mathew07ef6e42020-07-20 21:09:23 +0100288#ifdef TFM_CRYPTO_HASH_MODULE_DISABLED
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100289 return PSA_ERROR_NOT_SUPPORTED;
Soby Mathew07ef6e42020-07-20 21:09:23 +0100290#else
Soby Mathewd8abdfd2020-10-14 10:28:01 +0100291
292 CRYPTO_IN_OUT_LEN_VALIDATE(in_len, 1, 2, out_len, 0, 1);
Soby Mathew07ef6e42020-07-20 21:09:23 +0100293
294 if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec))) {
Soby Mathewc6e89362020-10-19 16:55:16 +0100295 return PSA_ERROR_PROGRAMMER_ERROR;
Soby Mathew07ef6e42020-07-20 21:09:23 +0100296 }
297
298 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
299 psa_algorithm_t alg = iov->alg;
300 const uint8_t *input = in_vec[1].base;
301 size_t input_length = in_vec[1].len;
302 uint8_t *hash = out_vec[0].base;
303 size_t hash_size = out_vec[0].len;
304
305 /* Initialize hash_length to zero */
306 out_vec[0].len = 0;
307 return psa_hash_compute(alg, input, input_length, hash, hash_size,
308 &out_vec[0].len);
309#endif /* TFM_CRYPTO_HASH_MODULE_DISABLED */
310}
311
312psa_status_t tfm_crypto_hash_compare(psa_invec in_vec[],
313 size_t in_len,
314 psa_outvec out_vec[],
315 size_t out_len)
316{
317#ifdef TFM_CRYPTO_HASH_MODULE_DISABLED
318 return PSA_ERROR_NOT_SUPPORTED;
319#else
Soby Mathewd8abdfd2020-10-14 10:28:01 +0100320
321 CRYPTO_IN_OUT_LEN_VALIDATE(in_len, 1, 3, out_len, 0, 0);
Soby Mathew07ef6e42020-07-20 21:09:23 +0100322
323 if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec))) {
Soby Mathewc6e89362020-10-19 16:55:16 +0100324 return PSA_ERROR_PROGRAMMER_ERROR;
Soby Mathew07ef6e42020-07-20 21:09:23 +0100325 }
326
327 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
328 psa_algorithm_t alg = iov->alg;
329 const uint8_t *input = in_vec[1].base;
330 size_t input_length = in_vec[1].len;
331 const uint8_t *hash = in_vec[2].base;
332 size_t hash_length = in_vec[2].len;
333
334 return psa_hash_compare(alg, input, input_length, hash, hash_length);
335#endif /* TFM_CRYPTO_HASH_MODULE_DISABLED */
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100336}
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100337/*!@}*/