55 */
66
77#include <zephyr/random/random.h>
8+ #include <mbedtls/entropy.h>
89#include <psa/crypto.h>
9- #include <mbedtls/platform.h>
1010
1111
12- #if defined(CONFIG_MBEDTLS_PSA_DRIVER_GET_ENTROPY ) || \
13- defined(CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG )
12+ #if defined(CONFIG_MBEDTLS_ENTROPY_POLL_ZEPHYR ) || defined(CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG )
1413static int get_random_data (uint8_t * output , size_t output_size , bool allow_non_cs )
1514{
16- int ret = - EINVAL ;
15+ int ret = MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED ;
1716
1817#if defined(CONFIG_CSPRNG_ENABLED )
1918 ret = sys_csrand_get (output , output_size );
@@ -29,24 +28,31 @@ static int get_random_data(uint8_t *output, size_t output_size, bool allow_non_c
2928
3029 return ret ;
3130}
32- #endif /* CONFIG_MBEDTLS_PSA_DRIVER_GET_ENTROPY || CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
31+ #endif /* CONFIG_MBEDTLS_ENTROPY_POLL_ZEPHYR || CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
3332
34- #if defined(CONFIG_MBEDTLS_PSA_DRIVER_GET_ENTROPY )
35- int mbedtls_platform_get_entropy (psa_driver_get_entropy_flags_t flags ,
36- size_t * estimate_bits ,
37- unsigned char * output , size_t output_size )
33+ #if defined(CONFIG_MBEDTLS_ENTROPY_POLL_ZEPHYR )
34+ int mbedtls_hardware_poll (void * data , unsigned char * output , size_t len ,
35+ size_t * olen )
3836{
39- ARG_UNUSED (flags );
37+ int ret ;
38+ uint16_t request_len = len > UINT16_MAX ? UINT16_MAX : len ;
39+
40+ ARG_UNUSED (data );
41+
42+ if (output == NULL || olen == NULL || len == 0 ) {
43+ return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ;
44+ }
4045
41- if (get_random_data (output , output_size , true) < 0 ) {
42- return - EIO ;
46+ ret = get_random_data (output , len , true);
47+ if (ret < 0 ) {
48+ return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ;
4349 }
4450
45- * estimate_bits = 8 * output_size ;
51+ * olen = request_len ;
4652
4753 return 0 ;
4854}
49- #endif /* CONFIG_MBEDTLS_PSA_DRIVER_GET_ENTROPY */
55+ #endif /* CONFIG_MBEDTLS_ENTROPY_POLL_ZEPHYR */
5056
5157#if defined(CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG )
5258psa_status_t mbedtls_psa_external_get_random (
0 commit comments