blob: ead5490621f955b485bba908ca3a6c0ea2196d45 [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 Rodgman7ff79652023-11-03 12:04:52 +00006 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Steven Cooreman37941cb2020-07-28 18:49:51 +02007 */
8
9#if !defined(MBEDTLS_CONFIG_FILE)
10#include "mbedtls/config.h"
11#else
12#include MBEDTLS_CONFIG_FILE
13#endif
14
15#if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) && defined(PSA_CRYPTO_DRIVER_TEST)
16#include "psa/crypto.h"
Ronald Cron8d310ad2020-12-15 15:17:20 +010017#include "psa_crypto_cipher.h"
Steven Cooremanacb5a102020-09-08 14:06:57 +020018#include "psa_crypto_core.h"
Steven Cooreman37941cb2020-07-28 18:49:51 +020019#include "mbedtls/cipher.h"
20
Steven Cooremanacb5a102020-09-08 14:06:57 +020021#include "test/drivers/cipher.h"
Steven Cooreman37941cb2020-07-28 18:49:51 +020022
23#include "test/random.h"
24
Ronald Cronb814bda2021-09-13 14:50:42 +020025#if defined(MBEDTLS_TEST_LIBTESTDRIVER1)
26#include "libtestdriver1/library/psa_crypto_cipher.h"
27#endif
28
Steven Cooreman37941cb2020-07-28 18:49:51 +020029#include <string.h>
30
Ronald Cronc4bc12e2021-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-armfa990b52021-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-armfa990b52021-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 Crona8331692021-07-09 09:19:35 +020039 const uint8_t *iv,
40 size_t iv_length,
gabor-mezei-armfa990b52021-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 Peskine1b6c09a2023-01-11 14:52:35 +010045 size_t *output_length)
Steven Cooremanfe0ab552020-09-10 13:07:02 +020046{
Ronald Cronc4bc12e2021-04-13 12:41:34 +020047 mbedtls_test_driver_cipher_hooks.hits++;
Steven Cooremanfe0ab552020-09-10 13:07:02 +020048
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010049 if (mbedtls_test_driver_cipher_hooks.forced_output != NULL) {
50 if (output_size < mbedtls_test_driver_cipher_hooks.forced_output_length) {
51 return PSA_ERROR_BUFFER_TOO_SMALL;
52 }
Steven Cooremanfe0ab552020-09-10 13:07:02 +020053
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010054 memcpy(output,
55 mbedtls_test_driver_cipher_hooks.forced_output,
56 mbedtls_test_driver_cipher_hooks.forced_output_length);
Ronald Cronc4bc12e2021-04-13 12:41:34 +020057 *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length;
Steven Cooremanfe0ab552020-09-10 13:07:02 +020058
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010059 return mbedtls_test_driver_cipher_hooks.forced_status;
Steven Cooremanfe0ab552020-09-10 13:07:02 +020060 }
61
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010062 if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
63 return mbedtls_test_driver_cipher_hooks.forced_status;
64 }
Steven Cooremanfe0ab552020-09-10 13:07:02 +020065
Ronald Cronb814bda2021-09-13 14:50:42 +020066#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
67 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +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 Cron2091eed2021-04-09 11:09:54 +020073#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +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 Cron2091eed2021-04-09 11:09:54 +020078#endif
79
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010080 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +020081}
82
Ronald Cronc4bc12e2021-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-armfa990b52021-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-armfa990b52021-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 Peskine1b6c09a2023-01-11 14:52:35 +010092 size_t *output_length)
Steven Cooreman37941cb2020-07-28 18:49:51 +020093{
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010094 mbedtls_test_driver_cipher_hooks.hits++;
gabor-mezei-armfa990b52021-03-25 11:17:10 +010095
Gilles Peskine1b6c09a2023-01-11 14:52:35 +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-armfa990b52021-03-25 11:17:10 +0100100
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100101 memcpy(output,
102 mbedtls_test_driver_cipher_hooks.forced_output,
103 mbedtls_test_driver_cipher_hooks.forced_output_length);
gabor-mezei-armfa990b52021-03-25 11:17:10 +0100104 *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length;
105
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100106 return mbedtls_test_driver_cipher_hooks.forced_status;
gabor-mezei-armfa990b52021-03-25 11:17:10 +0100107 }
108
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100109 if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
110 return mbedtls_test_driver_cipher_hooks.forced_status;
111 }
gabor-mezei-armfa990b52021-03-25 11:17:10 +0100112
Ronald Cronb814bda2021-09-13 14:50:42 +0200113#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
114 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +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 Cron2091eed2021-04-09 11:09:54 +0200120#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +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 Cron2091eed2021-04-09 11:09:54 +0200125#endif
126
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100127 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200128}
129
Ronald Cronc4bc12e2021-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 Cronc4bc12e2021-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 Peskine1b6c09a2023-01-11 14:52:35 +0100142 memset(operation, 0, sizeof(*operation));
Ronald Cron8d310ad2020-12-15 15:17:20 +0100143
Gilles Peskine1b6c09a2023-01-11 14:52:35 +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 Cronb814bda2021-09-13 14:50:42 +0200148#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
149 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100150 return libtestdriver1_mbedtls_psa_cipher_encrypt_setup(
151 operation,
152 (const libtestdriver1_psa_key_attributes_t *) attributes,
153 key, key_length, alg);
Ronald Cron2091eed2021-04-09 11:09:54 +0200154#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100155 return mbedtls_psa_cipher_encrypt_setup(
156 operation, attributes, key, key_length, alg);
Ronald Cron2091eed2021-04-09 11:09:54 +0200157#endif
158
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100159 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman16afd3d2020-09-09 15:36:39 +0200160}
161
Ronald Cronc4bc12e2021-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 Cronc4bc12e2021-04-13 12:41:34 +0200168 mbedtls_test_driver_cipher_hooks.hits++;
Ronald Cron8d310ad2020-12-15 15:17:20 +0100169
Gilles Peskine1b6c09a2023-01-11 14:52:35 +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 Cronb814bda2021-09-13 14:50:42 +0200174#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
175 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100176 return libtestdriver1_mbedtls_psa_cipher_decrypt_setup(
177 operation,
178 (const libtestdriver1_psa_key_attributes_t *) attributes,
179 key, key_length, alg);
Ronald Cron2091eed2021-04-09 11:09:54 +0200180#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100181 return mbedtls_psa_cipher_decrypt_setup(
182 operation, attributes, key, key_length, alg);
Ronald Cron2091eed2021-04-09 11:09:54 +0200183#endif
184
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100185 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200186}
187
Ronald Cronc4bc12e2021-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 Cronc4bc12e2021-04-13 12:41:34 +0200191 mbedtls_test_driver_cipher_hooks.hits++;
Steven Cooreman89e54f22020-09-10 18:07:57 +0200192
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100193 if (operation->alg == 0) {
194 return PSA_SUCCESS;
195 }
Steven Cooreman8b122252020-09-03 15:30:32 +0200196
Ronald Cronb814bda2021-09-13 14:50:42 +0200197#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
198 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100199 libtestdriver1_mbedtls_psa_cipher_abort(operation);
Ronald Cron2091eed2021-04-09 11:09:54 +0200200#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100201 mbedtls_psa_cipher_abort(operation);
Ronald Cron2091eed2021-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 Peskine1b6c09a2023-01-11 14:52:35 +0100208 memset(operation, 0, sizeof(*operation));
Steven Cooreman37941cb2020-07-28 18:49:51 +0200209
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100210 return mbedtls_test_driver_cipher_hooks.forced_status;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200211}
212
Ronald Cronc4bc12e2021-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 Cronc4bc12e2021-04-13 12:41:34 +0200218 mbedtls_test_driver_cipher_hooks.hits++;
Steven Cooreman8b122252020-09-03 15:30:32 +0200219
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100220 if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
221 return mbedtls_test_driver_cipher_hooks.forced_status;
222 }
Steven Cooreman89e54f22020-09-10 18:07:57 +0200223
Ronald Cronb814bda2021-09-13 14:50:42 +0200224#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
225 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100226 return libtestdriver1_mbedtls_psa_cipher_set_iv(
227 operation, iv, iv_length);
Ronald Cron2091eed2021-04-09 11:09:54 +0200228#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100229 return mbedtls_psa_cipher_set_iv(operation, iv, iv_length);
Ronald Cron2091eed2021-04-09 11:09:54 +0200230#endif
231
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100232 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200233}
234
Ronald Cronc4bc12e2021-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 Cronc4bc12e2021-04-13 12:41:34 +0200243 mbedtls_test_driver_cipher_hooks.hits++;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200244
Gilles Peskine1b6c09a2023-01-11 14:52:35 +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 Peskine1b6c09a2023-01-11 14:52:35 +0100248 }
Steven Cooreman8b122252020-09-03 15:30:32 +0200249
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100250 memcpy(output,
251 mbedtls_test_driver_cipher_hooks.forced_output,
252 mbedtls_test_driver_cipher_hooks.forced_output_length);
Ronald Cronc4bc12e2021-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 Peskine1b6c09a2023-01-11 14:52:35 +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 Peskine1b6c09a2023-01-11 14:52:35 +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 Cronb814bda2021-09-13 14:50:42 +0200262#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
263 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100264 return libtestdriver1_mbedtls_psa_cipher_update(
265 operation, input, input_length,
266 output, output_size, output_length);
Ronald Cron2091eed2021-04-09 11:09:54 +0200267#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100268 return mbedtls_psa_cipher_update(
269 operation, input, input_length,
270 output, output_size, output_length);
Ronald Cron2091eed2021-04-09 11:09:54 +0200271#endif
272
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100273 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200274}
275
Ronald Cronc4bc12e2021-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 Cronc4bc12e2021-04-13 12:41:34 +0200282 mbedtls_test_driver_cipher_hooks.hits++;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200283
Gilles Peskine1b6c09a2023-01-11 14:52:35 +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 Peskine1b6c09a2023-01-11 14:52:35 +0100287 }
Steven Cooreman8b122252020-09-03 15:30:32 +0200288
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100289 memcpy(output,
290 mbedtls_test_driver_cipher_hooks.forced_output,
291 mbedtls_test_driver_cipher_hooks.forced_output_length);
Ronald Cronc4bc12e2021-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 Peskine1b6c09a2023-01-11 14:52:35 +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 Peskine1b6c09a2023-01-11 14:52:35 +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 Cronb814bda2021-09-13 14:50:42 +0200301#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
302 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100303 return libtestdriver1_mbedtls_psa_cipher_finish(
304 operation, output, output_size, output_length);
Ronald Cron2091eed2021-04-09 11:09:54 +0200305#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100306 return mbedtls_psa_cipher_finish(
307 operation, output, output_size, output_length);
Ronald Cron2091eed2021-04-09 11:09:54 +0200308#endif
309
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100310 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200311}
312
313/*
314 * opaque versions, to do
315 */
Ronald Cronc4bc12e2021-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 Crona8331692021-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 Crona8331692021-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 Peskine1b6c09a2023-01-11 14:52:35 +0100335 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200336}
337
Ronald Cronc4bc12e2021-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 Peskine1b6c09a2023-01-11 14:52:35 +0100354 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200355}
356
Ronald Cronc4bc12e2021-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 Peskine1b6c09a2023-01-11 14:52:35 +0100368 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200369}
370
Ronald Cronc4bc12e2021-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 Peskine1b6c09a2023-01-11 14:52:35 +0100382 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200383}
384
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200385psa_status_t mbedtls_test_opaque_cipher_abort(
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100386 mbedtls_opaque_test_driver_cipher_operation_t *operation)
Steven Cooreman37941cb2020-07-28 18:49:51 +0200387{
388 (void) operation;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100389 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200390}
391
Ronald Cronc4bc12e2021-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 Peskine1b6c09a2023-01-11 14:52:35 +0100400 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200401}
402
Ronald Cronc4bc12e2021-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 Peskine1b6c09a2023-01-11 14:52:35 +0100417 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200418}
419
Ronald Cronc4bc12e2021-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 Peskine1b6c09a2023-01-11 14:52:35 +0100430 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200431}
432#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */