blob: 56b11591f2249a94e1e5f61c75609a3393c8600a [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;
44} test_driver_cipher_hooks_t;
Steven Cooreman37941cb2020-07-28 18:49:51 +020045
Steven Cooremanacb5a102020-09-08 14:06:57 +020046#define TEST_DRIVER_CIPHER_INIT { NULL, 0, PSA_SUCCESS, 0 }
47static inline test_driver_cipher_hooks_t test_driver_cipher_hooks_init( void )
48{
49 const test_driver_cipher_hooks_t v = TEST_DRIVER_CIPHER_INIT;
50 return( v );
51}
52
53extern test_driver_cipher_hooks_t test_driver_cipher_hooks;
Steven Cooreman37941cb2020-07-28 18:49:51 +020054
55psa_status_t test_transparent_cipher_encrypt(
56 const psa_key_attributes_t *attributes,
57 const uint8_t *key, size_t key_length,
58 psa_algorithm_t alg,
59 const uint8_t *input, size_t input_length,
60 uint8_t *output, size_t output_size, size_t *output_length);
61
62psa_status_t test_transparent_cipher_decrypt(
63 const psa_key_attributes_t *attributes,
64 const uint8_t *key, size_t key_length,
65 psa_algorithm_t alg,
66 const uint8_t *input, size_t input_length,
67 uint8_t *output, size_t output_size, size_t *output_length);
68
69psa_status_t test_transparent_cipher_encrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +010070 mbedtls_transparent_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +020071 const psa_key_attributes_t *attributes,
72 const uint8_t *key, size_t key_length,
73 psa_algorithm_t alg);
74
75psa_status_t test_transparent_cipher_decrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +010076 mbedtls_transparent_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +020077 const psa_key_attributes_t *attributes,
78 const uint8_t *key, size_t key_length,
79 psa_algorithm_t alg);
80
81psa_status_t test_transparent_cipher_abort(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +010082 mbedtls_transparent_test_driver_cipher_operation_t *operation );
Steven Cooreman37941cb2020-07-28 18:49:51 +020083
84psa_status_t test_transparent_cipher_generate_iv(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +010085 mbedtls_transparent_test_driver_cipher_operation_t *operation,
86 uint8_t *iv, size_t iv_size, size_t *iv_length);
Steven Cooreman37941cb2020-07-28 18:49:51 +020087
88psa_status_t test_transparent_cipher_set_iv(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +010089 mbedtls_transparent_test_driver_cipher_operation_t *operation,
90 const uint8_t *iv, size_t iv_length);
Steven Cooreman37941cb2020-07-28 18:49:51 +020091
92psa_status_t test_transparent_cipher_update(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +010093 mbedtls_transparent_test_driver_cipher_operation_t *operation,
94 const uint8_t *input, size_t input_length,
95 uint8_t *output, size_t output_size, size_t *output_length);
Steven Cooreman37941cb2020-07-28 18:49:51 +020096
97psa_status_t test_transparent_cipher_finish(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +010098 mbedtls_transparent_test_driver_cipher_operation_t *operation,
99 uint8_t *output, size_t output_size, size_t *output_length);
Steven Cooreman37941cb2020-07-28 18:49:51 +0200100
101/*
102 * opaque versions
103 */
104psa_status_t test_opaque_cipher_encrypt(
105 const psa_key_attributes_t *attributes,
106 const uint8_t *key, size_t key_length,
107 psa_algorithm_t alg,
108 const uint8_t *input, size_t input_length,
109 uint8_t *output, size_t output_size, size_t *output_length);
110
111psa_status_t test_opaque_cipher_decrypt(
112 const psa_key_attributes_t *attributes,
113 const uint8_t *key, size_t key_length,
114 psa_algorithm_t alg,
115 const uint8_t *input, size_t input_length,
116 uint8_t *output, size_t output_size, size_t *output_length);
117
118psa_status_t test_opaque_cipher_encrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100119 mbedtls_opaque_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200120 const psa_key_attributes_t *attributes,
121 const uint8_t *key, size_t key_length,
122 psa_algorithm_t alg);
123
124psa_status_t test_opaque_cipher_decrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100125 mbedtls_opaque_test_driver_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200126 const psa_key_attributes_t *attributes,
127 const uint8_t *key, size_t key_length,
128 psa_algorithm_t alg);
129
130psa_status_t test_opaque_cipher_abort(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100131 mbedtls_opaque_test_driver_cipher_operation_t *operation);
Steven Cooreman37941cb2020-07-28 18:49:51 +0200132
133psa_status_t test_opaque_cipher_generate_iv(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100134 mbedtls_opaque_test_driver_cipher_operation_t *operation,
135 uint8_t *iv, size_t iv_size, size_t *iv_length);
Steven Cooreman37941cb2020-07-28 18:49:51 +0200136
137psa_status_t test_opaque_cipher_set_iv(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100138 mbedtls_opaque_test_driver_cipher_operation_t *operation,
139 const uint8_t *iv, size_t iv_length);
Steven Cooreman37941cb2020-07-28 18:49:51 +0200140
141psa_status_t test_opaque_cipher_update(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100142 mbedtls_opaque_test_driver_cipher_operation_t *operation,
143 const uint8_t *input, size_t input_length,
144 uint8_t *output, size_t output_size, size_t *output_length);
Steven Cooreman37941cb2020-07-28 18:49:51 +0200145
146psa_status_t test_opaque_cipher_finish(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +0100147 mbedtls_opaque_test_driver_cipher_operation_t *operation,
148 uint8_t *output, size_t output_size, size_t *output_length);
Steven Cooreman37941cb2020-07-28 18:49:51 +0200149
150#endif /* PSA_CRYPTO_DRIVER_TEST */
151#endif /* PSA_CRYPTO_TEST_DRIVERS_CIPHER_H */