blob: 42eb74da6d654c12465c2e67bd571710aa9960f9 [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
Steven Cooreman37941cb2020-07-28 18:49:51 +02006 * SPDX-License-Identifier: Apache-2.0
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License"); you may
9 * not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
Steven Cooreman37941cb2020-07-28 18:49:51 +020019 */
20
21#if !defined(MBEDTLS_CONFIG_FILE)
22#include "mbedtls/config.h"
23#else
24#include MBEDTLS_CONFIG_FILE
25#endif
26
27#if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) && defined(PSA_CRYPTO_DRIVER_TEST)
28#include "psa/crypto.h"
Ronald Cron8d310ad2020-12-15 15:17:20 +010029#include "psa_crypto_cipher.h"
Steven Cooremanacb5a102020-09-08 14:06:57 +020030#include "psa_crypto_core.h"
Steven Cooreman37941cb2020-07-28 18:49:51 +020031#include "mbedtls/cipher.h"
32
Steven Cooremanacb5a102020-09-08 14:06:57 +020033#include "test/drivers/cipher.h"
Steven Cooreman37941cb2020-07-28 18:49:51 +020034
35#include "test/random.h"
36
Ronald Cronb814bda2021-09-13 14:50:42 +020037#if defined(MBEDTLS_TEST_LIBTESTDRIVER1)
38#include "libtestdriver1/library/psa_crypto_cipher.h"
39#endif
40
Steven Cooreman37941cb2020-07-28 18:49:51 +020041#include <string.h>
42
Ronald Cronc4bc12e2021-04-13 12:41:34 +020043mbedtls_test_driver_cipher_hooks_t mbedtls_test_driver_cipher_hooks =
44 MBEDTLS_TEST_DRIVER_CIPHER_INIT;
Steven Cooreman37941cb2020-07-28 18:49:51 +020045
gabor-mezei-armfa990b52021-03-25 11:17:10 +010046psa_status_t mbedtls_test_transparent_cipher_encrypt(
Steven Cooremanfe0ab552020-09-10 13:07:02 +020047 const psa_key_attributes_t *attributes,
gabor-mezei-armfa990b52021-03-25 11:17:10 +010048 const uint8_t *key_buffer,
49 size_t key_buffer_size,
Steven Cooremanfe0ab552020-09-10 13:07:02 +020050 psa_algorithm_t alg,
Ronald Crona8331692021-07-09 09:19:35 +020051 const uint8_t *iv,
52 size_t iv_length,
gabor-mezei-armfa990b52021-03-25 11:17:10 +010053 const uint8_t *input,
54 size_t input_length,
55 uint8_t *output,
56 size_t output_size,
David Horstmannceeaeb92023-01-05 15:44:23 +000057 size_t *output_length)
Steven Cooremanfe0ab552020-09-10 13:07:02 +020058{
Ronald Cronc4bc12e2021-04-13 12:41:34 +020059 mbedtls_test_driver_cipher_hooks.hits++;
Steven Cooremanfe0ab552020-09-10 13:07:02 +020060
David Horstmannceeaeb92023-01-05 15:44:23 +000061 if (mbedtls_test_driver_cipher_hooks.forced_output != NULL) {
62 if (output_size < mbedtls_test_driver_cipher_hooks.forced_output_length) {
63 return PSA_ERROR_BUFFER_TOO_SMALL;
64 }
Steven Cooremanfe0ab552020-09-10 13:07:02 +020065
David Horstmannceeaeb92023-01-05 15:44:23 +000066 memcpy(output,
67 mbedtls_test_driver_cipher_hooks.forced_output,
68 mbedtls_test_driver_cipher_hooks.forced_output_length);
Ronald Cronc4bc12e2021-04-13 12:41:34 +020069 *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length;
Steven Cooremanfe0ab552020-09-10 13:07:02 +020070
David Horstmannceeaeb92023-01-05 15:44:23 +000071 return mbedtls_test_driver_cipher_hooks.forced_status;
Steven Cooremanfe0ab552020-09-10 13:07:02 +020072 }
73
David Horstmannceeaeb92023-01-05 15:44:23 +000074 if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
75 return mbedtls_test_driver_cipher_hooks.forced_status;
76 }
Steven Cooremanfe0ab552020-09-10 13:07:02 +020077
Ronald Cronb814bda2021-09-13 14:50:42 +020078#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
79 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
David Horstmannceeaeb92023-01-05 15:44:23 +000080 return libtestdriver1_mbedtls_psa_cipher_encrypt(
81 (const libtestdriver1_psa_key_attributes_t *) attributes,
82 key_buffer, key_buffer_size,
83 alg, iv, iv_length, input, input_length,
84 output, output_size, output_length);
Ronald Cron2091eed2021-04-09 11:09:54 +020085#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
David Horstmannceeaeb92023-01-05 15:44:23 +000086 return mbedtls_psa_cipher_encrypt(
87 attributes, key_buffer, key_buffer_size,
88 alg, iv, iv_length, input, input_length,
89 output, output_size, output_length);
Ronald Cron2091eed2021-04-09 11:09:54 +020090#endif
91
David Horstmannceeaeb92023-01-05 15:44:23 +000092 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +020093}
94
Ronald Cronc4bc12e2021-04-13 12:41:34 +020095psa_status_t mbedtls_test_transparent_cipher_decrypt(
Steven Cooreman37941cb2020-07-28 18:49:51 +020096 const psa_key_attributes_t *attributes,
gabor-mezei-armfa990b52021-03-25 11:17:10 +010097 const uint8_t *key_buffer,
98 size_t key_buffer_size,
Steven Cooreman37941cb2020-07-28 18:49:51 +020099 psa_algorithm_t alg,
gabor-mezei-armfa990b52021-03-25 11:17:10 +0100100 const uint8_t *input,
101 size_t input_length,
102 uint8_t *output,
103 size_t output_size,
David Horstmannceeaeb92023-01-05 15:44:23 +0000104 size_t *output_length)
Steven Cooreman37941cb2020-07-28 18:49:51 +0200105{
David Horstmannceeaeb92023-01-05 15:44:23 +0000106 mbedtls_test_driver_cipher_hooks.hits++;
gabor-mezei-armfa990b52021-03-25 11:17:10 +0100107
David Horstmannceeaeb92023-01-05 15:44:23 +0000108 if (mbedtls_test_driver_cipher_hooks.forced_output != NULL) {
109 if (output_size < mbedtls_test_driver_cipher_hooks.forced_output_length) {
110 return PSA_ERROR_BUFFER_TOO_SMALL;
111 }
gabor-mezei-armfa990b52021-03-25 11:17:10 +0100112
David Horstmannceeaeb92023-01-05 15:44:23 +0000113 memcpy(output,
114 mbedtls_test_driver_cipher_hooks.forced_output,
115 mbedtls_test_driver_cipher_hooks.forced_output_length);
gabor-mezei-armfa990b52021-03-25 11:17:10 +0100116 *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length;
117
David Horstmannceeaeb92023-01-05 15:44:23 +0000118 return mbedtls_test_driver_cipher_hooks.forced_status;
gabor-mezei-armfa990b52021-03-25 11:17:10 +0100119 }
120
David Horstmannceeaeb92023-01-05 15:44:23 +0000121 if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
122 return mbedtls_test_driver_cipher_hooks.forced_status;
123 }
gabor-mezei-armfa990b52021-03-25 11:17:10 +0100124
Ronald Cronb814bda2021-09-13 14:50:42 +0200125#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
126 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
David Horstmannceeaeb92023-01-05 15:44:23 +0000127 return libtestdriver1_mbedtls_psa_cipher_decrypt(
128 (const libtestdriver1_psa_key_attributes_t *) attributes,
129 key_buffer, key_buffer_size,
130 alg, input, input_length,
131 output, output_size, output_length);
Ronald Cron2091eed2021-04-09 11:09:54 +0200132#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
David Horstmannceeaeb92023-01-05 15:44:23 +0000133 return mbedtls_psa_cipher_decrypt(
134 attributes, key_buffer, key_buffer_size,
135 alg, input, input_length,
136 output, output_size, output_length);
Ronald Cron2091eed2021-04-09 11:09:54 +0200137#endif
138
David Horstmannceeaeb92023-01-05 15:44:23 +0000139 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200140}
141
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200142psa_status_t mbedtls_test_transparent_cipher_encrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100143 mbedtls_transparent_test_driver_cipher_operation_t *operation,
Steven Cooreman16afd3d2020-09-09 15:36:39 +0200144 const psa_key_attributes_t *attributes,
145 const uint8_t *key, size_t key_length,
146 psa_algorithm_t alg)
147{
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200148 mbedtls_test_driver_cipher_hooks.hits++;
Ronald Cron8d310ad2020-12-15 15:17:20 +0100149
150 /* Wiping the entire struct here, instead of member-by-member. This is
151 * useful for the test suite, since it gives a chance of catching memory
152 * corruption errors should the core not have allocated (enough) memory for
153 * our context struct. */
David Horstmannceeaeb92023-01-05 15:44:23 +0000154 memset(operation, 0, sizeof(*operation));
Ronald Cron8d310ad2020-12-15 15:17:20 +0100155
David Horstmannceeaeb92023-01-05 15:44:23 +0000156 if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
157 return mbedtls_test_driver_cipher_hooks.forced_status;
158 }
Ronald Cron8d310ad2020-12-15 15:17:20 +0100159
Ronald Cronb814bda2021-09-13 14:50:42 +0200160#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
161 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
David Horstmannceeaeb92023-01-05 15:44:23 +0000162 return libtestdriver1_mbedtls_psa_cipher_encrypt_setup(
163 operation,
164 (const libtestdriver1_psa_key_attributes_t *) attributes,
165 key, key_length, alg);
Ronald Cron2091eed2021-04-09 11:09:54 +0200166#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
David Horstmannceeaeb92023-01-05 15:44:23 +0000167 return mbedtls_psa_cipher_encrypt_setup(
168 operation, attributes, key, key_length, alg);
Ronald Cron2091eed2021-04-09 11:09:54 +0200169#endif
170
David Horstmannceeaeb92023-01-05 15:44:23 +0000171 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman16afd3d2020-09-09 15:36:39 +0200172}
173
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200174psa_status_t mbedtls_test_transparent_cipher_decrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100175 mbedtls_transparent_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200176 const psa_key_attributes_t *attributes,
177 const uint8_t *key, size_t key_length,
178 psa_algorithm_t alg)
179{
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200180 mbedtls_test_driver_cipher_hooks.hits++;
Ronald Cron8d310ad2020-12-15 15:17:20 +0100181
David Horstmannceeaeb92023-01-05 15:44:23 +0000182 if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
183 return mbedtls_test_driver_cipher_hooks.forced_status;
184 }
Ronald Cron8d310ad2020-12-15 15:17:20 +0100185
Ronald Cronb814bda2021-09-13 14:50:42 +0200186#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
187 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
David Horstmannceeaeb92023-01-05 15:44:23 +0000188 return libtestdriver1_mbedtls_psa_cipher_decrypt_setup(
189 operation,
190 (const libtestdriver1_psa_key_attributes_t *) attributes,
191 key, key_length, alg);
Ronald Cron2091eed2021-04-09 11:09:54 +0200192#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
David Horstmannceeaeb92023-01-05 15:44:23 +0000193 return mbedtls_psa_cipher_decrypt_setup(
194 operation, attributes, key, key_length, alg);
Ronald Cron2091eed2021-04-09 11:09:54 +0200195#endif
196
David Horstmannceeaeb92023-01-05 15:44:23 +0000197 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200198}
199
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200200psa_status_t mbedtls_test_transparent_cipher_abort(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100201 mbedtls_transparent_test_driver_cipher_operation_t *operation)
Steven Cooreman37941cb2020-07-28 18:49:51 +0200202{
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200203 mbedtls_test_driver_cipher_hooks.hits++;
Steven Cooreman89e54f22020-09-10 18:07:57 +0200204
David Horstmannceeaeb92023-01-05 15:44:23 +0000205 if (operation->alg == 0) {
206 return PSA_SUCCESS;
207 }
Steven Cooreman8b122252020-09-03 15:30:32 +0200208
Ronald Cronb814bda2021-09-13 14:50:42 +0200209#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
210 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
David Horstmannceeaeb92023-01-05 15:44:23 +0000211 libtestdriver1_mbedtls_psa_cipher_abort(operation);
Ronald Cron2091eed2021-04-09 11:09:54 +0200212#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
David Horstmannceeaeb92023-01-05 15:44:23 +0000213 mbedtls_psa_cipher_abort(operation);
Ronald Cron2091eed2021-04-09 11:09:54 +0200214#endif
Steven Cooreman8b122252020-09-03 15:30:32 +0200215
Ronald Cron8d310ad2020-12-15 15:17:20 +0100216 /* Wiping the entire struct here, instead of member-by-member. This is
217 * useful for the test suite, since it gives a chance of catching memory
218 * corruption errors should the core not have allocated (enough) memory for
219 * our context struct. */
David Horstmannceeaeb92023-01-05 15:44:23 +0000220 memset(operation, 0, sizeof(*operation));
Steven Cooreman37941cb2020-07-28 18:49:51 +0200221
David Horstmannceeaeb92023-01-05 15:44:23 +0000222 return mbedtls_test_driver_cipher_hooks.forced_status;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200223}
224
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200225psa_status_t mbedtls_test_transparent_cipher_set_iv(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100226 mbedtls_transparent_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200227 const uint8_t *iv,
228 size_t iv_length)
229{
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200230 mbedtls_test_driver_cipher_hooks.hits++;
Steven Cooreman8b122252020-09-03 15:30:32 +0200231
David Horstmannceeaeb92023-01-05 15:44:23 +0000232 if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
233 return mbedtls_test_driver_cipher_hooks.forced_status;
234 }
Steven Cooreman89e54f22020-09-10 18:07:57 +0200235
Ronald Cronb814bda2021-09-13 14:50:42 +0200236#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
237 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
David Horstmannceeaeb92023-01-05 15:44:23 +0000238 return libtestdriver1_mbedtls_psa_cipher_set_iv(
239 operation, iv, iv_length);
Ronald Cron2091eed2021-04-09 11:09:54 +0200240#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
David Horstmannceeaeb92023-01-05 15:44:23 +0000241 return mbedtls_psa_cipher_set_iv(operation, iv, iv_length);
Ronald Cron2091eed2021-04-09 11:09:54 +0200242#endif
243
David Horstmannceeaeb92023-01-05 15:44:23 +0000244 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200245}
246
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200247psa_status_t mbedtls_test_transparent_cipher_update(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100248 mbedtls_transparent_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200249 const uint8_t *input,
250 size_t input_length,
251 uint8_t *output,
252 size_t output_size,
253 size_t *output_length)
254{
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200255 mbedtls_test_driver_cipher_hooks.hits++;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200256
David Horstmannceeaeb92023-01-05 15:44:23 +0000257 if (mbedtls_test_driver_cipher_hooks.forced_output != NULL) {
258 if (output_size < mbedtls_test_driver_cipher_hooks.forced_output_length) {
Steven Cooreman8b122252020-09-03 15:30:32 +0200259 return PSA_ERROR_BUFFER_TOO_SMALL;
David Horstmannceeaeb92023-01-05 15:44:23 +0000260 }
Steven Cooreman8b122252020-09-03 15:30:32 +0200261
David Horstmannceeaeb92023-01-05 15:44:23 +0000262 memcpy(output,
263 mbedtls_test_driver_cipher_hooks.forced_output,
264 mbedtls_test_driver_cipher_hooks.forced_output_length);
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200265 *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length;
Ronald Cron8d310ad2020-12-15 15:17:20 +0100266
David Horstmannceeaeb92023-01-05 15:44:23 +0000267 return mbedtls_test_driver_cipher_hooks.forced_status;
Steven Cooreman8b122252020-09-03 15:30:32 +0200268 }
Steven Cooreman37941cb2020-07-28 18:49:51 +0200269
David Horstmannceeaeb92023-01-05 15:44:23 +0000270 if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
271 return mbedtls_test_driver_cipher_hooks.forced_status;
272 }
Ronald Cron8d310ad2020-12-15 15:17:20 +0100273
Ronald Cronb814bda2021-09-13 14:50:42 +0200274#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
275 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
David Horstmannceeaeb92023-01-05 15:44:23 +0000276 return libtestdriver1_mbedtls_psa_cipher_update(
277 operation, input, input_length,
278 output, output_size, output_length);
Ronald Cron2091eed2021-04-09 11:09:54 +0200279#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
David Horstmannceeaeb92023-01-05 15:44:23 +0000280 return mbedtls_psa_cipher_update(
281 operation, input, input_length,
282 output, output_size, output_length);
Ronald Cron2091eed2021-04-09 11:09:54 +0200283#endif
284
David Horstmannceeaeb92023-01-05 15:44:23 +0000285 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200286}
287
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200288psa_status_t mbedtls_test_transparent_cipher_finish(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100289 mbedtls_transparent_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200290 uint8_t *output,
291 size_t output_size,
292 size_t *output_length)
293{
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200294 mbedtls_test_driver_cipher_hooks.hits++;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200295
David Horstmannceeaeb92023-01-05 15:44:23 +0000296 if (mbedtls_test_driver_cipher_hooks.forced_output != NULL) {
297 if (output_size < mbedtls_test_driver_cipher_hooks.forced_output_length) {
Steven Cooreman8b122252020-09-03 15:30:32 +0200298 return PSA_ERROR_BUFFER_TOO_SMALL;
David Horstmannceeaeb92023-01-05 15:44:23 +0000299 }
Steven Cooreman8b122252020-09-03 15:30:32 +0200300
David Horstmannceeaeb92023-01-05 15:44:23 +0000301 memcpy(output,
302 mbedtls_test_driver_cipher_hooks.forced_output,
303 mbedtls_test_driver_cipher_hooks.forced_output_length);
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200304 *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length;
Ronald Cron8d310ad2020-12-15 15:17:20 +0100305
David Horstmannceeaeb92023-01-05 15:44:23 +0000306 return mbedtls_test_driver_cipher_hooks.forced_status;
Steven Cooreman8b122252020-09-03 15:30:32 +0200307 }
Steven Cooreman37941cb2020-07-28 18:49:51 +0200308
David Horstmannceeaeb92023-01-05 15:44:23 +0000309 if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
310 return mbedtls_test_driver_cipher_hooks.forced_status;
311 }
Ronald Cron8d310ad2020-12-15 15:17:20 +0100312
Ronald Cronb814bda2021-09-13 14:50:42 +0200313#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
314 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
David Horstmannceeaeb92023-01-05 15:44:23 +0000315 return libtestdriver1_mbedtls_psa_cipher_finish(
316 operation, output, output_size, output_length);
Ronald Cron2091eed2021-04-09 11:09:54 +0200317#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
David Horstmannceeaeb92023-01-05 15:44:23 +0000318 return mbedtls_psa_cipher_finish(
319 operation, output, output_size, output_length);
Ronald Cron2091eed2021-04-09 11:09:54 +0200320#endif
321
David Horstmannceeaeb92023-01-05 15:44:23 +0000322 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200323}
324
325/*
326 * opaque versions, to do
327 */
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200328psa_status_t mbedtls_test_opaque_cipher_encrypt(
Steven Cooreman37941cb2020-07-28 18:49:51 +0200329 const psa_key_attributes_t *attributes,
330 const uint8_t *key, size_t key_length,
331 psa_algorithm_t alg,
Ronald Crona8331692021-07-09 09:19:35 +0200332 const uint8_t *iv, size_t iv_length,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200333 const uint8_t *input, size_t input_length,
334 uint8_t *output, size_t output_size, size_t *output_length)
335{
336 (void) attributes;
337 (void) key;
338 (void) key_length;
339 (void) alg;
Ronald Crona8331692021-07-09 09:19:35 +0200340 (void) iv;
341 (void) iv_length;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200342 (void) input;
343 (void) input_length;
344 (void) output;
345 (void) output_size;
346 (void) output_length;
David Horstmannceeaeb92023-01-05 15:44:23 +0000347 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200348}
349
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200350psa_status_t mbedtls_test_opaque_cipher_decrypt(
Steven Cooreman37941cb2020-07-28 18:49:51 +0200351 const psa_key_attributes_t *attributes,
352 const uint8_t *key, size_t key_length,
353 psa_algorithm_t alg,
354 const uint8_t *input, size_t input_length,
355 uint8_t *output, size_t output_size, size_t *output_length)
356{
357 (void) attributes;
358 (void) key;
359 (void) key_length;
360 (void) alg;
361 (void) input;
362 (void) input_length;
363 (void) output;
364 (void) output_size;
365 (void) output_length;
David Horstmannceeaeb92023-01-05 15:44:23 +0000366 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200367}
368
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200369psa_status_t mbedtls_test_opaque_cipher_encrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100370 mbedtls_opaque_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200371 const psa_key_attributes_t *attributes,
372 const uint8_t *key, size_t key_length,
373 psa_algorithm_t alg)
374{
375 (void) operation;
376 (void) attributes;
377 (void) key;
378 (void) key_length;
379 (void) alg;
David Horstmannceeaeb92023-01-05 15:44:23 +0000380 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200381}
382
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200383psa_status_t mbedtls_test_opaque_cipher_decrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100384 mbedtls_opaque_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200385 const psa_key_attributes_t *attributes,
386 const uint8_t *key, size_t key_length,
387 psa_algorithm_t alg)
388{
389 (void) operation;
390 (void) attributes;
391 (void) key;
392 (void) key_length;
393 (void) alg;
David Horstmannceeaeb92023-01-05 15:44:23 +0000394 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200395}
396
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200397psa_status_t mbedtls_test_opaque_cipher_abort(
David Horstmannceeaeb92023-01-05 15:44:23 +0000398 mbedtls_opaque_test_driver_cipher_operation_t *operation)
Steven Cooreman37941cb2020-07-28 18:49:51 +0200399{
400 (void) operation;
David Horstmannceeaeb92023-01-05 15:44:23 +0000401 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200402}
403
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200404psa_status_t mbedtls_test_opaque_cipher_set_iv(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100405 mbedtls_opaque_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200406 const uint8_t *iv,
407 size_t iv_length)
408{
409 (void) operation;
410 (void) iv;
411 (void) iv_length;
David Horstmannceeaeb92023-01-05 15:44:23 +0000412 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200413}
414
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200415psa_status_t mbedtls_test_opaque_cipher_update(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100416 mbedtls_opaque_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200417 const uint8_t *input,
418 size_t input_length,
419 uint8_t *output,
420 size_t output_size,
421 size_t *output_length)
422{
423 (void) operation;
424 (void) input;
425 (void) input_length;
426 (void) output;
427 (void) output_size;
428 (void) output_length;
David Horstmannceeaeb92023-01-05 15:44:23 +0000429 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200430}
431
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200432psa_status_t mbedtls_test_opaque_cipher_finish(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100433 mbedtls_opaque_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200434 uint8_t *output,
435 size_t output_size,
436 size_t *output_length)
437{
438 (void) operation;
439 (void) output;
440 (void) output_size;
441 (void) output_length;
David Horstmannceeaeb92023-01-05 15:44:23 +0000442 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200443}
444#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */