Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Test driver for cipher functions |
| 3 | */ |
Steven Cooreman | 3ec4018 | 2020-09-02 16:27:46 +0200 | [diff] [blame] | 4 | /* Copyright The Mbed TLS Contributors |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 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. |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #ifndef PSA_CRYPTO_TEST_DRIVERS_CIPHER_H |
| 21 | #define PSA_CRYPTO_TEST_DRIVERS_CIPHER_H |
| 22 | |
| 23 | #if !defined(MBEDTLS_CONFIG_FILE) |
| 24 | #include "mbedtls/config.h" |
| 25 | #else |
| 26 | #include MBEDTLS_CONFIG_FILE |
| 27 | #endif |
| 28 | |
| 29 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 30 | #include <psa/crypto_driver_common.h> |
Ronald Cron | 8d310ad | 2020-12-15 15:17:20 +0100 | [diff] [blame] | 31 | #include <psa/crypto.h> |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 32 | |
| 33 | #include "mbedtls/cipher.h" |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 34 | |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 35 | typedef struct { |
| 36 | /* If non-null, on success, copy this to the output. */ |
| 37 | void *forced_output; |
| 38 | size_t forced_output_length; |
| 39 | /* If not PSA_SUCCESS, return this error code instead of processing the |
| 40 | * function call. */ |
| 41 | psa_status_t forced_status; |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 42 | /* Count the amount of times one of the cipher driver functions is called. */ |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 43 | unsigned long hits; |
| 44 | } test_driver_cipher_hooks_t; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 45 | |
Steven Cooreman | acb5a10 | 2020-09-08 14:06:57 +0200 | [diff] [blame] | 46 | #define TEST_DRIVER_CIPHER_INIT { NULL, 0, PSA_SUCCESS, 0 } |
| 47 | static inline test_driver_cipher_hooks_t test_driver_cipher_hooks_init( void ) |
| 48 | { |
| 49 | const test_driver_cipher_hooks_t v = TEST_DRIVER_CIPHER_INIT; |
| 50 | return( v ); |
| 51 | } |
| 52 | |
| 53 | extern test_driver_cipher_hooks_t test_driver_cipher_hooks; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 54 | |
| 55 | psa_status_t test_transparent_cipher_encrypt( |
| 56 | const psa_key_attributes_t *attributes, |
| 57 | const uint8_t *key, size_t key_length, |
| 58 | psa_algorithm_t alg, |
| 59 | const uint8_t *input, size_t input_length, |
| 60 | uint8_t *output, size_t output_size, size_t *output_length); |
| 61 | |
| 62 | psa_status_t test_transparent_cipher_decrypt( |
| 63 | const psa_key_attributes_t *attributes, |
| 64 | const uint8_t *key, size_t key_length, |
| 65 | psa_algorithm_t alg, |
| 66 | const uint8_t *input, size_t input_length, |
| 67 | uint8_t *output, size_t output_size, size_t *output_length); |
| 68 | |
| 69 | psa_status_t test_transparent_cipher_encrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 70 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 71 | const psa_key_attributes_t *attributes, |
| 72 | const uint8_t *key, size_t key_length, |
| 73 | psa_algorithm_t alg); |
| 74 | |
| 75 | psa_status_t test_transparent_cipher_decrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 76 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 77 | const psa_key_attributes_t *attributes, |
| 78 | const uint8_t *key, size_t key_length, |
| 79 | psa_algorithm_t alg); |
| 80 | |
| 81 | psa_status_t test_transparent_cipher_abort( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 82 | mbedtls_transparent_test_driver_cipher_operation_t *operation ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 83 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 84 | psa_status_t test_transparent_cipher_set_iv( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 85 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
| 86 | const uint8_t *iv, size_t iv_length); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 87 | |
| 88 | psa_status_t test_transparent_cipher_update( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 89 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
| 90 | const uint8_t *input, size_t input_length, |
| 91 | uint8_t *output, size_t output_size, size_t *output_length); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 92 | |
| 93 | psa_status_t test_transparent_cipher_finish( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 94 | mbedtls_transparent_test_driver_cipher_operation_t *operation, |
| 95 | uint8_t *output, size_t output_size, size_t *output_length); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 96 | |
| 97 | /* |
| 98 | * opaque versions |
| 99 | */ |
| 100 | psa_status_t test_opaque_cipher_encrypt( |
| 101 | const psa_key_attributes_t *attributes, |
| 102 | const uint8_t *key, size_t key_length, |
| 103 | psa_algorithm_t alg, |
| 104 | const uint8_t *input, size_t input_length, |
| 105 | uint8_t *output, size_t output_size, size_t *output_length); |
| 106 | |
| 107 | psa_status_t test_opaque_cipher_decrypt( |
| 108 | const psa_key_attributes_t *attributes, |
| 109 | const uint8_t *key, size_t key_length, |
| 110 | psa_algorithm_t alg, |
| 111 | const uint8_t *input, size_t input_length, |
| 112 | uint8_t *output, size_t output_size, size_t *output_length); |
| 113 | |
| 114 | psa_status_t test_opaque_cipher_encrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 115 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 116 | const psa_key_attributes_t *attributes, |
| 117 | const uint8_t *key, size_t key_length, |
| 118 | psa_algorithm_t alg); |
| 119 | |
| 120 | psa_status_t test_opaque_cipher_decrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 121 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 122 | const psa_key_attributes_t *attributes, |
| 123 | const uint8_t *key, size_t key_length, |
| 124 | psa_algorithm_t alg); |
| 125 | |
| 126 | psa_status_t test_opaque_cipher_abort( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 127 | mbedtls_opaque_test_driver_cipher_operation_t *operation); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 128 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 129 | psa_status_t test_opaque_cipher_set_iv( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 130 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
| 131 | const uint8_t *iv, size_t iv_length); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 132 | |
| 133 | psa_status_t test_opaque_cipher_update( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 134 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
| 135 | const uint8_t *input, size_t input_length, |
| 136 | uint8_t *output, size_t output_size, size_t *output_length); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 137 | |
| 138 | psa_status_t test_opaque_cipher_finish( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 139 | mbedtls_opaque_test_driver_cipher_operation_t *operation, |
| 140 | uint8_t *output, size_t output_size, size_t *output_length); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 141 | |
| 142 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 143 | #endif /* PSA_CRYPTO_TEST_DRIVERS_CIPHER_H */ |