0.2.0-dev Download ZIP
85 lines ·3.4 KB Raw
| 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 | /* |
| 12 | * Copyright The Mbed TLS Contributors |
| 13 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 14 | */ |
| 15 | |
| 16 | #ifndef TF_PSA_CRYPTO_PSA_CRYPTO_INVASIVE_H |
| 17 | #define TF_PSA_CRYPTO_PSA_CRYPTO_INVASIVE_H |
| 18 | |
| 19 | #include "tf-psa-crypto/build_info.h" |
| 20 | |
| 21 | #include "psa/crypto.h" |
| 22 | #include "tf_psa_crypto_common.h" |
| 23 | |
| 24 | #include "mbedtls/private/entropy.h" |
| 25 | |
| 26 | #if !defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) |
| 27 | /** \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 | * |
| 51 | * \retval #PSA_SUCCESS |
| 52 | * Success. |
| 53 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 54 | * The caller does not have the permission to configure |
| 55 | * entropy sources. |
| 56 | * \retval #PSA_ERROR_BAD_STATE |
| 57 | * The library has already been initialized. |
| 58 | */ |
| 59 | psa_status_t mbedtls_psa_crypto_configure_entropy_sources( |
| 60 | void (* entropy_init)(mbedtls_entropy_context *ctx), |
| 61 | void (* entropy_free)(mbedtls_entropy_context *ctx)); |
| 62 | #endif /* !defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) */ |
| 63 | |
| 64 | #if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_PSA_CRYPTO_C) |
| 65 | psa_status_t psa_mac_key_can_do( |
| 66 | psa_algorithm_t algorithm, |
| 67 | psa_key_type_t key_type); |
| 68 | |
| 69 | psa_status_t psa_crypto_copy_input(const uint8_t *input, size_t input_len, |
| 70 | uint8_t *input_copy, size_t input_copy_len); |
| 71 | |
| 72 | psa_status_t psa_crypto_copy_output(const uint8_t *output_copy, size_t output_copy_len, |
| 73 | uint8_t *output, size_t output_len); |
| 74 | |
| 75 | /* |
| 76 | * Test hooks to use for memory unpoisoning/poisoning in copy functions. |
| 77 | */ |
| 78 | extern void (*psa_input_pre_copy_hook)(const uint8_t *input, size_t input_len); |
| 79 | extern void (*psa_input_post_copy_hook)(const uint8_t *input, size_t input_len); |
| 80 | extern void (*psa_output_pre_copy_hook)(const uint8_t *output, size_t output_len); |
| 81 | extern void (*psa_output_post_copy_hook)(const uint8_t *output, size_t output_len); |
| 82 | |
| 83 | #endif /* MBEDTLS_TEST_HOOKS && MBEDTLS_PSA_CRYPTO_C */ |
| 84 | |
| 85 | #endif /* TF_PSA_CRYPTO_PSA_CRYPTO_INVASIVE_H */ |