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> |
| 31 | |
| 32 | #include "mbedtls/cipher.h" |
| 33 | typedef struct { |
| 34 | psa_algorithm_t alg; |
| 35 | unsigned int key_set : 1; |
| 36 | unsigned int iv_required : 1; |
| 37 | unsigned int iv_set : 1; |
| 38 | uint8_t iv_size; |
| 39 | uint8_t block_size; |
| 40 | mbedtls_cipher_context_t cipher; |
| 41 | } test_transparent_cipher_operation_t; |
| 42 | |
| 43 | typedef struct{ |
| 44 | unsigned int initialised : 1; |
| 45 | test_transparent_cipher_operation_t ctx; |
| 46 | } test_opaque_cipher_operation_t; |
| 47 | |
| 48 | extern void *test_driver_cipher_forced_output; |
| 49 | extern size_t test_driver_cipher_forced_output_length; |
| 50 | |
| 51 | extern psa_status_t test_transparent_cipher_status; |
| 52 | extern unsigned long test_transparent_cipher_hit; |
| 53 | |
| 54 | psa_status_t test_transparent_cipher_encrypt( |
| 55 | const psa_key_attributes_t *attributes, |
| 56 | const uint8_t *key, size_t key_length, |
| 57 | psa_algorithm_t alg, |
| 58 | const uint8_t *input, size_t input_length, |
| 59 | uint8_t *output, size_t output_size, size_t *output_length); |
| 60 | |
| 61 | psa_status_t test_transparent_cipher_decrypt( |
| 62 | const psa_key_attributes_t *attributes, |
| 63 | const uint8_t *key, size_t key_length, |
| 64 | psa_algorithm_t alg, |
| 65 | const uint8_t *input, size_t input_length, |
| 66 | uint8_t *output, size_t output_size, size_t *output_length); |
| 67 | |
| 68 | psa_status_t test_transparent_cipher_encrypt_setup( |
| 69 | test_transparent_cipher_operation_t *operation, |
| 70 | const psa_key_attributes_t *attributes, |
| 71 | const uint8_t *key, size_t key_length, |
| 72 | psa_algorithm_t alg); |
| 73 | |
| 74 | psa_status_t test_transparent_cipher_decrypt_setup( |
| 75 | test_transparent_cipher_operation_t *operation, |
| 76 | const psa_key_attributes_t *attributes, |
| 77 | const uint8_t *key, size_t key_length, |
| 78 | psa_algorithm_t alg); |
| 79 | |
| 80 | psa_status_t test_transparent_cipher_abort( |
| 81 | test_transparent_cipher_operation_t *operation); |
| 82 | |
| 83 | psa_status_t test_transparent_cipher_generate_iv( |
| 84 | test_transparent_cipher_operation_t *operation, |
| 85 | uint8_t *iv, |
| 86 | size_t iv_size, |
| 87 | size_t *iv_length); |
| 88 | |
| 89 | psa_status_t test_transparent_cipher_set_iv( |
| 90 | test_transparent_cipher_operation_t *operation, |
| 91 | const uint8_t *iv, |
| 92 | size_t iv_length); |
| 93 | |
| 94 | psa_status_t test_transparent_cipher_update( |
| 95 | test_transparent_cipher_operation_t *operation, |
| 96 | const uint8_t *input, |
| 97 | size_t input_length, |
| 98 | uint8_t *output, |
| 99 | size_t output_size, |
| 100 | size_t *output_length); |
| 101 | |
| 102 | psa_status_t test_transparent_cipher_finish( |
| 103 | test_transparent_cipher_operation_t *operation, |
| 104 | uint8_t *output, |
| 105 | size_t output_size, |
| 106 | size_t *output_length); |
| 107 | |
| 108 | /* |
| 109 | * opaque versions |
| 110 | */ |
| 111 | psa_status_t test_opaque_cipher_encrypt( |
| 112 | const psa_key_attributes_t *attributes, |
| 113 | const uint8_t *key, size_t key_length, |
| 114 | psa_algorithm_t alg, |
| 115 | const uint8_t *input, size_t input_length, |
| 116 | uint8_t *output, size_t output_size, size_t *output_length); |
| 117 | |
| 118 | psa_status_t test_opaque_cipher_decrypt( |
| 119 | const psa_key_attributes_t *attributes, |
| 120 | const uint8_t *key, size_t key_length, |
| 121 | psa_algorithm_t alg, |
| 122 | const uint8_t *input, size_t input_length, |
| 123 | uint8_t *output, size_t output_size, size_t *output_length); |
| 124 | |
| 125 | psa_status_t test_opaque_cipher_encrypt_setup( |
| 126 | test_opaque_cipher_operation_t *operation, |
| 127 | const psa_key_attributes_t *attributes, |
| 128 | const uint8_t *key, size_t key_length, |
| 129 | psa_algorithm_t alg); |
| 130 | |
| 131 | psa_status_t test_opaque_cipher_decrypt_setup( |
| 132 | test_opaque_cipher_operation_t *operation, |
| 133 | const psa_key_attributes_t *attributes, |
| 134 | const uint8_t *key, size_t key_length, |
| 135 | psa_algorithm_t alg); |
| 136 | |
| 137 | psa_status_t test_opaque_cipher_abort( |
| 138 | test_opaque_cipher_operation_t *operation); |
| 139 | |
| 140 | psa_status_t test_opaque_cipher_generate_iv( |
| 141 | test_opaque_cipher_operation_t *operation, |
| 142 | uint8_t *iv, |
| 143 | size_t iv_size, |
| 144 | size_t *iv_length); |
| 145 | |
| 146 | psa_status_t test_opaque_cipher_set_iv( |
| 147 | test_opaque_cipher_operation_t *operation, |
| 148 | const uint8_t *iv, |
| 149 | size_t iv_length); |
| 150 | |
| 151 | psa_status_t test_opaque_cipher_update( |
| 152 | test_opaque_cipher_operation_t *operation, |
| 153 | const uint8_t *input, |
| 154 | size_t input_length, |
| 155 | uint8_t *output, |
| 156 | size_t output_size, |
| 157 | size_t *output_length); |
| 158 | |
| 159 | psa_status_t test_opaque_cipher_finish( |
| 160 | test_opaque_cipher_operation_t *operation, |
| 161 | uint8_t *output, |
| 162 | size_t output_size, |
| 163 | size_t *output_length); |
| 164 | |
| 165 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 166 | #endif /* PSA_CRYPTO_TEST_DRIVERS_CIPHER_H */ |