1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-21 23:18:13 +00:00

refactor(legacy): move wait_random into separate file

This commit is contained in:
Ondřej Vejpustek 2021-02-15 15:20:56 +01:00
parent 8ee17f69b3
commit 34f5d508b0
10 changed files with 71 additions and 23 deletions

View File

@ -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)

View File

@ -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));

View File

@ -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);

View File

@ -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

41
legacy/random_delays.c Normal file
View File

@ -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();
}
}

24
legacy/random_delays.h Normal file
View File

@ -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

View File

@ -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,

View File

@ -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"

View File

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

View File

@ -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; }