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