blob: 595e18d28b0c166f0e1d8c7f83187c70555092da [file] [log] [blame]
Przemyslaw Stekiel2d18c7e2021-12-22 12:02:03 +01001/*
Przemek Stekiel7a582082022-03-07 10:14:07 +01002 * Test driver for asymmetric encryption.
Przemyslaw Stekiel2d18c7e2021-12-22 12:02:03 +01003 */
4/* Copyright The Mbed TLS Contributors
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
Przemek Stekiel7a582082022-03-07 10:14:07 +010020#ifndef PSA_CRYPTO_TEST_DRIVERS_ASYMMETRIC_ENCRYPTION_H
21#define PSA_CRYPTO_TEST_DRIVERS_ASYMMETRIC_ENCRYPTION_H
Przemyslaw Stekiel2d18c7e2021-12-22 12:02:03 +010022
23#include "mbedtls/build_info.h"
24
25#if defined(PSA_CRYPTO_DRIVER_TEST)
26#include <psa/crypto_driver_common.h>
27#include <psa/crypto.h>
28
29typedef struct {
30 /* If non-null, on success, copy this to the output. */
31 void *forced_output;
32 size_t forced_output_length;
33 /* If not PSA_SUCCESS, return this error code instead of processing the
34 * function call. */
35 psa_status_t forced_status;
Przemek Stekielf8614a02022-03-08 10:48:35 +010036 /* Count the amount of times one of the asymmetric_encryption driver
Przemek Stekiel7a582082022-03-07 10:14:07 +010037 functions is called. */
Przemyslaw Stekiel2d18c7e2021-12-22 12:02:03 +010038 unsigned long hits;
Przemek Stekiel7a582082022-03-07 10:14:07 +010039} mbedtls_test_driver_asymmetric_encryption_hooks_t;
Przemyslaw Stekiel2d18c7e2021-12-22 12:02:03 +010040
Przemek Stekiel7a582082022-03-07 10:14:07 +010041#define MBEDTLS_TEST_DRIVER_ASYMMETRIC_ENCRYPTION_INIT { NULL, 0, PSA_SUCCESS, 0 }
Przemyslaw Stekiel2d18c7e2021-12-22 12:02:03 +010042
Przemek Stekiel7a582082022-03-07 10:14:07 +010043static inline mbedtls_test_driver_asymmetric_encryption_hooks_t
44 mbedtls_test_driver_asymmetric_encryption_hooks_init( void )
Przemyslaw Stekiel2d18c7e2021-12-22 12:02:03 +010045{
Przemek Stekiel7a582082022-03-07 10:14:07 +010046 const mbedtls_test_driver_asymmetric_encryption_hooks_t v =
47 MBEDTLS_TEST_DRIVER_ASYMMETRIC_ENCRYPTION_INIT;
Przemyslaw Stekiel2d18c7e2021-12-22 12:02:03 +010048 return( v );
49}
50
Przemek Stekielf8614a02022-03-08 10:48:35 +010051extern mbedtls_test_driver_asymmetric_encryption_hooks_t
Przemek Stekiel7a582082022-03-07 10:14:07 +010052 mbedtls_test_driver_asymmetric_encryption_hooks;
Przemyslaw Stekiel2d18c7e2021-12-22 12:02:03 +010053
54psa_status_t mbedtls_test_transparent_asymmetric_encrypt(
Przemyslaw Stekiel4576b912022-02-02 11:10:46 +010055 const psa_key_attributes_t *attributes, const uint8_t *key_buffer,
56 size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *input,
57 size_t input_length, const uint8_t *salt, size_t salt_length,
58 uint8_t *output, size_t output_size, size_t *output_length );
Przemyslaw Stekiel2d18c7e2021-12-22 12:02:03 +010059
60psa_status_t mbedtls_test_opaque_asymmetric_encrypt(
Przemyslaw Stekiel4576b912022-02-02 11:10:46 +010061 const psa_key_attributes_t *attributes, const uint8_t *key,
62 size_t key_length, psa_algorithm_t alg, const uint8_t *input,
63 size_t input_length, const uint8_t *salt, size_t salt_length,
64 uint8_t *output, size_t output_size, size_t *output_length );
Przemyslaw Stekiel2d18c7e2021-12-22 12:02:03 +010065
66psa_status_t mbedtls_test_transparent_asymmetric_decrypt(
Przemyslaw Stekiel4576b912022-02-02 11:10:46 +010067 const psa_key_attributes_t *attributes, const uint8_t *key_buffer,
68 size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *input,
69 size_t input_length, const uint8_t *salt, size_t salt_length,
70 uint8_t *output, size_t output_size, size_t *output_length );
Przemyslaw Stekiel2d18c7e2021-12-22 12:02:03 +010071
72psa_status_t mbedtls_test_opaque_asymmetric_decrypt(
Przemyslaw Stekiel4576b912022-02-02 11:10:46 +010073 const psa_key_attributes_t *attributes, const uint8_t *key,
74 size_t key_length, psa_algorithm_t alg, const uint8_t *input,
75 size_t input_length, const uint8_t *salt, size_t salt_length,
76 uint8_t *output, size_t output_size, size_t *output_length );
Przemyslaw Stekiel2d18c7e2021-12-22 12:02:03 +010077
78#endif /* PSA_CRYPTO_DRIVER_TEST */
Przemek Stekiel7a582082022-03-07 10:14:07 +010079#endif /* PSA_CRYPTO_TEST_DRIVERS_ASYMMETRIC_ENCRYPTION_H */