mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-12-18 17:14:12 +03:00
Tests: provide necessary functions for MBEDTLS_PSA_INJECT_ENTROPY
The build option MBEDTLS_PSA_INJECT_ENTROPY requires some extra platform functions, for historical reasons. To enable us to test this option, provide a version of these functions for testing. (These versions would actually work in production, but providing them in the library in a way that doesn't break existing users might be slightly tricky, so it's out of scope of this commit.) Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
@@ -149,4 +149,35 @@ int mbedtls_test_fail_if_psa_leaking(int line_no, const char *filename)
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_PSA_INJECT_ENTROPY)
|
||||
|
||||
#include <mbedtls/entropy.h>
|
||||
#include <psa_crypto_its.h>
|
||||
|
||||
int mbedtls_test_inject_entropy_seed_read(unsigned char *buf, size_t len)
|
||||
{
|
||||
size_t actual_len = 0;
|
||||
psa_status_t status = psa_its_get(PSA_CRYPTO_ITS_RANDOM_SEED_UID,
|
||||
0, len, buf, &actual_len);
|
||||
if (status != 0) {
|
||||
return MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR;
|
||||
}
|
||||
if (actual_len != len) {
|
||||
return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mbedtls_test_inject_entropy_seed_write(unsigned char *buf, size_t len)
|
||||
{
|
||||
psa_status_t status = psa_its_set(PSA_CRYPTO_ITS_RANDOM_SEED_UID,
|
||||
len, buf, 0);
|
||||
if (status != 0) {
|
||||
return MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_PSA_INJECT_ENTROPY */
|
||||
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_C */
|
||||
|
||||
Reference in New Issue
Block a user