1/*
2 * Test driver for key agreement functions.
3 */
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
20#ifndef PSA_CRYPTO_TEST_DRIVERS_KEY_AGREEMENT_H
21#define PSA_CRYPTO_TEST_DRIVERS_KEY_AGREEMENT_H
22
23#include "mbedtls/build_info.h"
24
25#if defined(PSA_CRYPTO_DRIVER_TEST)
26#include <psa/crypto_driver_common.h>
27
28typedef struct {
29    /* If non-null, on success, copy this to the output. */
30    void *forced_output;
31    size_t forced_output_length;
32    /* If not PSA_SUCCESS, return this error code instead of processing the
33     * function call. */
34    psa_status_t forced_status;
35    /* Count the amount of times one of the signature driver functions is called. */
36    unsigned long hits;
37} mbedtls_test_driver_key_agreement_hooks_t;
38
39#define MBEDTLS_TEST_DRIVER_KEY_AGREEMENT_INIT { NULL, 0, PSA_SUCCESS, 0 }
40static inline mbedtls_test_driver_key_agreement_hooks_t
41mbedtls_test_driver_key_agreement_hooks_init(void)
42{
43    const mbedtls_test_driver_key_agreement_hooks_t
44        v = MBEDTLS_TEST_DRIVER_KEY_AGREEMENT_INIT;
45    return v;
46}
47
48extern mbedtls_test_driver_key_agreement_hooks_t
49    mbedtls_test_driver_key_agreement_hooks;
50
51psa_status_t mbedtls_test_transparent_key_agreement(
52    const psa_key_attributes_t *attributes,
53    const uint8_t *key_buffer,
54    size_t key_buffer_size,
55    psa_algorithm_t alg,
56    const uint8_t *peer_key,
57    size_t peer_key_length,
58    uint8_t *shared_secret,
59    size_t shared_secret_size,
60    size_t *shared_secret_length);
61
62psa_status_t mbedtls_test_opaque_key_agreement(
63    const psa_key_attributes_t *attributes,
64    const uint8_t *key_buffer,
65    size_t key_buffer_size,
66    psa_algorithm_t alg,
67    const uint8_t *peer_key,
68    size_t peer_key_length,
69    uint8_t *shared_secret,
70    size_t shared_secret_size,
71    size_t *shared_secret_length);
72
73#endif /*PSA_CRYPTO_DRIVER_TEST */
74#endif /* PSA_CRYPTO_TEST_DRIVERS_KEY_AGREEMENT_H */
75