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