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 | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 49 | #if defined(MBEDTLS_PSA_BUILTIN_AEAD) |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 50 | mbedtls_test_driver_aead_hooks.driver_status = |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 51 | mbedtls_psa_aead_encrypt( |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 52 | attributes, key_buffer, key_buffer_size, |
| 53 | alg, |
| 54 | nonce, nonce_length, |
| 55 | additional_data, additional_data_length, |
| 56 | plaintext, plaintext_length, |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 57 | ciphertext, ciphertext_size, ciphertext_length ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 58 | #else |
| 59 | (void) attributes; |
| 60 | (void) key_buffer; |
| 61 | (void) key_buffer_size; |
| 62 | (void) alg; |
| 63 | (void) nonce; |
| 64 | (void) nonce_length; |
| 65 | (void) additional_data; |
| 66 | (void) additional_data_length; |
| 67 | (void) plaintext; |
| 68 | (void) plaintext_length; |
| 69 | (void) ciphertext; |
| 70 | (void) ciphertext_size; |
| 71 | (void) ciphertext_length; |
| 72 | mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 73 | #endif |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 76 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 77 | } |
| 78 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 79 | psa_status_t mbedtls_test_transparent_aead_decrypt( |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 80 | const psa_key_attributes_t *attributes, |
| 81 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 82 | psa_algorithm_t alg, |
| 83 | const uint8_t *nonce, size_t nonce_length, |
| 84 | const uint8_t *additional_data, size_t additional_data_length, |
| 85 | const uint8_t *ciphertext, size_t ciphertext_length, |
| 86 | uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length ) |
| 87 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 88 | mbedtls_test_driver_aead_hooks.hits_decrypt++; |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 89 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 90 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 91 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 92 | mbedtls_test_driver_aead_hooks.driver_status = |
| 93 | mbedtls_test_driver_aead_hooks.forced_status; |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 94 | } |
| 95 | else |
| 96 | { |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 97 | #if defined(MBEDTLS_PSA_BUILTIN_AEAD) |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 98 | mbedtls_test_driver_aead_hooks.driver_status = |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 99 | mbedtls_psa_aead_decrypt( |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 100 | attributes, key_buffer, key_buffer_size, |
| 101 | alg, |
| 102 | nonce, nonce_length, |
| 103 | additional_data, additional_data_length, |
| 104 | ciphertext, ciphertext_length, |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 105 | plaintext, plaintext_size, plaintext_length ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 106 | #else |
| 107 | (void) attributes; |
| 108 | (void) key_buffer; |
| 109 | (void) key_buffer_size; |
| 110 | (void) alg; |
| 111 | (void) nonce; |
| 112 | (void) nonce_length; |
| 113 | (void) additional_data; |
| 114 | (void) additional_data_length; |
| 115 | (void) ciphertext; |
| 116 | (void) ciphertext_length; |
| 117 | (void) plaintext; |
| 118 | (void) plaintext_size; |
| 119 | (void) plaintext_length; |
| 120 | mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 121 | #endif |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 122 | } |
| 123 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 124 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 125 | } |
| 126 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 127 | psa_status_t mbedtls_test_transparent_aead_encrypt_setup( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 128 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 129 | const psa_key_attributes_t *attributes, |
| 130 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 131 | psa_algorithm_t alg ) |
| 132 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 133 | mbedtls_test_driver_aead_hooks.hits_encrypt_setup++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 134 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 135 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 136 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 137 | mbedtls_test_driver_aead_hooks.driver_status = |
| 138 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 139 | } |
| 140 | else |
| 141 | { |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 142 | #if defined(MBEDTLS_PSA_BUILTIN_AEAD) |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 143 | mbedtls_test_driver_aead_hooks.driver_status = |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 144 | mbedtls_psa_aead_encrypt_setup( operation, attributes, key_buffer, |
| 145 | key_buffer_size, alg ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 146 | #else |
| 147 | (void) operation; |
| 148 | (void) attributes; |
| 149 | (void) key_buffer; |
| 150 | (void) key_buffer_size; |
| 151 | (void) alg; |
| 152 | mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 153 | #endif |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 154 | } |
| 155 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 156 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 157 | } |
| 158 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 159 | psa_status_t mbedtls_test_transparent_aead_decrypt_setup( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 160 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 161 | const psa_key_attributes_t *attributes, |
| 162 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 163 | psa_algorithm_t alg ) |
| 164 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 165 | mbedtls_test_driver_aead_hooks.hits_decrypt_setup++; |
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 | { |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 174 | #if defined(MBEDTLS_PSA_BUILTIN_AEAD) |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 175 | mbedtls_test_driver_aead_hooks.driver_status = |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 176 | mbedtls_psa_aead_decrypt_setup( operation, attributes, key_buffer, |
| 177 | key_buffer_size, alg ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 178 | #else |
| 179 | (void) operation; |
| 180 | (void) attributes; |
| 181 | (void) key_buffer; |
| 182 | (void) key_buffer_size; |
| 183 | (void) alg; |
| 184 | mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 185 | #endif |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 186 | } |
| 187 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 188 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 189 | } |
| 190 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 191 | psa_status_t mbedtls_test_transparent_aead_set_nonce( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 192 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 193 | const uint8_t *nonce, |
| 194 | size_t nonce_length ) |
| 195 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 196 | mbedtls_test_driver_aead_hooks.hits_set_nonce++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 197 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 198 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
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 | mbedtls_test_driver_aead_hooks.driver_status = |
| 201 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 202 | } |
| 203 | else |
| 204 | { |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 205 | #if defined(MBEDTLS_PSA_BUILTIN_AEAD) |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 206 | mbedtls_test_driver_aead_hooks.driver_status = |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 207 | mbedtls_psa_aead_set_nonce( operation, nonce, nonce_length ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 208 | #else |
| 209 | (void) operation; |
| 210 | (void) nonce; |
| 211 | (void) nonce_length; |
| 212 | mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 213 | #endif |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 214 | } |
| 215 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 216 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 217 | } |
| 218 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 219 | psa_status_t mbedtls_test_transparent_aead_set_lengths( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 220 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 221 | size_t ad_length, |
| 222 | size_t plaintext_length ) |
| 223 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 224 | mbedtls_test_driver_aead_hooks.hits_set_lengths++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 225 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 226 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 227 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 228 | mbedtls_test_driver_aead_hooks.driver_status = |
| 229 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 230 | } |
| 231 | else |
| 232 | { |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 233 | #if defined(MBEDTLS_PSA_BUILTIN_AEAD) |
Paul Elliott | dff6c5d | 2021-09-28 11:00:20 +0100 | [diff] [blame] | 234 | mbedtls_test_driver_aead_hooks.driver_status = |
| 235 | mbedtls_psa_aead_set_lengths( operation, ad_length, |
| 236 | plaintext_length ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 237 | #else |
| 238 | (void) operation; |
| 239 | (void) ad_length; |
| 240 | (void) plaintext_length; |
| 241 | mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 242 | #endif |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 243 | } |
| 244 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 245 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 246 | } |
| 247 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 248 | psa_status_t mbedtls_test_transparent_aead_update_ad( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 249 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 250 | const uint8_t *input, |
| 251 | size_t input_length ) |
| 252 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 253 | mbedtls_test_driver_aead_hooks.hits_update_ad++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 254 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 255 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 256 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 257 | mbedtls_test_driver_aead_hooks.driver_status = |
| 258 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 259 | } |
| 260 | else |
| 261 | { |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 262 | #if defined(MBEDTLS_PSA_BUILTIN_AEAD) |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 263 | mbedtls_test_driver_aead_hooks.driver_status = |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 264 | mbedtls_psa_aead_update_ad( operation, input, input_length ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 265 | #else |
| 266 | (void) operation; |
| 267 | (void) input; |
| 268 | (void) input_length; |
| 269 | mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 270 | #endif |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 271 | } |
| 272 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 273 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 274 | } |
| 275 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 276 | psa_status_t mbedtls_test_transparent_aead_update( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 277 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 278 | const uint8_t *input, |
| 279 | size_t input_length, |
| 280 | uint8_t *output, |
| 281 | size_t output_size, |
| 282 | size_t *output_length ) |
| 283 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 284 | mbedtls_test_driver_aead_hooks.hits_update++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 285 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 286 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
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 | mbedtls_test_driver_aead_hooks.driver_status = |
| 289 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 290 | } |
| 291 | else |
| 292 | { |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 293 | #if defined(MBEDTLS_PSA_BUILTIN_AEAD) |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 294 | mbedtls_test_driver_aead_hooks.driver_status = |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 295 | mbedtls_psa_aead_update( operation, input, input_length, output, |
| 296 | output_size, output_length ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 297 | #else |
| 298 | (void) operation; |
| 299 | (void) input; |
| 300 | (void) input_length; |
| 301 | (void) output; |
| 302 | (void) output_size; |
| 303 | (void) output_length; |
| 304 | mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 305 | #endif |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 306 | } |
| 307 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 308 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 309 | } |
| 310 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 311 | psa_status_t mbedtls_test_transparent_aead_finish( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 312 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 313 | uint8_t *ciphertext, |
| 314 | size_t ciphertext_size, |
| 315 | size_t *ciphertext_length, |
| 316 | uint8_t *tag, |
| 317 | size_t tag_size, |
| 318 | size_t *tag_length ) |
| 319 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 320 | mbedtls_test_driver_aead_hooks.hits_finish++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 321 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 322 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 323 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 324 | mbedtls_test_driver_aead_hooks.driver_status = |
| 325 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 326 | } |
| 327 | else |
| 328 | { |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 329 | #if defined(MBEDTLS_PSA_BUILTIN_AEAD) |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 330 | mbedtls_test_driver_aead_hooks.driver_status = |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 331 | mbedtls_psa_aead_finish( operation, ciphertext, ciphertext_size, |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 332 | ciphertext_length, tag, tag_size, |
| 333 | tag_length ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 334 | #else |
| 335 | (void) operation; |
| 336 | (void) ciphertext; |
| 337 | (void) ciphertext_size; |
| 338 | (void) ciphertext_length; |
| 339 | (void) tag; |
| 340 | (void) tag_size; |
| 341 | (void) tag_length; |
| 342 | mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 343 | #endif |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 344 | } |
| 345 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 346 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 347 | } |
| 348 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 349 | psa_status_t mbedtls_test_transparent_aead_verify( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 350 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 351 | uint8_t *plaintext, |
| 352 | size_t plaintext_size, |
| 353 | size_t *plaintext_length, |
| 354 | const uint8_t *tag, |
| 355 | size_t tag_length ) |
| 356 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 357 | mbedtls_test_driver_aead_hooks.hits_verify++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 358 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 359 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 360 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 361 | mbedtls_test_driver_aead_hooks.driver_status = |
| 362 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 363 | } |
| 364 | else |
| 365 | { |
Paul Elliott | 26f4aef | 2021-07-22 21:47:27 +0100 | [diff] [blame] | 366 | uint8_t check_tag[PSA_AEAD_TAG_MAX_SIZE]; |
| 367 | size_t check_tag_length; |
| 368 | |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 369 | #if defined(MBEDTLS_PSA_BUILTIN_AEAD) |
Paul Elliott | 26f4aef | 2021-07-22 21:47:27 +0100 | [diff] [blame] | 370 | mbedtls_test_driver_aead_hooks.driver_status = |
| 371 | mbedtls_psa_aead_finish( operation, |
| 372 | plaintext, |
| 373 | plaintext_size, |
| 374 | plaintext_length, |
| 375 | check_tag, |
Paul Elliott | 0f32b7d | 2021-09-20 18:46:03 +0100 | [diff] [blame] | 376 | sizeof( check_tag ), |
Paul Elliott | 26f4aef | 2021-07-22 21:47:27 +0100 | [diff] [blame] | 377 | &check_tag_length ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 378 | #else |
| 379 | (void) operation; |
| 380 | (void) plaintext; |
| 381 | (void) plaintext_size; |
| 382 | (void) plaintext_length; |
| 383 | mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 384 | #endif |
Paul Elliott | 26f4aef | 2021-07-22 21:47:27 +0100 | [diff] [blame] | 385 | |
| 386 | if( mbedtls_test_driver_aead_hooks.driver_status == PSA_SUCCESS ) |
| 387 | { |
| 388 | if( tag_length != check_tag_length || |
| 389 | mbedtls_psa_safer_memcmp( tag, check_tag, tag_length ) |
| 390 | != 0 ) |
| 391 | mbedtls_test_driver_aead_hooks.driver_status = |
| 392 | PSA_ERROR_INVALID_SIGNATURE; |
| 393 | } |
Paul Elliott | 0f32b7d | 2021-09-20 18:46:03 +0100 | [diff] [blame] | 394 | |
| 395 | mbedtls_platform_zeroize( check_tag, sizeof( check_tag ) ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 396 | } |
| 397 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 398 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 399 | } |
| 400 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 401 | psa_status_t mbedtls_test_transparent_aead_abort( |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 402 | mbedtls_transparent_test_driver_aead_operation_t *operation ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 403 | { |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 404 | mbedtls_test_driver_aead_hooks.hits_abort++; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 405 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 406 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 407 | { |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 408 | mbedtls_test_driver_aead_hooks.driver_status = |
| 409 | mbedtls_test_driver_aead_hooks.forced_status; |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 410 | } |
| 411 | else |
| 412 | { |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 413 | #if defined(MBEDTLS_PSA_BUILTIN_AEAD) |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 414 | mbedtls_test_driver_aead_hooks.driver_status = |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 415 | mbedtls_psa_aead_abort( operation ); |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 416 | #else |
| 417 | (void) operation; |
| 418 | mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 419 | #endif |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 420 | } |
| 421 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 422 | return( mbedtls_test_driver_aead_hooks.driver_status ); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 423 | } |
| 424 | |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 425 | #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ |