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> |
| 21 | |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 22 | #if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) && defined(PSA_CRYPTO_DRIVER_TEST) |
| 23 | #include "psa_crypto_aead.h" |
| 24 | |
| 25 | #include "test/drivers/aead.h" |
| 26 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 27 | mbedtls_test_driver_aead_hooks_t |
| 28 | mbedtls_test_driver_aead_hooks = MBEDTLS_TEST_DRIVER_AEAD_INIT; |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 29 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 30 | psa_status_t mbedtls_test_transparent_aead_encrypt( |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 31 | const psa_key_attributes_t *attributes, |
| 32 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 33 | psa_algorithm_t alg, |
| 34 | const uint8_t *nonce, size_t nonce_length, |
| 35 | const uint8_t *additional_data, size_t additional_data_length, |
| 36 | const uint8_t *plaintext, size_t plaintext_length, |
| 37 | uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length ) |
| 38 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 39 | mbedtls_test_driver_aead_hooks.hits++; |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 40 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 41 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 42 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 43 | mbedtls_test_driver_aead_hooks.driver_status = |
| 44 | mbedtls_test_driver_aead_hooks.forced_status; |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 45 | } |
| 46 | else |
| 47 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 48 | mbedtls_test_driver_aead_hooks.driver_status = |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 49 | mbedtls_psa_aead_encrypt( |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 50 | attributes, key_buffer, key_buffer_size, |
| 51 | alg, |
| 52 | nonce, nonce_length, |
| 53 | additional_data, additional_data_length, |
| 54 | plaintext, plaintext_length, |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 55 | ciphertext, ciphertext_size, ciphertext_length ); |
| 56 | } |
| 57 | |
Mateusz Starzyk | e36f5b1 | 2021-07-22 16:43:35 +0200 | [diff] [blame^] | 58 | return mbedtls_test_driver_aead_hooks.driver_status ; |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 59 | } |
| 60 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 61 | psa_status_t mbedtls_test_transparent_aead_decrypt( |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 62 | const psa_key_attributes_t *attributes, |
| 63 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 64 | psa_algorithm_t alg, |
| 65 | const uint8_t *nonce, size_t nonce_length, |
| 66 | const uint8_t *additional_data, size_t additional_data_length, |
| 67 | const uint8_t *ciphertext, size_t ciphertext_length, |
| 68 | uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length ) |
| 69 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 70 | mbedtls_test_driver_aead_hooks.hits++; |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 71 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 72 | if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS ) |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 73 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 74 | mbedtls_test_driver_aead_hooks.driver_status = |
| 75 | mbedtls_test_driver_aead_hooks.forced_status; |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 76 | } |
| 77 | else |
| 78 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 79 | mbedtls_test_driver_aead_hooks.driver_status = |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 80 | mbedtls_psa_aead_decrypt( |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 81 | attributes, key_buffer, key_buffer_size, |
| 82 | alg, |
| 83 | nonce, nonce_length, |
| 84 | additional_data, additional_data_length, |
| 85 | ciphertext, ciphertext_length, |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 86 | plaintext, plaintext_size, plaintext_length ); |
| 87 | } |
| 88 | |
Mateusz Starzyk | e36f5b1 | 2021-07-22 16:43:35 +0200 | [diff] [blame^] | 89 | return mbedtls_test_driver_aead_hooks.driver_status ; |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ |