blob: 4fe559618f8dc4bc245e51180b3d3d57fec1dac2 [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 Cron7f13fa22021-04-13 12:41:34 +020044} mbedtls_test_driver_cipher_hooks_t;
Steven Cooreman37941cb2020-07-28 18:49:51 +020045
Ronald Cron7f13fa22021-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 Cron7f13fa22021-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 Cron7f13fa22021-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 Cron7f13fa22021-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,
60 const uint8_t *input, size_t input_length,
61 uint8_t *output, size_t output_size, size_t *output_length);
62
Ronald Cron7f13fa22021-04-13 12:41:34 +020063psa_status_t mbedtls_test_transparent_cipher_decrypt(
Steven Cooreman37941cb2020-07-28 18:49:51 +020064 const psa_key_attributes_t *attributes,
65 const uint8_t *key, size_t key_length,
66 psa_algorithm_t alg,
67 const uint8_t *input, size_t input_length,
68 uint8_t *output, size_t output_size, size_t *output_length);
69
Ronald Cron7f13fa22021-04-13 12:41:34 +020070psa_status_t mbedtls_test_transparent_cipher_encrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +010071 mbedtls_transparent_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +020072 const psa_key_attributes_t *attributes,
73 const uint8_t *key, size_t key_length,
74 psa_algorithm_t alg);
75
Ronald Cron7f13fa22021-04-13 12:41:34 +020076psa_status_t mbedtls_test_transparent_cipher_decrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +010077 mbedtls_transparent_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +020078 const psa_key_attributes_t *attributes,
79 const uint8_t *key, size_t key_length,
80 psa_algorithm_t alg);
81
Ronald Cron7f13fa22021-04-13 12:41:34 +020082psa_status_t mbedtls_test_transparent_cipher_abort(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +010083 mbedtls_transparent_test_driver_cipher_operation_t *operation );
Steven Cooreman37941cb2020-07-28 18:49:51 +020084
Ronald Cron7f13fa22021-04-13 12:41:34 +020085psa_status_t mbedtls_test_transparent_cipher_set_iv(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +010086 mbedtls_transparent_test_driver_cipher_operation_t *operation,
87 const uint8_t *iv, size_t iv_length);
Steven Cooreman37941cb2020-07-28 18:49:51 +020088
Ronald Cron7f13fa22021-04-13 12:41:34 +020089psa_status_t mbedtls_test_transparent_cipher_update(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +010090 mbedtls_transparent_test_driver_cipher_operation_t *operation,
91 const uint8_t *input, size_t input_length,
92 uint8_t *output, size_t output_size, size_t *output_length);
Steven Cooreman37941cb2020-07-28 18:49:51 +020093
Ronald Cron7f13fa22021-04-13 12:41:34 +020094psa_status_t mbedtls_test_transparent_cipher_finish(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +010095 mbedtls_transparent_test_driver_cipher_operation_t *operation,
96 uint8_t *output, size_t output_size, size_t *output_length);
Steven Cooreman37941cb2020-07-28 18:49:51 +020097
98/*
99 * opaque versions
100 */
Ronald Cron7f13fa22021-04-13 12:41:34 +0200101psa_status_t mbedtls_test_opaque_cipher_encrypt(
Steven Cooreman37941cb2020-07-28 18:49:51 +0200102 const psa_key_attributes_t *attributes,
103 const uint8_t *key, size_t key_length,
104 psa_algorithm_t alg,
105 const uint8_t *input, size_t input_length,
106 uint8_t *output, size_t output_size, size_t *output_length);
107
Ronald Cron7f13fa22021-04-13 12:41:34 +0200108psa_status_t mbedtls_test_opaque_cipher_decrypt(
Steven Cooreman37941cb2020-07-28 18:49:51 +0200109 const psa_key_attributes_t *attributes,
110 const uint8_t *key, size_t key_length,
111 psa_algorithm_t alg,
112 const uint8_t *input, size_t input_length,
113 uint8_t *output, size_t output_size, size_t *output_length);
114
Ronald Cron7f13fa22021-04-13 12:41:34 +0200115psa_status_t mbedtls_test_opaque_cipher_encrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100116 mbedtls_opaque_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200117 const psa_key_attributes_t *attributes,
118 const uint8_t *key, size_t key_length,
119 psa_algorithm_t alg);
120
Ronald Cron7f13fa22021-04-13 12:41:34 +0200121psa_status_t mbedtls_test_opaque_cipher_decrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100122 mbedtls_opaque_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200123 const psa_key_attributes_t *attributes,
124 const uint8_t *key, size_t key_length,
125 psa_algorithm_t alg);
126
Ronald Cron7f13fa22021-04-13 12:41:34 +0200127psa_status_t mbedtls_test_opaque_cipher_abort(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100128 mbedtls_opaque_test_driver_cipher_operation_t *operation);
Steven Cooreman37941cb2020-07-28 18:49:51 +0200129
Ronald Cron7f13fa22021-04-13 12:41:34 +0200130psa_status_t mbedtls_test_opaque_cipher_set_iv(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100131 mbedtls_opaque_test_driver_cipher_operation_t *operation,
132 const uint8_t *iv, size_t iv_length);
Steven Cooreman37941cb2020-07-28 18:49:51 +0200133
Ronald Cron7f13fa22021-04-13 12:41:34 +0200134psa_status_t mbedtls_test_opaque_cipher_update(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100135 mbedtls_opaque_test_driver_cipher_operation_t *operation,
136 const uint8_t *input, size_t input_length,
137 uint8_t *output, size_t output_size, size_t *output_length);
Steven Cooreman37941cb2020-07-28 18:49:51 +0200138
Ronald Cron7f13fa22021-04-13 12:41:34 +0200139psa_status_t mbedtls_test_opaque_cipher_finish(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100140 mbedtls_opaque_test_driver_cipher_operation_t *operation,
141 uint8_t *output, size_t output_size, size_t *output_length);
Steven Cooreman37941cb2020-07-28 18:49:51 +0200142
143#endif /* PSA_CRYPTO_DRIVER_TEST */
144#endif /* PSA_CRYPTO_TEST_DRIVERS_CIPHER_H */