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