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 ) |
Steven Cooreman | fe0ab55 | 2020-09-10 13:07:02 +0200 | [diff] [blame] | 54 | return( PSA_ERROR_BUFFER_TOO_SMALL ); |
| 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 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +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 ) |
| 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 | |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 69 | #if defined(MBEDTLS_PSA_CRYPTO_CONFIG) |
Ronald Cron | 40170d9 | 2021-03-13 18:19:08 +0100 | [diff] [blame] | 70 | return( libtestdriver1_mbedtls_psa_cipher_encrypt( |
gabor-mezei-arm | a9449a0 | 2021-03-25 11:17:10 +0100 | [diff] [blame] | 71 | attributes, key_buffer, key_buffer_size, |
| 72 | alg, input, input_length, |
| 73 | output, output_size, output_length ) ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 74 | #elif defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
| 75 | return( mbedtls_psa_cipher_encrypt( |
| 76 | attributes, key_buffer, key_buffer_size, |
| 77 | alg, input, input_length, |
| 78 | output, output_size, output_length ) ); |
| 79 | #endif |
| 80 | |
| 81 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 82 | } |
| 83 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 84 | psa_status_t mbedtls_test_transparent_cipher_decrypt( |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 85 | const psa_key_attributes_t *attributes, |
gabor-mezei-arm | a9449a0 | 2021-03-25 11:17:10 +0100 | [diff] [blame] | 86 | const uint8_t *key_buffer, |
| 87 | size_t key_buffer_size, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 88 | psa_algorithm_t alg, |
gabor-mezei-arm | a9449a0 | 2021-03-25 11:17:10 +0100 | [diff] [blame] | 89 | const uint8_t *input, |
| 90 | size_t input_length, |
| 91 | uint8_t *output, |
| 92 | size_t output_size, |
| 93 | size_t *output_length ) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 94 | { |
gabor-mezei-arm | a9449a0 | 2021-03-25 11:17:10 +0100 | [diff] [blame] | 95 | mbedtls_test_driver_cipher_hooks.hits++; |
| 96 | |
| 97 | if( mbedtls_test_driver_cipher_hooks.forced_output != NULL ) |
| 98 | { |
| 99 | if( output_size < mbedtls_test_driver_cipher_hooks.forced_output_length ) |
| 100 | return( PSA_ERROR_BUFFER_TOO_SMALL ); |
| 101 | |
| 102 | memcpy( output, |
| 103 | mbedtls_test_driver_cipher_hooks.forced_output, |
| 104 | mbedtls_test_driver_cipher_hooks.forced_output_length ); |
| 105 | *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length; |
| 106 | |
| 107 | return( mbedtls_test_driver_cipher_hooks.forced_status ); |
| 108 | } |
| 109 | |
| 110 | if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) |
| 111 | return( mbedtls_test_driver_cipher_hooks.forced_status ); |
| 112 | |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 113 | #if defined(MBEDTLS_PSA_CRYPTO_CONFIG) |
Ronald Cron | 40170d9 | 2021-03-13 18:19:08 +0100 | [diff] [blame] | 114 | return( libtestdriver1_mbedtls_psa_cipher_decrypt( |
gabor-mezei-arm | a9449a0 | 2021-03-25 11:17:10 +0100 | [diff] [blame] | 115 | attributes, key_buffer, key_buffer_size, |
| 116 | alg, input, input_length, |
| 117 | output, output_size, output_length ) ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 118 | #elif defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
| 119 | return( mbedtls_psa_cipher_decrypt( |
| 120 | attributes, key_buffer, key_buffer_size, |
| 121 | alg, input, input_length, |
| 122 | output, output_size, output_length ) ); |
| 123 | #endif |
| 124 | |
| 125 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 126 | } |
| 127 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 128 | psa_status_t mbedtls_test_transparent_cipher_encrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 129 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 16afd3d | 2020-09-09 15:36:39 +0200 | [diff] [blame] | 130 | const psa_key_attributes_t *attributes, |
| 131 | const uint8_t *key, size_t key_length, |
| 132 | psa_algorithm_t alg) |
| 133 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 134 | mbedtls_test_driver_cipher_hooks.hits++; |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 135 | |
| 136 | /* Wiping the entire struct here, instead of member-by-member. This is |
| 137 | * useful for the test suite, since it gives a chance of catching memory |
| 138 | * corruption errors should the core not have allocated (enough) memory for |
| 139 | * our context struct. */ |
| 140 | memset( operation, 0, sizeof( *operation ) ); |
| 141 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 142 | if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) |
| 143 | return( mbedtls_test_driver_cipher_hooks.forced_status ); |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 144 | |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 145 | #if defined(MBEDTLS_PSA_CRYPTO_CONFIG) |
Ronald Cron | 40170d9 | 2021-03-13 18:19:08 +0100 | [diff] [blame] | 146 | return( libtestdriver1_mbedtls_psa_cipher_encrypt_setup( |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 147 | operation, attributes, key, key_length, alg ) ); |
| 148 | #elif defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
| 149 | return( mbedtls_psa_cipher_encrypt_setup( |
| 150 | operation, attributes, key, key_length, alg ) ); |
| 151 | #endif |
| 152 | |
| 153 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 16afd3d | 2020-09-09 15:36:39 +0200 | [diff] [blame] | 154 | } |
| 155 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 156 | psa_status_t mbedtls_test_transparent_cipher_decrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 157 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 158 | const psa_key_attributes_t *attributes, |
| 159 | const uint8_t *key, size_t key_length, |
| 160 | psa_algorithm_t alg) |
| 161 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 162 | mbedtls_test_driver_cipher_hooks.hits++; |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 163 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 164 | if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) |
| 165 | return( mbedtls_test_driver_cipher_hooks.forced_status ); |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 166 | |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 167 | #if defined(MBEDTLS_PSA_CRYPTO_CONFIG) |
Ronald Cron | 40170d9 | 2021-03-13 18:19:08 +0100 | [diff] [blame] | 168 | return( libtestdriver1_mbedtls_psa_cipher_decrypt_setup( |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 169 | operation, attributes, key, key_length, alg ) ); |
| 170 | #elif defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
| 171 | return( mbedtls_psa_cipher_decrypt_setup( |
| 172 | operation, attributes, key, key_length, alg ) ); |
| 173 | #endif |
| 174 | |
| 175 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 176 | } |
| 177 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 178 | psa_status_t mbedtls_test_transparent_cipher_abort( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 179 | mbedtls_transparent_test_driver_cipher_operation_t *operation) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 180 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 181 | mbedtls_test_driver_cipher_hooks.hits++; |
Steven Cooreman | 89e54f2 | 2020-09-10 18:07:57 +0200 | [diff] [blame] | 182 | |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 183 | #if defined(MBEDTLS_PSA_CRYPTO_CONFIG) |
Ronald Cron | 40170d9 | 2021-03-13 18:19:08 +0100 | [diff] [blame] | 184 | libtestdriver1_mbedtls_psa_cipher_abort( operation ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 185 | #elif defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
| 186 | mbedtls_psa_cipher_abort( operation ); |
| 187 | #endif |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 188 | |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 189 | /* Wiping the entire struct here, instead of member-by-member. This is |
| 190 | * useful for the test suite, since it gives a chance of catching memory |
| 191 | * corruption errors should the core not have allocated (enough) memory for |
| 192 | * our context struct. */ |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 193 | memset( operation, 0, sizeof( *operation ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 194 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 195 | return( mbedtls_test_driver_cipher_hooks.forced_status ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 196 | } |
| 197 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 198 | psa_status_t mbedtls_test_transparent_cipher_set_iv( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 199 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 200 | const uint8_t *iv, |
| 201 | size_t iv_length) |
| 202 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 203 | mbedtls_test_driver_cipher_hooks.hits++; |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 204 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 205 | if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) |
| 206 | return( mbedtls_test_driver_cipher_hooks.forced_status ); |
Steven Cooreman | 89e54f2 | 2020-09-10 18:07:57 +0200 | [diff] [blame] | 207 | |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 208 | #if defined(MBEDTLS_PSA_CRYPTO_CONFIG) |
Ronald Cron | 40170d9 | 2021-03-13 18:19:08 +0100 | [diff] [blame] | 209 | return( libtestdriver1_mbedtls_psa_cipher_set_iv( |
Ronald Cron | 3522e32 | 2021-03-12 11:08:49 +0100 | [diff] [blame] | 210 | operation, iv, iv_length ) ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 211 | #elif defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
| 212 | return( mbedtls_psa_cipher_set_iv( operation, iv, iv_length ) ); |
| 213 | #endif |
| 214 | |
| 215 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 216 | } |
| 217 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 218 | psa_status_t mbedtls_test_transparent_cipher_update( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 219 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 220 | const uint8_t *input, |
| 221 | size_t input_length, |
| 222 | uint8_t *output, |
| 223 | size_t output_size, |
| 224 | size_t *output_length) |
| 225 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 226 | mbedtls_test_driver_cipher_hooks.hits++; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 227 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 228 | if( mbedtls_test_driver_cipher_hooks.forced_output != NULL ) |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 229 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 230 | if( output_size < mbedtls_test_driver_cipher_hooks.forced_output_length ) |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 231 | return PSA_ERROR_BUFFER_TOO_SMALL; |
| 232 | |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 233 | memcpy( output, |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 234 | mbedtls_test_driver_cipher_hooks.forced_output, |
| 235 | mbedtls_test_driver_cipher_hooks.forced_output_length ); |
| 236 | *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length; |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 237 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 238 | return( mbedtls_test_driver_cipher_hooks.forced_status ); |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 239 | } |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 240 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 241 | if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) |
| 242 | return( mbedtls_test_driver_cipher_hooks.forced_status ); |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 243 | |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 244 | #if defined(MBEDTLS_PSA_CRYPTO_CONFIG) |
Ronald Cron | 40170d9 | 2021-03-13 18:19:08 +0100 | [diff] [blame] | 245 | return( libtestdriver1_mbedtls_psa_cipher_update( |
Ronald Cron | 3522e32 | 2021-03-12 11:08:49 +0100 | [diff] [blame] | 246 | operation, input, input_length, |
| 247 | output, output_size, output_length ) ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 248 | #elif defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
| 249 | return( mbedtls_psa_cipher_update( |
| 250 | operation, input, input_length, |
| 251 | output, output_size, output_length ) ); |
| 252 | #endif |
| 253 | |
| 254 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 255 | } |
| 256 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 257 | psa_status_t mbedtls_test_transparent_cipher_finish( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 258 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 259 | uint8_t *output, |
| 260 | size_t output_size, |
| 261 | size_t *output_length) |
| 262 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 263 | mbedtls_test_driver_cipher_hooks.hits++; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 264 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 265 | if( mbedtls_test_driver_cipher_hooks.forced_output != NULL ) |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 266 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 267 | if( output_size < mbedtls_test_driver_cipher_hooks.forced_output_length ) |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 268 | return PSA_ERROR_BUFFER_TOO_SMALL; |
| 269 | |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 270 | memcpy( output, |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 271 | mbedtls_test_driver_cipher_hooks.forced_output, |
| 272 | mbedtls_test_driver_cipher_hooks.forced_output_length ); |
| 273 | *output_length = mbedtls_test_driver_cipher_hooks.forced_output_length; |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 274 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 275 | return( mbedtls_test_driver_cipher_hooks.forced_status ); |
Steven Cooreman | 8b12225 | 2020-09-03 15:30:32 +0200 | [diff] [blame] | 276 | } |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 277 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 278 | if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS ) |
| 279 | return( mbedtls_test_driver_cipher_hooks.forced_status ); |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 280 | |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 281 | #if defined(MBEDTLS_PSA_CRYPTO_CONFIG) |
Ronald Cron | 40170d9 | 2021-03-13 18:19:08 +0100 | [diff] [blame] | 282 | return( libtestdriver1_mbedtls_psa_cipher_finish( |
Ronald Cron | 3522e32 | 2021-03-12 11:08:49 +0100 | [diff] [blame] | 283 | operation, output, output_size, output_length ) ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 284 | #elif defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
| 285 | return( mbedtls_psa_cipher_finish( |
| 286 | operation, output, output_size, output_length ) ); |
| 287 | #endif |
| 288 | |
| 289 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | /* |
| 293 | * opaque versions, to do |
| 294 | */ |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 295 | psa_status_t mbedtls_test_opaque_cipher_encrypt( |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 296 | const psa_key_attributes_t *attributes, |
| 297 | const uint8_t *key, size_t key_length, |
| 298 | psa_algorithm_t alg, |
| 299 | const uint8_t *input, size_t input_length, |
| 300 | uint8_t *output, size_t output_size, size_t *output_length) |
| 301 | { |
| 302 | (void) attributes; |
| 303 | (void) key; |
| 304 | (void) key_length; |
| 305 | (void) alg; |
| 306 | (void) input; |
| 307 | (void) input_length; |
| 308 | (void) output; |
| 309 | (void) output_size; |
| 310 | (void) output_length; |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +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_decrypt( |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 315 | const psa_key_attributes_t *attributes, |
| 316 | const uint8_t *key, size_t key_length, |
| 317 | psa_algorithm_t alg, |
| 318 | const uint8_t *input, size_t input_length, |
| 319 | uint8_t *output, size_t output_size, size_t *output_length) |
| 320 | { |
| 321 | (void) attributes; |
| 322 | (void) key; |
| 323 | (void) key_length; |
| 324 | (void) alg; |
| 325 | (void) input; |
| 326 | (void) input_length; |
| 327 | (void) output; |
| 328 | (void) output_size; |
| 329 | (void) output_length; |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 330 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 331 | } |
| 332 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 333 | psa_status_t mbedtls_test_opaque_cipher_encrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 334 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 335 | const psa_key_attributes_t *attributes, |
| 336 | const uint8_t *key, size_t key_length, |
| 337 | psa_algorithm_t alg) |
| 338 | { |
| 339 | (void) operation; |
| 340 | (void) attributes; |
| 341 | (void) key; |
| 342 | (void) key_length; |
| 343 | (void) alg; |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 344 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 345 | } |
| 346 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 347 | psa_status_t mbedtls_test_opaque_cipher_decrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 348 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 349 | const psa_key_attributes_t *attributes, |
| 350 | const uint8_t *key, size_t key_length, |
| 351 | psa_algorithm_t alg) |
| 352 | { |
| 353 | (void) operation; |
| 354 | (void) attributes; |
| 355 | (void) key; |
| 356 | (void) key_length; |
| 357 | (void) alg; |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 358 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 359 | } |
| 360 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 361 | psa_status_t mbedtls_test_opaque_cipher_abort( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 362 | mbedtls_opaque_test_driver_cipher_operation_t *operation ) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 363 | { |
| 364 | (void) operation; |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 365 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 366 | } |
| 367 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 368 | psa_status_t mbedtls_test_opaque_cipher_set_iv( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 369 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 370 | const uint8_t *iv, |
| 371 | size_t iv_length) |
| 372 | { |
| 373 | (void) operation; |
| 374 | (void) iv; |
| 375 | (void) iv_length; |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 376 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 377 | } |
| 378 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 379 | psa_status_t mbedtls_test_opaque_cipher_update( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 380 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 381 | const uint8_t *input, |
| 382 | size_t input_length, |
| 383 | uint8_t *output, |
| 384 | size_t output_size, |
| 385 | size_t *output_length) |
| 386 | { |
| 387 | (void) operation; |
| 388 | (void) input; |
| 389 | (void) input_length; |
| 390 | (void) output; |
| 391 | (void) output_size; |
| 392 | (void) output_length; |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 393 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 394 | } |
| 395 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 396 | psa_status_t mbedtls_test_opaque_cipher_finish( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 397 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 398 | uint8_t *output, |
| 399 | size_t output_size, |
| 400 | size_t *output_length) |
| 401 | { |
| 402 | (void) operation; |
| 403 | (void) output; |
| 404 | (void) output_size; |
| 405 | (void) output_length; |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 406 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 407 | } |
| 408 | #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ |