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 | |
| 20 | #if !defined(MBEDTLS_CONFIG_FILE) |
| 21 | #include "mbedtls/config.h" |
| 22 | #else |
| 23 | #include MBEDTLS_CONFIG_FILE |
| 24 | #endif |
| 25 | |
| 26 | #if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) && defined(PSA_CRYPTO_DRIVER_TEST) |
| 27 | #include "psa_crypto_aead.h" |
| 28 | |
| 29 | #include "test/drivers/aead.h" |
| 30 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 31 | mbedtls_test_driver_aead_hooks_t |
| 32 | mbedtls_test_driver_aead_hooks = MBEDTLS_TEST_DRIVER_AEAD_INIT; |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 33 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 34 | psa_status_t mbedtls_test_transparent_aead_encrypt( |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 35 | const psa_key_attributes_t *attributes, |
| 36 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 37 | psa_algorithm_t alg, |
| 38 | const uint8_t *nonce, size_t nonce_length, |
| 39 | const uint8_t *additional_data, size_t additional_data_length, |
| 40 | const uint8_t *plaintext, size_t plaintext_length, |
| 41 | uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length ) |
| 42 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 43 | mbedtls_test_driver_aead_hooks.hits_encrypt++; |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 44 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 45 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 46 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 47 | mbedtls_test_driver_aead_hooks.driver_status = |
| 48 | mbedtls_test_driver_aead_hooks.forced_status; |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 49 | } |
| 50 | else |
| 51 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 52 | mbedtls_test_driver_aead_hooks.driver_status = |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 53 | mbedtls_psa_aead_encrypt( |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 54 | attributes, key_buffer, key_buffer_size, |
| 55 | alg, |
| 56 | nonce, nonce_length, |
| 57 | additional_data, additional_data_length, |
| 58 | plaintext, plaintext_length, |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 59 | ciphertext, ciphertext_size, ciphertext_length ); |
| 60 | } |
| 61 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 62 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 63 | } |
| 64 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 65 | psa_status_t mbedtls_test_transparent_aead_decrypt( |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 66 | const psa_key_attributes_t *attributes, |
| 67 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 68 | psa_algorithm_t alg, |
| 69 | const uint8_t *nonce, size_t nonce_length, |
| 70 | const uint8_t *additional_data, size_t additional_data_length, |
| 71 | const uint8_t *ciphertext, size_t ciphertext_length, |
| 72 | uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length ) |
| 73 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 74 | mbedtls_test_driver_aead_hooks.hits_decrypt++; |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 75 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 76 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 77 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 78 | mbedtls_test_driver_aead_hooks.driver_status = |
| 79 | mbedtls_test_driver_aead_hooks.forced_status; |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 80 | } |
| 81 | else |
| 82 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 83 | mbedtls_test_driver_aead_hooks.driver_status = |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 84 | mbedtls_psa_aead_decrypt( |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 85 | attributes, key_buffer, key_buffer_size, |
| 86 | alg, |
| 87 | nonce, nonce_length, |
| 88 | additional_data, additional_data_length, |
| 89 | ciphertext, ciphertext_length, |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 90 | plaintext, plaintext_size, plaintext_length ); |
| 91 | } |
| 92 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 93 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 94 | } |
| 95 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 96 | psa_status_t mbedtls_test_transparent_aead_encrypt_setup( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 97 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 98 | const psa_key_attributes_t *attributes, |
| 99 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 100 | psa_algorithm_t alg ) |
| 101 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 102 | mbedtls_test_driver_aead_hooks.hits_encrypt_setup++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 103 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 104 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 105 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 106 | mbedtls_test_driver_aead_hooks.driver_status = |
| 107 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 108 | } |
| 109 | else |
| 110 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 111 | mbedtls_test_driver_aead_hooks.driver_status = |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 112 | mbedtls_psa_aead_encrypt_setup( operation, attributes, key_buffer, |
| 113 | key_buffer_size, alg ); |
| 114 | } |
| 115 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 116 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 117 | } |
| 118 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 119 | psa_status_t mbedtls_test_transparent_aead_decrypt_setup( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 120 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 121 | const psa_key_attributes_t *attributes, |
| 122 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 123 | psa_algorithm_t alg ) |
| 124 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 125 | mbedtls_test_driver_aead_hooks.hits_decrypt_setup++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 126 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 127 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 128 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 129 | mbedtls_test_driver_aead_hooks.driver_status = |
| 130 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 131 | } |
| 132 | else |
| 133 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 134 | mbedtls_test_driver_aead_hooks.driver_status = |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 135 | mbedtls_psa_aead_decrypt_setup( operation, attributes, key_buffer, |
| 136 | key_buffer_size, alg ); |
| 137 | } |
| 138 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 139 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 140 | } |
| 141 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 142 | psa_status_t mbedtls_test_transparent_aead_set_nonce( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 143 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 144 | const uint8_t *nonce, |
| 145 | size_t nonce_length ) |
| 146 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 147 | mbedtls_test_driver_aead_hooks.hits_set_nonce++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 148 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 149 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 150 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 151 | mbedtls_test_driver_aead_hooks.driver_status = |
| 152 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 153 | } |
| 154 | else |
| 155 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 156 | mbedtls_test_driver_aead_hooks.driver_status = |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 157 | mbedtls_psa_aead_set_nonce( operation, nonce, nonce_length ); |
| 158 | } |
| 159 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 160 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 161 | } |
| 162 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 163 | psa_status_t mbedtls_test_transparent_aead_set_lengths( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 164 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 165 | size_t ad_length, |
| 166 | size_t plaintext_length ) |
| 167 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 168 | mbedtls_test_driver_aead_hooks.hits_set_lengths++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 169 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 170 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 171 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 172 | mbedtls_test_driver_aead_hooks.driver_status = |
| 173 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 174 | } |
| 175 | else |
| 176 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 177 | mbedtls_test_driver_aead_hooks.driver_status = |
| 178 | mbedtls_psa_aead_set_lengths( operation, ad_length, |
| 179 | plaintext_length ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 180 | } |
| 181 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 182 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 183 | } |
| 184 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 185 | psa_status_t mbedtls_test_transparent_aead_update_ad( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 186 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 187 | const uint8_t *input, |
| 188 | size_t input_length ) |
| 189 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 190 | mbedtls_test_driver_aead_hooks.hits_update_ad++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 191 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 192 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 193 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 194 | mbedtls_test_driver_aead_hooks.driver_status = |
| 195 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 196 | } |
| 197 | else |
| 198 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 199 | mbedtls_test_driver_aead_hooks.driver_status = |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 200 | mbedtls_psa_aead_update_ad( operation, input, input_length ); |
| 201 | } |
| 202 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 203 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 204 | } |
| 205 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 206 | psa_status_t mbedtls_test_transparent_aead_update( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 207 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 208 | const uint8_t *input, |
| 209 | size_t input_length, |
| 210 | uint8_t *output, |
| 211 | size_t output_size, |
| 212 | size_t *output_length ) |
| 213 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 214 | mbedtls_test_driver_aead_hooks.hits_update++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 215 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 216 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 217 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 218 | mbedtls_test_driver_aead_hooks.driver_status = |
| 219 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 220 | } |
| 221 | else |
| 222 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 223 | mbedtls_test_driver_aead_hooks.driver_status = |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 224 | mbedtls_psa_aead_update( operation, input, input_length, output, |
| 225 | output_size, output_length ); |
| 226 | } |
| 227 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 228 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 229 | } |
| 230 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 231 | psa_status_t mbedtls_test_transparent_aead_finish( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 232 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 233 | uint8_t *ciphertext, |
| 234 | size_t ciphertext_size, |
| 235 | size_t *ciphertext_length, |
| 236 | uint8_t *tag, |
| 237 | size_t tag_size, |
| 238 | size_t *tag_length ) |
| 239 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 240 | mbedtls_test_driver_aead_hooks.hits_finish++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 241 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 242 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 243 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 244 | mbedtls_test_driver_aead_hooks.driver_status = |
| 245 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 246 | } |
| 247 | else |
| 248 | { |
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_finish( operation, ciphertext, ciphertext_size, |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 251 | ciphertext_length, tag, tag_size, |
| 252 | tag_length ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 253 | } |
| 254 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 255 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 256 | } |
| 257 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 258 | psa_status_t mbedtls_test_transparent_aead_verify( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 259 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 260 | uint8_t *plaintext, |
| 261 | size_t plaintext_size, |
| 262 | size_t *plaintext_length, |
| 263 | const uint8_t *tag, |
| 264 | size_t tag_length ) |
| 265 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 266 | mbedtls_test_driver_aead_hooks.hits_verify++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 267 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 268 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 269 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 270 | mbedtls_test_driver_aead_hooks.driver_status = |
| 271 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 272 | } |
| 273 | else |
| 274 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 275 | mbedtls_test_driver_aead_hooks.driver_status = |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 276 | mbedtls_psa_aead_verify( operation, plaintext, plaintext_size, |
| 277 | plaintext_length, tag, tag_length ); |
| 278 | } |
| 279 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 280 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 281 | } |
| 282 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 283 | psa_status_t mbedtls_test_transparent_aead_abort( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 284 | mbedtls_transparent_test_driver_aead_operation_t *operation ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 285 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 286 | mbedtls_test_driver_aead_hooks.hits_abort++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 287 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 288 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 289 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 290 | mbedtls_test_driver_aead_hooks.driver_status = |
| 291 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 292 | } |
| 293 | else |
| 294 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 295 | mbedtls_test_driver_aead_hooks.driver_status = |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 296 | mbedtls_psa_aead_abort( operation ); |
| 297 | } |
| 298 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 299 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 300 | } |
| 301 | |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 302 | #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ |