blob: 90256fc4ea7c7afd5eedd5163b64d47a30785b05 [file] [log] [blame]
Steven Cooreman37941cb2020-07-28 18:49:51 +02001/*
2 * Test driver for cipher functions.
3 * Currently only supports multi-part operations using AES-CTR.
4 */
Steven Cooreman3ec40182020-09-02 16:27:46 +02005/* Copyright The Mbed TLS Contributors
Dave Rodgman16799db2023-11-02 19:47:20 +00006 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Steven Cooreman37941cb2020-07-28 18:49:51 +02007 */
8
Mateusz Starzyk2c09c9b2021-05-14 22:20:10 +02009#include <test/helpers.h>
10
Ronald Crone6e6b752023-01-16 16:56:51 +010011#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooreman37941cb2020-07-28 18:49:51 +020012#include "psa/crypto.h"
Ronald Cron8d310ad2020-12-15 15:17:20 +010013#include "psa_crypto_cipher.h"
Steven Cooremanacb5a102020-09-08 14:06:57 +020014#include "psa_crypto_core.h"
Steven Cooreman37941cb2020-07-28 18:49:51 +020015#include "mbedtls/cipher.h"
16
Steven Cooremanacb5a102020-09-08 14:06:57 +020017#include "test/drivers/cipher.h"
Steven Cooreman37941cb2020-07-28 18:49:51 +020018
19#include "test/random.h"
20
Ronald Cron7975fae2021-09-13 14:50:42 +020021#if defined(MBEDTLS_TEST_LIBTESTDRIVER1)
David Horstmann0d8287c2024-07-26 18:01:04 +010022#if MBEDTLS_VERSION_MAJOR < 4
23#include "libtestdriver1/library/psa_crypto_cipher.h"
24#else
Ronald Cron69c489c2024-07-31 08:36:59 +020025#include "libtestdriver1/tf-psa-crypto/drivers/builtin/src/psa_crypto_cipher.h"
Ronald Cron7975fae2021-09-13 14:50:42 +020026#endif
David Horstmann0d8287c2024-07-26 18:01:04 +010027#endif
Ronald Cron7975fae2021-09-13 14:50:42 +020028
Steven Cooreman37941cb2020-07-28 18:49:51 +020029#include <string.h>
30
Ronald Cron7f13fa22021-04-13 12:41:34 +020031mbedtls_test_driver_cipher_hooks_t mbedtls_test_driver_cipher_hooks =
32 MBEDTLS_TEST_DRIVER_CIPHER_INIT;
Steven Cooreman37941cb2020-07-28 18:49:51 +020033
gabor-mezei-arma9449a02021-03-25 11:17:10 +010034psa_status_t mbedtls_test_transparent_cipher_encrypt(
Steven Cooremanfe0ab552020-09-10 13:07:02 +020035 const psa_key_attributes_t *attributes,
gabor-mezei-arma9449a02021-03-25 11:17:10 +010036 const uint8_t *key_buffer,
37 size_t key_buffer_size,
Steven Cooremanfe0ab552020-09-10 13:07:02 +020038 psa_algorithm_t alg,
Ronald Cron9b674282021-07-09 09:19:35 +020039 const uint8_t *iv,
40 size_t iv_length,
gabor-mezei-arma9449a02021-03-25 11:17:10 +010041 const uint8_t *input,
42 size_t input_length,
43 uint8_t *output,
44 size_t output_size,
Gilles Peskine449bd832023-01-11 14:50:10 +010045 size_t *output_length)
Steven Cooremanfe0ab552020-09-10 13:07:02 +020046{
Ronald Cron7f13fa22021-04-13 12:41:34 +020047 mbedtls_test_driver_cipher_hooks.hits++;
Valerio Setti829ce0f2023-11-27 12:27:46 +010048 mbedtls_test_driver_cipher_hooks.hits_encrypt++;
Steven Cooremanfe0ab552020-09-10 13:07:02 +020049
Gilles Peskine449bd832023-01-11 14:50:10 +010050 if (mbedtls_test_driver_cipher_hooks.forced_output != NULL) {
51 if (output_size < mbedtls_test_driver_cipher_hooks.forced_output_length) {
52 return PSA_ERROR_BUFFER_TOO_SMALL;
53 }
Steven Cooremanfe0ab552020-09-10 13:07:02 +020054
Gilles Peskine449bd832023-01-11 14:50:10 +010055 memcpy(output,
56 mbedtls_test_driver_cipher_hooks.forced_output,
57 mbedtls_test_driver_cipher_hooks.forced_output_length);
Ronald Cron7f13fa22021-04-13 12:41:34 +020058 *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length;
Steven Cooremanfe0ab552020-09-10 13:07:02 +020059
Gilles Peskine449bd832023-01-11 14:50:10 +010060 return mbedtls_test_driver_cipher_hooks.forced_status;
Steven Cooremanfe0ab552020-09-10 13:07:02 +020061 }
62
Gilles Peskine449bd832023-01-11 14:50:10 +010063 if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
64 return mbedtls_test_driver_cipher_hooks.forced_status;
65 }
Valerio Setti829ce0f2023-11-27 12:27:46 +010066 if (mbedtls_test_driver_cipher_hooks.forced_status_encrypt != PSA_SUCCESS) {
67 return mbedtls_test_driver_cipher_hooks.forced_status_encrypt;
68 }
Steven Cooremanfe0ab552020-09-10 13:07:02 +020069
Ronald Cron7975fae2021-09-13 14:50:42 +020070#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
71 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +010072 return libtestdriver1_mbedtls_psa_cipher_encrypt(
73 (const libtestdriver1_psa_key_attributes_t *) attributes,
74 key_buffer, key_buffer_size,
75 alg, iv, iv_length, input, input_length,
76 output, output_size, output_length);
Ronald Cron73c9d9e2021-04-09 11:09:54 +020077#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +010078 return mbedtls_psa_cipher_encrypt(
79 attributes, key_buffer, key_buffer_size,
80 alg, iv, iv_length, input, input_length,
81 output, output_size, output_length);
Ronald Cron73c9d9e2021-04-09 11:09:54 +020082#endif
83
Gilles Peskine449bd832023-01-11 14:50:10 +010084 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +020085}
86
Ronald Cron7f13fa22021-04-13 12:41:34 +020087psa_status_t mbedtls_test_transparent_cipher_decrypt(
Steven Cooreman37941cb2020-07-28 18:49:51 +020088 const psa_key_attributes_t *attributes,
gabor-mezei-arma9449a02021-03-25 11:17:10 +010089 const uint8_t *key_buffer,
90 size_t key_buffer_size,
Steven Cooreman37941cb2020-07-28 18:49:51 +020091 psa_algorithm_t alg,
gabor-mezei-arma9449a02021-03-25 11:17:10 +010092 const uint8_t *input,
93 size_t input_length,
94 uint8_t *output,
95 size_t output_size,
Gilles Peskine449bd832023-01-11 14:50:10 +010096 size_t *output_length)
Steven Cooreman37941cb2020-07-28 18:49:51 +020097{
Gilles Peskine449bd832023-01-11 14:50:10 +010098 mbedtls_test_driver_cipher_hooks.hits++;
gabor-mezei-arma9449a02021-03-25 11:17:10 +010099
Gilles Peskine449bd832023-01-11 14:50:10 +0100100 if (mbedtls_test_driver_cipher_hooks.forced_output != NULL) {
101 if (output_size < mbedtls_test_driver_cipher_hooks.forced_output_length) {
102 return PSA_ERROR_BUFFER_TOO_SMALL;
103 }
gabor-mezei-arma9449a02021-03-25 11:17:10 +0100104
Gilles Peskine449bd832023-01-11 14:50:10 +0100105 memcpy(output,
106 mbedtls_test_driver_cipher_hooks.forced_output,
107 mbedtls_test_driver_cipher_hooks.forced_output_length);
gabor-mezei-arma9449a02021-03-25 11:17:10 +0100108 *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length;
109
Gilles Peskine449bd832023-01-11 14:50:10 +0100110 return mbedtls_test_driver_cipher_hooks.forced_status;
gabor-mezei-arma9449a02021-03-25 11:17:10 +0100111 }
112
Gilles Peskine449bd832023-01-11 14:50:10 +0100113 if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
114 return mbedtls_test_driver_cipher_hooks.forced_status;
115 }
gabor-mezei-arma9449a02021-03-25 11:17:10 +0100116
Ronald Cron7975fae2021-09-13 14:50:42 +0200117#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
118 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100119 return libtestdriver1_mbedtls_psa_cipher_decrypt(
120 (const libtestdriver1_psa_key_attributes_t *) attributes,
121 key_buffer, key_buffer_size,
122 alg, input, input_length,
123 output, output_size, output_length);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200124#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100125 return mbedtls_psa_cipher_decrypt(
126 attributes, key_buffer, key_buffer_size,
127 alg, input, input_length,
128 output, output_size, output_length);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200129#endif
130
Gilles Peskine449bd832023-01-11 14:50:10 +0100131 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200132}
133
Ronald Cron7f13fa22021-04-13 12:41:34 +0200134psa_status_t mbedtls_test_transparent_cipher_encrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100135 mbedtls_transparent_test_driver_cipher_operation_t *operation,
Steven Cooreman16afd3d2020-09-09 15:36:39 +0200136 const psa_key_attributes_t *attributes,
137 const uint8_t *key, size_t key_length,
138 psa_algorithm_t alg)
139{
Ronald Cron7f13fa22021-04-13 12:41:34 +0200140 mbedtls_test_driver_cipher_hooks.hits++;
Ronald Cron8d310ad2020-12-15 15:17:20 +0100141
142 /* Wiping the entire struct here, instead of member-by-member. This is
143 * useful for the test suite, since it gives a chance of catching memory
144 * corruption errors should the core not have allocated (enough) memory for
145 * our context struct. */
Gilles Peskine449bd832023-01-11 14:50:10 +0100146 memset(operation, 0, sizeof(*operation));
Ronald Cron8d310ad2020-12-15 15:17:20 +0100147
Gilles Peskine449bd832023-01-11 14:50:10 +0100148 if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
149 return mbedtls_test_driver_cipher_hooks.forced_status;
150 }
Ronald Cron8d310ad2020-12-15 15:17:20 +0100151
Ronald Cron7975fae2021-09-13 14:50:42 +0200152#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
153 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100154 return libtestdriver1_mbedtls_psa_cipher_encrypt_setup(
155 operation,
156 (const libtestdriver1_psa_key_attributes_t *) attributes,
157 key, key_length, alg);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200158#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100159 return mbedtls_psa_cipher_encrypt_setup(
160 operation, attributes, key, key_length, alg);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200161#endif
162
Gilles Peskine449bd832023-01-11 14:50:10 +0100163 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman16afd3d2020-09-09 15:36:39 +0200164}
165
Ronald Cron7f13fa22021-04-13 12:41:34 +0200166psa_status_t mbedtls_test_transparent_cipher_decrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100167 mbedtls_transparent_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200168 const psa_key_attributes_t *attributes,
169 const uint8_t *key, size_t key_length,
170 psa_algorithm_t alg)
171{
Ronald Cron7f13fa22021-04-13 12:41:34 +0200172 mbedtls_test_driver_cipher_hooks.hits++;
Ronald Cron8d310ad2020-12-15 15:17:20 +0100173
Gilles Peskine449bd832023-01-11 14:50:10 +0100174 if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
175 return mbedtls_test_driver_cipher_hooks.forced_status;
176 }
Ronald Cron8d310ad2020-12-15 15:17:20 +0100177
Ronald Cron7975fae2021-09-13 14:50:42 +0200178#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
179 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100180 return libtestdriver1_mbedtls_psa_cipher_decrypt_setup(
181 operation,
182 (const libtestdriver1_psa_key_attributes_t *) attributes,
183 key, key_length, alg);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200184#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100185 return mbedtls_psa_cipher_decrypt_setup(
186 operation, attributes, key, key_length, alg);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200187#endif
188
Gilles Peskine449bd832023-01-11 14:50:10 +0100189 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200190}
191
Ronald Cron7f13fa22021-04-13 12:41:34 +0200192psa_status_t mbedtls_test_transparent_cipher_abort(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100193 mbedtls_transparent_test_driver_cipher_operation_t *operation)
Steven Cooreman37941cb2020-07-28 18:49:51 +0200194{
Ronald Cron7f13fa22021-04-13 12:41:34 +0200195 mbedtls_test_driver_cipher_hooks.hits++;
Steven Cooreman89e54f22020-09-10 18:07:57 +0200196
Ronald Cron7975fae2021-09-13 14:50:42 +0200197#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
198 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100199 libtestdriver1_mbedtls_psa_cipher_abort(operation);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200200#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100201 mbedtls_psa_cipher_abort(operation);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200202#endif
Steven Cooreman8b122252020-09-03 15:30:32 +0200203
Ronald Cron8d310ad2020-12-15 15:17:20 +0100204 /* Wiping the entire struct here, instead of member-by-member. This is
205 * useful for the test suite, since it gives a chance of catching memory
206 * corruption errors should the core not have allocated (enough) memory for
207 * our context struct. */
Gilles Peskine449bd832023-01-11 14:50:10 +0100208 memset(operation, 0, sizeof(*operation));
Steven Cooreman37941cb2020-07-28 18:49:51 +0200209
Gilles Peskine449bd832023-01-11 14:50:10 +0100210 return mbedtls_test_driver_cipher_hooks.forced_status;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200211}
212
Ronald Cron7f13fa22021-04-13 12:41:34 +0200213psa_status_t mbedtls_test_transparent_cipher_set_iv(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100214 mbedtls_transparent_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200215 const uint8_t *iv,
216 size_t iv_length)
217{
Ronald Cron7f13fa22021-04-13 12:41:34 +0200218 mbedtls_test_driver_cipher_hooks.hits++;
Valerio Setti829ce0f2023-11-27 12:27:46 +0100219 mbedtls_test_driver_cipher_hooks.hits_set_iv++;
Steven Cooreman8b122252020-09-03 15:30:32 +0200220
Gilles Peskine449bd832023-01-11 14:50:10 +0100221 if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
222 return mbedtls_test_driver_cipher_hooks.forced_status;
223 }
Valerio Setti829ce0f2023-11-27 12:27:46 +0100224 if (mbedtls_test_driver_cipher_hooks.forced_status_set_iv != PSA_SUCCESS) {
225 return mbedtls_test_driver_cipher_hooks.forced_status_set_iv;
226 }
Steven Cooreman89e54f22020-09-10 18:07:57 +0200227
Ronald Cron7975fae2021-09-13 14:50:42 +0200228#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
229 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100230 return libtestdriver1_mbedtls_psa_cipher_set_iv(
231 operation, iv, iv_length);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200232#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100233 return mbedtls_psa_cipher_set_iv(operation, iv, iv_length);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200234#endif
235
Gilles Peskine449bd832023-01-11 14:50:10 +0100236 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200237}
238
Ronald Cron7f13fa22021-04-13 12:41:34 +0200239psa_status_t mbedtls_test_transparent_cipher_update(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100240 mbedtls_transparent_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200241 const uint8_t *input,
242 size_t input_length,
243 uint8_t *output,
244 size_t output_size,
245 size_t *output_length)
246{
Ronald Cron7f13fa22021-04-13 12:41:34 +0200247 mbedtls_test_driver_cipher_hooks.hits++;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200248
Gilles Peskine449bd832023-01-11 14:50:10 +0100249 if (mbedtls_test_driver_cipher_hooks.forced_output != NULL) {
250 if (output_size < mbedtls_test_driver_cipher_hooks.forced_output_length) {
Steven Cooreman8b122252020-09-03 15:30:32 +0200251 return PSA_ERROR_BUFFER_TOO_SMALL;
Gilles Peskine449bd832023-01-11 14:50:10 +0100252 }
Steven Cooreman8b122252020-09-03 15:30:32 +0200253
Gilles Peskine449bd832023-01-11 14:50:10 +0100254 memcpy(output,
255 mbedtls_test_driver_cipher_hooks.forced_output,
256 mbedtls_test_driver_cipher_hooks.forced_output_length);
Ronald Cron7f13fa22021-04-13 12:41:34 +0200257 *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length;
Ronald Cron8d310ad2020-12-15 15:17:20 +0100258
Gilles Peskine449bd832023-01-11 14:50:10 +0100259 return mbedtls_test_driver_cipher_hooks.forced_status;
Steven Cooreman8b122252020-09-03 15:30:32 +0200260 }
Steven Cooreman37941cb2020-07-28 18:49:51 +0200261
Gilles Peskine449bd832023-01-11 14:50:10 +0100262 if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
263 return mbedtls_test_driver_cipher_hooks.forced_status;
264 }
Ronald Cron8d310ad2020-12-15 15:17:20 +0100265
Ronald Cron7975fae2021-09-13 14:50:42 +0200266#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
267 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100268 return libtestdriver1_mbedtls_psa_cipher_update(
269 operation, input, input_length,
270 output, output_size, output_length);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200271#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100272 return mbedtls_psa_cipher_update(
273 operation, input, input_length,
274 output, output_size, output_length);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200275#endif
276
Gilles Peskine449bd832023-01-11 14:50:10 +0100277 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200278}
279
Ronald Cron7f13fa22021-04-13 12:41:34 +0200280psa_status_t mbedtls_test_transparent_cipher_finish(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100281 mbedtls_transparent_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200282 uint8_t *output,
283 size_t output_size,
284 size_t *output_length)
285{
Ronald Cron7f13fa22021-04-13 12:41:34 +0200286 mbedtls_test_driver_cipher_hooks.hits++;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200287
Gilles Peskine449bd832023-01-11 14:50:10 +0100288 if (mbedtls_test_driver_cipher_hooks.forced_output != NULL) {
289 if (output_size < mbedtls_test_driver_cipher_hooks.forced_output_length) {
Steven Cooreman8b122252020-09-03 15:30:32 +0200290 return PSA_ERROR_BUFFER_TOO_SMALL;
Gilles Peskine449bd832023-01-11 14:50:10 +0100291 }
Steven Cooreman8b122252020-09-03 15:30:32 +0200292
Gilles Peskine449bd832023-01-11 14:50:10 +0100293 memcpy(output,
294 mbedtls_test_driver_cipher_hooks.forced_output,
295 mbedtls_test_driver_cipher_hooks.forced_output_length);
Ronald Cron7f13fa22021-04-13 12:41:34 +0200296 *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length;
Ronald Cron8d310ad2020-12-15 15:17:20 +0100297
Gilles Peskine449bd832023-01-11 14:50:10 +0100298 return mbedtls_test_driver_cipher_hooks.forced_status;
Steven Cooreman8b122252020-09-03 15:30:32 +0200299 }
Steven Cooreman37941cb2020-07-28 18:49:51 +0200300
Gilles Peskine449bd832023-01-11 14:50:10 +0100301 if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
302 return mbedtls_test_driver_cipher_hooks.forced_status;
303 }
Ronald Cron8d310ad2020-12-15 15:17:20 +0100304
Ronald Cron7975fae2021-09-13 14:50:42 +0200305#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
306 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100307 return libtestdriver1_mbedtls_psa_cipher_finish(
308 operation, output, output_size, output_length);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200309#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100310 return mbedtls_psa_cipher_finish(
311 operation, output, output_size, output_length);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200312#endif
313
Gilles Peskine449bd832023-01-11 14:50:10 +0100314 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200315}
316
317/*
318 * opaque versions, to do
319 */
Ronald Cron7f13fa22021-04-13 12:41:34 +0200320psa_status_t mbedtls_test_opaque_cipher_encrypt(
Steven Cooreman37941cb2020-07-28 18:49:51 +0200321 const psa_key_attributes_t *attributes,
322 const uint8_t *key, size_t key_length,
323 psa_algorithm_t alg,
Ronald Cron9b674282021-07-09 09:19:35 +0200324 const uint8_t *iv, size_t iv_length,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200325 const uint8_t *input, size_t input_length,
326 uint8_t *output, size_t output_size, size_t *output_length)
327{
328 (void) attributes;
329 (void) key;
330 (void) key_length;
331 (void) alg;
Ronald Cron9b674282021-07-09 09:19:35 +0200332 (void) iv;
333 (void) iv_length;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200334 (void) input;
335 (void) input_length;
336 (void) output;
337 (void) output_size;
338 (void) output_length;
Gilles Peskine449bd832023-01-11 14:50:10 +0100339 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200340}
341
Ronald Cron7f13fa22021-04-13 12:41:34 +0200342psa_status_t mbedtls_test_opaque_cipher_decrypt(
Steven Cooreman37941cb2020-07-28 18:49:51 +0200343 const psa_key_attributes_t *attributes,
344 const uint8_t *key, size_t key_length,
345 psa_algorithm_t alg,
346 const uint8_t *input, size_t input_length,
347 uint8_t *output, size_t output_size, size_t *output_length)
348{
349 (void) attributes;
350 (void) key;
351 (void) key_length;
352 (void) alg;
353 (void) input;
354 (void) input_length;
355 (void) output;
356 (void) output_size;
357 (void) output_length;
Gilles Peskine449bd832023-01-11 14:50:10 +0100358 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200359}
360
Ronald Cron7f13fa22021-04-13 12:41:34 +0200361psa_status_t mbedtls_test_opaque_cipher_encrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100362 mbedtls_opaque_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200363 const psa_key_attributes_t *attributes,
364 const uint8_t *key, size_t key_length,
365 psa_algorithm_t alg)
366{
367 (void) operation;
368 (void) attributes;
369 (void) key;
370 (void) key_length;
371 (void) alg;
Gilles Peskine449bd832023-01-11 14:50:10 +0100372 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200373}
374
Ronald Cron7f13fa22021-04-13 12:41:34 +0200375psa_status_t mbedtls_test_opaque_cipher_decrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100376 mbedtls_opaque_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200377 const psa_key_attributes_t *attributes,
378 const uint8_t *key, size_t key_length,
379 psa_algorithm_t alg)
380{
381 (void) operation;
382 (void) attributes;
383 (void) key;
384 (void) key_length;
385 (void) alg;
Gilles Peskine449bd832023-01-11 14:50:10 +0100386 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200387}
388
Ronald Cron7f13fa22021-04-13 12:41:34 +0200389psa_status_t mbedtls_test_opaque_cipher_abort(
Gilles Peskine449bd832023-01-11 14:50:10 +0100390 mbedtls_opaque_test_driver_cipher_operation_t *operation)
Steven Cooreman37941cb2020-07-28 18:49:51 +0200391{
392 (void) operation;
Gilles Peskine449bd832023-01-11 14:50:10 +0100393 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200394}
395
Ronald Cron7f13fa22021-04-13 12:41:34 +0200396psa_status_t mbedtls_test_opaque_cipher_set_iv(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100397 mbedtls_opaque_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200398 const uint8_t *iv,
399 size_t iv_length)
400{
401 (void) operation;
402 (void) iv;
403 (void) iv_length;
Gilles Peskine449bd832023-01-11 14:50:10 +0100404 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200405}
406
Ronald Cron7f13fa22021-04-13 12:41:34 +0200407psa_status_t mbedtls_test_opaque_cipher_update(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100408 mbedtls_opaque_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200409 const uint8_t *input,
410 size_t input_length,
411 uint8_t *output,
412 size_t output_size,
413 size_t *output_length)
414{
415 (void) operation;
416 (void) input;
417 (void) input_length;
418 (void) output;
419 (void) output_size;
420 (void) output_length;
Gilles Peskine449bd832023-01-11 14:50:10 +0100421 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200422}
423
Ronald Cron7f13fa22021-04-13 12:41:34 +0200424psa_status_t mbedtls_test_opaque_cipher_finish(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100425 mbedtls_opaque_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200426 uint8_t *output,
427 size_t output_size,
428 size_t *output_length)
429{
430 (void) operation;
431 (void) output;
432 (void) output_size;
433 (void) output_length;
Gilles Peskine449bd832023-01-11 14:50:10 +0100434 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200435}
Ronald Crone6e6b752023-01-16 16:56:51 +0100436#endif /* PSA_CRYPTO_DRIVER_TEST */