2020-07-28 18:49:51 +02:00
|
|
|
/*
|
|
|
|
* Test driver for cipher functions
|
|
|
|
*/
|
2020-09-02 16:27:46 +02:00
|
|
|
/* Copyright The Mbed TLS Contributors
|
2020-07-28 18:49:51 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
* not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PSA_CRYPTO_TEST_DRIVERS_CIPHER_H
|
|
|
|
#define PSA_CRYPTO_TEST_DRIVERS_CIPHER_H
|
|
|
|
|
2021-05-27 11:25:03 +02:00
|
|
|
#include "mbedtls/build_info.h"
|
2020-07-28 18:49:51 +02:00
|
|
|
|
|
|
|
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
|
|
|
#include <psa/crypto_driver_common.h>
|
2020-12-15 15:17:20 +01:00
|
|
|
#include <psa/crypto.h>
|
2020-07-28 18:49:51 +02:00
|
|
|
|
|
|
|
#include "mbedtls/cipher.h"
|
|
|
|
|
2020-09-08 14:06:57 +02:00
|
|
|
typedef struct {
|
|
|
|
/* If non-null, on success, copy this to the output. */
|
|
|
|
void *forced_output;
|
|
|
|
size_t forced_output_length;
|
|
|
|
/* If not PSA_SUCCESS, return this error code instead of processing the
|
|
|
|
* function call. */
|
|
|
|
psa_status_t forced_status;
|
2020-09-09 11:51:45 +02:00
|
|
|
/* Count the amount of times one of the cipher driver functions is called. */
|
2020-09-08 14:06:57 +02:00
|
|
|
unsigned long hits;
|
2021-04-13 12:41:34 +02:00
|
|
|
} mbedtls_test_driver_cipher_hooks_t;
|
2020-09-08 14:06:57 +02:00
|
|
|
|
2021-04-13 12:41:34 +02:00
|
|
|
#define MBEDTLS_TEST_DRIVER_CIPHER_INIT { NULL, 0, PSA_SUCCESS, 0 }
|
|
|
|
static inline mbedtls_test_driver_cipher_hooks_t
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_test_driver_cipher_hooks_init(void)
|
2020-09-08 14:06:57 +02:00
|
|
|
{
|
2021-04-13 12:41:34 +02:00
|
|
|
const mbedtls_test_driver_cipher_hooks_t v = MBEDTLS_TEST_DRIVER_CIPHER_INIT;
|
2023-01-11 14:50:10 +01:00
|
|
|
return v;
|
2020-09-08 14:06:57 +02:00
|
|
|
}
|
2020-07-28 18:49:51 +02:00
|
|
|
|
2021-04-13 12:41:34 +02:00
|
|
|
extern mbedtls_test_driver_cipher_hooks_t mbedtls_test_driver_cipher_hooks;
|
2020-07-28 18:49:51 +02:00
|
|
|
|
2021-04-13 12:41:34 +02:00
|
|
|
psa_status_t mbedtls_test_transparent_cipher_encrypt(
|
2020-07-28 18:49:51 +02:00
|
|
|
const psa_key_attributes_t *attributes,
|
|
|
|
const uint8_t *key, size_t key_length,
|
|
|
|
psa_algorithm_t alg,
|
2021-07-09 09:19:35 +02:00
|
|
|
const uint8_t *iv, size_t iv_length,
|
2020-07-28 18:49:51 +02:00
|
|
|
const uint8_t *input, size_t input_length,
|
|
|
|
uint8_t *output, size_t output_size, size_t *output_length);
|
|
|
|
|
2021-04-13 12:41:34 +02:00
|
|
|
psa_status_t mbedtls_test_transparent_cipher_decrypt(
|
2020-07-28 18:49:51 +02:00
|
|
|
const psa_key_attributes_t *attributes,
|
|
|
|
const uint8_t *key, size_t key_length,
|
|
|
|
psa_algorithm_t alg,
|
|
|
|
const uint8_t *input, size_t input_length,
|
|
|
|
uint8_t *output, size_t output_size, size_t *output_length);
|
|
|
|
|
2021-04-13 12:41:34 +02:00
|
|
|
psa_status_t mbedtls_test_transparent_cipher_encrypt_setup(
|
2021-03-10 12:21:48 +01:00
|
|
|
mbedtls_transparent_test_driver_cipher_operation_t *operation,
|
2020-07-28 18:49:51 +02:00
|
|
|
const psa_key_attributes_t *attributes,
|
|
|
|
const uint8_t *key, size_t key_length,
|
|
|
|
psa_algorithm_t alg);
|
|
|
|
|
2021-04-13 12:41:34 +02:00
|
|
|
psa_status_t mbedtls_test_transparent_cipher_decrypt_setup(
|
2021-03-10 12:21:48 +01:00
|
|
|
mbedtls_transparent_test_driver_cipher_operation_t *operation,
|
2020-07-28 18:49:51 +02:00
|
|
|
const psa_key_attributes_t *attributes,
|
|
|
|
const uint8_t *key, size_t key_length,
|
|
|
|
psa_algorithm_t alg);
|
|
|
|
|
2021-04-13 12:41:34 +02:00
|
|
|
psa_status_t mbedtls_test_transparent_cipher_abort(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_transparent_test_driver_cipher_operation_t *operation);
|
2020-07-28 18:49:51 +02:00
|
|
|
|
2021-04-13 12:41:34 +02:00
|
|
|
psa_status_t mbedtls_test_transparent_cipher_set_iv(
|
2021-03-10 12:21:48 +01:00
|
|
|
mbedtls_transparent_test_driver_cipher_operation_t *operation,
|
|
|
|
const uint8_t *iv, size_t iv_length);
|
2020-07-28 18:49:51 +02:00
|
|
|
|
2021-04-13 12:41:34 +02:00
|
|
|
psa_status_t mbedtls_test_transparent_cipher_update(
|
2021-03-10 12:21:48 +01:00
|
|
|
mbedtls_transparent_test_driver_cipher_operation_t *operation,
|
|
|
|
const uint8_t *input, size_t input_length,
|
|
|
|
uint8_t *output, size_t output_size, size_t *output_length);
|
2020-07-28 18:49:51 +02:00
|
|
|
|
2021-04-13 12:41:34 +02:00
|
|
|
psa_status_t mbedtls_test_transparent_cipher_finish(
|
2021-03-10 12:21:48 +01:00
|
|
|
mbedtls_transparent_test_driver_cipher_operation_t *operation,
|
|
|
|
uint8_t *output, size_t output_size, size_t *output_length);
|
2020-07-28 18:49:51 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* opaque versions
|
|
|
|
*/
|
2021-04-13 12:41:34 +02:00
|
|
|
psa_status_t mbedtls_test_opaque_cipher_encrypt(
|
2020-07-28 18:49:51 +02:00
|
|
|
const psa_key_attributes_t *attributes,
|
|
|
|
const uint8_t *key, size_t key_length,
|
|
|
|
psa_algorithm_t alg,
|
2021-07-09 09:19:35 +02:00
|
|
|
const uint8_t *iv, size_t iv_length,
|
2020-07-28 18:49:51 +02:00
|
|
|
const uint8_t *input, size_t input_length,
|
|
|
|
uint8_t *output, size_t output_size, size_t *output_length);
|
|
|
|
|
2021-04-13 12:41:34 +02:00
|
|
|
psa_status_t mbedtls_test_opaque_cipher_decrypt(
|
2020-07-28 18:49:51 +02:00
|
|
|
const psa_key_attributes_t *attributes,
|
|
|
|
const uint8_t *key, size_t key_length,
|
|
|
|
psa_algorithm_t alg,
|
|
|
|
const uint8_t *input, size_t input_length,
|
|
|
|
uint8_t *output, size_t output_size, size_t *output_length);
|
|
|
|
|
2021-04-13 12:41:34 +02:00
|
|
|
psa_status_t mbedtls_test_opaque_cipher_encrypt_setup(
|
2021-03-10 12:21:48 +01:00
|
|
|
mbedtls_opaque_test_driver_cipher_operation_t *operation,
|
2020-07-28 18:49:51 +02:00
|
|
|
const psa_key_attributes_t *attributes,
|
|
|
|
const uint8_t *key, size_t key_length,
|
|
|
|
psa_algorithm_t alg);
|
|
|
|
|
2021-04-13 12:41:34 +02:00
|
|
|
psa_status_t mbedtls_test_opaque_cipher_decrypt_setup(
|
2021-03-10 12:21:48 +01:00
|
|
|
mbedtls_opaque_test_driver_cipher_operation_t *operation,
|
2020-07-28 18:49:51 +02:00
|
|
|
const psa_key_attributes_t *attributes,
|
|
|
|
const uint8_t *key, size_t key_length,
|
|
|
|
psa_algorithm_t alg);
|
|
|
|
|
2021-04-13 12:41:34 +02:00
|
|
|
psa_status_t mbedtls_test_opaque_cipher_abort(
|
2021-03-10 12:21:48 +01:00
|
|
|
mbedtls_opaque_test_driver_cipher_operation_t *operation);
|
2020-07-28 18:49:51 +02:00
|
|
|
|
2021-04-13 12:41:34 +02:00
|
|
|
psa_status_t mbedtls_test_opaque_cipher_set_iv(
|
2021-03-10 12:21:48 +01:00
|
|
|
mbedtls_opaque_test_driver_cipher_operation_t *operation,
|
|
|
|
const uint8_t *iv, size_t iv_length);
|
2020-07-28 18:49:51 +02:00
|
|
|
|
2021-04-13 12:41:34 +02:00
|
|
|
psa_status_t mbedtls_test_opaque_cipher_update(
|
2021-03-10 12:21:48 +01:00
|
|
|
mbedtls_opaque_test_driver_cipher_operation_t *operation,
|
|
|
|
const uint8_t *input, size_t input_length,
|
|
|
|
uint8_t *output, size_t output_size, size_t *output_length);
|
2020-07-28 18:49:51 +02:00
|
|
|
|
2021-04-13 12:41:34 +02:00
|
|
|
psa_status_t mbedtls_test_opaque_cipher_finish(
|
2021-03-10 12:21:48 +01:00
|
|
|
mbedtls_opaque_test_driver_cipher_operation_t *operation,
|
|
|
|
uint8_t *output, size_t output_size, size_t *output_length);
|
2020-07-28 18:49:51 +02:00
|
|
|
|
|
|
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
|
|
|
#endif /* PSA_CRYPTO_TEST_DRIVERS_CIPHER_H */
|