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 | |
gabor-mezei-arm | a9449a0 | 2021-03-25 11:17:10 +0100 | [diff] [blame] | 38 | psa_status_t mbedtls_test_transparent_cipher_encrypt( |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 39 | const psa_key_attributes_t *attributes, |
gabor-mezei-arm | a9449a0 | 2021-03-25 11:17:10 +0100 | [diff] [blame] | 40 | const uint8_t *key_buffer, |
| 41 | size_t key_buffer_size, |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 42 | psa_algorithm_t alg, |
gabor-mezei-arm | a9449a0 | 2021-03-25 11:17:10 +0100 | [diff] [blame] | 43 | const uint8_t *input, |
| 44 | size_t input_length, |
| 45 | uint8_t *output, |
| 46 | size_t output_size, |
| 47 | size_t *output_length ) |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 48 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 49 | mbedtls_test_driver_cipher_hooks.hits++; |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 50 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 51 | if( mbedtls_test_driver_cipher_hooks.forced_output != NULL ) |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 52 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 53 | if( output_size < mbedtls_test_driver_cipher_hooks.forced_output_length ) |
Mateusz Starzyk | e36f5b1 | 2021-07-22 16:43:35 +0200 | [diff] [blame] | 54 | return PSA_ERROR_BUFFER_TOO_SMALL ; |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 55 | |
| 56 | memcpy( output, |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 57 | mbedtls_test_driver_cipher_hooks.forced_output, |
| 58 | mbedtls_test_driver_cipher_hooks.forced_output_length ); |
| 59 | *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length; |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 60 | |
Mateusz Starzyk | e36f5b1 | 2021-07-22 16:43:35 +0200 | [diff] [blame] | 61 | return mbedtls_test_driver_cipher_hooks.forced_status ; |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 62 | } |
| 63 | |
gabor-mezei-arm | a9449a0 | 2021-03-25 11:17:10 +0100 | [diff] [blame] | 64 | if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) |
Mateusz Starzyk | e36f5b1 | 2021-07-22 16:43:35 +0200 | [diff] [blame] | 65 | return mbedtls_test_driver_cipher_hooks.forced_status ; |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 66 | |
gabor-mezei-arm | a9449a0 | 2021-03-25 11:17:10 +0100 | [diff] [blame] | 67 | psa_generate_random( output, PSA_CIPHER_IV_LENGTH( attributes->core.type, alg ) ); |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 68 | |
gabor-mezei-arm | a9449a0 | 2021-03-25 11:17:10 +0100 | [diff] [blame] | 69 | return( mbedtls_transparent_test_driver_cipher_encrypt( |
| 70 | attributes, key_buffer, key_buffer_size, |
| 71 | alg, input, input_length, |
| 72 | output, output_size, output_length ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 73 | } |
| 74 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 75 | psa_status_t mbedtls_test_transparent_cipher_decrypt( |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 76 | const psa_key_attributes_t *attributes, |
gabor-mezei-arm | a9449a0 | 2021-03-25 11:17:10 +0100 | [diff] [blame] | 77 | const uint8_t *key_buffer, |
| 78 | size_t key_buffer_size, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 79 | psa_algorithm_t alg, |
gabor-mezei-arm | a9449a0 | 2021-03-25 11:17:10 +0100 | [diff] [blame] | 80 | const uint8_t *input, |
| 81 | size_t input_length, |
| 82 | uint8_t *output, |
| 83 | size_t output_size, |
| 84 | size_t *output_length ) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 85 | { |
gabor-mezei-arm | a9449a0 | 2021-03-25 11:17:10 +0100 | [diff] [blame] | 86 | mbedtls_test_driver_cipher_hooks.hits++; |
| 87 | |
| 88 | if( mbedtls_test_driver_cipher_hooks.forced_output != NULL ) |
| 89 | { |
| 90 | if( output_size < mbedtls_test_driver_cipher_hooks.forced_output_length ) |
Mateusz Starzyk | e36f5b1 | 2021-07-22 16:43:35 +0200 | [diff] [blame] | 91 | return PSA_ERROR_BUFFER_TOO_SMALL ; |
gabor-mezei-arm | a9449a0 | 2021-03-25 11:17:10 +0100 | [diff] [blame] | 92 | |
| 93 | memcpy( output, |
| 94 | mbedtls_test_driver_cipher_hooks.forced_output, |
| 95 | mbedtls_test_driver_cipher_hooks.forced_output_length ); |
| 96 | *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length; |
| 97 | |
Mateusz Starzyk | e36f5b1 | 2021-07-22 16:43:35 +0200 | [diff] [blame] | 98 | return mbedtls_test_driver_cipher_hooks.forced_status ; |
gabor-mezei-arm | a9449a0 | 2021-03-25 11:17:10 +0100 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) |
Mateusz Starzyk | e36f5b1 | 2021-07-22 16:43:35 +0200 | [diff] [blame] | 102 | return mbedtls_test_driver_cipher_hooks.forced_status ; |
gabor-mezei-arm | a9449a0 | 2021-03-25 11:17:10 +0100 | [diff] [blame] | 103 | |
| 104 | return( mbedtls_transparent_test_driver_cipher_decrypt( |
| 105 | attributes, key_buffer, key_buffer_size, |
| 106 | alg, input, input_length, |
| 107 | output, output_size, output_length ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 108 | } |
| 109 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 110 | psa_status_t mbedtls_test_transparent_cipher_encrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 111 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 16afd3d | 2020-09-09 15:36:39 +0200 | [diff] [blame] | 112 | const psa_key_attributes_t *attributes, |
| 113 | const uint8_t *key, size_t key_length, |
| 114 | psa_algorithm_t alg) |
| 115 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 116 | mbedtls_test_driver_cipher_hooks.hits++; |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 117 | |
| 118 | /* Wiping the entire struct here, instead of member-by-member. This is |
| 119 | * useful for the test suite, since it gives a chance of catching memory |
| 120 | * corruption errors should the core not have allocated (enough) memory for |
| 121 | * our context struct. */ |
| 122 | memset( operation, 0, sizeof( *operation ) ); |
| 123 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 124 | if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) |
Mateusz Starzyk | e36f5b1 | 2021-07-22 16:43:35 +0200 | [diff] [blame] | 125 | return mbedtls_test_driver_cipher_hooks.forced_status ; |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 126 | |
Ronald Cron | 3522e32 | 2021-03-12 11:08:49 +0100 | [diff] [blame] | 127 | return ( mbedtls_transparent_test_driver_cipher_encrypt_setup( |
| 128 | operation, attributes, key, key_length, alg ) ); |
Steven Cooreman | 16afd3d | 2020-09-09 15:36:39 +0200 | [diff] [blame] | 129 | } |
| 130 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 131 | psa_status_t mbedtls_test_transparent_cipher_decrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 132 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 133 | const psa_key_attributes_t *attributes, |
| 134 | const uint8_t *key, size_t key_length, |
| 135 | psa_algorithm_t alg) |
| 136 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 137 | mbedtls_test_driver_cipher_hooks.hits++; |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 138 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 139 | if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) |
Mateusz Starzyk | e36f5b1 | 2021-07-22 16:43:35 +0200 | [diff] [blame] | 140 | return mbedtls_test_driver_cipher_hooks.forced_status ; |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 141 | |
Ronald Cron | 3522e32 | 2021-03-12 11:08:49 +0100 | [diff] [blame] | 142 | return ( mbedtls_transparent_test_driver_cipher_decrypt_setup( |
| 143 | operation, attributes, key, key_length, alg ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 144 | } |
| 145 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 146 | psa_status_t mbedtls_test_transparent_cipher_abort( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 147 | mbedtls_transparent_test_driver_cipher_operation_t *operation) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 148 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 149 | mbedtls_test_driver_cipher_hooks.hits++; |
Steven Cooreman | 89e54f2 | 2020-09-10 18:07:57 +0200 | [diff] [blame] | 150 | |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 151 | if( operation->alg == 0 ) |
Mateusz Starzyk | e36f5b1 | 2021-07-22 16:43:35 +0200 | [diff] [blame] | 152 | return PSA_SUCCESS ; |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 153 | |
Ronald Cron | 3522e32 | 2021-03-12 11:08:49 +0100 | [diff] [blame] | 154 | mbedtls_transparent_test_driver_cipher_abort( operation ); |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 155 | |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 156 | /* Wiping the entire struct here, instead of member-by-member. This is |
| 157 | * useful for the test suite, since it gives a chance of catching memory |
| 158 | * corruption errors should the core not have allocated (enough) memory for |
| 159 | * our context struct. */ |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 160 | memset( operation, 0, sizeof( *operation ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 161 | |
Mateusz Starzyk | e36f5b1 | 2021-07-22 16:43:35 +0200 | [diff] [blame] | 162 | return mbedtls_test_driver_cipher_hooks.forced_status ; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 163 | } |
| 164 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 165 | psa_status_t mbedtls_test_transparent_cipher_set_iv( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 166 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 167 | const uint8_t *iv, |
| 168 | size_t iv_length) |
| 169 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 170 | mbedtls_test_driver_cipher_hooks.hits++; |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 171 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 172 | if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) |
Mateusz Starzyk | e36f5b1 | 2021-07-22 16:43:35 +0200 | [diff] [blame] | 173 | return mbedtls_test_driver_cipher_hooks.forced_status ; |
Steven Cooreman | 89e54f2 | 2020-09-10 18:07:57 +0200 | [diff] [blame] | 174 | |
Ronald Cron | 3522e32 | 2021-03-12 11:08:49 +0100 | [diff] [blame] | 175 | return( mbedtls_transparent_test_driver_cipher_set_iv( |
| 176 | operation, iv, iv_length ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 177 | } |
| 178 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 179 | psa_status_t mbedtls_test_transparent_cipher_update( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 180 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 181 | const uint8_t *input, |
| 182 | size_t input_length, |
| 183 | uint8_t *output, |
| 184 | size_t output_size, |
| 185 | size_t *output_length) |
| 186 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 187 | mbedtls_test_driver_cipher_hooks.hits++; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 188 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 189 | if( mbedtls_test_driver_cipher_hooks.forced_output != NULL ) |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 190 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 191 | if( output_size < mbedtls_test_driver_cipher_hooks.forced_output_length ) |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 192 | return PSA_ERROR_BUFFER_TOO_SMALL; |
| 193 | |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 194 | memcpy( output, |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 195 | mbedtls_test_driver_cipher_hooks.forced_output, |
| 196 | mbedtls_test_driver_cipher_hooks.forced_output_length ); |
| 197 | *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length; |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 198 | |
Mateusz Starzyk | e36f5b1 | 2021-07-22 16:43:35 +0200 | [diff] [blame] | 199 | return mbedtls_test_driver_cipher_hooks.forced_status ; |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 200 | } |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 201 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 202 | if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) |
Mateusz Starzyk | e36f5b1 | 2021-07-22 16:43:35 +0200 | [diff] [blame] | 203 | return mbedtls_test_driver_cipher_hooks.forced_status ; |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 204 | |
Ronald Cron | 3522e32 | 2021-03-12 11:08:49 +0100 | [diff] [blame] | 205 | return( mbedtls_transparent_test_driver_cipher_update( |
| 206 | operation, input, input_length, |
| 207 | output, output_size, output_length ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 208 | } |
| 209 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 210 | psa_status_t mbedtls_test_transparent_cipher_finish( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 211 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 212 | uint8_t *output, |
| 213 | size_t output_size, |
| 214 | size_t *output_length) |
| 215 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 216 | mbedtls_test_driver_cipher_hooks.hits++; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 217 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 218 | if( mbedtls_test_driver_cipher_hooks.forced_output != NULL ) |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 219 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 220 | if( output_size < mbedtls_test_driver_cipher_hooks.forced_output_length ) |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 221 | return PSA_ERROR_BUFFER_TOO_SMALL; |
| 222 | |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 223 | memcpy( output, |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 224 | mbedtls_test_driver_cipher_hooks.forced_output, |
| 225 | mbedtls_test_driver_cipher_hooks.forced_output_length ); |
| 226 | *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length; |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 227 | |
Mateusz Starzyk | e36f5b1 | 2021-07-22 16:43:35 +0200 | [diff] [blame] | 228 | return mbedtls_test_driver_cipher_hooks.forced_status ; |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 229 | } |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 230 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 231 | if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) |
Mateusz Starzyk | e36f5b1 | 2021-07-22 16:43:35 +0200 | [diff] [blame] | 232 | return mbedtls_test_driver_cipher_hooks.forced_status ; |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 233 | |
Ronald Cron | 3522e32 | 2021-03-12 11:08:49 +0100 | [diff] [blame] | 234 | return( mbedtls_transparent_test_driver_cipher_finish( |
| 235 | operation, output, output_size, output_length ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | /* |
| 239 | * opaque versions, to do |
| 240 | */ |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 241 | psa_status_t mbedtls_test_opaque_cipher_encrypt( |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 242 | const psa_key_attributes_t *attributes, |
| 243 | const uint8_t *key, size_t key_length, |
| 244 | psa_algorithm_t alg, |
| 245 | const uint8_t *input, size_t input_length, |
| 246 | uint8_t *output, size_t output_size, size_t *output_length) |
| 247 | { |
| 248 | (void) attributes; |
| 249 | (void) key; |
| 250 | (void) key_length; |
| 251 | (void) alg; |
| 252 | (void) input; |
| 253 | (void) input_length; |
| 254 | (void) output; |
| 255 | (void) output_size; |
| 256 | (void) output_length; |
Mateusz Starzyk | e36f5b1 | 2021-07-22 16:43:35 +0200 | [diff] [blame] | 257 | return PSA_ERROR_NOT_SUPPORTED ; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 258 | } |
| 259 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 260 | psa_status_t mbedtls_test_opaque_cipher_decrypt( |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 261 | const psa_key_attributes_t *attributes, |
| 262 | const uint8_t *key, size_t key_length, |
| 263 | psa_algorithm_t alg, |
| 264 | const uint8_t *input, size_t input_length, |
| 265 | uint8_t *output, size_t output_size, size_t *output_length) |
| 266 | { |
| 267 | (void) attributes; |
| 268 | (void) key; |
| 269 | (void) key_length; |
| 270 | (void) alg; |
| 271 | (void) input; |
| 272 | (void) input_length; |
| 273 | (void) output; |
| 274 | (void) output_size; |
| 275 | (void) output_length; |
Mateusz Starzyk | e36f5b1 | 2021-07-22 16:43:35 +0200 | [diff] [blame] | 276 | return PSA_ERROR_NOT_SUPPORTED ; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 277 | } |
| 278 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 279 | psa_status_t mbedtls_test_opaque_cipher_encrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 280 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 281 | const psa_key_attributes_t *attributes, |
| 282 | const uint8_t *key, size_t key_length, |
| 283 | psa_algorithm_t alg) |
| 284 | { |
| 285 | (void) operation; |
| 286 | (void) attributes; |
| 287 | (void) key; |
| 288 | (void) key_length; |
| 289 | (void) alg; |
Mateusz Starzyk | e36f5b1 | 2021-07-22 16:43:35 +0200 | [diff] [blame] | 290 | return PSA_ERROR_NOT_SUPPORTED ; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 291 | } |
| 292 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 293 | psa_status_t mbedtls_test_opaque_cipher_decrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 294 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 295 | const psa_key_attributes_t *attributes, |
| 296 | const uint8_t *key, size_t key_length, |
| 297 | psa_algorithm_t alg) |
| 298 | { |
| 299 | (void) operation; |
| 300 | (void) attributes; |
| 301 | (void) key; |
| 302 | (void) key_length; |
| 303 | (void) alg; |
Mateusz Starzyk | e36f5b1 | 2021-07-22 16:43:35 +0200 | [diff] [blame] | 304 | return PSA_ERROR_NOT_SUPPORTED ; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 305 | } |
| 306 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 307 | psa_status_t mbedtls_test_opaque_cipher_abort( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 308 | mbedtls_opaque_test_driver_cipher_operation_t *operation ) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 309 | { |
| 310 | (void) operation; |
Mateusz Starzyk | e36f5b1 | 2021-07-22 16:43:35 +0200 | [diff] [blame] | 311 | return PSA_ERROR_NOT_SUPPORTED ; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 312 | } |
| 313 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 314 | psa_status_t mbedtls_test_opaque_cipher_set_iv( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 315 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 316 | const uint8_t *iv, |
| 317 | size_t iv_length) |
| 318 | { |
| 319 | (void) operation; |
| 320 | (void) iv; |
| 321 | (void) iv_length; |
Mateusz Starzyk | e36f5b1 | 2021-07-22 16:43:35 +0200 | [diff] [blame] | 322 | return PSA_ERROR_NOT_SUPPORTED ; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 323 | } |
| 324 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 325 | psa_status_t mbedtls_test_opaque_cipher_update( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 326 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 327 | const uint8_t *input, |
| 328 | size_t input_length, |
| 329 | uint8_t *output, |
| 330 | size_t output_size, |
| 331 | size_t *output_length) |
| 332 | { |
| 333 | (void) operation; |
| 334 | (void) input; |
| 335 | (void) input_length; |
| 336 | (void) output; |
| 337 | (void) output_size; |
| 338 | (void) output_length; |
Mateusz Starzyk | e36f5b1 | 2021-07-22 16:43:35 +0200 | [diff] [blame] | 339 | return PSA_ERROR_NOT_SUPPORTED ; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 340 | } |
| 341 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 342 | psa_status_t mbedtls_test_opaque_cipher_finish( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 343 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 344 | uint8_t *output, |
| 345 | size_t output_size, |
| 346 | size_t *output_length) |
| 347 | { |
| 348 | (void) operation; |
| 349 | (void) output; |
| 350 | (void) output_size; |
| 351 | (void) output_length; |
Mateusz Starzyk | e36f5b1 | 2021-07-22 16:43:35 +0200 | [diff] [blame] | 352 | return PSA_ERROR_NOT_SUPPORTED ; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 353 | } |
| 354 | #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ |