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