| Gilles Peskine | 5e76952 | 2018-11-20 21:59:56 +0100 | [diff] [blame] | 1 | /** | 
|  | 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úti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 12 | *  Copyright The Mbed TLS Contributors | 
| Gilles Peskine | 5e76952 | 2018-11-20 21:59:56 +0100 | [diff] [blame] | 13 | *  SPDX-License-Identifier: Apache-2.0 | 
|  | 14 | * | 
|  | 15 | *  Licensed under the Apache License, Version 2.0 (the "License"); you may | 
|  | 16 | *  not use this file except in compliance with the License. | 
|  | 17 | *  You may obtain a copy of the License at | 
|  | 18 | * | 
|  | 19 | *  http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 20 | * | 
|  | 21 | *  Unless required by applicable law or agreed to in writing, software | 
|  | 22 | *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | 
|  | 23 | *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 24 | *  See the License for the specific language governing permissions and | 
|  | 25 | *  limitations under the License. | 
| Gilles Peskine | 5e76952 | 2018-11-20 21:59:56 +0100 | [diff] [blame] | 26 | */ | 
|  | 27 |  | 
|  | 28 | #ifndef PSA_CRYPTO_INVASIVE_H | 
|  | 29 | #define PSA_CRYPTO_INVASIVE_H | 
|  | 30 |  | 
| Bence Szépkúti | c662b36 | 2021-05-27 11:25:03 +0200 | [diff] [blame] | 31 | #include "mbedtls/build_info.h" | 
| Gilles Peskine | 5e76952 | 2018-11-20 21:59:56 +0100 | [diff] [blame] | 32 |  | 
|  | 33 | #include "psa/crypto.h" | 
| Steven Cooreman | 58c94d3 | 2021-03-02 21:31:17 +0100 | [diff] [blame] | 34 | #include "common.h" | 
| Gilles Peskine | 5e76952 | 2018-11-20 21:59:56 +0100 | [diff] [blame] | 35 |  | 
|  | 36 | #include "mbedtls/entropy.h" | 
|  | 37 |  | 
| Gilles Peskine | 4fc21fd | 2020-11-13 18:47:18 +0100 | [diff] [blame] | 38 | #if !defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) | 
| Gilles Peskine | 5e76952 | 2018-11-20 21:59:56 +0100 | [diff] [blame] | 39 | /** \brief Configure entropy sources. | 
|  | 40 | * | 
|  | 41 | * This function may only be called before a call to psa_crypto_init(), | 
|  | 42 | * or after a call to mbedtls_psa_crypto_free() and before any | 
|  | 43 | * subsequent call to psa_crypto_init(). | 
|  | 44 | * | 
|  | 45 | * This function is only intended for test purposes. The functionality | 
|  | 46 | * it provides is also useful for system integrators, but | 
|  | 47 | * system integrators should configure entropy drivers instead of | 
|  | 48 | * breaking through to the Mbed TLS API. | 
|  | 49 | * | 
|  | 50 | * \param entropy_init  Function to initialize the entropy context | 
|  | 51 | *                      and set up the desired entropy sources. | 
|  | 52 | *                      It is called by psa_crypto_init(). | 
|  | 53 | *                      By default this is mbedtls_entropy_init(). | 
|  | 54 | *                      This function cannot report failures directly. | 
|  | 55 | *                      To indicate a failure, set the entropy context | 
|  | 56 | *                      to a state where mbedtls_entropy_func() will | 
|  | 57 | *                      return an error. | 
|  | 58 | * \param entropy_free  Function to free the entropy context | 
|  | 59 | *                      and associated resources. | 
|  | 60 | *                      It is called by mbedtls_psa_crypto_free(). | 
|  | 61 | *                      By default this is mbedtls_entropy_free(). | 
|  | 62 | * | 
| Ronald Cron | 9678355 | 2020-10-19 12:06:30 +0200 | [diff] [blame] | 63 | * \retval #PSA_SUCCESS | 
| Gilles Peskine | 5e76952 | 2018-11-20 21:59:56 +0100 | [diff] [blame] | 64 | *         Success. | 
| Ronald Cron | 9678355 | 2020-10-19 12:06:30 +0200 | [diff] [blame] | 65 | * \retval #PSA_ERROR_NOT_PERMITTED | 
| Gilles Peskine | 5e76952 | 2018-11-20 21:59:56 +0100 | [diff] [blame] | 66 | *         The caller does not have the permission to configure | 
|  | 67 | *         entropy sources. | 
| Ronald Cron | 9678355 | 2020-10-19 12:06:30 +0200 | [diff] [blame] | 68 | * \retval #PSA_ERROR_BAD_STATE | 
| Gilles Peskine | 5e76952 | 2018-11-20 21:59:56 +0100 | [diff] [blame] | 69 | *         The library has already been initialized. | 
|  | 70 | */ | 
|  | 71 | psa_status_t mbedtls_psa_crypto_configure_entropy_sources( | 
|  | 72 | void (* entropy_init )( mbedtls_entropy_context *ctx ), | 
|  | 73 | void (* entropy_free )( mbedtls_entropy_context *ctx ) ); | 
| Gilles Peskine | 4fc21fd | 2020-11-13 18:47:18 +0100 | [diff] [blame] | 74 | #endif /* !defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) */ | 
| Gilles Peskine | 5e76952 | 2018-11-20 21:59:56 +0100 | [diff] [blame] | 75 |  | 
| Steven Cooreman | 58c94d3 | 2021-03-02 21:31:17 +0100 | [diff] [blame] | 76 | #if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_PSA_CRYPTO_C) | 
| Steven Cooreman | f9f7fdf | 2021-03-03 19:04:05 +0100 | [diff] [blame] | 77 | psa_status_t psa_mac_key_can_do( | 
|  | 78 | psa_algorithm_t algorithm, | 
|  | 79 | psa_key_type_t key_type ); | 
| Steven Cooreman | 58c94d3 | 2021-03-02 21:31:17 +0100 | [diff] [blame] | 80 | #endif /* MBEDTLS_TEST_HOOKS && MBEDTLS_PSA_CRYPTO_C */ | 
|  | 81 |  | 
| Gilles Peskine | 5e76952 | 2018-11-20 21:59:56 +0100 | [diff] [blame] | 82 | #endif /* PSA_CRYPTO_INVASIVE_H */ |