blob: 33a5e66579cac3718295aa975178f47e32e240dc [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
Bence Szépkútic662b362021-05-27 11:25:03 +020023#include "mbedtls/build_info.h"
Steven Cooreman37941cb2020-07-28 18:49:51 +020024
25#if defined(PSA_CRYPTO_DRIVER_TEST)
26#include <psa/crypto_driver_common.h>
Ronald Cron8d310ad2020-12-15 15:17:20 +010027#include <psa/crypto.h>
Steven Cooreman37941cb2020-07-28 18:49:51 +020028
29#include "mbedtls/cipher.h"
Steven Cooreman37941cb2020-07-28 18:49:51 +020030
Steven Cooremanacb5a102020-09-08 14:06:57 +020031typedef struct {
32 /* If non-null, on success, copy this to the output. */
33 void *forced_output;
34 size_t forced_output_length;
35 /* If not PSA_SUCCESS, return this error code instead of processing the
36 * function call. */
37 psa_status_t forced_status;
Steven Cooreman5240e8b2020-09-09 11:51:45 +020038 /* Count the amount of times one of the cipher driver functions is called. */
Steven Cooremanacb5a102020-09-08 14:06:57 +020039 unsigned long hits;
Ronald Cron7f13fa22021-04-13 12:41:34 +020040} mbedtls_test_driver_cipher_hooks_t;
Steven Cooreman37941cb2020-07-28 18:49:51 +020041
Ronald Cron7f13fa22021-04-13 12:41:34 +020042#define MBEDTLS_TEST_DRIVER_CIPHER_INIT { NULL, 0, PSA_SUCCESS, 0 }
43static inline mbedtls_test_driver_cipher_hooks_t
44 mbedtls_test_driver_cipher_hooks_init( void )
Steven Cooremanacb5a102020-09-08 14:06:57 +020045{
Ronald Cron7f13fa22021-04-13 12:41:34 +020046 const mbedtls_test_driver_cipher_hooks_t v = MBEDTLS_TEST_DRIVER_CIPHER_INIT;
Steven Cooremanacb5a102020-09-08 14:06:57 +020047 return( v );
48}
49
Ronald Cron7f13fa22021-04-13 12:41:34 +020050extern mbedtls_test_driver_cipher_hooks_t mbedtls_test_driver_cipher_hooks;
Steven Cooreman37941cb2020-07-28 18:49:51 +020051
Ronald Cron7f13fa22021-04-13 12:41:34 +020052psa_status_t mbedtls_test_transparent_cipher_encrypt(
Steven Cooreman37941cb2020-07-28 18:49:51 +020053 const psa_key_attributes_t *attributes,
54 const uint8_t *key, size_t key_length,
55 psa_algorithm_t alg,
Ronald Cron9b674282021-07-09 09:19:35 +020056 const uint8_t *iv, size_t iv_length,
Steven Cooreman37941cb2020-07-28 18:49:51 +020057 const uint8_t *input, size_t input_length,
58 uint8_t *output, size_t output_size, size_t *output_length);
59
Ronald Cron7f13fa22021-04-13 12:41:34 +020060psa_status_t mbedtls_test_transparent_cipher_decrypt(
Steven Cooreman37941cb2020-07-28 18:49:51 +020061 const psa_key_attributes_t *attributes,
62 const uint8_t *key, size_t key_length,
63 psa_algorithm_t alg,
64 const uint8_t *input, size_t input_length,
65 uint8_t *output, size_t output_size, size_t *output_length);
66
Ronald Cron7f13fa22021-04-13 12:41:34 +020067psa_status_t mbedtls_test_transparent_cipher_encrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +010068 mbedtls_transparent_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +020069 const psa_key_attributes_t *attributes,
70 const uint8_t *key, size_t key_length,
71 psa_algorithm_t alg);
72
Ronald Cron7f13fa22021-04-13 12:41:34 +020073psa_status_t mbedtls_test_transparent_cipher_decrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +010074 mbedtls_transparent_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +020075 const psa_key_attributes_t *attributes,
76 const uint8_t *key, size_t key_length,
77 psa_algorithm_t alg);
78
Ronald Cron7f13fa22021-04-13 12:41:34 +020079psa_status_t mbedtls_test_transparent_cipher_abort(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +010080 mbedtls_transparent_test_driver_cipher_operation_t *operation );
Steven Cooreman37941cb2020-07-28 18:49:51 +020081
Ronald Cron7f13fa22021-04-13 12:41:34 +020082psa_status_t mbedtls_test_transparent_cipher_set_iv(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +010083 mbedtls_transparent_test_driver_cipher_operation_t *operation,
84 const uint8_t *iv, size_t iv_length);
Steven Cooreman37941cb2020-07-28 18:49:51 +020085
Ronald Cron7f13fa22021-04-13 12:41:34 +020086psa_status_t mbedtls_test_transparent_cipher_update(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +010087 mbedtls_transparent_test_driver_cipher_operation_t *operation,
88 const uint8_t *input, size_t input_length,
89 uint8_t *output, size_t output_size, size_t *output_length);
Steven Cooreman37941cb2020-07-28 18:49:51 +020090
Ronald Cron7f13fa22021-04-13 12:41:34 +020091psa_status_t mbedtls_test_transparent_cipher_finish(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +010092 mbedtls_transparent_test_driver_cipher_operation_t *operation,
93 uint8_t *output, size_t output_size, size_t *output_length);
Steven Cooreman37941cb2020-07-28 18:49:51 +020094
95/*
96 * opaque versions
97 */
Ronald Cron7f13fa22021-04-13 12:41:34 +020098psa_status_t mbedtls_test_opaque_cipher_encrypt(
Steven Cooreman37941cb2020-07-28 18:49:51 +020099 const psa_key_attributes_t *attributes,
100 const uint8_t *key, size_t key_length,
101 psa_algorithm_t alg,
Ronald Cron9b674282021-07-09 09:19:35 +0200102 const uint8_t *iv, size_t iv_length,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200103 const uint8_t *input, size_t input_length,
104 uint8_t *output, size_t output_size, size_t *output_length);
105
Ronald Cron7f13fa22021-04-13 12:41:34 +0200106psa_status_t mbedtls_test_opaque_cipher_decrypt(
Steven Cooreman37941cb2020-07-28 18:49:51 +0200107 const psa_key_attributes_t *attributes,
108 const uint8_t *key, size_t key_length,
109 psa_algorithm_t alg,
110 const uint8_t *input, size_t input_length,
111 uint8_t *output, size_t output_size, size_t *output_length);
112
Ronald Cron7f13fa22021-04-13 12:41:34 +0200113psa_status_t mbedtls_test_opaque_cipher_encrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100114 mbedtls_opaque_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200115 const psa_key_attributes_t *attributes,
116 const uint8_t *key, size_t key_length,
117 psa_algorithm_t alg);
118
Ronald Cron7f13fa22021-04-13 12:41:34 +0200119psa_status_t mbedtls_test_opaque_cipher_decrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100120 mbedtls_opaque_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200121 const psa_key_attributes_t *attributes,
122 const uint8_t *key, size_t key_length,
123 psa_algorithm_t alg);
124
Ronald Cron7f13fa22021-04-13 12:41:34 +0200125psa_status_t mbedtls_test_opaque_cipher_abort(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100126 mbedtls_opaque_test_driver_cipher_operation_t *operation);
Steven Cooreman37941cb2020-07-28 18:49:51 +0200127
Ronald Cron7f13fa22021-04-13 12:41:34 +0200128psa_status_t mbedtls_test_opaque_cipher_set_iv(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100129 mbedtls_opaque_test_driver_cipher_operation_t *operation,
130 const uint8_t *iv, size_t iv_length);
Steven Cooreman37941cb2020-07-28 18:49:51 +0200131
Ronald Cron7f13fa22021-04-13 12:41:34 +0200132psa_status_t mbedtls_test_opaque_cipher_update(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100133 mbedtls_opaque_test_driver_cipher_operation_t *operation,
134 const uint8_t *input, size_t input_length,
135 uint8_t *output, size_t output_size, size_t *output_length);
Steven Cooreman37941cb2020-07-28 18:49:51 +0200136
Ronald Cron7f13fa22021-04-13 12:41:34 +0200137psa_status_t mbedtls_test_opaque_cipher_finish(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100138 mbedtls_opaque_test_driver_cipher_operation_t *operation,
139 uint8_t *output, size_t output_size, size_t *output_length);
Steven Cooreman37941cb2020-07-28 18:49:51 +0200140
141#endif /* PSA_CRYPTO_DRIVER_TEST */
142#endif /* PSA_CRYPTO_TEST_DRIVERS_CIPHER_H */