Merge pull request #2957 from cesanta/picornd

Use Pico-SDK RNG
This commit is contained in:
Sergio R. Caprile 2024-11-07 11:59:47 -03:00 committed by GitHub
commit 7a30a42797
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 12 additions and 4 deletions

View File

@ -12,7 +12,7 @@ add_executable(firmware
target_include_directories(firmware PUBLIC target_include_directories(firmware PUBLIC
.) .)
target_link_libraries(firmware hardware_pio hardware_dma pico_stdlib) target_link_libraries(firmware hardware_pio hardware_dma pico_stdlib pico_rand)
pico_add_extra_outputs(firmware) # create map/bin/hex file etc. pico_add_extra_outputs(firmware) # create map/bin/hex file etc.
pico_enable_stdio_usb(firmware 1) # Route stdio pico_enable_stdio_usb(firmware 1) # Route stdio

View File

@ -17,7 +17,7 @@ target_include_directories(firmware PUBLIC
. .
pico-sdk/lib/tinyusb/lib/networking) pico-sdk/lib/tinyusb/lib/networking)
target_link_libraries(firmware pico_stdlib hardware_spi tinyusb_device) target_link_libraries(firmware pico_stdlib pico_rand hardware_spi tinyusb_device)
pico_add_extra_outputs(firmware) # create map/bin/hex file etc. pico_add_extra_outputs(firmware) # create map/bin/hex file etc.
pico_enable_stdio_usb(firmware 0) # Route stdio pico_enable_stdio_usb(firmware 0) # Route stdio

View File

@ -15,7 +15,7 @@ target_include_directories(firmware PUBLIC
. .
pico-sdk/lib/tinyusb/lib/networking) pico-sdk/lib/tinyusb/lib/networking)
target_link_libraries(firmware pico_stdlib hardware_spi tinyusb_device) target_link_libraries(firmware pico_stdlib pico_rand hardware_spi tinyusb_device)
pico_add_extra_outputs(firmware) # create map/bin/hex file etc. pico_add_extra_outputs(firmware) # create map/bin/hex file etc.
pico_enable_stdio_usb(firmware 0) # Route stdio pico_enable_stdio_usb(firmware 0) # Route stdio

View File

@ -16,7 +16,7 @@ target_include_directories(firmware PUBLIC
. .
) )
target_link_libraries(firmware hardware_pio hardware_dma pico_stdlib cyw43_driver_picow) target_link_libraries(firmware hardware_pio hardware_dma pico_stdlib pico_rand cyw43_driver_picow)
pico_add_extra_outputs(firmware) # create map/bin/hex file etc. pico_add_extra_outputs(firmware) # create map/bin/hex file etc.
pico_enable_stdio_usb(firmware 1) # Route stdio pico_enable_stdio_usb(firmware 1) # Route stdio

View File

@ -16784,6 +16784,9 @@ bool mg_random(void *buf, size_t len) {
#if MG_ARCH == MG_ARCH_ESP32 #if MG_ARCH == MG_ARCH_ESP32
while (len--) *p++ = (unsigned char) (esp_random() & 255); while (len--) *p++ = (unsigned char) (esp_random() & 255);
success = true; success = true;
#elif MG_ARCH == MG_ARCH_RP2040
while (len--) *p++ = (unsigned char) (get_rand_32() & 255);
success = true;
#elif MG_ARCH == MG_ARCH_WIN32 #elif MG_ARCH == MG_ARCH_WIN32
static bool initialised = false; static bool initialised = false;
#if defined(_MSC_VER) && _MSC_VER < 1700 #if defined(_MSC_VER) && _MSC_VER < 1700

View File

@ -254,6 +254,7 @@ static inline int mg_mkdir(const char *path, mode_t mode) {
#include <time.h> #include <time.h>
#include <pico/stdlib.h> #include <pico/stdlib.h>
#include <pico/rand.h>
int mkdir(const char *, mode_t); int mkdir(const char *, mode_t);
#if MG_OTA == MG_OTA_PICOSDK #if MG_OTA == MG_OTA_PICOSDK

View File

@ -11,6 +11,7 @@
#include <time.h> #include <time.h>
#include <pico/stdlib.h> #include <pico/stdlib.h>
#include <pico/rand.h>
int mkdir(const char *, mode_t); int mkdir(const char *, mode_t);
#if MG_OTA == MG_OTA_PICOSDK #if MG_OTA == MG_OTA_PICOSDK

View File

@ -17,6 +17,9 @@ bool mg_random(void *buf, size_t len) {
#if MG_ARCH == MG_ARCH_ESP32 #if MG_ARCH == MG_ARCH_ESP32
while (len--) *p++ = (unsigned char) (esp_random() & 255); while (len--) *p++ = (unsigned char) (esp_random() & 255);
success = true; success = true;
#elif MG_ARCH == MG_ARCH_RP2040
while (len--) *p++ = (unsigned char) (get_rand_32() & 255);
success = true;
#elif MG_ARCH == MG_ARCH_WIN32 #elif MG_ARCH == MG_ARCH_WIN32
static bool initialised = false; static bool initialised = false;
#if defined(_MSC_VER) && _MSC_VER < 1700 #if defined(_MSC_VER) && _MSC_VER < 1700