blob: 6897bdd663e8f50c819a889e11e856d097bd56c2 [file] [log] [blame]
Gilles Peskine5e769522018-11-20 21:59:56 +01001/**
2 * \file psa_crypto_invasive.h
3 *
4 * \brief PSA cryptography module: invasive interfaces for test only.
5 *
6 * The interfaces in this file are intended for testing purposes only.
7 * They MUST NOT be made available to clients over IPC in integrations
8 * with isolation, and they SHOULD NOT be made available in library
9 * integrations except when building the library for testing.
10 */
11/*
Bence Szépkúti1e148272020-08-07 13:07:28 +020012 * Copyright The Mbed TLS Contributors
Dave Rodgmane3c05852023-11-03 12:21:36 +000013 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Gilles Peskine5e769522018-11-20 21:59:56 +010014 */
15
16#ifndef PSA_CRYPTO_INVASIVE_H
17#define PSA_CRYPTO_INVASIVE_H
18
Bence Szépkútic662b362021-05-27 11:25:03 +020019#include "mbedtls/build_info.h"
Gilles Peskine5e769522018-11-20 21:59:56 +010020
21#include "psa/crypto.h"
Steven Cooreman58c94d32021-03-02 21:31:17 +010022#include "common.h"
Gilles Peskine5e769522018-11-20 21:59:56 +010023
24#include "mbedtls/entropy.h"
25
Gilles Peskine4fc21fd2020-11-13 18:47:18 +010026#if !defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
Gilles Peskine5e769522018-11-20 21:59:56 +010027/** \brief Configure entropy sources.
28 *
29 * This function may only be called before a call to psa_crypto_init(),
30 * or after a call to mbedtls_psa_crypto_free() and before any
31 * subsequent call to psa_crypto_init().
32 *
33 * This function is only intended for test purposes. The functionality
34 * it provides is also useful for system integrators, but
35 * system integrators should configure entropy drivers instead of
36 * breaking through to the Mbed TLS API.
37 *
38 * \param entropy_init Function to initialize the entropy context
39 * and set up the desired entropy sources.
40 * It is called by psa_crypto_init().
41 * By default this is mbedtls_entropy_init().
42 * This function cannot report failures directly.
43 * To indicate a failure, set the entropy context
44 * to a state where mbedtls_entropy_func() will
45 * return an error.
46 * \param entropy_free Function to free the entropy context
47 * and associated resources.
48 * It is called by mbedtls_psa_crypto_free().
49 * By default this is mbedtls_entropy_free().
50 *
Ronald Cron96783552020-10-19 12:06:30 +020051 * \retval #PSA_SUCCESS
Gilles Peskine5e769522018-11-20 21:59:56 +010052 * Success.
Ronald Cron96783552020-10-19 12:06:30 +020053 * \retval #PSA_ERROR_NOT_PERMITTED
Gilles Peskine5e769522018-11-20 21:59:56 +010054 * The caller does not have the permission to configure
55 * entropy sources.
Ronald Cron96783552020-10-19 12:06:30 +020056 * \retval #PSA_ERROR_BAD_STATE
Gilles Peskine5e769522018-11-20 21:59:56 +010057 * The library has already been initialized.
58 */
59psa_status_t mbedtls_psa_crypto_configure_entropy_sources(
Gilles Peskine449bd832023-01-11 14:50:10 +010060 void (* entropy_init)(mbedtls_entropy_context *ctx),
61 void (* entropy_free)(mbedtls_entropy_context *ctx));
Gilles Peskine4fc21fd2020-11-13 18:47:18 +010062#endif /* !defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) */
Gilles Peskine5e769522018-11-20 21:59:56 +010063
Steven Cooreman58c94d32021-03-02 21:31:17 +010064#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_PSA_CRYPTO_C)
Steven Cooremanf9f7fdf2021-03-03 19:04:05 +010065psa_status_t psa_mac_key_can_do(
66 psa_algorithm_t algorithm,
Gilles Peskine449bd832023-01-11 14:50:10 +010067 psa_key_type_t key_type);
Steven Cooreman58c94d32021-03-02 21:31:17 +010068#endif /* MBEDTLS_TEST_HOOKS && MBEDTLS_PSA_CRYPTO_C */
69
Gilles Peskine5e769522018-11-20 21:59:56 +010070#endif /* PSA_CRYPTO_INVASIVE_H */