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