refactor(legacy): move wait_random into separate file

pull/1625/head
Ondřej Vejpustek 3 years ago
parent 8ee17f69b3
commit 34f5d508b0

@ -7,6 +7,7 @@ OBJS += common.o
OBJS += flash.o
OBJS += layout.o
OBJS += oled.o
OBJS += random_delays.o
OBJS += rng.o
ifneq ($(EMULATOR),1)

@ -85,23 +85,6 @@ void __assert_func(const char *file, int line, const char *func,
void hal_delay(uint32_t ms) { usbSleep(ms); }
void wait_random(void) {
int wait = random32() & 0xff;
volatile int i = 0;
volatile int j = wait;
while (i < wait) {
if (i + j != wait) {
shutdown();
}
++i;
--j;
}
// Double-check loop completion.
if (i != wait || j != 0) {
shutdown();
}
}
void drbg_init() {
uint8_t entropy[48] = {0};
random_buffer(entropy, sizeof(entropy));

@ -41,8 +41,6 @@ error_shutdown(const char *line1, const char *line2, const char *line3,
void hal_delay(uint32_t ms);
void wait_random(void);
void drbg_init(void);
void drbg_reseed(const uint8_t *entropy, size_t len);
void drbg_generate(uint8_t *buf, size_t len);

@ -24,6 +24,7 @@
#include "config.h"
#include "debug.h"
#include "messages.h"
#include "random_delays.h"
#include "timer.h"
#include "trezor.h"
#if U2F_ENABLED

@ -0,0 +1,41 @@
/*
* This file is part of the Trezor project, https://trezor.io/
*
* Copyright (c) SatoshiLabs
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "random_delays.h"
#include "common.h"
#include "rng.h"
#include "util.h"
void wait_random(void) {
int wait = random32() & 0xff;
volatile int i = 0;
volatile int j = wait;
while (i < wait) {
if (i + j != wait) {
shutdown();
}
++i;
--j;
}
// Double-check loop completion.
if (i != wait || j != 0) {
shutdown();
}
}

@ -0,0 +1,24 @@
/*
* This file is part of the Trezor project, https://trezor.io/
*
* Copyright (c) SatoshiLabs
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __RANDOM_DELAYS_H__
#define __RANDOM_DELAYS_H__
void wait_random(void);
#endif

@ -19,7 +19,7 @@
#include "usb21_standard.h"
#include <stdint.h>
#include <string.h>
#include "common.h"
#include "random_delays.h"
#include "util.h"
static uint16_t build_bos_descriptor(const struct usb_bos_descriptor *bos,

@ -38,7 +38,7 @@ LGPL License Terms @ref lgpl_license
#include <string.h>
#include <libopencm3/usb/usbd.h>
#include "common.h"
#include "random_delays.h"
#include "usb_private.h"
#include "util.h"

@ -18,7 +18,7 @@
#include <string.h>
#include "common.h"
#include "random_delays.h"
#include "usb21_standard.h"
#include "util.h"
#include "webusb.h"

@ -18,7 +18,7 @@
#include "winusb.h"
#include <libopencm3/usb/usbd.h>
#include "common.h"
#include "random_delays.h"
#include "util.h"
static int usb_descriptor_type(uint16_t wValue) { return wValue >> 8; }

Loading…
Cancel
Save