Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * Test driver for cipher functions |
| 3 | */ |
| 4 | /* Copyright (C) 2020, ARM Limited, All Rights Reserved |
| 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 | * This file is part of mbed TLS (https://tls.mbed.org) |
| 20 | */ |
| 21 | |
| 22 | #ifndef PSA_CRYPTO_TEST_DRIVERS_CIPHER_H |
| 23 | #define PSA_CRYPTO_TEST_DRIVERS_CIPHER_H |
| 24 | |
| 25 | #if !defined(MBEDTLS_CONFIG_FILE) |
| 26 | #include "mbedtls/config.h" |
| 27 | #else |
| 28 | #include MBEDTLS_CONFIG_FILE |
| 29 | #endif |
| 30 | |
| 31 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 32 | #include <psa/crypto_driver_common.h> |
| 33 | |
| 34 | #include "mbedtls/cipher.h" |
| 35 | typedef struct { |
| 36 | psa_algorithm_t alg; |
| 37 | unsigned int key_set : 1; |
| 38 | unsigned int iv_required : 1; |
| 39 | unsigned int iv_set : 1; |
| 40 | uint8_t iv_size; |
| 41 | uint8_t block_size; |
| 42 | mbedtls_cipher_context_t cipher; |
| 43 | } test_transparent_cipher_operation_t; |
| 44 | |
| 45 | typedef struct{ |
| 46 | unsigned int initialised : 1; |
| 47 | test_transparent_cipher_operation_t ctx; |
| 48 | } test_opaque_cipher_operation_t; |
| 49 | |
| 50 | extern void *test_driver_cipher_forced_output; |
| 51 | extern size_t test_driver_cipher_forced_output_length; |
| 52 | |
| 53 | extern psa_status_t test_transparent_cipher_status; |
| 54 | extern unsigned long test_transparent_cipher_hit; |
| 55 | |
| 56 | psa_status_t test_transparent_cipher_encrypt( |
| 57 | const psa_key_attributes_t *attributes, |
| 58 | const uint8_t *key, size_t key_length, |
| 59 | psa_algorithm_t alg, |
| 60 | const uint8_t *input, size_t input_length, |
| 61 | uint8_t *output, size_t output_size, size_t *output_length); |
| 62 | |
| 63 | psa_status_t test_transparent_cipher_decrypt( |
| 64 | const psa_key_attributes_t *attributes, |
| 65 | const uint8_t *key, size_t key_length, |
| 66 | psa_algorithm_t alg, |
| 67 | const uint8_t *input, size_t input_length, |
| 68 | uint8_t *output, size_t output_size, size_t *output_length); |
| 69 | |
| 70 | psa_status_t test_transparent_cipher_encrypt_setup( |
| 71 | test_transparent_cipher_operation_t *operation, |
| 72 | const psa_key_attributes_t *attributes, |
| 73 | const uint8_t *key, size_t key_length, |
| 74 | psa_algorithm_t alg); |
| 75 | |
| 76 | psa_status_t test_transparent_cipher_decrypt_setup( |
| 77 | test_transparent_cipher_operation_t *operation, |
| 78 | const psa_key_attributes_t *attributes, |
| 79 | const uint8_t *key, size_t key_length, |
| 80 | psa_algorithm_t alg); |
| 81 | |
| 82 | psa_status_t test_transparent_cipher_abort( |
| 83 | test_transparent_cipher_operation_t *operation); |
| 84 | |
| 85 | psa_status_t test_transparent_cipher_generate_iv( |
| 86 | test_transparent_cipher_operation_t *operation, |
| 87 | uint8_t *iv, |
| 88 | size_t iv_size, |
| 89 | size_t *iv_length); |
| 90 | |
| 91 | psa_status_t test_transparent_cipher_set_iv( |
| 92 | test_transparent_cipher_operation_t *operation, |
| 93 | const uint8_t *iv, |
| 94 | size_t iv_length); |
| 95 | |
| 96 | psa_status_t test_transparent_cipher_update( |
| 97 | test_transparent_cipher_operation_t *operation, |
| 98 | const uint8_t *input, |
| 99 | size_t input_length, |
| 100 | uint8_t *output, |
| 101 | size_t output_size, |
| 102 | size_t *output_length); |
| 103 | |
| 104 | psa_status_t test_transparent_cipher_finish( |
| 105 | test_transparent_cipher_operation_t *operation, |
| 106 | uint8_t *output, |
| 107 | size_t output_size, |
| 108 | size_t *output_length); |
| 109 | |
| 110 | /* |
| 111 | * opaque versions |
| 112 | */ |
| 113 | psa_status_t test_opaque_cipher_encrypt( |
| 114 | const psa_key_attributes_t *attributes, |
| 115 | const uint8_t *key, size_t key_length, |
| 116 | psa_algorithm_t alg, |
| 117 | const uint8_t *input, size_t input_length, |
| 118 | uint8_t *output, size_t output_size, size_t *output_length); |
| 119 | |
| 120 | psa_status_t test_opaque_cipher_decrypt( |
| 121 | const psa_key_attributes_t *attributes, |
| 122 | const uint8_t *key, size_t key_length, |
| 123 | psa_algorithm_t alg, |
| 124 | const uint8_t *input, size_t input_length, |
| 125 | uint8_t *output, size_t output_size, size_t *output_length); |
| 126 | |
| 127 | psa_status_t test_opaque_cipher_encrypt_setup( |
| 128 | test_opaque_cipher_operation_t *operation, |
| 129 | const psa_key_attributes_t *attributes, |
| 130 | const uint8_t *key, size_t key_length, |
| 131 | psa_algorithm_t alg); |
| 132 | |
| 133 | psa_status_t test_opaque_cipher_decrypt_setup( |
| 134 | test_opaque_cipher_operation_t *operation, |
| 135 | const psa_key_attributes_t *attributes, |
| 136 | const uint8_t *key, size_t key_length, |
| 137 | psa_algorithm_t alg); |
| 138 | |
| 139 | psa_status_t test_opaque_cipher_abort( |
| 140 | test_opaque_cipher_operation_t *operation); |
| 141 | |
| 142 | psa_status_t test_opaque_cipher_generate_iv( |
| 143 | test_opaque_cipher_operation_t *operation, |
| 144 | uint8_t *iv, |
| 145 | size_t iv_size, |
| 146 | size_t *iv_length); |
| 147 | |
| 148 | psa_status_t test_opaque_cipher_set_iv( |
| 149 | test_opaque_cipher_operation_t *operation, |
| 150 | const uint8_t *iv, |
| 151 | size_t iv_length); |
| 152 | |
| 153 | psa_status_t test_opaque_cipher_update( |
| 154 | test_opaque_cipher_operation_t *operation, |
| 155 | const uint8_t *input, |
| 156 | size_t input_length, |
| 157 | uint8_t *output, |
| 158 | size_t output_size, |
| 159 | size_t *output_length); |
| 160 | |
| 161 | psa_status_t test_opaque_cipher_finish( |
| 162 | test_opaque_cipher_operation_t *operation, |
| 163 | uint8_t *output, |
| 164 | size_t output_size, |
| 165 | size_t *output_length); |
| 166 | |
| 167 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 168 | #endif /* PSA_CRYPTO_TEST_DRIVERS_CIPHER_H */ |