|
|
|
@ -25,13 +25,15 @@
|
|
|
|
|
#include "display.h"
|
|
|
|
|
#include "flash.h"
|
|
|
|
|
#include "rand.h"
|
|
|
|
|
#include "rng.h"
|
|
|
|
|
#include "hmac_drbg.h"
|
|
|
|
|
|
|
|
|
|
#include "stm32f4xx_ll_utils.h"
|
|
|
|
|
|
|
|
|
|
// from util.s
|
|
|
|
|
extern void shutdown(void);
|
|
|
|
|
|
|
|
|
|
static HMAC_DRBG_CTX drbg_ctx;
|
|
|
|
|
|
|
|
|
|
#define COLOR_FATAL_ERROR RGB16(0x7F, 0x00, 0x00)
|
|
|
|
|
|
|
|
|
|
void __attribute__((noreturn))
|
|
|
|
@ -121,7 +123,7 @@ void __assert_func(const char *file, int line, const char *func,
|
|
|
|
|
void hal_delay(uint32_t ms) { HAL_Delay(ms); }
|
|
|
|
|
|
|
|
|
|
void delay_random(void) {
|
|
|
|
|
int wait = rng_get() & 0xff;
|
|
|
|
|
int wait = drbg_random32() & 0xff;
|
|
|
|
|
volatile int i = 0;
|
|
|
|
|
volatile int j = wait;
|
|
|
|
|
while (i < wait) {
|
|
|
|
@ -185,3 +187,23 @@ void collect_hw_entropy(void) {
|
|
|
|
|
FLASH_OTP_BLOCK_SIZE),
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void drbg_init() {
|
|
|
|
|
uint8_t entropy[48];
|
|
|
|
|
random_buffer(entropy, sizeof(entropy));
|
|
|
|
|
hmac_drbg_init(&drbg_ctx, entropy, sizeof(entropy), NULL, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void drbg_reseed(const uint8_t *entropy, size_t len) {
|
|
|
|
|
hmac_drbg_reseed(&drbg_ctx, entropy, len, NULL, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void drbg_generate(uint8_t *buf, size_t len) {
|
|
|
|
|
hmac_drbg_generate(&drbg_ctx, buf, len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t drbg_random32(void) {
|
|
|
|
|
uint32_t value;
|
|
|
|
|
drbg_generate((uint8_t *)&value, sizeof(value));
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|