Add mbedtls_hardware_poll implementation to pico_mbedtls

This commit is contained in:
Peter Harper 2023-01-27 17:15:22 +00:00 committed by GitHub
parent 1bd9de95de
commit 1552324a64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -130,12 +130,13 @@ if (EXISTS ${PICO_MBEDTLS_PATH}/${MBEDTLS_TEST_PATH})
target_sources(pico_mbedtls_tls INTERFACE ${src_tls}) target_sources(pico_mbedtls_tls INTERFACE ${src_tls})
pico_add_impl_library(pico_mbedtls) 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) if (DEFINED PICO_MBEDTLS_CONFIG_FILE)
target_compile_definitions(pico_mbedtls INTERFACE MBEDTLS_CONFIG_FILE="${PICO_MBEDTLS_CONFIG_FILE}") target_compile_definitions(pico_mbedtls INTERFACE MBEDTLS_CONFIG_FILE="${PICO_MBEDTLS_CONFIG_FILE}")
else() else()
target_compile_definitions(pico_mbedtls INTERFACE MBEDTLS_CONFIG_FILE="mbedtls_config.h") target_compile_definitions(pico_mbedtls INTERFACE MBEDTLS_CONFIG_FILE="mbedtls_config.h")
endif() 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/) target_include_directories(pico_mbedtls INTERFACE ${PICO_MBEDTLS_PATH}/include/ ${PICO_MBEDTLS_PATH}/library/)
function(suppress_mbedtls_warnings) function(suppress_mbedtls_warnings)

View File

@ -0,0 +1,15 @@
#include <string.h>
#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;
}