blob: 2bc751a8a248bd9202166c9c3e0aad591623c7d5 [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)
22#include "libtestdriver1/library/psa_crypto_cipher.h"
23#endif
24
Steven Cooreman37941cb2020-07-28 18:49:51 +020025#include <string.h>
26
Ronald Cron7f13fa22021-04-13 12:41:34 +020027mbedtls_test_driver_cipher_hooks_t mbedtls_test_driver_cipher_hooks =
28 MBEDTLS_TEST_DRIVER_CIPHER_INIT;
Steven Cooreman37941cb2020-07-28 18:49:51 +020029
gabor-mezei-arma9449a02021-03-25 11:17:10 +010030psa_status_t mbedtls_test_transparent_cipher_encrypt(
Steven Cooremanfe0ab552020-09-10 13:07:02 +020031 const psa_key_attributes_t *attributes,
gabor-mezei-arma9449a02021-03-25 11:17:10 +010032 const uint8_t *key_buffer,
33 size_t key_buffer_size,
Steven Cooremanfe0ab552020-09-10 13:07:02 +020034 psa_algorithm_t alg,
Ronald Cron9b674282021-07-09 09:19:35 +020035 const uint8_t *iv,
36 size_t iv_length,
gabor-mezei-arma9449a02021-03-25 11:17:10 +010037 const uint8_t *input,
38 size_t input_length,
39 uint8_t *output,
40 size_t output_size,
Gilles Peskine449bd832023-01-11 14:50:10 +010041 size_t *output_length)
Steven Cooremanfe0ab552020-09-10 13:07:02 +020042{
Ronald Cron7f13fa22021-04-13 12:41:34 +020043 mbedtls_test_driver_cipher_hooks.hits++;
Valerio Setti829ce0f2023-11-27 12:27:46 +010044 mbedtls_test_driver_cipher_hooks.hits_encrypt++;
Steven Cooremanfe0ab552020-09-10 13:07:02 +020045
Gilles Peskine449bd832023-01-11 14:50:10 +010046 if (mbedtls_test_driver_cipher_hooks.forced_output != NULL) {
47 if (output_size < mbedtls_test_driver_cipher_hooks.forced_output_length) {
48 return PSA_ERROR_BUFFER_TOO_SMALL;
49 }
Steven Cooremanfe0ab552020-09-10 13:07:02 +020050
Gilles Peskine449bd832023-01-11 14:50:10 +010051 memcpy(output,
52 mbedtls_test_driver_cipher_hooks.forced_output,
53 mbedtls_test_driver_cipher_hooks.forced_output_length);
Ronald Cron7f13fa22021-04-13 12:41:34 +020054 *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length;
Steven Cooremanfe0ab552020-09-10 13:07:02 +020055
Gilles Peskine449bd832023-01-11 14:50:10 +010056 return mbedtls_test_driver_cipher_hooks.forced_status;
Steven Cooremanfe0ab552020-09-10 13:07:02 +020057 }
58
Gilles Peskine449bd832023-01-11 14:50:10 +010059 if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
60 return mbedtls_test_driver_cipher_hooks.forced_status;
61 }
Valerio Setti829ce0f2023-11-27 12:27:46 +010062 if (mbedtls_test_driver_cipher_hooks.forced_status_encrypt != PSA_SUCCESS) {
63 return mbedtls_test_driver_cipher_hooks.forced_status_encrypt;
64 }
Steven Cooremanfe0ab552020-09-10 13:07:02 +020065
Ronald Cron7975fae2021-09-13 14:50:42 +020066#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
67 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +010068 return libtestdriver1_mbedtls_psa_cipher_encrypt(
69 (const libtestdriver1_psa_key_attributes_t *) attributes,
70 key_buffer, key_buffer_size,
71 alg, iv, iv_length, input, input_length,
72 output, output_size, output_length);
Ronald Cron73c9d9e2021-04-09 11:09:54 +020073#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +010074 return mbedtls_psa_cipher_encrypt(
75 attributes, key_buffer, key_buffer_size,
76 alg, iv, iv_length, input, input_length,
77 output, output_size, output_length);
Ronald Cron73c9d9e2021-04-09 11:09:54 +020078#endif
79
Gilles Peskine449bd832023-01-11 14:50:10 +010080 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +020081}
82
Ronald Cron7f13fa22021-04-13 12:41:34 +020083psa_status_t mbedtls_test_transparent_cipher_decrypt(
Steven Cooreman37941cb2020-07-28 18:49:51 +020084 const psa_key_attributes_t *attributes,
gabor-mezei-arma9449a02021-03-25 11:17:10 +010085 const uint8_t *key_buffer,
86 size_t key_buffer_size,
Steven Cooreman37941cb2020-07-28 18:49:51 +020087 psa_algorithm_t alg,
gabor-mezei-arma9449a02021-03-25 11:17:10 +010088 const uint8_t *input,
89 size_t input_length,
90 uint8_t *output,
91 size_t output_size,
Gilles Peskine449bd832023-01-11 14:50:10 +010092 size_t *output_length)
Steven Cooreman37941cb2020-07-28 18:49:51 +020093{
Gilles Peskine449bd832023-01-11 14:50:10 +010094 mbedtls_test_driver_cipher_hooks.hits++;
gabor-mezei-arma9449a02021-03-25 11:17:10 +010095
Gilles Peskine449bd832023-01-11 14:50:10 +010096 if (mbedtls_test_driver_cipher_hooks.forced_output != NULL) {
97 if (output_size < mbedtls_test_driver_cipher_hooks.forced_output_length) {
98 return PSA_ERROR_BUFFER_TOO_SMALL;
99 }
gabor-mezei-arma9449a02021-03-25 11:17:10 +0100100
Gilles Peskine449bd832023-01-11 14:50:10 +0100101 memcpy(output,
102 mbedtls_test_driver_cipher_hooks.forced_output,
103 mbedtls_test_driver_cipher_hooks.forced_output_length);
gabor-mezei-arma9449a02021-03-25 11:17:10 +0100104 *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length;
105
Gilles Peskine449bd832023-01-11 14:50:10 +0100106 return mbedtls_test_driver_cipher_hooks.forced_status;
gabor-mezei-arma9449a02021-03-25 11:17:10 +0100107 }
108
Gilles Peskine449bd832023-01-11 14:50:10 +0100109 if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
110 return mbedtls_test_driver_cipher_hooks.forced_status;
111 }
gabor-mezei-arma9449a02021-03-25 11:17:10 +0100112
Ronald Cron7975fae2021-09-13 14:50:42 +0200113#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
114 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100115 return libtestdriver1_mbedtls_psa_cipher_decrypt(
116 (const libtestdriver1_psa_key_attributes_t *) attributes,
117 key_buffer, key_buffer_size,
118 alg, input, input_length,
119 output, output_size, output_length);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200120#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100121 return mbedtls_psa_cipher_decrypt(
122 attributes, key_buffer, key_buffer_size,
123 alg, input, input_length,
124 output, output_size, output_length);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200125#endif
126
Gilles Peskine449bd832023-01-11 14:50:10 +0100127 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200128}
129
Ronald Cron7f13fa22021-04-13 12:41:34 +0200130psa_status_t mbedtls_test_transparent_cipher_encrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100131 mbedtls_transparent_test_driver_cipher_operation_t *operation,
Steven Cooreman16afd3d2020-09-09 15:36:39 +0200132 const psa_key_attributes_t *attributes,
133 const uint8_t *key, size_t key_length,
134 psa_algorithm_t alg)
135{
Ronald Cron7f13fa22021-04-13 12:41:34 +0200136 mbedtls_test_driver_cipher_hooks.hits++;
Ronald Cron8d310ad2020-12-15 15:17:20 +0100137
138 /* Wiping the entire struct here, instead of member-by-member. This is
139 * useful for the test suite, since it gives a chance of catching memory
140 * corruption errors should the core not have allocated (enough) memory for
141 * our context struct. */
Gilles Peskine449bd832023-01-11 14:50:10 +0100142 memset(operation, 0, sizeof(*operation));
Ronald Cron8d310ad2020-12-15 15:17:20 +0100143
Gilles Peskine449bd832023-01-11 14:50:10 +0100144 if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
145 return mbedtls_test_driver_cipher_hooks.forced_status;
146 }
Ronald Cron8d310ad2020-12-15 15:17:20 +0100147
Ronald Cron7975fae2021-09-13 14:50:42 +0200148#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
149 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100150 return libtestdriver1_mbedtls_psa_cipher_encrypt_setup(
151 operation,
152 (const libtestdriver1_psa_key_attributes_t *) attributes,
153 key, key_length, alg);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200154#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100155 return mbedtls_psa_cipher_encrypt_setup(
156 operation, attributes, key, key_length, alg);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200157#endif
158
Gilles Peskine449bd832023-01-11 14:50:10 +0100159 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman16afd3d2020-09-09 15:36:39 +0200160}
161
Ronald Cron7f13fa22021-04-13 12:41:34 +0200162psa_status_t mbedtls_test_transparent_cipher_decrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100163 mbedtls_transparent_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200164 const psa_key_attributes_t *attributes,
165 const uint8_t *key, size_t key_length,
166 psa_algorithm_t alg)
167{
Ronald Cron7f13fa22021-04-13 12:41:34 +0200168 mbedtls_test_driver_cipher_hooks.hits++;
Ronald Cron8d310ad2020-12-15 15:17:20 +0100169
Gilles Peskine449bd832023-01-11 14:50:10 +0100170 if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
171 return mbedtls_test_driver_cipher_hooks.forced_status;
172 }
Ronald Cron8d310ad2020-12-15 15:17:20 +0100173
Ronald Cron7975fae2021-09-13 14:50:42 +0200174#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
175 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100176 return libtestdriver1_mbedtls_psa_cipher_decrypt_setup(
177 operation,
178 (const libtestdriver1_psa_key_attributes_t *) attributes,
179 key, key_length, alg);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200180#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100181 return mbedtls_psa_cipher_decrypt_setup(
182 operation, attributes, key, key_length, alg);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200183#endif
184
Gilles Peskine449bd832023-01-11 14:50:10 +0100185 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200186}
187
Ronald Cron7f13fa22021-04-13 12:41:34 +0200188psa_status_t mbedtls_test_transparent_cipher_abort(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100189 mbedtls_transparent_test_driver_cipher_operation_t *operation)
Steven Cooreman37941cb2020-07-28 18:49:51 +0200190{
Ronald Cron7f13fa22021-04-13 12:41:34 +0200191 mbedtls_test_driver_cipher_hooks.hits++;
Steven Cooreman89e54f22020-09-10 18:07:57 +0200192
Ronald Cron7975fae2021-09-13 14:50:42 +0200193#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
194 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100195 libtestdriver1_mbedtls_psa_cipher_abort(operation);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200196#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100197 mbedtls_psa_cipher_abort(operation);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200198#endif
Steven Cooreman8b122252020-09-03 15:30:32 +0200199
Ronald Cron8d310ad2020-12-15 15:17:20 +0100200 /* Wiping the entire struct here, instead of member-by-member. This is
201 * useful for the test suite, since it gives a chance of catching memory
202 * corruption errors should the core not have allocated (enough) memory for
203 * our context struct. */
Gilles Peskine449bd832023-01-11 14:50:10 +0100204 memset(operation, 0, sizeof(*operation));
Steven Cooreman37941cb2020-07-28 18:49:51 +0200205
Gilles Peskine449bd832023-01-11 14:50:10 +0100206 return mbedtls_test_driver_cipher_hooks.forced_status;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200207}
208
Ronald Cron7f13fa22021-04-13 12:41:34 +0200209psa_status_t mbedtls_test_transparent_cipher_set_iv(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100210 mbedtls_transparent_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200211 const uint8_t *iv,
212 size_t iv_length)
213{
Ronald Cron7f13fa22021-04-13 12:41:34 +0200214 mbedtls_test_driver_cipher_hooks.hits++;
Valerio Setti829ce0f2023-11-27 12:27:46 +0100215 mbedtls_test_driver_cipher_hooks.hits_set_iv++;
Steven Cooreman8b122252020-09-03 15:30:32 +0200216
Gilles Peskine449bd832023-01-11 14:50:10 +0100217 if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
218 return mbedtls_test_driver_cipher_hooks.forced_status;
219 }
Valerio Setti829ce0f2023-11-27 12:27:46 +0100220 if (mbedtls_test_driver_cipher_hooks.forced_status_set_iv != PSA_SUCCESS) {
221 return mbedtls_test_driver_cipher_hooks.forced_status_set_iv;
222 }
Steven Cooreman89e54f22020-09-10 18:07:57 +0200223
Ronald Cron7975fae2021-09-13 14:50:42 +0200224#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
225 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100226 return libtestdriver1_mbedtls_psa_cipher_set_iv(
227 operation, iv, iv_length);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200228#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100229 return mbedtls_psa_cipher_set_iv(operation, iv, iv_length);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200230#endif
231
Gilles Peskine449bd832023-01-11 14:50:10 +0100232 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200233}
234
Ronald Cron7f13fa22021-04-13 12:41:34 +0200235psa_status_t mbedtls_test_transparent_cipher_update(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100236 mbedtls_transparent_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200237 const uint8_t *input,
238 size_t input_length,
239 uint8_t *output,
240 size_t output_size,
241 size_t *output_length)
242{
Ronald Cron7f13fa22021-04-13 12:41:34 +0200243 mbedtls_test_driver_cipher_hooks.hits++;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200244
Gilles Peskine449bd832023-01-11 14:50:10 +0100245 if (mbedtls_test_driver_cipher_hooks.forced_output != NULL) {
246 if (output_size < mbedtls_test_driver_cipher_hooks.forced_output_length) {
Steven Cooreman8b122252020-09-03 15:30:32 +0200247 return PSA_ERROR_BUFFER_TOO_SMALL;
Gilles Peskine449bd832023-01-11 14:50:10 +0100248 }
Steven Cooreman8b122252020-09-03 15:30:32 +0200249
Gilles Peskine449bd832023-01-11 14:50:10 +0100250 memcpy(output,
251 mbedtls_test_driver_cipher_hooks.forced_output,
252 mbedtls_test_driver_cipher_hooks.forced_output_length);
Ronald Cron7f13fa22021-04-13 12:41:34 +0200253 *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length;
Ronald Cron8d310ad2020-12-15 15:17:20 +0100254
Gilles Peskine449bd832023-01-11 14:50:10 +0100255 return mbedtls_test_driver_cipher_hooks.forced_status;
Steven Cooreman8b122252020-09-03 15:30:32 +0200256 }
Steven Cooreman37941cb2020-07-28 18:49:51 +0200257
Gilles Peskine449bd832023-01-11 14:50:10 +0100258 if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
259 return mbedtls_test_driver_cipher_hooks.forced_status;
260 }
Ronald Cron8d310ad2020-12-15 15:17:20 +0100261
Ronald Cron7975fae2021-09-13 14:50:42 +0200262#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
263 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100264 return libtestdriver1_mbedtls_psa_cipher_update(
265 operation, input, input_length,
266 output, output_size, output_length);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200267#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100268 return mbedtls_psa_cipher_update(
269 operation, input, input_length,
270 output, output_size, output_length);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200271#endif
272
Gilles Peskine449bd832023-01-11 14:50:10 +0100273 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200274}
275
Ronald Cron7f13fa22021-04-13 12:41:34 +0200276psa_status_t mbedtls_test_transparent_cipher_finish(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100277 mbedtls_transparent_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200278 uint8_t *output,
279 size_t output_size,
280 size_t *output_length)
281{
Ronald Cron7f13fa22021-04-13 12:41:34 +0200282 mbedtls_test_driver_cipher_hooks.hits++;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200283
Gilles Peskine449bd832023-01-11 14:50:10 +0100284 if (mbedtls_test_driver_cipher_hooks.forced_output != NULL) {
285 if (output_size < mbedtls_test_driver_cipher_hooks.forced_output_length) {
Steven Cooreman8b122252020-09-03 15:30:32 +0200286 return PSA_ERROR_BUFFER_TOO_SMALL;
Gilles Peskine449bd832023-01-11 14:50:10 +0100287 }
Steven Cooreman8b122252020-09-03 15:30:32 +0200288
Gilles Peskine449bd832023-01-11 14:50:10 +0100289 memcpy(output,
290 mbedtls_test_driver_cipher_hooks.forced_output,
291 mbedtls_test_driver_cipher_hooks.forced_output_length);
Ronald Cron7f13fa22021-04-13 12:41:34 +0200292 *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length;
Ronald Cron8d310ad2020-12-15 15:17:20 +0100293
Gilles Peskine449bd832023-01-11 14:50:10 +0100294 return mbedtls_test_driver_cipher_hooks.forced_status;
Steven Cooreman8b122252020-09-03 15:30:32 +0200295 }
Steven Cooreman37941cb2020-07-28 18:49:51 +0200296
Gilles Peskine449bd832023-01-11 14:50:10 +0100297 if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
298 return mbedtls_test_driver_cipher_hooks.forced_status;
299 }
Ronald Cron8d310ad2020-12-15 15:17:20 +0100300
Ronald Cron7975fae2021-09-13 14:50:42 +0200301#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
302 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100303 return libtestdriver1_mbedtls_psa_cipher_finish(
304 operation, output, output_size, output_length);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200305#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine449bd832023-01-11 14:50:10 +0100306 return mbedtls_psa_cipher_finish(
307 operation, output, output_size, output_length);
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200308#endif
309
Gilles Peskine449bd832023-01-11 14:50:10 +0100310 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200311}
312
313/*
314 * opaque versions, to do
315 */
Ronald Cron7f13fa22021-04-13 12:41:34 +0200316psa_status_t mbedtls_test_opaque_cipher_encrypt(
Steven Cooreman37941cb2020-07-28 18:49:51 +0200317 const psa_key_attributes_t *attributes,
318 const uint8_t *key, size_t key_length,
319 psa_algorithm_t alg,
Ronald Cron9b674282021-07-09 09:19:35 +0200320 const uint8_t *iv, size_t iv_length,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200321 const uint8_t *input, size_t input_length,
322 uint8_t *output, size_t output_size, size_t *output_length)
323{
324 (void) attributes;
325 (void) key;
326 (void) key_length;
327 (void) alg;
Ronald Cron9b674282021-07-09 09:19:35 +0200328 (void) iv;
329 (void) iv_length;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200330 (void) input;
331 (void) input_length;
332 (void) output;
333 (void) output_size;
334 (void) output_length;
Gilles Peskine449bd832023-01-11 14:50:10 +0100335 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200336}
337
Ronald Cron7f13fa22021-04-13 12:41:34 +0200338psa_status_t mbedtls_test_opaque_cipher_decrypt(
Steven Cooreman37941cb2020-07-28 18:49:51 +0200339 const psa_key_attributes_t *attributes,
340 const uint8_t *key, size_t key_length,
341 psa_algorithm_t alg,
342 const uint8_t *input, size_t input_length,
343 uint8_t *output, size_t output_size, size_t *output_length)
344{
345 (void) attributes;
346 (void) key;
347 (void) key_length;
348 (void) alg;
349 (void) input;
350 (void) input_length;
351 (void) output;
352 (void) output_size;
353 (void) output_length;
Gilles Peskine449bd832023-01-11 14:50:10 +0100354 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200355}
356
Ronald Cron7f13fa22021-04-13 12:41:34 +0200357psa_status_t mbedtls_test_opaque_cipher_encrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100358 mbedtls_opaque_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200359 const psa_key_attributes_t *attributes,
360 const uint8_t *key, size_t key_length,
361 psa_algorithm_t alg)
362{
363 (void) operation;
364 (void) attributes;
365 (void) key;
366 (void) key_length;
367 (void) alg;
Gilles Peskine449bd832023-01-11 14:50:10 +0100368 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200369}
370
Ronald Cron7f13fa22021-04-13 12:41:34 +0200371psa_status_t mbedtls_test_opaque_cipher_decrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100372 mbedtls_opaque_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200373 const psa_key_attributes_t *attributes,
374 const uint8_t *key, size_t key_length,
375 psa_algorithm_t alg)
376{
377 (void) operation;
378 (void) attributes;
379 (void) key;
380 (void) key_length;
381 (void) alg;
Gilles Peskine449bd832023-01-11 14:50:10 +0100382 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200383}
384
Ronald Cron7f13fa22021-04-13 12:41:34 +0200385psa_status_t mbedtls_test_opaque_cipher_abort(
Gilles Peskine449bd832023-01-11 14:50:10 +0100386 mbedtls_opaque_test_driver_cipher_operation_t *operation)
Steven Cooreman37941cb2020-07-28 18:49:51 +0200387{
388 (void) operation;
Gilles Peskine449bd832023-01-11 14:50:10 +0100389 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200390}
391
Ronald Cron7f13fa22021-04-13 12:41:34 +0200392psa_status_t mbedtls_test_opaque_cipher_set_iv(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100393 mbedtls_opaque_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200394 const uint8_t *iv,
395 size_t iv_length)
396{
397 (void) operation;
398 (void) iv;
399 (void) iv_length;
Gilles Peskine449bd832023-01-11 14:50:10 +0100400 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200401}
402
Ronald Cron7f13fa22021-04-13 12:41:34 +0200403psa_status_t mbedtls_test_opaque_cipher_update(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100404 mbedtls_opaque_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200405 const uint8_t *input,
406 size_t input_length,
407 uint8_t *output,
408 size_t output_size,
409 size_t *output_length)
410{
411 (void) operation;
412 (void) input;
413 (void) input_length;
414 (void) output;
415 (void) output_size;
416 (void) output_length;
Gilles Peskine449bd832023-01-11 14:50:10 +0100417 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200418}
419
Ronald Cron7f13fa22021-04-13 12:41:34 +0200420psa_status_t mbedtls_test_opaque_cipher_finish(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100421 mbedtls_opaque_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200422 uint8_t *output,
423 size_t output_size,
424 size_t *output_length)
425{
426 (void) operation;
427 (void) output;
428 (void) output_size;
429 (void) output_length;
Gilles Peskine449bd832023-01-11 14:50:10 +0100430 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200431}
Ronald Crone6e6b752023-01-16 16:56:51 +0100432#endif /* PSA_CRYPTO_DRIVER_TEST */