Add mbedtls_hardware_poll implementation to pico_mbedtls
This commit is contained in:
		@ -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)
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										15
									
								
								src/rp2_common/pico_mbedtls/pico_mbedtls.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/rp2_common/pico_mbedtls/pico_mbedtls.c
									
									
									
									
									
										Normal 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;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user