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