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