2020-07-28 16:49:51 +00:00
|
|
|
/*
|
|
|
|
* Test driver for cipher functions
|
|
|
|
*/
|
2020-09-02 14:27:46 +00:00
|
|
|
/* Copyright The Mbed TLS Contributors
|
2020-07-28 16:49:51 +00: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
|
|
|
|
|
|
|
|
#if !defined(MBEDTLS_CONFIG_FILE)
|
|
|
|
#include "mbedtls/config.h"
|
|
|
|
#else
|
|
|
|
#include MBEDTLS_CONFIG_FILE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
|
|
|
#include <psa/crypto_driver_common.h>
|
2020-12-15 14:17:20 +00:00
|
|
|
#include <psa/crypto.h>
|
2020-07-28 16:49:51 +00:00
|
|
|
|
|
|
|
#include "mbedtls/cipher.h"
|
|
|
|
|
2020-09-08 12:06:57 +00: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 09:51:45 +00:00
|
|
|
/* Count the amount of times one of the cipher driver functions is called. */
|
2020-09-08 12:06:57 +00:00
|
|
|
unsigned long hits;
|
2021-04-13 10:41:34 +00:00
|
|
|
} mbedtls_test_driver_cipher_hooks_t;
|
2020-09-08 12:06:57 +00:00
|
|
|
|
2021-04-13 10:41:34 +00:00
|
|
|
#define MBEDTLS_TEST_DRIVER_CIPHER_INIT { NULL, 0, PSA_SUCCESS, 0 }
|
|
|
|
static inline mbedtls_test_driver_cipher_hooks_t
|
|
|
|
mbedtls_test_driver_cipher_hooks_init( void )
|
2020-09-08 12:06:57 +00:00
|
|
|
{
|
2021-04-13 10:41:34 +00:00
|
|
|
const mbedtls_test_driver_cipher_hooks_t v = MBEDTLS_TEST_DRIVER_CIPHER_INIT;
|
2020-09-08 12:06:57 +00:00
|
|
|
return( v );
|
|
|
|
}
|
2020-07-28 16:49:51 +00:00
|
|
|
|
2021-04-13 10:41:34 +00:00
|
|
|
extern mbedtls_test_driver_cipher_hooks_t mbedtls_test_driver_cipher_hooks;
|
2020-07-28 16:49:51 +00:00
|
|
|
|
2021-04-13 10:41:34 +00:00
|
|
|
psa_status_t mbedtls_test_transparent_cipher_encrypt(
|
2020-07-28 16:49:51 +00: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 10:41:34 +00:00
|
|
|
psa_status_t mbedtls_test_transparent_cipher_decrypt(
|
2020-07-28 16:49:51 +00: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 10:41:34 +00:00
|
|
|
psa_status_t mbedtls_test_transparent_cipher_encrypt_setup(
|
2021-03-10 11:21:48 +00:00
|
|
|
mbedtls_transparent_test_driver_cipher_operation_t *operation,
|
2020-07-28 16:49:51 +00:00
|
|
|
const psa_key_attributes_t *attributes,
|
|
|
|
const uint8_t *key, size_t key_length,
|
|
|
|
psa_algorithm_t alg);
|
|
|
|
|
2021-04-13 10:41:34 +00:00
|
|
|
psa_status_t mbedtls_test_transparent_cipher_decrypt_setup(
|
2021-03-10 11:21:48 +00:00
|
|
|
mbedtls_transparent_test_driver_cipher_operation_t *operation,
|
2020-07-28 16:49:51 +00:00
|
|
|
const psa_key_attributes_t *attributes,
|
|
|
|
const uint8_t *key, size_t key_length,
|
|
|
|
psa_algorithm_t alg);
|
|
|
|
|
2021-04-13 10:41:34 +00:00
|
|
|
psa_status_t mbedtls_test_transparent_cipher_abort(
|
2021-03-10 11:21:48 +00:00
|
|
|
mbedtls_transparent_test_driver_cipher_operation_t *operation );
|
2020-07-28 16:49:51 +00:00
|
|
|
|
2021-04-13 10:41:34 +00:00
|
|
|
psa_status_t mbedtls_test_transparent_cipher_set_iv(
|
2021-03-10 11:21:48 +00:00
|
|
|
mbedtls_transparent_test_driver_cipher_operation_t *operation,
|
|
|
|
const uint8_t *iv, size_t iv_length);
|
2020-07-28 16:49:51 +00:00
|
|
|
|
2021-04-13 10:41:34 +00:00
|
|
|
psa_status_t mbedtls_test_transparent_cipher_update(
|
2021-03-10 11:21:48 +00: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 16:49:51 +00:00
|
|
|
|
2021-04-13 10:41:34 +00:00
|
|
|
psa_status_t mbedtls_test_transparent_cipher_finish(
|
2021-03-10 11:21:48 +00:00
|
|
|
mbedtls_transparent_test_driver_cipher_operation_t *operation,
|
|
|
|
uint8_t *output, size_t output_size, size_t *output_length);
|
2020-07-28 16:49:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* opaque versions
|
|
|
|
*/
|
2021-04-13 10:41:34 +00:00
|
|
|
psa_status_t mbedtls_test_opaque_cipher_encrypt(
|
2020-07-28 16:49:51 +00: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 10:41:34 +00:00
|
|
|
psa_status_t mbedtls_test_opaque_cipher_decrypt(
|
2020-07-28 16:49:51 +00: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 10:41:34 +00:00
|
|
|
psa_status_t mbedtls_test_opaque_cipher_encrypt_setup(
|
2021-03-10 11:21:48 +00:00
|
|
|
mbedtls_opaque_test_driver_cipher_operation_t *operation,
|
2020-07-28 16:49:51 +00:00
|
|
|
const psa_key_attributes_t *attributes,
|
|
|
|
const uint8_t *key, size_t key_length,
|
|
|
|
psa_algorithm_t alg);
|
|
|
|
|
2021-04-13 10:41:34 +00:00
|
|
|
psa_status_t mbedtls_test_opaque_cipher_decrypt_setup(
|
2021-03-10 11:21:48 +00:00
|
|
|
mbedtls_opaque_test_driver_cipher_operation_t *operation,
|
2020-07-28 16:49:51 +00:00
|
|
|
const psa_key_attributes_t *attributes,
|
|
|
|
const uint8_t *key, size_t key_length,
|
|
|
|
psa_algorithm_t alg);
|
|
|
|
|
2021-04-13 10:41:34 +00:00
|
|
|
psa_status_t mbedtls_test_opaque_cipher_abort(
|
2021-03-10 11:21:48 +00:00
|
|
|
mbedtls_opaque_test_driver_cipher_operation_t *operation);
|
2020-07-28 16:49:51 +00:00
|
|
|
|
2021-04-13 10:41:34 +00:00
|
|
|
psa_status_t mbedtls_test_opaque_cipher_set_iv(
|
2021-03-10 11:21:48 +00:00
|
|
|
mbedtls_opaque_test_driver_cipher_operation_t *operation,
|
|
|
|
const uint8_t *iv, size_t iv_length);
|
2020-07-28 16:49:51 +00:00
|
|
|
|
2021-04-13 10:41:34 +00:00
|
|
|
psa_status_t mbedtls_test_opaque_cipher_update(
|
2021-03-10 11:21:48 +00: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 16:49:51 +00:00
|
|
|
|
2021-04-13 10:41:34 +00:00
|
|
|
psa_status_t mbedtls_test_opaque_cipher_finish(
|
2021-03-10 11:21:48 +00:00
|
|
|
mbedtls_opaque_test_driver_cipher_operation_t *operation,
|
|
|
|
uint8_t *output, size_t output_size, size_t *output_length);
|
2020-07-28 16:49:51 +00:00
|
|
|
|
|
|
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
|
|
|
#endif /* PSA_CRYPTO_TEST_DRIVERS_CIPHER_H */
|