blob: c1aa616b52f064cf69dad330e08928365036fdb7 [file] [log] [blame]
Steven Cooreman37941cb2020-07-28 18:49:51 +02001/*
2 * Test driver for cipher functions
3 */
Steven Cooreman3ec40182020-09-02 16:27:46 +02004/* Copyright The Mbed TLS Contributors
Steven Cooreman37941cb2020-07-28 18:49:51 +02005 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
Steven Cooreman37941cb2020-07-28 18:49:51 +020018 */
19
20#ifndef PSA_CRYPTO_TEST_DRIVERS_CIPHER_H
21#define PSA_CRYPTO_TEST_DRIVERS_CIPHER_H
22
23#if !defined(MBEDTLS_CONFIG_FILE)
24#include "mbedtls/config.h"
25#else
26#include MBEDTLS_CONFIG_FILE
27#endif
28
29#if defined(PSA_CRYPTO_DRIVER_TEST)
30#include <psa/crypto_driver_common.h>
Ronald Cron8d310ad2020-12-15 15:17:20 +010031#include <psa/crypto.h>
Steven Cooreman37941cb2020-07-28 18:49:51 +020032
33#include "mbedtls/cipher.h"
Steven Cooreman37941cb2020-07-28 18:49:51 +020034
Steven Cooremanacb5a102020-09-08 14:06:57 +020035typedef struct {
36 /* If non-null, on success, copy this to the output. */
37 void *forced_output;
38 size_t forced_output_length;
39 /* If not PSA_SUCCESS, return this error code instead of processing the
40 * function call. */
41 psa_status_t forced_status;
Steven Cooreman5240e8b2020-09-09 11:51:45 +020042 /* Count the amount of times one of the cipher driver functions is called. */
Steven Cooremanacb5a102020-09-08 14:06:57 +020043 unsigned long hits;
Ronald Cronc4bc12e2021-04-13 12:41:34 +020044} mbedtls_test_driver_cipher_hooks_t;
Steven Cooreman37941cb2020-07-28 18:49:51 +020045
Ronald Cronc4bc12e2021-04-13 12:41:34 +020046#define MBEDTLS_TEST_DRIVER_CIPHER_INIT { NULL, 0, PSA_SUCCESS, 0 }
47static inline mbedtls_test_driver_cipher_hooks_t
48 mbedtls_test_driver_cipher_hooks_init( void )
Steven Cooremanacb5a102020-09-08 14:06:57 +020049{
Ronald Cronc4bc12e2021-04-13 12:41:34 +020050 const mbedtls_test_driver_cipher_hooks_t v = MBEDTLS_TEST_DRIVER_CIPHER_INIT;
Steven Cooremanacb5a102020-09-08 14:06:57 +020051 return( v );
52}
53
Ronald Cronc4bc12e2021-04-13 12:41:34 +020054extern mbedtls_test_driver_cipher_hooks_t mbedtls_test_driver_cipher_hooks;
Steven Cooreman37941cb2020-07-28 18:49:51 +020055
Ronald Cronc4bc12e2021-04-13 12:41:34 +020056psa_status_t mbedtls_test_transparent_cipher_encrypt(
Steven Cooreman37941cb2020-07-28 18:49:51 +020057 const psa_key_attributes_t *attributes,
58 const uint8_t *key, size_t key_length,
59 psa_algorithm_t alg,
Ronald Crona8331692021-07-09 09:19:35 +020060 const uint8_t *iv, size_t iv_length,
Steven Cooreman37941cb2020-07-28 18:49:51 +020061 const uint8_t *input, size_t input_length,
62 uint8_t *output, size_t output_size, size_t *output_length);
63
Ronald Cronc4bc12e2021-04-13 12:41:34 +020064psa_status_t mbedtls_test_transparent_cipher_decrypt(
Steven Cooreman37941cb2020-07-28 18:49:51 +020065 const psa_key_attributes_t *attributes,
66 const uint8_t *key, size_t key_length,
67 psa_algorithm_t alg,
68 const uint8_t *input, size_t input_length,
69 uint8_t *output, size_t output_size, size_t *output_length);
70
Ronald Cronc4bc12e2021-04-13 12:41:34 +020071psa_status_t mbedtls_test_transparent_cipher_encrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +010072 mbedtls_transparent_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +020073 const psa_key_attributes_t *attributes,
74 const uint8_t *key, size_t key_length,
75 psa_algorithm_t alg);
76
Ronald Cronc4bc12e2021-04-13 12:41:34 +020077psa_status_t mbedtls_test_transparent_cipher_decrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +010078 mbedtls_transparent_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +020079 const psa_key_attributes_t *attributes,
80 const uint8_t *key, size_t key_length,
81 psa_algorithm_t alg);
82
Ronald Cronc4bc12e2021-04-13 12:41:34 +020083psa_status_t mbedtls_test_transparent_cipher_abort(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +010084 mbedtls_transparent_test_driver_cipher_operation_t *operation );
Steven Cooreman37941cb2020-07-28 18:49:51 +020085
Ronald Cronc4bc12e2021-04-13 12:41:34 +020086psa_status_t mbedtls_test_transparent_cipher_set_iv(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +010087 mbedtls_transparent_test_driver_cipher_operation_t *operation,
88 const uint8_t *iv, size_t iv_length);
Steven Cooreman37941cb2020-07-28 18:49:51 +020089
Ronald Cronc4bc12e2021-04-13 12:41:34 +020090psa_status_t mbedtls_test_transparent_cipher_update(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +010091 mbedtls_transparent_test_driver_cipher_operation_t *operation,
92 const uint8_t *input, size_t input_length,
93 uint8_t *output, size_t output_size, size_t *output_length);
Steven Cooreman37941cb2020-07-28 18:49:51 +020094
Ronald Cronc4bc12e2021-04-13 12:41:34 +020095psa_status_t mbedtls_test_transparent_cipher_finish(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +010096 mbedtls_transparent_test_driver_cipher_operation_t *operation,
97 uint8_t *output, size_t output_size, size_t *output_length);
Steven Cooreman37941cb2020-07-28 18:49:51 +020098
99/*
100 * opaque versions
101 */
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200102psa_status_t mbedtls_test_opaque_cipher_encrypt(
Steven Cooreman37941cb2020-07-28 18:49:51 +0200103 const psa_key_attributes_t *attributes,
104 const uint8_t *key, size_t key_length,
105 psa_algorithm_t alg,
Ronald Crona8331692021-07-09 09:19:35 +0200106 const uint8_t *iv, size_t iv_length,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200107 const uint8_t *input, size_t input_length,
108 uint8_t *output, size_t output_size, size_t *output_length);
109
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200110psa_status_t mbedtls_test_opaque_cipher_decrypt(
Steven Cooreman37941cb2020-07-28 18:49:51 +0200111 const psa_key_attributes_t *attributes,
112 const uint8_t *key, size_t key_length,
113 psa_algorithm_t alg,
114 const uint8_t *input, size_t input_length,
115 uint8_t *output, size_t output_size, size_t *output_length);
116
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200117psa_status_t mbedtls_test_opaque_cipher_encrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100118 mbedtls_opaque_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200119 const psa_key_attributes_t *attributes,
120 const uint8_t *key, size_t key_length,
121 psa_algorithm_t alg);
122
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200123psa_status_t mbedtls_test_opaque_cipher_decrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100124 mbedtls_opaque_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200125 const psa_key_attributes_t *attributes,
126 const uint8_t *key, size_t key_length,
127 psa_algorithm_t alg);
128
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200129psa_status_t mbedtls_test_opaque_cipher_abort(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100130 mbedtls_opaque_test_driver_cipher_operation_t *operation);
Steven Cooreman37941cb2020-07-28 18:49:51 +0200131
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200132psa_status_t mbedtls_test_opaque_cipher_set_iv(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100133 mbedtls_opaque_test_driver_cipher_operation_t *operation,
134 const uint8_t *iv, size_t iv_length);
Steven Cooreman37941cb2020-07-28 18:49:51 +0200135
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200136psa_status_t mbedtls_test_opaque_cipher_update(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100137 mbedtls_opaque_test_driver_cipher_operation_t *operation,
138 const uint8_t *input, size_t input_length,
139 uint8_t *output, size_t output_size, size_t *output_length);
Steven Cooreman37941cb2020-07-28 18:49:51 +0200140
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200141psa_status_t mbedtls_test_opaque_cipher_finish(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100142 mbedtls_opaque_test_driver_cipher_operation_t *operation,
143 uint8_t *output, size_t output_size, size_t *output_length);
Steven Cooreman37941cb2020-07-28 18:49:51 +0200144
145#endif /* PSA_CRYPTO_DRIVER_TEST */
146#endif /* PSA_CRYPTO_TEST_DRIVERS_CIPHER_H */