Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Test driver for AEAD driver entry points. |
| 3 | */ |
| 4 | /* Copyright The Mbed TLS Contributors |
Dave Rodgman | 16799db | 2023-11-02 19:47:20 +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 | #ifndef PSA_CRYPTO_TEST_DRIVERS_AEAD_H |
| 9 | #define PSA_CRYPTO_TEST_DRIVERS_AEAD_H |
| 10 | |
Bence Szépkúti | c662b36 | 2021-05-27 11:25:03 +0200 | [diff] [blame] | 11 | #include "mbedtls/build_info.h" |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 12 | |
| 13 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 14 | #include <psa/crypto_driver_common.h> |
| 15 | |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 16 | typedef struct { |
| 17 | /* If not PSA_SUCCESS, return this error code instead of processing the |
| 18 | * function call. */ |
| 19 | psa_status_t forced_status; |
| 20 | /* Count the amount of times AEAD driver functions are called. */ |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 21 | unsigned long hits_encrypt; |
| 22 | unsigned long hits_decrypt; |
| 23 | unsigned long hits_encrypt_setup; |
| 24 | unsigned long hits_decrypt_setup; |
| 25 | unsigned long hits_set_nonce; |
| 26 | unsigned long hits_set_lengths; |
| 27 | unsigned long hits_update_ad; |
| 28 | unsigned long hits_update; |
| 29 | unsigned long hits_finish; |
| 30 | unsigned long hits_verify; |
| 31 | unsigned long hits_abort; |
| 32 | |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 33 | /* Status returned by the last AEAD driver function call. */ |
| 34 | psa_status_t driver_status; |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 35 | } mbedtls_test_driver_aead_hooks_t; |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 36 | |
Paul Elliott | fcb5cdc | 2021-06-23 09:40:12 +0100 | [diff] [blame] | 37 | #define MBEDTLS_TEST_DRIVER_AEAD_INIT { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 38 | static inline mbedtls_test_driver_aead_hooks_t |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 39 | mbedtls_test_driver_aead_hooks_init(void) |
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 | const mbedtls_test_driver_aead_hooks_t v = MBEDTLS_TEST_DRIVER_AEAD_INIT; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 42 | return v; |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 43 | } |
| 44 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 45 | extern mbedtls_test_driver_aead_hooks_t mbedtls_test_driver_aead_hooks; |
Ronald Cron | bfe551d | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 46 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 47 | psa_status_t mbedtls_test_transparent_aead_encrypt( |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 48 | const psa_key_attributes_t *attributes, |
| 49 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 50 | psa_algorithm_t alg, |
| 51 | const uint8_t *nonce, size_t nonce_length, |
| 52 | const uint8_t *additional_data, size_t additional_data_length, |
| 53 | const uint8_t *plaintext, size_t plaintext_length, |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 54 | uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length); |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 55 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 56 | psa_status_t mbedtls_test_transparent_aead_decrypt( |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 57 | const psa_key_attributes_t *attributes, |
| 58 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 59 | psa_algorithm_t alg, |
| 60 | const uint8_t *nonce, size_t nonce_length, |
| 61 | const uint8_t *additional_data, size_t additional_data_length, |
| 62 | const uint8_t *ciphertext, size_t ciphertext_length, |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 63 | uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length); |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 64 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 65 | psa_status_t mbedtls_test_transparent_aead_encrypt_setup( |
Ronald Cron | 9a37ff6 | 2021-12-02 17:50:50 +0100 | [diff] [blame] | 66 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 67 | const psa_key_attributes_t *attributes, |
| 68 | const uint8_t *key_buffer, size_t key_buffer_size, |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 69 | psa_algorithm_t alg); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 70 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 71 | psa_status_t mbedtls_test_transparent_aead_decrypt_setup( |
Ronald Cron | 9a37ff6 | 2021-12-02 17:50:50 +0100 | [diff] [blame] | 72 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 73 | const psa_key_attributes_t *attributes, |
| 74 | const uint8_t *key_buffer, size_t key_buffer_size, |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 75 | psa_algorithm_t alg); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 76 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 77 | psa_status_t mbedtls_test_transparent_aead_set_nonce( |
Ronald Cron | 9a37ff6 | 2021-12-02 17:50:50 +0100 | [diff] [blame] | 78 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 79 | const uint8_t *nonce, |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 80 | size_t nonce_length); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 81 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 82 | psa_status_t mbedtls_test_transparent_aead_set_lengths( |
Ronald Cron | 9a37ff6 | 2021-12-02 17:50:50 +0100 | [diff] [blame] | 83 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 84 | size_t ad_length, |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 85 | size_t plaintext_length); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 86 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 87 | psa_status_t mbedtls_test_transparent_aead_update_ad( |
Ronald Cron | 9a37ff6 | 2021-12-02 17:50:50 +0100 | [diff] [blame] | 88 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 89 | const uint8_t *input, |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 90 | size_t input_length); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 91 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 92 | psa_status_t mbedtls_test_transparent_aead_update( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 93 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
| 94 | const uint8_t *input, |
| 95 | size_t input_length, |
| 96 | uint8_t *output, |
| 97 | size_t output_size, |
| 98 | size_t *output_length); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 99 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 100 | psa_status_t mbedtls_test_transparent_aead_finish( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 101 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
| 102 | uint8_t *ciphertext, |
| 103 | size_t ciphertext_size, |
| 104 | size_t *ciphertext_length, |
| 105 | uint8_t *tag, |
| 106 | size_t tag_size, |
| 107 | size_t *tag_length); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 108 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 109 | psa_status_t mbedtls_test_transparent_aead_verify( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 110 | mbedtls_transparent_test_driver_aead_operation_t *operation, |
| 111 | uint8_t *plaintext, |
| 112 | size_t plaintext_size, |
| 113 | size_t *plaintext_length, |
| 114 | const uint8_t *tag, |
| 115 | size_t tag_length); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 116 | |
Paul Elliott | a218ceb | 2021-05-07 15:10:31 +0100 | [diff] [blame] | 117 | psa_status_t mbedtls_test_transparent_aead_abort( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 118 | mbedtls_transparent_test_driver_aead_operation_t *operation); |
Paul Elliott | 4bbe82b | 2021-04-27 12:11:56 +0100 | [diff] [blame] | 119 | |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 120 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 121 | #endif /* PSA_CRYPTO_TEST_DRIVERS_AEAD_H */ |