Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Test driver for cipher functions. |
| 3 | * Currently only supports multi-part operations using AES-CTR. |
| 4 | */ |
Steven Cooreman | 3ec4018 | 2020-09-02 16:27:46 +0200 | [diff] [blame] | 5 | /* Copyright The Mbed TLS Contributors |
Dave Rodgman | 7ff7965 | 2023-11-03 12:04:52 +0000 | [diff] [blame] | 6 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #if !defined(MBEDTLS_CONFIG_FILE) |
| 10 | #include "mbedtls/config.h" |
| 11 | #else |
| 12 | #include MBEDTLS_CONFIG_FILE |
| 13 | #endif |
| 14 | |
| 15 | #if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) && defined(PSA_CRYPTO_DRIVER_TEST) |
| 16 | #include "psa/crypto.h" |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 17 | #include "psa_crypto_cipher.h" |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 18 | #include "psa_crypto_core.h" |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 19 | #include "mbedtls/cipher.h" |
| 20 | |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 21 | #include "test/drivers/cipher.h" |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 22 | |
| 23 | #include "test/random.h" |
| 24 | |
Ronald Cron | b814bda | 2021-09-13 14:50:42 +0200 | [diff] [blame] | 25 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) |
| 26 | #include "libtestdriver1/library/psa_crypto_cipher.h" |
| 27 | #endif |
| 28 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 29 | #include <string.h> |
| 30 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 31 | mbedtls_test_driver_cipher_hooks_t mbedtls_test_driver_cipher_hooks = |
| 32 | MBEDTLS_TEST_DRIVER_CIPHER_INIT; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 33 | |
gabor-mezei-arm | fa990b5 | 2021-03-25 11:17:10 +0100 | [diff] [blame] | 34 | psa_status_t mbedtls_test_transparent_cipher_encrypt( |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 35 | const psa_key_attributes_t *attributes, |
gabor-mezei-arm | fa990b5 | 2021-03-25 11:17:10 +0100 | [diff] [blame] | 36 | const uint8_t *key_buffer, |
| 37 | size_t key_buffer_size, |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 38 | psa_algorithm_t alg, |
Ronald Cron | a833169 | 2021-07-09 09:19:35 +0200 | [diff] [blame] | 39 | const uint8_t *iv, |
| 40 | size_t iv_length, |
gabor-mezei-arm | fa990b5 | 2021-03-25 11:17:10 +0100 | [diff] [blame] | 41 | const uint8_t *input, |
| 42 | size_t input_length, |
| 43 | uint8_t *output, |
| 44 | size_t output_size, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 45 | size_t *output_length) |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 46 | { |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 47 | mbedtls_test_driver_cipher_hooks.hits++; |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 48 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 49 | if (mbedtls_test_driver_cipher_hooks.forced_output != NULL) { |
| 50 | if (output_size < mbedtls_test_driver_cipher_hooks.forced_output_length) { |
| 51 | return PSA_ERROR_BUFFER_TOO_SMALL; |
| 52 | } |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 53 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 54 | memcpy(output, |
| 55 | mbedtls_test_driver_cipher_hooks.forced_output, |
| 56 | mbedtls_test_driver_cipher_hooks.forced_output_length); |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 57 | *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length; |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 58 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 59 | return mbedtls_test_driver_cipher_hooks.forced_status; |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 60 | } |
| 61 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 62 | if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) { |
| 63 | return mbedtls_test_driver_cipher_hooks.forced_status; |
| 64 | } |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 65 | |
Ronald Cron | b814bda | 2021-09-13 14:50:42 +0200 | [diff] [blame] | 66 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
| 67 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER) |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 68 | return libtestdriver1_mbedtls_psa_cipher_encrypt( |
| 69 | (const libtestdriver1_psa_key_attributes_t *) attributes, |
| 70 | key_buffer, key_buffer_size, |
| 71 | alg, iv, iv_length, input, input_length, |
| 72 | output, output_size, output_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 73 | #elif defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 74 | return mbedtls_psa_cipher_encrypt( |
| 75 | attributes, key_buffer, key_buffer_size, |
| 76 | alg, iv, iv_length, input, input_length, |
| 77 | output, output_size, output_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 78 | #endif |
| 79 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 80 | return PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 81 | } |
| 82 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 83 | psa_status_t mbedtls_test_transparent_cipher_decrypt( |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 84 | const psa_key_attributes_t *attributes, |
gabor-mezei-arm | fa990b5 | 2021-03-25 11:17:10 +0100 | [diff] [blame] | 85 | const uint8_t *key_buffer, |
| 86 | size_t key_buffer_size, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 87 | psa_algorithm_t alg, |
gabor-mezei-arm | fa990b5 | 2021-03-25 11:17:10 +0100 | [diff] [blame] | 88 | const uint8_t *input, |
| 89 | size_t input_length, |
| 90 | uint8_t *output, |
| 91 | size_t output_size, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 92 | size_t *output_length) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 93 | { |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 94 | mbedtls_test_driver_cipher_hooks.hits++; |
gabor-mezei-arm | fa990b5 | 2021-03-25 11:17:10 +0100 | [diff] [blame] | 95 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 96 | if (mbedtls_test_driver_cipher_hooks.forced_output != NULL) { |
| 97 | if (output_size < mbedtls_test_driver_cipher_hooks.forced_output_length) { |
| 98 | return PSA_ERROR_BUFFER_TOO_SMALL; |
| 99 | } |
gabor-mezei-arm | fa990b5 | 2021-03-25 11:17:10 +0100 | [diff] [blame] | 100 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 101 | memcpy(output, |
| 102 | mbedtls_test_driver_cipher_hooks.forced_output, |
| 103 | mbedtls_test_driver_cipher_hooks.forced_output_length); |
gabor-mezei-arm | fa990b5 | 2021-03-25 11:17:10 +0100 | [diff] [blame] | 104 | *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length; |
| 105 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 106 | return mbedtls_test_driver_cipher_hooks.forced_status; |
gabor-mezei-arm | fa990b5 | 2021-03-25 11:17:10 +0100 | [diff] [blame] | 107 | } |
| 108 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 109 | if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) { |
| 110 | return mbedtls_test_driver_cipher_hooks.forced_status; |
| 111 | } |
gabor-mezei-arm | fa990b5 | 2021-03-25 11:17:10 +0100 | [diff] [blame] | 112 | |
Ronald Cron | b814bda | 2021-09-13 14:50:42 +0200 | [diff] [blame] | 113 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
| 114 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER) |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 115 | return libtestdriver1_mbedtls_psa_cipher_decrypt( |
| 116 | (const libtestdriver1_psa_key_attributes_t *) attributes, |
| 117 | key_buffer, key_buffer_size, |
| 118 | alg, input, input_length, |
| 119 | output, output_size, output_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 120 | #elif defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 121 | return mbedtls_psa_cipher_decrypt( |
| 122 | attributes, key_buffer, key_buffer_size, |
| 123 | alg, input, input_length, |
| 124 | output, output_size, output_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 125 | #endif |
| 126 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 127 | return PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 128 | } |
| 129 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 130 | psa_status_t mbedtls_test_transparent_cipher_encrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 131 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 16afd3d | 2020-09-09 15:36:39 +0200 | [diff] [blame] | 132 | const psa_key_attributes_t *attributes, |
| 133 | const uint8_t *key, size_t key_length, |
| 134 | psa_algorithm_t alg) |
| 135 | { |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 136 | mbedtls_test_driver_cipher_hooks.hits++; |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 137 | |
| 138 | /* Wiping the entire struct here, instead of member-by-member. This is |
| 139 | * useful for the test suite, since it gives a chance of catching memory |
| 140 | * corruption errors should the core not have allocated (enough) memory for |
| 141 | * our context struct. */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 142 | memset(operation, 0, sizeof(*operation)); |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 143 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 144 | if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) { |
| 145 | return mbedtls_test_driver_cipher_hooks.forced_status; |
| 146 | } |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 147 | |
Ronald Cron | b814bda | 2021-09-13 14:50:42 +0200 | [diff] [blame] | 148 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
| 149 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER) |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 150 | return libtestdriver1_mbedtls_psa_cipher_encrypt_setup( |
| 151 | operation, |
| 152 | (const libtestdriver1_psa_key_attributes_t *) attributes, |
| 153 | key, key_length, alg); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 154 | #elif defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 155 | return mbedtls_psa_cipher_encrypt_setup( |
| 156 | operation, attributes, key, key_length, alg); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 157 | #endif |
| 158 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 159 | return PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | 16afd3d | 2020-09-09 15:36:39 +0200 | [diff] [blame] | 160 | } |
| 161 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 162 | psa_status_t mbedtls_test_transparent_cipher_decrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 163 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 164 | const psa_key_attributes_t *attributes, |
| 165 | const uint8_t *key, size_t key_length, |
| 166 | psa_algorithm_t alg) |
| 167 | { |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 168 | mbedtls_test_driver_cipher_hooks.hits++; |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 169 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 170 | if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) { |
| 171 | return mbedtls_test_driver_cipher_hooks.forced_status; |
| 172 | } |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 173 | |
Ronald Cron | b814bda | 2021-09-13 14:50:42 +0200 | [diff] [blame] | 174 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
| 175 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER) |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 176 | return libtestdriver1_mbedtls_psa_cipher_decrypt_setup( |
| 177 | operation, |
| 178 | (const libtestdriver1_psa_key_attributes_t *) attributes, |
| 179 | key, key_length, alg); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 180 | #elif defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 181 | return mbedtls_psa_cipher_decrypt_setup( |
| 182 | operation, attributes, key, key_length, alg); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 183 | #endif |
| 184 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 185 | return PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 186 | } |
| 187 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 188 | psa_status_t mbedtls_test_transparent_cipher_abort( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 189 | mbedtls_transparent_test_driver_cipher_operation_t *operation) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 190 | { |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 191 | mbedtls_test_driver_cipher_hooks.hits++; |
Steven Cooreman | 89e54f2 | 2020-09-10 18:07:57 +0200 | [diff] [blame] | 192 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 193 | if (operation->alg == 0) { |
| 194 | return PSA_SUCCESS; |
| 195 | } |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 196 | |
Ronald Cron | b814bda | 2021-09-13 14:50:42 +0200 | [diff] [blame] | 197 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
| 198 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER) |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 199 | libtestdriver1_mbedtls_psa_cipher_abort(operation); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 200 | #elif defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 201 | mbedtls_psa_cipher_abort(operation); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 202 | #endif |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 203 | |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 204 | /* Wiping the entire struct here, instead of member-by-member. This is |
| 205 | * useful for the test suite, since it gives a chance of catching memory |
| 206 | * corruption errors should the core not have allocated (enough) memory for |
| 207 | * our context struct. */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 208 | memset(operation, 0, sizeof(*operation)); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 209 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 210 | return mbedtls_test_driver_cipher_hooks.forced_status; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 211 | } |
| 212 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 213 | psa_status_t mbedtls_test_transparent_cipher_set_iv( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 214 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 215 | const uint8_t *iv, |
| 216 | size_t iv_length) |
| 217 | { |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 218 | mbedtls_test_driver_cipher_hooks.hits++; |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 219 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 220 | if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) { |
| 221 | return mbedtls_test_driver_cipher_hooks.forced_status; |
| 222 | } |
Steven Cooreman | 89e54f2 | 2020-09-10 18:07:57 +0200 | [diff] [blame] | 223 | |
Ronald Cron | b814bda | 2021-09-13 14:50:42 +0200 | [diff] [blame] | 224 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
| 225 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER) |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 226 | return libtestdriver1_mbedtls_psa_cipher_set_iv( |
| 227 | operation, iv, iv_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 228 | #elif defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 229 | return mbedtls_psa_cipher_set_iv(operation, iv, iv_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 230 | #endif |
| 231 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 232 | return PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 233 | } |
| 234 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 235 | psa_status_t mbedtls_test_transparent_cipher_update( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 236 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 237 | const uint8_t *input, |
| 238 | size_t input_length, |
| 239 | uint8_t *output, |
| 240 | size_t output_size, |
| 241 | size_t *output_length) |
| 242 | { |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 243 | mbedtls_test_driver_cipher_hooks.hits++; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 244 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 245 | if (mbedtls_test_driver_cipher_hooks.forced_output != NULL) { |
| 246 | if (output_size < mbedtls_test_driver_cipher_hooks.forced_output_length) { |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 247 | return PSA_ERROR_BUFFER_TOO_SMALL; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 248 | } |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 249 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 250 | memcpy(output, |
| 251 | mbedtls_test_driver_cipher_hooks.forced_output, |
| 252 | mbedtls_test_driver_cipher_hooks.forced_output_length); |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 253 | *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length; |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 254 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 255 | return mbedtls_test_driver_cipher_hooks.forced_status; |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 256 | } |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 257 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 258 | if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) { |
| 259 | return mbedtls_test_driver_cipher_hooks.forced_status; |
| 260 | } |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 261 | |
Ronald Cron | b814bda | 2021-09-13 14:50:42 +0200 | [diff] [blame] | 262 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
| 263 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER) |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 264 | return libtestdriver1_mbedtls_psa_cipher_update( |
| 265 | operation, input, input_length, |
| 266 | output, output_size, output_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 267 | #elif defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 268 | return mbedtls_psa_cipher_update( |
| 269 | operation, input, input_length, |
| 270 | output, output_size, output_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 271 | #endif |
| 272 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 273 | return PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 274 | } |
| 275 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 276 | psa_status_t mbedtls_test_transparent_cipher_finish( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 277 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 278 | uint8_t *output, |
| 279 | size_t output_size, |
| 280 | size_t *output_length) |
| 281 | { |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 282 | mbedtls_test_driver_cipher_hooks.hits++; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 283 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 284 | if (mbedtls_test_driver_cipher_hooks.forced_output != NULL) { |
| 285 | if (output_size < mbedtls_test_driver_cipher_hooks.forced_output_length) { |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 286 | return PSA_ERROR_BUFFER_TOO_SMALL; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 287 | } |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 288 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 289 | memcpy(output, |
| 290 | mbedtls_test_driver_cipher_hooks.forced_output, |
| 291 | mbedtls_test_driver_cipher_hooks.forced_output_length); |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 292 | *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length; |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 293 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 294 | return mbedtls_test_driver_cipher_hooks.forced_status; |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 295 | } |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 296 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 297 | if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) { |
| 298 | return mbedtls_test_driver_cipher_hooks.forced_status; |
| 299 | } |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 300 | |
Ronald Cron | b814bda | 2021-09-13 14:50:42 +0200 | [diff] [blame] | 301 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
| 302 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER) |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 303 | return libtestdriver1_mbedtls_psa_cipher_finish( |
| 304 | operation, output, output_size, output_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 305 | #elif defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 306 | return mbedtls_psa_cipher_finish( |
| 307 | operation, output, output_size, output_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 308 | #endif |
| 309 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 310 | return PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | /* |
| 314 | * opaque versions, to do |
| 315 | */ |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 316 | psa_status_t mbedtls_test_opaque_cipher_encrypt( |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 317 | const psa_key_attributes_t *attributes, |
| 318 | const uint8_t *key, size_t key_length, |
| 319 | psa_algorithm_t alg, |
Ronald Cron | a833169 | 2021-07-09 09:19:35 +0200 | [diff] [blame] | 320 | const uint8_t *iv, size_t iv_length, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 321 | const uint8_t *input, size_t input_length, |
| 322 | uint8_t *output, size_t output_size, size_t *output_length) |
| 323 | { |
| 324 | (void) attributes; |
| 325 | (void) key; |
| 326 | (void) key_length; |
| 327 | (void) alg; |
Ronald Cron | a833169 | 2021-07-09 09:19:35 +0200 | [diff] [blame] | 328 | (void) iv; |
| 329 | (void) iv_length; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 330 | (void) input; |
| 331 | (void) input_length; |
| 332 | (void) output; |
| 333 | (void) output_size; |
| 334 | (void) output_length; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 335 | return PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 336 | } |
| 337 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 338 | psa_status_t mbedtls_test_opaque_cipher_decrypt( |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 339 | const psa_key_attributes_t *attributes, |
| 340 | const uint8_t *key, size_t key_length, |
| 341 | psa_algorithm_t alg, |
| 342 | const uint8_t *input, size_t input_length, |
| 343 | uint8_t *output, size_t output_size, size_t *output_length) |
| 344 | { |
| 345 | (void) attributes; |
| 346 | (void) key; |
| 347 | (void) key_length; |
| 348 | (void) alg; |
| 349 | (void) input; |
| 350 | (void) input_length; |
| 351 | (void) output; |
| 352 | (void) output_size; |
| 353 | (void) output_length; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 354 | return PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 355 | } |
| 356 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 357 | psa_status_t mbedtls_test_opaque_cipher_encrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 358 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 359 | const psa_key_attributes_t *attributes, |
| 360 | const uint8_t *key, size_t key_length, |
| 361 | psa_algorithm_t alg) |
| 362 | { |
| 363 | (void) operation; |
| 364 | (void) attributes; |
| 365 | (void) key; |
| 366 | (void) key_length; |
| 367 | (void) alg; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 368 | return PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 369 | } |
| 370 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 371 | psa_status_t mbedtls_test_opaque_cipher_decrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 372 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 373 | const psa_key_attributes_t *attributes, |
| 374 | const uint8_t *key, size_t key_length, |
| 375 | psa_algorithm_t alg) |
| 376 | { |
| 377 | (void) operation; |
| 378 | (void) attributes; |
| 379 | (void) key; |
| 380 | (void) key_length; |
| 381 | (void) alg; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 382 | return PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 383 | } |
| 384 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 385 | psa_status_t mbedtls_test_opaque_cipher_abort( |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 386 | mbedtls_opaque_test_driver_cipher_operation_t *operation) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 387 | { |
| 388 | (void) operation; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 389 | return PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 390 | } |
| 391 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 392 | psa_status_t mbedtls_test_opaque_cipher_set_iv( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 393 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 394 | const uint8_t *iv, |
| 395 | size_t iv_length) |
| 396 | { |
| 397 | (void) operation; |
| 398 | (void) iv; |
| 399 | (void) iv_length; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 400 | return PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 401 | } |
| 402 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 403 | psa_status_t mbedtls_test_opaque_cipher_update( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 404 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 405 | const uint8_t *input, |
| 406 | size_t input_length, |
| 407 | uint8_t *output, |
| 408 | size_t output_size, |
| 409 | size_t *output_length) |
| 410 | { |
| 411 | (void) operation; |
| 412 | (void) input; |
| 413 | (void) input_length; |
| 414 | (void) output; |
| 415 | (void) output_size; |
| 416 | (void) output_length; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 417 | return PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 418 | } |
| 419 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 420 | psa_status_t mbedtls_test_opaque_cipher_finish( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 421 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 422 | uint8_t *output, |
| 423 | size_t output_size, |
| 424 | size_t *output_length) |
| 425 | { |
| 426 | (void) operation; |
| 427 | (void) output; |
| 428 | (void) output_size; |
| 429 | (void) output_length; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 430 | return PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 431 | } |
| 432 | #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ |