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