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 | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 174 | mbedtls_test_driver_aead_hooks.driver_status = |
| 175 | mbedtls_psa_aead_set_lengths( operation, ad_length, |
| 176 | plaintext_length ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 177 | } |
| 178 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 179 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
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 | psa_status_t mbedtls_test_transparent_aead_update_ad( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 183 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 184 | const uint8_t *input, |
| 185 | size_t input_length ) |
| 186 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 187 | mbedtls_test_driver_aead_hooks.hits_update_ad++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 188 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 189 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 190 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 191 | mbedtls_test_driver_aead_hooks.driver_status = |
| 192 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 193 | } |
| 194 | else |
| 195 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 196 | mbedtls_test_driver_aead_hooks.driver_status = |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 197 | mbedtls_psa_aead_update_ad( operation, input, input_length ); |
| 198 | } |
| 199 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 200 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 201 | } |
| 202 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 203 | psa_status_t mbedtls_test_transparent_aead_update( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 204 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 205 | const uint8_t *input, |
| 206 | size_t input_length, |
| 207 | uint8_t *output, |
| 208 | size_t output_size, |
| 209 | size_t *output_length ) |
| 210 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 211 | mbedtls_test_driver_aead_hooks.hits_update++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 212 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 213 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 214 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 215 | mbedtls_test_driver_aead_hooks.driver_status = |
| 216 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 217 | } |
| 218 | else |
| 219 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 220 | mbedtls_test_driver_aead_hooks.driver_status = |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 221 | mbedtls_psa_aead_update( operation, input, input_length, output, |
| 222 | output_size, output_length ); |
| 223 | } |
| 224 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 225 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 226 | } |
| 227 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 228 | psa_status_t mbedtls_test_transparent_aead_finish( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 229 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 230 | uint8_t *ciphertext, |
| 231 | size_t ciphertext_size, |
| 232 | size_t *ciphertext_length, |
| 233 | uint8_t *tag, |
| 234 | size_t tag_size, |
| 235 | size_t *tag_length ) |
| 236 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 237 | mbedtls_test_driver_aead_hooks.hits_finish++; |
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 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 240 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 241 | mbedtls_test_driver_aead_hooks.driver_status = |
| 242 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 243 | } |
| 244 | else |
| 245 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 246 | mbedtls_test_driver_aead_hooks.driver_status = |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 247 | mbedtls_psa_aead_finish( operation, ciphertext, ciphertext_size, |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 248 | ciphertext_length, tag, tag_size, |
| 249 | tag_length ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 250 | } |
| 251 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 252 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
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 | psa_status_t mbedtls_test_transparent_aead_verify( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 256 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 257 | uint8_t *plaintext, |
| 258 | size_t plaintext_size, |
| 259 | size_t *plaintext_length, |
| 260 | const uint8_t *tag, |
| 261 | size_t tag_length ) |
| 262 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 263 | mbedtls_test_driver_aead_hooks.hits_verify++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 264 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 265 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 266 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 267 | mbedtls_test_driver_aead_hooks.driver_status = |
| 268 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 269 | } |
| 270 | else |
| 271 | { |
Paul Elliott | 26f4aef | 2021-07-22 21:47:27 +0100 | [diff] [blame] | 272 | uint8_t check_tag[PSA_AEAD_TAG_MAX_SIZE]; |
| 273 | size_t check_tag_length; |
| 274 | |
| 275 | mbedtls_test_driver_aead_hooks.driver_status = |
| 276 | mbedtls_psa_aead_finish( operation, |
| 277 | plaintext, |
| 278 | plaintext_size, |
| 279 | plaintext_length, |
| 280 | check_tag, |
Paul Elliott | 0f32b7d | 2021-09-20 18:46:03 +0100 | [diff] [blame] | 281 | sizeof( check_tag ), |
Paul Elliott | 26f4aef | 2021-07-22 21:47:27 +0100 | [diff] [blame] | 282 | &check_tag_length ); |
| 283 | |
| 284 | if( mbedtls_test_driver_aead_hooks.driver_status == PSA_SUCCESS ) |
| 285 | { |
| 286 | if( tag_length != check_tag_length || |
| 287 | mbedtls_psa_safer_memcmp( tag, check_tag, tag_length ) |
| 288 | != 0 ) |
| 289 | mbedtls_test_driver_aead_hooks.driver_status = |
| 290 | PSA_ERROR_INVALID_SIGNATURE; |
| 291 | } |
Paul Elliott | 0f32b7d | 2021-09-20 18:46:03 +0100 | [diff] [blame] | 292 | |
| 293 | mbedtls_platform_zeroize( check_tag, sizeof( check_tag ) ); |
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 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 297 | } |
| 298 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 299 | psa_status_t mbedtls_test_transparent_aead_abort( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 300 | mbedtls_transparent_test_driver_aead_operation_t *operation ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 301 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 302 | mbedtls_test_driver_aead_hooks.hits_abort++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 303 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 304 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
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 | mbedtls_test_driver_aead_hooks.driver_status = |
| 307 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 308 | } |
| 309 | else |
| 310 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 311 | mbedtls_test_driver_aead_hooks.driver_status = |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 312 | mbedtls_psa_aead_abort( operation ); |
| 313 | } |
| 314 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 315 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 316 | } |
| 317 | |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 318 | #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ |