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 | |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 39 | /* Test driver implements AES-CTR only. Its default behaviour (when its return |
| 40 | * status is not overridden through the hooks) is to take care of all AES-CTR |
| 41 | * operations, and return PSA_ERROR_NOT_SUPPORTED for all others. |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 42 | * Set test_driver_cipher_hooks.forced_status to PSA_ERROR_NOT_SUPPORTED to use |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 43 | * fallback even for AES-CTR. */ |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 44 | test_driver_cipher_hooks_t test_driver_cipher_hooks = TEST_DRIVER_CIPHER_INIT; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 45 | |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 46 | static psa_status_t test_transparent_cipher_oneshot( |
| 47 | mbedtls_operation_t direction, |
| 48 | const psa_key_attributes_t *attributes, |
| 49 | const uint8_t *key, size_t key_length, |
| 50 | psa_algorithm_t alg, |
| 51 | const uint8_t *input, size_t input_length, |
| 52 | uint8_t *output, size_t output_size, size_t *output_length) |
| 53 | { |
| 54 | test_driver_cipher_hooks.hits++; |
| 55 | |
| 56 | /* Test driver supports AES-CTR only, to verify operation calls. */ |
| 57 | if( alg != PSA_ALG_CTR || |
| 58 | psa_get_key_type( attributes ) != PSA_KEY_TYPE_AES ) |
| 59 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 60 | |
| 61 | /* If test driver response code is not SUCCESS, we can return early */ |
| 62 | if( test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) |
| 63 | return( test_driver_cipher_hooks.forced_status ); |
| 64 | |
| 65 | /* If test driver output is overridden, we don't need to do actual crypto */ |
| 66 | if( test_driver_cipher_hooks.forced_output != NULL ) |
| 67 | { |
| 68 | if( output_size < test_driver_cipher_hooks.forced_output_length ) |
| 69 | return( PSA_ERROR_BUFFER_TOO_SMALL ); |
| 70 | |
| 71 | memcpy( output, |
| 72 | test_driver_cipher_hooks.forced_output, |
| 73 | test_driver_cipher_hooks.forced_output_length ); |
| 74 | *output_length = test_driver_cipher_hooks.forced_output_length; |
| 75 | |
| 76 | return( test_driver_cipher_hooks.forced_status ); |
| 77 | } |
| 78 | |
| 79 | /* Run AES-CTR using the cipher module */ |
| 80 | { |
| 81 | mbedtls_test_rnd_pseudo_info rnd_info; |
| 82 | memset( &rnd_info, 0x5A, sizeof( mbedtls_test_rnd_pseudo_info ) ); |
| 83 | |
| 84 | const mbedtls_cipher_info_t *cipher_info = |
| 85 | mbedtls_cipher_info_from_values( MBEDTLS_CIPHER_ID_AES, |
| 86 | key_length * 8, |
| 87 | MBEDTLS_MODE_CTR ); |
| 88 | mbedtls_cipher_context_t cipher; |
| 89 | int ret = 0; |
| 90 | uint8_t temp_output_buffer[16] = {0}; |
| 91 | size_t temp_output_length = 0; |
| 92 | |
| 93 | if( direction == MBEDTLS_ENCRYPT ) |
| 94 | { |
| 95 | /* Oneshot encrypt needs to prepend the IV to the output */ |
| 96 | if( output_size < ( input_length + 16 ) ) |
| 97 | return( PSA_ERROR_BUFFER_TOO_SMALL ); |
| 98 | } |
| 99 | else |
| 100 | { |
| 101 | /* Oneshot decrypt has the IV prepended to the input */ |
| 102 | if( output_size < ( input_length - 16 ) ) |
| 103 | return( PSA_ERROR_BUFFER_TOO_SMALL ); |
| 104 | } |
| 105 | |
| 106 | if( cipher_info == NULL ) |
| 107 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 108 | |
| 109 | mbedtls_cipher_init( &cipher ); |
| 110 | ret = mbedtls_cipher_setup( &cipher, cipher_info ); |
| 111 | if( ret != 0 ) |
| 112 | goto exit; |
| 113 | |
| 114 | ret = mbedtls_cipher_setkey( &cipher, |
| 115 | key, |
| 116 | key_length * 8, direction ); |
| 117 | if( ret != 0 ) |
| 118 | goto exit; |
| 119 | |
| 120 | if( direction == MBEDTLS_ENCRYPT ) |
| 121 | { |
| 122 | mbedtls_test_rnd_pseudo_info rnd_info; |
| 123 | memset( &rnd_info, 0x5A, sizeof( mbedtls_test_rnd_pseudo_info ) ); |
| 124 | |
| 125 | ret = mbedtls_test_rnd_pseudo_rand( &rnd_info, |
| 126 | temp_output_buffer, |
| 127 | 16 ); |
| 128 | if( ret != 0 ) |
| 129 | goto exit; |
| 130 | |
| 131 | ret = mbedtls_cipher_set_iv( &cipher, temp_output_buffer, 16 ); |
| 132 | } |
| 133 | else |
| 134 | ret = mbedtls_cipher_set_iv( &cipher, input, 16 ); |
| 135 | |
| 136 | if( ret != 0 ) |
| 137 | goto exit; |
| 138 | |
| 139 | if( direction == MBEDTLS_ENCRYPT ) |
| 140 | { |
| 141 | ret = mbedtls_cipher_update( &cipher, |
| 142 | input, input_length, |
| 143 | &output[16], output_length ); |
| 144 | if( ret == 0 ) |
| 145 | { |
| 146 | memcpy( output, temp_output_buffer, 16 ); |
| 147 | *output_length += 16; |
| 148 | } |
| 149 | } |
| 150 | else |
| 151 | ret = mbedtls_cipher_update( &cipher, |
| 152 | &input[16], input_length - 16, |
| 153 | output, output_length ); |
| 154 | |
| 155 | if( ret != 0 ) |
| 156 | goto exit; |
| 157 | |
| 158 | ret = mbedtls_cipher_finish( &cipher, |
| 159 | temp_output_buffer, |
| 160 | &temp_output_length ); |
| 161 | |
| 162 | exit: |
| 163 | if( ret != 0 ) |
| 164 | { |
| 165 | *output_length = 0; |
| 166 | memset(output, 0, output_size); |
| 167 | } |
| 168 | |
| 169 | mbedtls_cipher_free( &cipher ); |
| 170 | return( mbedtls_to_psa_error( ret ) ); |
| 171 | } |
| 172 | } |
| 173 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 174 | psa_status_t test_transparent_cipher_encrypt( |
| 175 | const psa_key_attributes_t *attributes, |
| 176 | const uint8_t *key, size_t key_length, |
| 177 | psa_algorithm_t alg, |
| 178 | const uint8_t *input, size_t input_length, |
| 179 | uint8_t *output, size_t output_size, size_t *output_length) |
| 180 | { |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 181 | return ( |
| 182 | test_transparent_cipher_oneshot( |
| 183 | MBEDTLS_ENCRYPT, |
| 184 | attributes, |
| 185 | key, key_length, |
| 186 | alg, |
| 187 | input, input_length, |
| 188 | output, output_size, output_length) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | psa_status_t test_transparent_cipher_decrypt( |
| 192 | const psa_key_attributes_t *attributes, |
| 193 | const uint8_t *key, size_t key_length, |
| 194 | psa_algorithm_t alg, |
| 195 | const uint8_t *input, size_t input_length, |
| 196 | uint8_t *output, size_t output_size, size_t *output_length) |
| 197 | { |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 198 | return ( |
| 199 | test_transparent_cipher_oneshot( |
| 200 | MBEDTLS_DECRYPT, |
| 201 | attributes, |
| 202 | key, key_length, |
| 203 | alg, |
| 204 | input, input_length, |
| 205 | output, output_size, output_length) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 206 | } |
| 207 | |
Steven Cooreman | 16afd3d | 2020-09-09 15:36:39 +0200 | [diff] [blame] | 208 | psa_status_t test_transparent_cipher_encrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 209 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 16afd3d | 2020-09-09 15:36:39 +0200 | [diff] [blame] | 210 | const psa_key_attributes_t *attributes, |
| 211 | const uint8_t *key, size_t key_length, |
| 212 | psa_algorithm_t alg) |
| 213 | { |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 214 | test_driver_cipher_hooks.hits++; |
| 215 | |
| 216 | /* Wiping the entire struct here, instead of member-by-member. This is |
| 217 | * useful for the test suite, since it gives a chance of catching memory |
| 218 | * corruption errors should the core not have allocated (enough) memory for |
| 219 | * our context struct. */ |
| 220 | memset( operation, 0, sizeof( *operation ) ); |
| 221 | |
| 222 | if( test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) |
| 223 | return( test_driver_cipher_hooks.forced_status ); |
| 224 | |
Ronald Cron | 3522e32 | 2021-03-12 11:08:49 +0100 | [diff] [blame^] | 225 | return ( mbedtls_transparent_test_driver_cipher_encrypt_setup( |
| 226 | operation, attributes, key, key_length, alg ) ); |
Steven Cooreman | 16afd3d | 2020-09-09 15:36:39 +0200 | [diff] [blame] | 227 | } |
| 228 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 229 | psa_status_t test_transparent_cipher_decrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 230 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 231 | const psa_key_attributes_t *attributes, |
| 232 | const uint8_t *key, size_t key_length, |
| 233 | psa_algorithm_t alg) |
| 234 | { |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 235 | test_driver_cipher_hooks.hits++; |
| 236 | |
| 237 | if( test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) |
| 238 | return( test_driver_cipher_hooks.forced_status ); |
| 239 | |
Ronald Cron | 3522e32 | 2021-03-12 11:08:49 +0100 | [diff] [blame^] | 240 | return ( mbedtls_transparent_test_driver_cipher_decrypt_setup( |
| 241 | operation, attributes, key, key_length, alg ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | psa_status_t test_transparent_cipher_abort( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 245 | mbedtls_transparent_test_driver_cipher_operation_t *operation) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 246 | { |
Steven Cooreman | 89e54f2 | 2020-09-10 18:07:57 +0200 | [diff] [blame] | 247 | test_driver_cipher_hooks.hits++; |
| 248 | |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 249 | if( operation->alg == 0 ) |
| 250 | return( PSA_SUCCESS ); |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 251 | |
Ronald Cron | 3522e32 | 2021-03-12 11:08:49 +0100 | [diff] [blame^] | 252 | mbedtls_transparent_test_driver_cipher_abort( operation ); |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 253 | |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 254 | /* Wiping the entire struct here, instead of member-by-member. This is |
| 255 | * useful for the test suite, since it gives a chance of catching memory |
| 256 | * corruption errors should the core not have allocated (enough) memory for |
| 257 | * our context struct. */ |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 258 | memset( operation, 0, sizeof( *operation ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 259 | |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 260 | return( test_driver_cipher_hooks.forced_status ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | psa_status_t test_transparent_cipher_generate_iv( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 264 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 265 | uint8_t *iv, |
| 266 | size_t iv_size, |
| 267 | size_t *iv_length) |
| 268 | { |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 269 | test_driver_cipher_hooks.hits++; |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 270 | |
Steven Cooreman | 89e54f2 | 2020-09-10 18:07:57 +0200 | [diff] [blame] | 271 | if( test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) |
| 272 | return( test_driver_cipher_hooks.forced_status ); |
| 273 | |
Ronald Cron | 3522e32 | 2021-03-12 11:08:49 +0100 | [diff] [blame^] | 274 | return( mbedtls_transparent_test_driver_cipher_generate_iv( |
| 275 | operation, iv, iv_size, iv_length ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | psa_status_t test_transparent_cipher_set_iv( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 279 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 280 | const uint8_t *iv, |
| 281 | size_t iv_length) |
| 282 | { |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 283 | test_driver_cipher_hooks.hits++; |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 284 | |
Steven Cooreman | 89e54f2 | 2020-09-10 18:07:57 +0200 | [diff] [blame] | 285 | if( test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) |
| 286 | return( test_driver_cipher_hooks.forced_status ); |
| 287 | |
Ronald Cron | 3522e32 | 2021-03-12 11:08:49 +0100 | [diff] [blame^] | 288 | return( mbedtls_transparent_test_driver_cipher_set_iv( |
| 289 | operation, iv, iv_length ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | psa_status_t test_transparent_cipher_update( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 293 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 294 | const uint8_t *input, |
| 295 | size_t input_length, |
| 296 | uint8_t *output, |
| 297 | size_t output_size, |
| 298 | size_t *output_length) |
| 299 | { |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 300 | test_driver_cipher_hooks.hits++; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 301 | |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 302 | if( test_driver_cipher_hooks.forced_output != NULL ) |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 303 | { |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 304 | if( output_size < test_driver_cipher_hooks.forced_output_length ) |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 305 | return PSA_ERROR_BUFFER_TOO_SMALL; |
| 306 | |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 307 | memcpy( output, |
| 308 | test_driver_cipher_hooks.forced_output, |
| 309 | test_driver_cipher_hooks.forced_output_length ); |
| 310 | *output_length = test_driver_cipher_hooks.forced_output_length; |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 311 | |
| 312 | return( test_driver_cipher_hooks.forced_status ); |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 313 | } |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 314 | |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 315 | if( test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) |
| 316 | return( test_driver_cipher_hooks.forced_status ); |
| 317 | |
Ronald Cron | 3522e32 | 2021-03-12 11:08:49 +0100 | [diff] [blame^] | 318 | return( mbedtls_transparent_test_driver_cipher_update( |
| 319 | operation, input, input_length, |
| 320 | output, output_size, output_length ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | psa_status_t test_transparent_cipher_finish( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 324 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 325 | uint8_t *output, |
| 326 | size_t output_size, |
| 327 | size_t *output_length) |
| 328 | { |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 329 | test_driver_cipher_hooks.hits++; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 330 | |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 331 | if( test_driver_cipher_hooks.forced_output != NULL ) |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 332 | { |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 333 | if( output_size < test_driver_cipher_hooks.forced_output_length ) |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 334 | return PSA_ERROR_BUFFER_TOO_SMALL; |
| 335 | |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 336 | memcpy( output, |
| 337 | test_driver_cipher_hooks.forced_output, |
| 338 | test_driver_cipher_hooks.forced_output_length ); |
| 339 | *output_length = test_driver_cipher_hooks.forced_output_length; |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 340 | |
| 341 | return( test_driver_cipher_hooks.forced_status ); |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 342 | } |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 343 | |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 344 | if( test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) |
| 345 | return( test_driver_cipher_hooks.forced_status ); |
| 346 | |
Ronald Cron | 3522e32 | 2021-03-12 11:08:49 +0100 | [diff] [blame^] | 347 | return( mbedtls_transparent_test_driver_cipher_finish( |
| 348 | operation, output, output_size, output_length ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | /* |
| 352 | * opaque versions, to do |
| 353 | */ |
| 354 | psa_status_t test_opaque_cipher_encrypt( |
| 355 | const psa_key_attributes_t *attributes, |
| 356 | const uint8_t *key, size_t key_length, |
| 357 | psa_algorithm_t alg, |
| 358 | const uint8_t *input, size_t input_length, |
| 359 | uint8_t *output, size_t output_size, size_t *output_length) |
| 360 | { |
| 361 | (void) attributes; |
| 362 | (void) key; |
| 363 | (void) key_length; |
| 364 | (void) alg; |
| 365 | (void) input; |
| 366 | (void) input_length; |
| 367 | (void) output; |
| 368 | (void) output_size; |
| 369 | (void) output_length; |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 370 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | psa_status_t test_opaque_cipher_decrypt( |
| 374 | const psa_key_attributes_t *attributes, |
| 375 | const uint8_t *key, size_t key_length, |
| 376 | psa_algorithm_t alg, |
| 377 | const uint8_t *input, size_t input_length, |
| 378 | uint8_t *output, size_t output_size, size_t *output_length) |
| 379 | { |
| 380 | (void) attributes; |
| 381 | (void) key; |
| 382 | (void) key_length; |
| 383 | (void) alg; |
| 384 | (void) input; |
| 385 | (void) input_length; |
| 386 | (void) output; |
| 387 | (void) output_size; |
| 388 | (void) output_length; |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 389 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | psa_status_t test_opaque_cipher_encrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 393 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 394 | const psa_key_attributes_t *attributes, |
| 395 | const uint8_t *key, size_t key_length, |
| 396 | psa_algorithm_t alg) |
| 397 | { |
| 398 | (void) operation; |
| 399 | (void) attributes; |
| 400 | (void) key; |
| 401 | (void) key_length; |
| 402 | (void) alg; |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 403 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | psa_status_t test_opaque_cipher_decrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 407 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 408 | const psa_key_attributes_t *attributes, |
| 409 | const uint8_t *key, size_t key_length, |
| 410 | psa_algorithm_t alg) |
| 411 | { |
| 412 | (void) operation; |
| 413 | (void) attributes; |
| 414 | (void) key; |
| 415 | (void) key_length; |
| 416 | (void) alg; |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 417 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | psa_status_t test_opaque_cipher_abort( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 421 | mbedtls_opaque_test_driver_cipher_operation_t *operation ) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 422 | { |
| 423 | (void) operation; |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 424 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | psa_status_t test_opaque_cipher_generate_iv( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 428 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 429 | uint8_t *iv, |
| 430 | size_t iv_size, |
| 431 | size_t *iv_length) |
| 432 | { |
| 433 | (void) operation; |
| 434 | (void) iv; |
| 435 | (void) iv_size; |
| 436 | (void) iv_length; |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 437 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | psa_status_t test_opaque_cipher_set_iv( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 441 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 442 | const uint8_t *iv, |
| 443 | size_t iv_length) |
| 444 | { |
| 445 | (void) operation; |
| 446 | (void) iv; |
| 447 | (void) iv_length; |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 448 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | psa_status_t test_opaque_cipher_update( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 452 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 453 | const uint8_t *input, |
| 454 | size_t input_length, |
| 455 | uint8_t *output, |
| 456 | size_t output_size, |
| 457 | size_t *output_length) |
| 458 | { |
| 459 | (void) operation; |
| 460 | (void) input; |
| 461 | (void) input_length; |
| 462 | (void) output; |
| 463 | (void) output_size; |
| 464 | (void) output_length; |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 465 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | psa_status_t test_opaque_cipher_finish( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 469 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 470 | uint8_t *output, |
| 471 | size_t output_size, |
| 472 | size_t *output_length) |
| 473 | { |
| 474 | (void) operation; |
| 475 | (void) output; |
| 476 | (void) output_size; |
| 477 | (void) output_length; |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 478 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 479 | } |
| 480 | #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ |