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 |
Dave Rodgman | 7ff7965 | 2023-11-03 12:04:52 +0000 | [diff] [blame] | 5 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #if !defined(MBEDTLS_CONFIG_FILE) |
| 9 | #include "mbedtls/config.h" |
| 10 | #else |
| 11 | #include MBEDTLS_CONFIG_FILE |
| 12 | #endif |
| 13 | |
| 14 | #if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) && defined(PSA_CRYPTO_DRIVER_TEST) |
| 15 | #include "psa_crypto_aead.h" |
| 16 | |
| 17 | #include "test/drivers/aead.h" |
| 18 | |
Przemek Stekiel | f886241 | 2022-10-02 21:01:23 +0200 | [diff] [blame] | 19 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) |
| 20 | #include "libtestdriver1/library/psa_crypto_aead.h" |
| 21 | #endif |
| 22 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 23 | mbedtls_test_driver_aead_hooks_t |
| 24 | mbedtls_test_driver_aead_hooks = MBEDTLS_TEST_DRIVER_AEAD_INIT; |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 25 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 26 | psa_status_t mbedtls_test_transparent_aead_encrypt( |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 27 | const psa_key_attributes_t *attributes, |
| 28 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 29 | psa_algorithm_t alg, |
| 30 | const uint8_t *nonce, size_t nonce_length, |
| 31 | const uint8_t *additional_data, size_t additional_data_length, |
| 32 | const uint8_t *plaintext, size_t plaintext_length, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 33 | uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length) |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 34 | { |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 35 | mbedtls_test_driver_aead_hooks.hits++; |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 36 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 37 | if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) { |
| 38 | mbedtls_test_driver_aead_hooks.driver_status = |
| 39 | mbedtls_test_driver_aead_hooks.forced_status; |
| 40 | } else { |
Przemek Stekiel | f886241 | 2022-10-02 21:01:23 +0200 | [diff] [blame] | 41 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 42 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD) |
Przemek Stekiel | f886241 | 2022-10-02 21:01:23 +0200 | [diff] [blame] | 43 | mbedtls_test_driver_aead_hooks.driver_status = |
| 44 | libtestdriver1_mbedtls_psa_aead_encrypt( |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 45 | (const libtestdriver1_psa_key_attributes_t *) attributes, |
Przemek Stekiel | f886241 | 2022-10-02 21:01:23 +0200 | [diff] [blame] | 46 | key_buffer, key_buffer_size, |
| 47 | alg, |
| 48 | nonce, nonce_length, |
| 49 | additional_data, additional_data_length, |
| 50 | plaintext, plaintext_length, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 51 | ciphertext, ciphertext_size, ciphertext_length); |
Przemek Stekiel | f886241 | 2022-10-02 21:01:23 +0200 | [diff] [blame] | 52 | #elif defined(MBEDTLS_PSA_BUILTIN_AEAD) |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 53 | mbedtls_test_driver_aead_hooks.driver_status = |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 54 | mbedtls_psa_aead_encrypt( |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 55 | attributes, key_buffer, key_buffer_size, |
| 56 | alg, |
| 57 | nonce, nonce_length, |
| 58 | additional_data, additional_data_length, |
| 59 | plaintext, plaintext_length, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 60 | ciphertext, ciphertext_size, ciphertext_length); |
Przemek Stekiel | f886241 | 2022-10-02 21:01:23 +0200 | [diff] [blame] | 61 | #else |
| 62 | (void) attributes; |
| 63 | (void) key_buffer; |
| 64 | (void) key_buffer_size; |
| 65 | (void) alg; |
| 66 | (void) nonce; |
| 67 | (void) nonce_length; |
| 68 | (void) additional_data; |
| 69 | (void) additional_data_length; |
| 70 | (void) plaintext; |
| 71 | (void) plaintext_length; |
| 72 | (void) ciphertext; |
| 73 | (void) ciphertext_size; |
| 74 | (void) ciphertext_length; |
| 75 | mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 76 | #endif |
| 77 | } |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 78 | return mbedtls_test_driver_aead_hooks.driver_status; |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 79 | } |
| 80 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 81 | psa_status_t mbedtls_test_transparent_aead_decrypt( |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 82 | const psa_key_attributes_t *attributes, |
| 83 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 84 | psa_algorithm_t alg, |
| 85 | const uint8_t *nonce, size_t nonce_length, |
| 86 | const uint8_t *additional_data, size_t additional_data_length, |
| 87 | const uint8_t *ciphertext, size_t ciphertext_length, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 88 | uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length) |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 89 | { |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 90 | mbedtls_test_driver_aead_hooks.hits++; |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 91 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 92 | if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) { |
| 93 | mbedtls_test_driver_aead_hooks.driver_status = |
| 94 | mbedtls_test_driver_aead_hooks.forced_status; |
| 95 | } else { |
Przemek Stekiel | f886241 | 2022-10-02 21:01:23 +0200 | [diff] [blame] | 96 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 97 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD) |
Przemek Stekiel | f886241 | 2022-10-02 21:01:23 +0200 | [diff] [blame] | 98 | mbedtls_test_driver_aead_hooks.driver_status = |
| 99 | libtestdriver1_mbedtls_psa_aead_decrypt( |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 100 | (const libtestdriver1_psa_key_attributes_t *) attributes, |
Przemek Stekiel | f886241 | 2022-10-02 21:01:23 +0200 | [diff] [blame] | 101 | key_buffer, key_buffer_size, |
| 102 | alg, |
| 103 | nonce, nonce_length, |
| 104 | additional_data, additional_data_length, |
| 105 | ciphertext, ciphertext_length, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 106 | plaintext, plaintext_size, plaintext_length); |
Przemek Stekiel | f886241 | 2022-10-02 21:01:23 +0200 | [diff] [blame] | 107 | #elif defined(MBEDTLS_PSA_BUILTIN_AEAD) |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 108 | mbedtls_test_driver_aead_hooks.driver_status = |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 109 | mbedtls_psa_aead_decrypt( |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 110 | attributes, key_buffer, key_buffer_size, |
| 111 | alg, |
| 112 | nonce, nonce_length, |
| 113 | additional_data, additional_data_length, |
| 114 | ciphertext, ciphertext_length, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 115 | plaintext, plaintext_size, plaintext_length); |
Przemek Stekiel | f886241 | 2022-10-02 21:01:23 +0200 | [diff] [blame] | 116 | #else |
| 117 | (void) attributes; |
| 118 | (void) key_buffer; |
| 119 | (void) key_buffer_size; |
| 120 | (void) alg; |
| 121 | (void) nonce; |
| 122 | (void) nonce_length; |
| 123 | (void) additional_data; |
| 124 | (void) additional_data_length; |
| 125 | (void) ciphertext; |
| 126 | (void) ciphertext_length; |
| 127 | (void) plaintext; |
| 128 | (void) plaintext_size; |
| 129 | (void) plaintext_length; |
| 130 | mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 131 | #endif |
| 132 | } |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 133 | return mbedtls_test_driver_aead_hooks.driver_status; |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ |