mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-13 19:18:56 +00:00
core/common: Change delay_random() to wait_random().
This commit is contained in:
parent
531c610a17
commit
c2bdd1cf32
@ -24,8 +24,8 @@
|
||||
#include "common.h"
|
||||
#include "display.h"
|
||||
#include "flash.h"
|
||||
#include "rand.h"
|
||||
#include "hmac_drbg.h"
|
||||
#include "rand.h"
|
||||
|
||||
#include "stm32f4xx_ll_utils.h"
|
||||
|
||||
@ -122,7 +122,11 @@ void __assert_func(const char *file, int line, const char *func,
|
||||
|
||||
void hal_delay(uint32_t ms) { HAL_Delay(ms); }
|
||||
|
||||
void delay_random(void) {
|
||||
/*
|
||||
* Generates a delay of random length. Use this to protect sensitive code
|
||||
* against fault injection.
|
||||
*/
|
||||
void wait_random(void) {
|
||||
int wait = drbg_random32() & 0xff;
|
||||
volatile int i = 0;
|
||||
volatile int j = wait;
|
||||
@ -188,7 +192,7 @@ void collect_hw_entropy(void) {
|
||||
NULL);
|
||||
}
|
||||
|
||||
void drbg_init() {
|
||||
void drbg_init(void) {
|
||||
uint8_t entropy[48];
|
||||
random_buffer(entropy, sizeof(entropy));
|
||||
hmac_drbg_init(&drbg_ctx, entropy, sizeof(entropy), NULL, 0);
|
||||
|
@ -66,7 +66,7 @@ error_shutdown(const char *line1, const char *line2, const char *line3,
|
||||
|
||||
void hal_delay(uint32_t ms);
|
||||
|
||||
void delay_random(void);
|
||||
void wait_random(void);
|
||||
|
||||
void clear_otg_hs_memory(void);
|
||||
|
||||
@ -76,7 +76,7 @@ void collect_hw_entropy(void);
|
||||
#define HW_ENTROPY_LEN (12 + 32)
|
||||
extern uint8_t HW_ENTROPY_DATA[HW_ENTROPY_LEN];
|
||||
|
||||
void drbg_init();
|
||||
void drbg_init(void);
|
||||
void drbg_reseed(const uint8_t *entropy, size_t len);
|
||||
void drbg_generate(uint8_t *buf, size_t len);
|
||||
uint32_t drbg_random32(void);
|
||||
|
@ -343,7 +343,7 @@ static uint8_t usb_class_deinit(USBD_HandleTypeDef *dev, uint8_t cfg_idx) {
|
||||
|
||||
static uint8_t usb_class_setup(USBD_HandleTypeDef *dev,
|
||||
USBD_SetupReqTypedef *req) {
|
||||
delay_random();
|
||||
wait_random();
|
||||
if (((req->bmRequest & USB_REQ_TYPE_MASK) != USB_REQ_TYPE_CLASS) &&
|
||||
((req->bmRequest & USB_REQ_TYPE_MASK) != USB_REQ_TYPE_STANDARD) &&
|
||||
((req->bmRequest & USB_REQ_TYPE_MASK) != USB_REQ_TYPE_VENDOR)) {
|
||||
@ -472,7 +472,7 @@ static uint8_t usb_class_setup(USBD_HandleTypeDef *dev,
|
||||
}
|
||||
|
||||
static uint8_t usb_class_data_in(USBD_HandleTypeDef *dev, uint8_t ep_num) {
|
||||
delay_random();
|
||||
wait_random();
|
||||
for (int i = 0; i < USBD_MAX_NUM_INTERFACES; i++) {
|
||||
switch (usb_ifaces[i].type) {
|
||||
case USB_IFACE_TYPE_HID:
|
||||
@ -492,7 +492,7 @@ static uint8_t usb_class_data_in(USBD_HandleTypeDef *dev, uint8_t ep_num) {
|
||||
}
|
||||
|
||||
static uint8_t usb_class_data_out(USBD_HandleTypeDef *dev, uint8_t ep_num) {
|
||||
delay_random();
|
||||
wait_random();
|
||||
for (int i = 0; i < USBD_MAX_NUM_INTERFACES; i++) {
|
||||
switch (usb_ifaces[i].type) {
|
||||
case USB_IFACE_TYPE_HID:
|
||||
@ -512,7 +512,7 @@ static uint8_t usb_class_data_out(USBD_HandleTypeDef *dev, uint8_t ep_num) {
|
||||
}
|
||||
|
||||
static uint8_t usb_class_sof(USBD_HandleTypeDef *dev) {
|
||||
delay_random();
|
||||
wait_random();
|
||||
for (int i = 0; i < USBD_MAX_NUM_INTERFACES; i++) {
|
||||
switch (usb_ifaces[i].type) {
|
||||
case USB_IFACE_TYPE_VCP:
|
||||
|
@ -109,6 +109,8 @@ error_shutdown(const char *line1, const char *line2, const char *line3,
|
||||
|
||||
void hal_delay(uint32_t ms) { usleep(1000 * ms); }
|
||||
|
||||
void wait_random(void) {}
|
||||
|
||||
uint8_t HW_ENTROPY_DATA[HW_ENTROPY_LEN];
|
||||
|
||||
void collect_hw_entropy(void) { memzero(HW_ENTROPY_DATA, HW_ENTROPY_LEN); }
|
||||
|
@ -56,6 +56,7 @@ error_shutdown(const char *line1, const char *line2, const char *line3,
|
||||
: __fatal_error(#expr, msg, __FILE__, __LINE__, __func__))
|
||||
|
||||
void hal_delay(uint32_t ms);
|
||||
void wait_random(void);
|
||||
|
||||
void collect_hw_entropy(void);
|
||||
#define HW_ENTROPY_LEN (12 + 32)
|
||||
|
Loading…
Reference in New Issue
Block a user