Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Test driver for AEAD entry points. |
| 3 | */ |
| 4 | /* Copyright The Mbed TLS Contributors |
| 5 | * SPDX-License-Identifier: Apache-2.0 |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 8 | * not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | */ |
| 19 | |
Mateusz Starzyk | 2c09c9b | 2021-05-14 22:20:10 +0200 | [diff] [blame] | 20 | #include <test/helpers.h> |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 21 | |
| 22 | #if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) && defined(PSA_CRYPTO_DRIVER_TEST) |
| 23 | #include "psa_crypto_aead.h" |
Paul Elliott | 0a6a569 | 2021-07-23 15:29:21 +0100 | [diff] [blame] | 24 | #include "psa_crypto_core.h" |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 25 | |
| 26 | #include "test/drivers/aead.h" |
| 27 | |
Przemek Stekiel | bd99a02 | 2022-10-02 21:01:23 +0200 | [diff] [blame] | 28 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) |
| 29 | #include "libtestdriver1/library/psa_crypto_aead.h" |
| 30 | #endif |
| 31 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 32 | mbedtls_test_driver_aead_hooks_t |
| 33 | mbedtls_test_driver_aead_hooks = MBEDTLS_TEST_DRIVER_AEAD_INIT; |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 34 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 35 | psa_status_t mbedtls_test_transparent_aead_encrypt( |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 36 | const psa_key_attributes_t *attributes, |
| 37 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 38 | psa_algorithm_t alg, |
| 39 | const uint8_t *nonce, size_t nonce_length, |
| 40 | const uint8_t *additional_data, size_t additional_data_length, |
| 41 | const uint8_t *plaintext, size_t plaintext_length, |
| 42 | uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length ) |
| 43 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 44 | mbedtls_test_driver_aead_hooks.hits_encrypt++; |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 45 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 46 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 47 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 48 | mbedtls_test_driver_aead_hooks.driver_status = |
| 49 | mbedtls_test_driver_aead_hooks.forced_status; |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 50 | } |
| 51 | else |
| 52 | { |
Przemek Stekiel | bd99a02 | 2022-10-02 21:01:23 +0200 | [diff] [blame] | 53 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
| 54 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD) |
| 55 | mbedtls_test_driver_aead_hooks.driver_status = |
| 56 | libtestdriver1_mbedtls_psa_aead_encrypt( |
| 57 | (const libtestdriver1_psa_key_attributes_t *)attributes, |
| 58 | key_buffer, key_buffer_size, |
| 59 | alg, |
| 60 | nonce, nonce_length, |
| 61 | additional_data, additional_data_length, |
| 62 | plaintext, plaintext_length, |
| 63 | ciphertext, ciphertext_size, ciphertext_length ); |
| 64 | #elif defined(MBEDTLS_PSA_BUILTIN_AEAD) |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 65 | mbedtls_test_driver_aead_hooks.driver_status = |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 66 | mbedtls_psa_aead_encrypt( |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 67 | attributes, key_buffer, key_buffer_size, |
| 68 | alg, |
| 69 | nonce, nonce_length, |
| 70 | additional_data, additional_data_length, |
| 71 | plaintext, plaintext_length, |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 72 | ciphertext, ciphertext_size, ciphertext_length ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 73 | #else |
| 74 | (void) attributes; |
| 75 | (void) key_buffer; |
| 76 | (void) key_buffer_size; |
| 77 | (void) alg; |
| 78 | (void) nonce; |
| 79 | (void) nonce_length; |
| 80 | (void) additional_data; |
| 81 | (void) additional_data_length; |
| 82 | (void) plaintext; |
| 83 | (void) plaintext_length; |
| 84 | (void) ciphertext; |
| 85 | (void) ciphertext_size; |
| 86 | (void) ciphertext_length; |
| 87 | mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 88 | #endif |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 89 | } |
| 90 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 91 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 92 | } |
| 93 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 94 | psa_status_t mbedtls_test_transparent_aead_decrypt( |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 95 | const psa_key_attributes_t *attributes, |
| 96 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 97 | psa_algorithm_t alg, |
| 98 | const uint8_t *nonce, size_t nonce_length, |
| 99 | const uint8_t *additional_data, size_t additional_data_length, |
| 100 | const uint8_t *ciphertext, size_t ciphertext_length, |
| 101 | uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length ) |
| 102 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 103 | mbedtls_test_driver_aead_hooks.hits_decrypt++; |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 104 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 105 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 106 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 107 | mbedtls_test_driver_aead_hooks.driver_status = |
| 108 | mbedtls_test_driver_aead_hooks.forced_status; |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 109 | } |
| 110 | else |
| 111 | { |
Przemek Stekiel | bd99a02 | 2022-10-02 21:01:23 +0200 | [diff] [blame] | 112 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
| 113 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD) |
| 114 | mbedtls_test_driver_aead_hooks.driver_status = |
| 115 | libtestdriver1_mbedtls_psa_aead_decrypt( |
| 116 | (const libtestdriver1_psa_key_attributes_t *)attributes, |
| 117 | key_buffer, key_buffer_size, |
| 118 | alg, |
| 119 | nonce, nonce_length, |
| 120 | additional_data, additional_data_length, |
| 121 | ciphertext, ciphertext_length, |
| 122 | plaintext, plaintext_size, plaintext_length ); |
| 123 | #elif defined(MBEDTLS_PSA_BUILTIN_AEAD) |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 124 | mbedtls_test_driver_aead_hooks.driver_status = |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 125 | mbedtls_psa_aead_decrypt( |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 126 | attributes, key_buffer, key_buffer_size, |
| 127 | alg, |
| 128 | nonce, nonce_length, |
| 129 | additional_data, additional_data_length, |
| 130 | ciphertext, ciphertext_length, |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 131 | plaintext, plaintext_size, plaintext_length ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 132 | #else |
| 133 | (void) attributes; |
| 134 | (void) key_buffer; |
| 135 | (void) key_buffer_size; |
| 136 | (void) alg; |
| 137 | (void) nonce; |
| 138 | (void) nonce_length; |
| 139 | (void) additional_data; |
| 140 | (void) additional_data_length; |
| 141 | (void) ciphertext; |
| 142 | (void) ciphertext_length; |
| 143 | (void) plaintext; |
| 144 | (void) plaintext_size; |
| 145 | (void) plaintext_length; |
| 146 | mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 147 | #endif |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 148 | } |
| 149 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 150 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 151 | } |
| 152 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 153 | psa_status_t mbedtls_test_transparent_aead_encrypt_setup( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 154 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 155 | const psa_key_attributes_t *attributes, |
| 156 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 157 | psa_algorithm_t alg ) |
| 158 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 159 | mbedtls_test_driver_aead_hooks.hits_encrypt_setup++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 160 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 161 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 162 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 163 | mbedtls_test_driver_aead_hooks.driver_status = |
| 164 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 165 | } |
| 166 | else |
| 167 | { |
Przemek Stekiel | bd99a02 | 2022-10-02 21:01:23 +0200 | [diff] [blame] | 168 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
| 169 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD) |
| 170 | mbedtls_test_driver_aead_hooks.driver_status = |
| 171 | libtestdriver1_mbedtls_psa_aead_encrypt_setup( operation, |
| 172 | (const libtestdriver1_psa_key_attributes_t *)attributes, |
| 173 | key_buffer, |
| 174 | key_buffer_size, alg ); |
| 175 | #elif defined(MBEDTLS_PSA_BUILTIN_AEAD) |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 176 | mbedtls_test_driver_aead_hooks.driver_status = |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 177 | mbedtls_psa_aead_encrypt_setup( operation, attributes, key_buffer, |
| 178 | key_buffer_size, alg ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 179 | #else |
| 180 | (void) operation; |
| 181 | (void) attributes; |
| 182 | (void) key_buffer; |
| 183 | (void) key_buffer_size; |
| 184 | (void) alg; |
| 185 | mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 186 | #endif |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 187 | } |
| 188 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 189 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 190 | } |
| 191 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 192 | psa_status_t mbedtls_test_transparent_aead_decrypt_setup( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 193 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 194 | const psa_key_attributes_t *attributes, |
| 195 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 196 | psa_algorithm_t alg ) |
| 197 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 198 | mbedtls_test_driver_aead_hooks.hits_decrypt_setup++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 199 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 200 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 201 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 202 | mbedtls_test_driver_aead_hooks.driver_status = |
| 203 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 204 | } |
| 205 | else |
| 206 | { |
Przemek Stekiel | bd99a02 | 2022-10-02 21:01:23 +0200 | [diff] [blame] | 207 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
| 208 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD) |
| 209 | mbedtls_test_driver_aead_hooks.driver_status = |
| 210 | libtestdriver1_mbedtls_psa_aead_decrypt_setup( operation, |
| 211 | (const libtestdriver1_psa_key_attributes_t *)attributes, |
| 212 | key_buffer, key_buffer_size, alg ); |
| 213 | #elif defined(MBEDTLS_PSA_BUILTIN_AEAD) |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 214 | mbedtls_test_driver_aead_hooks.driver_status = |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 215 | mbedtls_psa_aead_decrypt_setup( operation, attributes, key_buffer, |
| 216 | key_buffer_size, alg ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 217 | #else |
| 218 | (void) operation; |
| 219 | (void) attributes; |
| 220 | (void) key_buffer; |
| 221 | (void) key_buffer_size; |
| 222 | (void) alg; |
| 223 | mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 224 | #endif |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 225 | } |
| 226 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 227 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 228 | } |
| 229 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 230 | psa_status_t mbedtls_test_transparent_aead_set_nonce( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 231 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 232 | const uint8_t *nonce, |
| 233 | size_t nonce_length ) |
| 234 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 235 | mbedtls_test_driver_aead_hooks.hits_set_nonce++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 236 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 237 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 238 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 239 | mbedtls_test_driver_aead_hooks.driver_status = |
| 240 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 241 | } |
| 242 | else |
| 243 | { |
Przemek Stekiel | bd99a02 | 2022-10-02 21:01:23 +0200 | [diff] [blame] | 244 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
| 245 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD) |
| 246 | mbedtls_test_driver_aead_hooks.driver_status = |
| 247 | libtestdriver1_mbedtls_psa_aead_set_nonce( operation, nonce, nonce_length ); |
| 248 | #elif defined(MBEDTLS_PSA_BUILTIN_AEAD) |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 249 | mbedtls_test_driver_aead_hooks.driver_status = |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 250 | mbedtls_psa_aead_set_nonce( operation, nonce, nonce_length ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 251 | #else |
| 252 | (void) operation; |
| 253 | (void) nonce; |
| 254 | (void) nonce_length; |
| 255 | mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 256 | #endif |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 257 | } |
| 258 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 259 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 260 | } |
| 261 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 262 | psa_status_t mbedtls_test_transparent_aead_set_lengths( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 263 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 264 | size_t ad_length, |
| 265 | size_t plaintext_length ) |
| 266 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 267 | mbedtls_test_driver_aead_hooks.hits_set_lengths++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 268 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 269 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 270 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 271 | mbedtls_test_driver_aead_hooks.driver_status = |
| 272 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 273 | } |
| 274 | else |
| 275 | { |
Przemek Stekiel | bd99a02 | 2022-10-02 21:01:23 +0200 | [diff] [blame] | 276 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
| 277 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD) |
| 278 | mbedtls_test_driver_aead_hooks.driver_status = |
| 279 | libtestdriver1_mbedtls_psa_aead_set_lengths( operation, ad_length, |
| 280 | plaintext_length ); |
| 281 | #elif defined(MBEDTLS_PSA_BUILTIN_AEAD) |
Paul Elliott | dff6c5d | 2021-09-28 11:00:20 +0100 | [diff] [blame] | 282 | mbedtls_test_driver_aead_hooks.driver_status = |
| 283 | mbedtls_psa_aead_set_lengths( operation, ad_length, |
| 284 | plaintext_length ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 285 | #else |
| 286 | (void) operation; |
| 287 | (void) ad_length; |
| 288 | (void) plaintext_length; |
| 289 | mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 290 | #endif |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 291 | } |
| 292 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 293 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 294 | } |
| 295 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 296 | psa_status_t mbedtls_test_transparent_aead_update_ad( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 297 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 298 | const uint8_t *input, |
| 299 | size_t input_length ) |
| 300 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 301 | mbedtls_test_driver_aead_hooks.hits_update_ad++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 302 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 303 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 304 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 305 | mbedtls_test_driver_aead_hooks.driver_status = |
| 306 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 307 | } |
| 308 | else |
| 309 | { |
Przemek Stekiel | bd99a02 | 2022-10-02 21:01:23 +0200 | [diff] [blame] | 310 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
| 311 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD) |
| 312 | mbedtls_test_driver_aead_hooks.driver_status = |
| 313 | libtestdriver1_mbedtls_psa_aead_update_ad( operation, input, input_length ); |
| 314 | #elif defined(MBEDTLS_PSA_BUILTIN_AEAD) |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 315 | mbedtls_test_driver_aead_hooks.driver_status = |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 316 | mbedtls_psa_aead_update_ad( operation, input, input_length ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 317 | #else |
| 318 | (void) operation; |
| 319 | (void) input; |
| 320 | (void) input_length; |
| 321 | mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 322 | #endif |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 323 | } |
| 324 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 325 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 326 | } |
| 327 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 328 | psa_status_t mbedtls_test_transparent_aead_update( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 329 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 330 | const uint8_t *input, |
| 331 | size_t input_length, |
| 332 | uint8_t *output, |
| 333 | size_t output_size, |
| 334 | size_t *output_length ) |
| 335 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 336 | mbedtls_test_driver_aead_hooks.hits_update++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 337 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 338 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 339 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 340 | mbedtls_test_driver_aead_hooks.driver_status = |
| 341 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 342 | } |
| 343 | else |
| 344 | { |
Przemek Stekiel | bd99a02 | 2022-10-02 21:01:23 +0200 | [diff] [blame] | 345 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
| 346 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD) |
| 347 | mbedtls_test_driver_aead_hooks.driver_status = |
| 348 | libtestdriver1_mbedtls_psa_aead_update( operation, input, |
| 349 | input_length, output, |
| 350 | output_size, output_length ); |
| 351 | #elif defined(MBEDTLS_PSA_BUILTIN_AEAD) |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 352 | mbedtls_test_driver_aead_hooks.driver_status = |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 353 | mbedtls_psa_aead_update( operation, input, input_length, output, |
| 354 | output_size, output_length ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 355 | #else |
| 356 | (void) operation; |
| 357 | (void) input; |
| 358 | (void) input_length; |
| 359 | (void) output; |
| 360 | (void) output_size; |
| 361 | (void) output_length; |
| 362 | mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 363 | #endif |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 364 | } |
| 365 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 366 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 367 | } |
| 368 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 369 | psa_status_t mbedtls_test_transparent_aead_finish( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 370 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 371 | uint8_t *ciphertext, |
| 372 | size_t ciphertext_size, |
| 373 | size_t *ciphertext_length, |
| 374 | uint8_t *tag, |
| 375 | size_t tag_size, |
| 376 | size_t *tag_length ) |
| 377 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 378 | mbedtls_test_driver_aead_hooks.hits_finish++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 379 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 380 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 381 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 382 | mbedtls_test_driver_aead_hooks.driver_status = |
| 383 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 384 | } |
| 385 | else |
| 386 | { |
Przemek Stekiel | bd99a02 | 2022-10-02 21:01:23 +0200 | [diff] [blame] | 387 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
| 388 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD) |
| 389 | mbedtls_test_driver_aead_hooks.driver_status = |
| 390 | libtestdriver1_mbedtls_psa_aead_finish( operation, ciphertext, |
| 391 | ciphertext_size, ciphertext_length, |
| 392 | tag, tag_size, tag_length ); |
| 393 | #elif defined(MBEDTLS_PSA_BUILTIN_AEAD) |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 394 | mbedtls_test_driver_aead_hooks.driver_status = |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 395 | mbedtls_psa_aead_finish( operation, ciphertext, ciphertext_size, |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 396 | ciphertext_length, tag, tag_size, |
| 397 | tag_length ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 398 | #else |
| 399 | (void) operation; |
| 400 | (void) ciphertext; |
| 401 | (void) ciphertext_size; |
| 402 | (void) ciphertext_length; |
| 403 | (void) tag; |
| 404 | (void) tag_size; |
| 405 | (void) tag_length; |
| 406 | mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 407 | #endif |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 408 | } |
| 409 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 410 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 411 | } |
| 412 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 413 | psa_status_t mbedtls_test_transparent_aead_verify( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 414 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 415 | uint8_t *plaintext, |
| 416 | size_t plaintext_size, |
| 417 | size_t *plaintext_length, |
| 418 | const uint8_t *tag, |
| 419 | size_t tag_length ) |
| 420 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 421 | mbedtls_test_driver_aead_hooks.hits_verify++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 422 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 423 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 424 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 425 | mbedtls_test_driver_aead_hooks.driver_status = |
| 426 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 427 | } |
| 428 | else |
| 429 | { |
Paul Elliott | 26f4aef | 2021-07-22 21:47:27 +0100 | [diff] [blame] | 430 | uint8_t check_tag[PSA_AEAD_TAG_MAX_SIZE]; |
Przemek Stekiel | bd99a02 | 2022-10-02 21:01:23 +0200 | [diff] [blame] | 431 | size_t check_tag_length = 0; |
Paul Elliott | 26f4aef | 2021-07-22 21:47:27 +0100 | [diff] [blame] | 432 | |
Przemek Stekiel | bd99a02 | 2022-10-02 21:01:23 +0200 | [diff] [blame] | 433 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
| 434 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD) |
| 435 | mbedtls_test_driver_aead_hooks.driver_status = |
| 436 | libtestdriver1_mbedtls_psa_aead_finish( operation, |
| 437 | plaintext, |
| 438 | plaintext_size, |
| 439 | plaintext_length, |
| 440 | check_tag, |
| 441 | sizeof( check_tag ), |
| 442 | &check_tag_length ); |
| 443 | #elif defined(MBEDTLS_PSA_BUILTIN_AEAD) |
Paul Elliott | 26f4aef | 2021-07-22 21:47:27 +0100 | [diff] [blame] | 444 | mbedtls_test_driver_aead_hooks.driver_status = |
| 445 | mbedtls_psa_aead_finish( operation, |
| 446 | plaintext, |
| 447 | plaintext_size, |
| 448 | plaintext_length, |
| 449 | check_tag, |
Paul Elliott | 0f32b7d | 2021-09-20 18:46:03 +0100 | [diff] [blame] | 450 | sizeof( check_tag ), |
Paul Elliott | 26f4aef | 2021-07-22 21:47:27 +0100 | [diff] [blame] | 451 | &check_tag_length ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 452 | #else |
| 453 | (void) operation; |
| 454 | (void) plaintext; |
| 455 | (void) plaintext_size; |
| 456 | (void) plaintext_length; |
| 457 | mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 458 | #endif |
Paul Elliott | 26f4aef | 2021-07-22 21:47:27 +0100 | [diff] [blame] | 459 | |
| 460 | if( mbedtls_test_driver_aead_hooks.driver_status == PSA_SUCCESS ) |
| 461 | { |
| 462 | if( tag_length != check_tag_length || |
| 463 | mbedtls_psa_safer_memcmp( tag, check_tag, tag_length ) |
| 464 | != 0 ) |
| 465 | mbedtls_test_driver_aead_hooks.driver_status = |
| 466 | PSA_ERROR_INVALID_SIGNATURE; |
| 467 | } |
Paul Elliott | 0f32b7d | 2021-09-20 18:46:03 +0100 | [diff] [blame] | 468 | |
| 469 | mbedtls_platform_zeroize( check_tag, sizeof( check_tag ) ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 470 | } |
| 471 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 472 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 473 | } |
| 474 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 475 | psa_status_t mbedtls_test_transparent_aead_abort( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 476 | mbedtls_transparent_test_driver_aead_operation_t *operation ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 477 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 478 | mbedtls_test_driver_aead_hooks.hits_abort++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 479 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 480 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 481 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 482 | mbedtls_test_driver_aead_hooks.driver_status = |
| 483 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 484 | } |
| 485 | else |
| 486 | { |
Przemek Stekiel | bd99a02 | 2022-10-02 21:01:23 +0200 | [diff] [blame] | 487 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
| 488 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD) |
| 489 | mbedtls_test_driver_aead_hooks.driver_status = |
| 490 | libtestdriver1_mbedtls_psa_aead_abort( operation ); |
| 491 | #elif defined(MBEDTLS_PSA_BUILTIN_AEAD) |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 492 | mbedtls_test_driver_aead_hooks.driver_status = |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 493 | mbedtls_psa_aead_abort( operation ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 494 | #else |
| 495 | (void) operation; |
| 496 | mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 497 | #endif |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 498 | } |
| 499 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 500 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 501 | } |
| 502 | |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 503 | #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ |