mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-05-28 17:11:23 +02:00
Do not use mbedtls crt_dbrg as it it not reliable.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
@@ -238,13 +238,7 @@ if (ENABLE_EMULATION)
|
|||||||
${CMAKE_CURRENT_LIST_DIR}/src/usb/emulation/emulation.c
|
${CMAKE_CURRENT_LIST_DIR}/src/usb/emulation/emulation.c
|
||||||
)
|
)
|
||||||
set(MBEDTLS_SOURCES ${MBEDTLS_SOURCES}
|
set(MBEDTLS_SOURCES ${MBEDTLS_SOURCES}
|
||||||
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/ctr_drbg.c
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/entropy.c
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/entropy_poll.c
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/aesni.c
|
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/aesni.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/pem.c
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/x509write.c
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/base64.c
|
|
||||||
)
|
)
|
||||||
set(INCLUDES ${INCLUDES}
|
set(INCLUDES ${INCLUDES}
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/usb/emulation
|
${CMAKE_CURRENT_LIST_DIR}/src/usb/emulation
|
||||||
|
|||||||
@@ -19,10 +19,9 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#if defined(ENABLE_EMULATION)
|
#if defined(ENABLE_EMULATION)
|
||||||
#include "mbedtls/entropy.h"
|
#include <stdbool.h>
|
||||||
#include "mbedtls/ctr_drbg.h"
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
mbedtls_ctr_drbg_context ctr_drbg;
|
|
||||||
extern uint32_t board_millis();
|
extern uint32_t board_millis();
|
||||||
#elif (ESP_PLATFORM)
|
#elif (ESP_PLATFORM)
|
||||||
#include "bootloader_random.h"
|
#include "bootloader_random.h"
|
||||||
@@ -42,6 +41,7 @@ extern uint32_t board_millis();
|
|||||||
|
|
||||||
void adc_start() {
|
void adc_start() {
|
||||||
#if defined(ENABLE_EMULATION)
|
#if defined(ENABLE_EMULATION)
|
||||||
|
srand(time(0));
|
||||||
#elif defined(ESP_PLATFORM)
|
#elif defined(ESP_PLATFORM)
|
||||||
bootloader_random_enable();
|
bootloader_random_enable();
|
||||||
#else
|
#else
|
||||||
@@ -65,16 +65,6 @@ static uint8_t ep_round = 0;
|
|||||||
static void ep_init() {
|
static void ep_init() {
|
||||||
random_word = 0xcbf29ce484222325;
|
random_word = 0xcbf29ce484222325;
|
||||||
ep_round = 0;
|
ep_round = 0;
|
||||||
#ifdef ENABLE_EMULATION
|
|
||||||
mbedtls_entropy_context entropy;
|
|
||||||
mbedtls_entropy_init(&entropy);
|
|
||||||
mbedtls_ctr_drbg_init(&ctr_drbg);
|
|
||||||
mbedtls_ctr_drbg_seed(&ctr_drbg,
|
|
||||||
mbedtls_entropy_func,
|
|
||||||
&entropy,
|
|
||||||
(const unsigned char *) "RANDOM_GEN",
|
|
||||||
10);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Here, we assume a little endian architecture. */
|
/* Here, we assume a little endian architecture. */
|
||||||
@@ -85,7 +75,9 @@ static int ep_process() {
|
|||||||
uint64_t word = 0x0;
|
uint64_t word = 0x0;
|
||||||
|
|
||||||
#if defined(ENABLE_EMULATION)
|
#if defined(ENABLE_EMULATION)
|
||||||
mbedtls_ctr_drbg_random(&ctr_drbg, (uint8_t *) &word, sizeof(word));
|
word = rand();
|
||||||
|
word <<= 32;
|
||||||
|
word |= rand();
|
||||||
#elif defined(ESP_PLATFORM)
|
#elif defined(ESP_PLATFORM)
|
||||||
esp_fill_random((uint8_t *)&word, sizeof(word));
|
esp_fill_random((uint8_t *)&word, sizeof(word));
|
||||||
#else
|
#else
|
||||||
|
|||||||
Reference in New Issue
Block a user