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