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 | |
Mateusz Starzyk | 2c09c9b | 2021-05-14 22:20:10 +0200 | [diff] [blame^] | 27 | #include <test/helpers.h> |
| 28 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 29 | #if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) && defined(PSA_CRYPTO_DRIVER_TEST) |
| 30 | #include "psa/crypto.h" |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 31 | #include "psa_crypto_cipher.h" |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 32 | #include "psa_crypto_core.h" |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 33 | #include "mbedtls/cipher.h" |
| 34 | |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 35 | #include "test/drivers/cipher.h" |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 36 | |
| 37 | #include "test/random.h" |
| 38 | |
| 39 | #include <string.h> |
| 40 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 41 | mbedtls_test_driver_cipher_hooks_t mbedtls_test_driver_cipher_hooks = |
| 42 | MBEDTLS_TEST_DRIVER_CIPHER_INIT; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 43 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 44 | static psa_status_t mbedtls_test_transparent_cipher_oneshot( |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 45 | mbedtls_operation_t direction, |
| 46 | const psa_key_attributes_t *attributes, |
| 47 | const uint8_t *key, size_t key_length, |
| 48 | psa_algorithm_t alg, |
| 49 | const uint8_t *input, size_t input_length, |
| 50 | uint8_t *output, size_t output_size, size_t *output_length) |
| 51 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 52 | mbedtls_test_driver_cipher_hooks.hits++; |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 53 | |
| 54 | /* Test driver supports AES-CTR only, to verify operation calls. */ |
| 55 | if( alg != PSA_ALG_CTR || |
| 56 | psa_get_key_type( attributes ) != PSA_KEY_TYPE_AES ) |
| 57 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 58 | |
| 59 | /* If test driver response code is not SUCCESS, we can return early */ |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 60 | if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) |
| 61 | return( mbedtls_test_driver_cipher_hooks.forced_status ); |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 62 | |
| 63 | /* If test driver output is overridden, we don't need to do actual crypto */ |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 64 | if( mbedtls_test_driver_cipher_hooks.forced_output != NULL ) |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 65 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 66 | if( output_size < mbedtls_test_driver_cipher_hooks.forced_output_length ) |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 67 | return( PSA_ERROR_BUFFER_TOO_SMALL ); |
| 68 | |
| 69 | memcpy( output, |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 70 | mbedtls_test_driver_cipher_hooks.forced_output, |
| 71 | mbedtls_test_driver_cipher_hooks.forced_output_length ); |
| 72 | *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length; |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 73 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 74 | return( mbedtls_test_driver_cipher_hooks.forced_status ); |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /* Run AES-CTR using the cipher module */ |
| 78 | { |
| 79 | mbedtls_test_rnd_pseudo_info rnd_info; |
| 80 | memset( &rnd_info, 0x5A, sizeof( mbedtls_test_rnd_pseudo_info ) ); |
| 81 | |
| 82 | const mbedtls_cipher_info_t *cipher_info = |
| 83 | mbedtls_cipher_info_from_values( MBEDTLS_CIPHER_ID_AES, |
| 84 | key_length * 8, |
| 85 | MBEDTLS_MODE_CTR ); |
| 86 | mbedtls_cipher_context_t cipher; |
| 87 | int ret = 0; |
| 88 | uint8_t temp_output_buffer[16] = {0}; |
| 89 | size_t temp_output_length = 0; |
| 90 | |
| 91 | if( direction == MBEDTLS_ENCRYPT ) |
| 92 | { |
| 93 | /* Oneshot encrypt needs to prepend the IV to the output */ |
| 94 | if( output_size < ( input_length + 16 ) ) |
| 95 | return( PSA_ERROR_BUFFER_TOO_SMALL ); |
| 96 | } |
| 97 | else |
| 98 | { |
| 99 | /* Oneshot decrypt has the IV prepended to the input */ |
| 100 | if( output_size < ( input_length - 16 ) ) |
| 101 | return( PSA_ERROR_BUFFER_TOO_SMALL ); |
| 102 | } |
| 103 | |
| 104 | if( cipher_info == NULL ) |
| 105 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 106 | |
| 107 | mbedtls_cipher_init( &cipher ); |
| 108 | ret = mbedtls_cipher_setup( &cipher, cipher_info ); |
| 109 | if( ret != 0 ) |
| 110 | goto exit; |
| 111 | |
| 112 | ret = mbedtls_cipher_setkey( &cipher, |
| 113 | key, |
| 114 | key_length * 8, direction ); |
| 115 | if( ret != 0 ) |
| 116 | goto exit; |
| 117 | |
| 118 | if( direction == MBEDTLS_ENCRYPT ) |
| 119 | { |
| 120 | mbedtls_test_rnd_pseudo_info rnd_info; |
| 121 | memset( &rnd_info, 0x5A, sizeof( mbedtls_test_rnd_pseudo_info ) ); |
| 122 | |
| 123 | ret = mbedtls_test_rnd_pseudo_rand( &rnd_info, |
| 124 | temp_output_buffer, |
| 125 | 16 ); |
| 126 | if( ret != 0 ) |
| 127 | goto exit; |
| 128 | |
| 129 | ret = mbedtls_cipher_set_iv( &cipher, temp_output_buffer, 16 ); |
| 130 | } |
| 131 | else |
| 132 | ret = mbedtls_cipher_set_iv( &cipher, input, 16 ); |
| 133 | |
| 134 | if( ret != 0 ) |
| 135 | goto exit; |
| 136 | |
| 137 | if( direction == MBEDTLS_ENCRYPT ) |
| 138 | { |
| 139 | ret = mbedtls_cipher_update( &cipher, |
| 140 | input, input_length, |
| 141 | &output[16], output_length ); |
| 142 | if( ret == 0 ) |
| 143 | { |
| 144 | memcpy( output, temp_output_buffer, 16 ); |
| 145 | *output_length += 16; |
| 146 | } |
| 147 | } |
| 148 | else |
| 149 | ret = mbedtls_cipher_update( &cipher, |
| 150 | &input[16], input_length - 16, |
| 151 | output, output_length ); |
| 152 | |
| 153 | if( ret != 0 ) |
| 154 | goto exit; |
| 155 | |
| 156 | ret = mbedtls_cipher_finish( &cipher, |
| 157 | temp_output_buffer, |
| 158 | &temp_output_length ); |
| 159 | |
| 160 | exit: |
| 161 | if( ret != 0 ) |
| 162 | { |
| 163 | *output_length = 0; |
| 164 | memset(output, 0, output_size); |
| 165 | } |
| 166 | |
| 167 | mbedtls_cipher_free( &cipher ); |
| 168 | return( mbedtls_to_psa_error( ret ) ); |
| 169 | } |
| 170 | } |
| 171 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 172 | psa_status_t mbedtls_test_transparent_cipher_encrypt( |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 173 | const psa_key_attributes_t *attributes, |
| 174 | const uint8_t *key, size_t key_length, |
| 175 | psa_algorithm_t alg, |
| 176 | const uint8_t *input, size_t input_length, |
| 177 | uint8_t *output, size_t output_size, size_t *output_length) |
| 178 | { |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 179 | return ( |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 180 | mbedtls_test_transparent_cipher_oneshot( |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 181 | MBEDTLS_ENCRYPT, |
| 182 | attributes, |
| 183 | key, key_length, |
| 184 | alg, |
| 185 | input, input_length, |
| 186 | output, output_size, output_length) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 187 | } |
| 188 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 189 | psa_status_t mbedtls_test_transparent_cipher_decrypt( |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 190 | const psa_key_attributes_t *attributes, |
| 191 | const uint8_t *key, size_t key_length, |
| 192 | psa_algorithm_t alg, |
| 193 | const uint8_t *input, size_t input_length, |
| 194 | uint8_t *output, size_t output_size, size_t *output_length) |
| 195 | { |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 196 | return ( |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 197 | mbedtls_test_transparent_cipher_oneshot( |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 198 | MBEDTLS_DECRYPT, |
| 199 | attributes, |
| 200 | key, key_length, |
| 201 | alg, |
| 202 | input, input_length, |
| 203 | output, output_size, output_length) ); |
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_encrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 207 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 16afd3d | 2020-09-09 15:36:39 +0200 | [diff] [blame] | 208 | const psa_key_attributes_t *attributes, |
| 209 | const uint8_t *key, size_t key_length, |
| 210 | psa_algorithm_t alg) |
| 211 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 212 | mbedtls_test_driver_cipher_hooks.hits++; |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 213 | |
| 214 | /* Wiping the entire struct here, instead of member-by-member. This is |
| 215 | * useful for the test suite, since it gives a chance of catching memory |
| 216 | * corruption errors should the core not have allocated (enough) memory for |
| 217 | * our context struct. */ |
| 218 | memset( operation, 0, sizeof( *operation ) ); |
| 219 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 220 | if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) |
| 221 | return( mbedtls_test_driver_cipher_hooks.forced_status ); |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 222 | |
Ronald Cron | 3522e32 | 2021-03-12 11:08:49 +0100 | [diff] [blame] | 223 | return ( mbedtls_transparent_test_driver_cipher_encrypt_setup( |
| 224 | operation, attributes, key, key_length, alg ) ); |
Steven Cooreman | 16afd3d | 2020-09-09 15:36:39 +0200 | [diff] [blame] | 225 | } |
| 226 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 227 | psa_status_t mbedtls_test_transparent_cipher_decrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 228 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 229 | const psa_key_attributes_t *attributes, |
| 230 | const uint8_t *key, size_t key_length, |
| 231 | psa_algorithm_t alg) |
| 232 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 233 | mbedtls_test_driver_cipher_hooks.hits++; |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 234 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 235 | if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) |
| 236 | return( mbedtls_test_driver_cipher_hooks.forced_status ); |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 237 | |
Ronald Cron | 3522e32 | 2021-03-12 11:08:49 +0100 | [diff] [blame] | 238 | return ( mbedtls_transparent_test_driver_cipher_decrypt_setup( |
| 239 | operation, attributes, key, key_length, alg ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 240 | } |
| 241 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 242 | psa_status_t mbedtls_test_transparent_cipher_abort( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 243 | mbedtls_transparent_test_driver_cipher_operation_t *operation) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 244 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 245 | mbedtls_test_driver_cipher_hooks.hits++; |
Steven Cooreman | 89e54f2 | 2020-09-10 18:07:57 +0200 | [diff] [blame] | 246 | |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 247 | if( operation->alg == 0 ) |
| 248 | return( PSA_SUCCESS ); |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 249 | |
Ronald Cron | 3522e32 | 2021-03-12 11:08:49 +0100 | [diff] [blame] | 250 | mbedtls_transparent_test_driver_cipher_abort( operation ); |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 251 | |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 252 | /* Wiping the entire struct here, instead of member-by-member. This is |
| 253 | * useful for the test suite, since it gives a chance of catching memory |
| 254 | * corruption errors should the core not have allocated (enough) memory for |
| 255 | * our context struct. */ |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 256 | memset( operation, 0, sizeof( *operation ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 257 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 258 | return( mbedtls_test_driver_cipher_hooks.forced_status ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 259 | } |
| 260 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 261 | psa_status_t mbedtls_test_transparent_cipher_set_iv( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 262 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 263 | const uint8_t *iv, |
| 264 | size_t iv_length) |
| 265 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 266 | mbedtls_test_driver_cipher_hooks.hits++; |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 267 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 268 | if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) |
| 269 | return( mbedtls_test_driver_cipher_hooks.forced_status ); |
Steven Cooreman | 89e54f2 | 2020-09-10 18:07:57 +0200 | [diff] [blame] | 270 | |
Ronald Cron | 3522e32 | 2021-03-12 11:08:49 +0100 | [diff] [blame] | 271 | return( mbedtls_transparent_test_driver_cipher_set_iv( |
| 272 | operation, iv, iv_length ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 273 | } |
| 274 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 275 | psa_status_t mbedtls_test_transparent_cipher_update( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 276 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 277 | const uint8_t *input, |
| 278 | size_t input_length, |
| 279 | uint8_t *output, |
| 280 | size_t output_size, |
| 281 | size_t *output_length) |
| 282 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 283 | mbedtls_test_driver_cipher_hooks.hits++; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 284 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 285 | if( mbedtls_test_driver_cipher_hooks.forced_output != NULL ) |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 286 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 287 | if( output_size < mbedtls_test_driver_cipher_hooks.forced_output_length ) |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 288 | return PSA_ERROR_BUFFER_TOO_SMALL; |
| 289 | |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 290 | memcpy( output, |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 291 | mbedtls_test_driver_cipher_hooks.forced_output, |
| 292 | mbedtls_test_driver_cipher_hooks.forced_output_length ); |
| 293 | *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length; |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 294 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 295 | return( mbedtls_test_driver_cipher_hooks.forced_status ); |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 296 | } |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 297 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 298 | if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) |
| 299 | return( mbedtls_test_driver_cipher_hooks.forced_status ); |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 300 | |
Ronald Cron | 3522e32 | 2021-03-12 11:08:49 +0100 | [diff] [blame] | 301 | return( mbedtls_transparent_test_driver_cipher_update( |
| 302 | operation, input, input_length, |
| 303 | output, output_size, output_length ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 304 | } |
| 305 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 306 | psa_status_t mbedtls_test_transparent_cipher_finish( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 307 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 308 | uint8_t *output, |
| 309 | size_t output_size, |
| 310 | size_t *output_length) |
| 311 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 312 | mbedtls_test_driver_cipher_hooks.hits++; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 313 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 314 | if( mbedtls_test_driver_cipher_hooks.forced_output != NULL ) |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 315 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 316 | if( output_size < mbedtls_test_driver_cipher_hooks.forced_output_length ) |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 317 | return PSA_ERROR_BUFFER_TOO_SMALL; |
| 318 | |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 319 | memcpy( output, |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 320 | mbedtls_test_driver_cipher_hooks.forced_output, |
| 321 | mbedtls_test_driver_cipher_hooks.forced_output_length ); |
| 322 | *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length; |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 323 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 324 | return( mbedtls_test_driver_cipher_hooks.forced_status ); |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 325 | } |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 326 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 327 | if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) |
| 328 | return( mbedtls_test_driver_cipher_hooks.forced_status ); |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 329 | |
Ronald Cron | 3522e32 | 2021-03-12 11:08:49 +0100 | [diff] [blame] | 330 | return( mbedtls_transparent_test_driver_cipher_finish( |
| 331 | operation, output, output_size, output_length ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | /* |
| 335 | * opaque versions, to do |
| 336 | */ |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 337 | psa_status_t mbedtls_test_opaque_cipher_encrypt( |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 338 | const psa_key_attributes_t *attributes, |
| 339 | const uint8_t *key, size_t key_length, |
| 340 | psa_algorithm_t alg, |
| 341 | const uint8_t *input, size_t input_length, |
| 342 | uint8_t *output, size_t output_size, size_t *output_length) |
| 343 | { |
| 344 | (void) attributes; |
| 345 | (void) key; |
| 346 | (void) key_length; |
| 347 | (void) alg; |
| 348 | (void) input; |
| 349 | (void) input_length; |
| 350 | (void) output; |
| 351 | (void) output_size; |
| 352 | (void) output_length; |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 353 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 354 | } |
| 355 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 356 | psa_status_t mbedtls_test_opaque_cipher_decrypt( |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 357 | const psa_key_attributes_t *attributes, |
| 358 | const uint8_t *key, size_t key_length, |
| 359 | psa_algorithm_t alg, |
| 360 | const uint8_t *input, size_t input_length, |
| 361 | uint8_t *output, size_t output_size, size_t *output_length) |
| 362 | { |
| 363 | (void) attributes; |
| 364 | (void) key; |
| 365 | (void) key_length; |
| 366 | (void) alg; |
| 367 | (void) input; |
| 368 | (void) input_length; |
| 369 | (void) output; |
| 370 | (void) output_size; |
| 371 | (void) output_length; |
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 | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 375 | psa_status_t mbedtls_test_opaque_cipher_encrypt_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; |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [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_decrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +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 | const psa_key_attributes_t *attributes, |
| 392 | const uint8_t *key, size_t key_length, |
| 393 | psa_algorithm_t alg) |
| 394 | { |
| 395 | (void) operation; |
| 396 | (void) attributes; |
| 397 | (void) key; |
| 398 | (void) key_length; |
| 399 | (void) alg; |
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 | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 403 | psa_status_t mbedtls_test_opaque_cipher_abort( |
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 | { |
| 406 | (void) operation; |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 407 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 408 | } |
| 409 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 410 | psa_status_t mbedtls_test_opaque_cipher_set_iv( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 411 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 412 | const uint8_t *iv, |
| 413 | size_t iv_length) |
| 414 | { |
| 415 | (void) operation; |
| 416 | (void) iv; |
| 417 | (void) iv_length; |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 418 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 419 | } |
| 420 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 421 | psa_status_t mbedtls_test_opaque_cipher_update( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 422 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 423 | const uint8_t *input, |
| 424 | size_t input_length, |
| 425 | uint8_t *output, |
| 426 | size_t output_size, |
| 427 | size_t *output_length) |
| 428 | { |
| 429 | (void) operation; |
| 430 | (void) input; |
| 431 | (void) input_length; |
| 432 | (void) output; |
| 433 | (void) output_size; |
| 434 | (void) output_length; |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 435 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 436 | } |
| 437 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 438 | psa_status_t mbedtls_test_opaque_cipher_finish( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 439 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 440 | uint8_t *output, |
| 441 | size_t output_size, |
| 442 | size_t *output_length) |
| 443 | { |
| 444 | (void) operation; |
| 445 | (void) output; |
| 446 | (void) output_size; |
| 447 | (void) output_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 | #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ |