diff --git a/src/rp2_common/pico_mbedtls/CMakeLists.txt b/src/rp2_common/pico_mbedtls/CMakeLists.txt index 0d9685b..d2c7f3a 100644 --- a/src/rp2_common/pico_mbedtls/CMakeLists.txt +++ b/src/rp2_common/pico_mbedtls/CMakeLists.txt @@ -130,12 +130,13 @@ if (EXISTS ${PICO_MBEDTLS_PATH}/${MBEDTLS_TEST_PATH}) target_sources(pico_mbedtls_tls INTERFACE ${src_tls}) pico_add_impl_library(pico_mbedtls) - target_link_libraries(pico_mbedtls INTERFACE pico_mbedtls_crypto pico_mbedtls_x509 pico_mbedtls_tls) + target_link_libraries(pico_mbedtls INTERFACE pico_mbedtls_crypto pico_mbedtls_x509 pico_mbedtls_tls pico_rand) if (DEFINED PICO_MBEDTLS_CONFIG_FILE) target_compile_definitions(pico_mbedtls INTERFACE MBEDTLS_CONFIG_FILE="${PICO_MBEDTLS_CONFIG_FILE}") else() target_compile_definitions(pico_mbedtls INTERFACE MBEDTLS_CONFIG_FILE="mbedtls_config.h") endif() + target_sources(pico_mbedtls INTERFACE ${CMAKE_CURRENT_LIST_DIR}/pico_mbedtls.c) target_include_directories(pico_mbedtls INTERFACE ${PICO_MBEDTLS_PATH}/include/ ${PICO_MBEDTLS_PATH}/library/) function(suppress_mbedtls_warnings) diff --git a/src/rp2_common/pico_mbedtls/pico_mbedtls.c b/src/rp2_common/pico_mbedtls/pico_mbedtls.c new file mode 100644 index 0000000..5878956 --- /dev/null +++ b/src/rp2_common/pico_mbedtls/pico_mbedtls.c @@ -0,0 +1,15 @@ +#include +#include "pico/platform.h" +#include "pico/rand.h" + +/* Function to feed mbedtls entropy. */ +int mbedtls_hardware_poll(void *data __unused, unsigned char *output, size_t len, size_t *olen) { + *olen = 0; + while(*olen < len) { + uint64_t rand_data = get_rand_64(); + size_t to_copy = MIN(len, sizeof(rand_data)); + memcpy(output + *olen, &rand_data, to_copy); + *olen += to_copy; + } + return 0; +}