1*b0563631STom Van Eyck /** 2*b0563631STom Van Eyck * \file psa_crypto_invasive.h 3*b0563631STom Van Eyck * 4*b0563631STom Van Eyck * \brief PSA cryptography module: invasive interfaces for test only. 5*b0563631STom Van Eyck * 6*b0563631STom Van Eyck * The interfaces in this file are intended for testing purposes only. 7*b0563631STom Van Eyck * They MUST NOT be made available to clients over IPC in integrations 8*b0563631STom Van Eyck * with isolation, and they SHOULD NOT be made available in library 9*b0563631STom Van Eyck * integrations except when building the library for testing. 10*b0563631STom Van Eyck */ 11*b0563631STom Van Eyck /* 12*b0563631STom Van Eyck * Copyright The Mbed TLS Contributors 13*b0563631STom Van Eyck * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later 14*b0563631STom Van Eyck */ 15*b0563631STom Van Eyck 16*b0563631STom Van Eyck #ifndef PSA_CRYPTO_INVASIVE_H 17*b0563631STom Van Eyck #define PSA_CRYPTO_INVASIVE_H 18*b0563631STom Van Eyck 19*b0563631STom Van Eyck /* 20*b0563631STom Van Eyck * Include the build-time configuration information header. Here, we do not 21*b0563631STom Van Eyck * include `"mbedtls/build_info.h"` directly but `"psa/build_info.h"`, which 22*b0563631STom Van Eyck * is basically just an alias to it. This is to ease the maintenance of the 23*b0563631STom Van Eyck * TF-PSA-Crypto repository which has a different build system and 24*b0563631STom Van Eyck * configuration. 25*b0563631STom Van Eyck */ 26*b0563631STom Van Eyck #include "psa/build_info.h" 27*b0563631STom Van Eyck 28*b0563631STom Van Eyck #include "psa/crypto.h" 29*b0563631STom Van Eyck #include "common.h" 30*b0563631STom Van Eyck 31*b0563631STom Van Eyck #include "mbedtls/entropy.h" 32*b0563631STom Van Eyck 33*b0563631STom Van Eyck #if !defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) 34*b0563631STom Van Eyck /** \brief Configure entropy sources. 35*b0563631STom Van Eyck * 36*b0563631STom Van Eyck * This function may only be called before a call to psa_crypto_init(), 37*b0563631STom Van Eyck * or after a call to mbedtls_psa_crypto_free() and before any 38*b0563631STom Van Eyck * subsequent call to psa_crypto_init(). 39*b0563631STom Van Eyck * 40*b0563631STom Van Eyck * This function is only intended for test purposes. The functionality 41*b0563631STom Van Eyck * it provides is also useful for system integrators, but 42*b0563631STom Van Eyck * system integrators should configure entropy drivers instead of 43*b0563631STom Van Eyck * breaking through to the Mbed TLS API. 44*b0563631STom Van Eyck * 45*b0563631STom Van Eyck * \param entropy_init Function to initialize the entropy context 46*b0563631STom Van Eyck * and set up the desired entropy sources. 47*b0563631STom Van Eyck * It is called by psa_crypto_init(). 48*b0563631STom Van Eyck * By default this is mbedtls_entropy_init(). 49*b0563631STom Van Eyck * This function cannot report failures directly. 50*b0563631STom Van Eyck * To indicate a failure, set the entropy context 51*b0563631STom Van Eyck * to a state where mbedtls_entropy_func() will 52*b0563631STom Van Eyck * return an error. 53*b0563631STom Van Eyck * \param entropy_free Function to free the entropy context 54*b0563631STom Van Eyck * and associated resources. 55*b0563631STom Van Eyck * It is called by mbedtls_psa_crypto_free(). 56*b0563631STom Van Eyck * By default this is mbedtls_entropy_free(). 57*b0563631STom Van Eyck * 58*b0563631STom Van Eyck * \retval #PSA_SUCCESS 59*b0563631STom Van Eyck * Success. 60*b0563631STom Van Eyck * \retval #PSA_ERROR_NOT_PERMITTED 61*b0563631STom Van Eyck * The caller does not have the permission to configure 62*b0563631STom Van Eyck * entropy sources. 63*b0563631STom Van Eyck * \retval #PSA_ERROR_BAD_STATE 64*b0563631STom Van Eyck * The library has already been initialized. 65*b0563631STom Van Eyck */ 66*b0563631STom Van Eyck psa_status_t mbedtls_psa_crypto_configure_entropy_sources( 67*b0563631STom Van Eyck void (* entropy_init)(mbedtls_entropy_context *ctx), 68*b0563631STom Van Eyck void (* entropy_free)(mbedtls_entropy_context *ctx)); 69*b0563631STom Van Eyck #endif /* !defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) */ 70*b0563631STom Van Eyck 71*b0563631STom Van Eyck #if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_PSA_CRYPTO_C) 72*b0563631STom Van Eyck psa_status_t psa_mac_key_can_do( 73*b0563631STom Van Eyck psa_algorithm_t algorithm, 74*b0563631STom Van Eyck psa_key_type_t key_type); 75*b0563631STom Van Eyck 76*b0563631STom Van Eyck psa_status_t psa_crypto_copy_input(const uint8_t *input, size_t input_len, 77*b0563631STom Van Eyck uint8_t *input_copy, size_t input_copy_len); 78*b0563631STom Van Eyck 79*b0563631STom Van Eyck psa_status_t psa_crypto_copy_output(const uint8_t *output_copy, size_t output_copy_len, 80*b0563631STom Van Eyck uint8_t *output, size_t output_len); 81*b0563631STom Van Eyck 82*b0563631STom Van Eyck /* 83*b0563631STom Van Eyck * Test hooks to use for memory unpoisoning/poisoning in copy functions. 84*b0563631STom Van Eyck */ 85*b0563631STom Van Eyck extern void (*psa_input_pre_copy_hook)(const uint8_t *input, size_t input_len); 86*b0563631STom Van Eyck extern void (*psa_input_post_copy_hook)(const uint8_t *input, size_t input_len); 87*b0563631STom Van Eyck extern void (*psa_output_pre_copy_hook)(const uint8_t *output, size_t output_len); 88*b0563631STom Van Eyck extern void (*psa_output_post_copy_hook)(const uint8_t *output, size_t output_len); 89*b0563631STom Van Eyck 90*b0563631STom Van Eyck #endif /* MBEDTLS_TEST_HOOKS && MBEDTLS_PSA_CRYPTO_C */ 91*b0563631STom Van Eyck 92*b0563631STom Van Eyck #endif /* PSA_CRYPTO_INVASIVE_H */ 93