mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-12 08:20:56 +00:00
storage: Use wait_random() from common.h. Fix build for tests.
This commit is contained in:
parent
d95756ccf3
commit
531c610a17
@ -330,30 +330,6 @@ static secbool auth_get(uint16_t key, const void **val, uint16_t *len) {
|
|||||||
return sectrue;
|
return sectrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Generates a delay of random length. Use this to protect sensitive code
|
|
||||||
* against fault injection.
|
|
||||||
*/
|
|
||||||
static void wait_random(void) {
|
|
||||||
#ifndef TREZOR_STORAGE_TEST
|
|
||||||
int wait = random32() & 0xff;
|
|
||||||
volatile int i = 0;
|
|
||||||
volatile int j = wait;
|
|
||||||
while (i < wait) {
|
|
||||||
if (i + j != wait) {
|
|
||||||
handle_fault("sanity check");
|
|
||||||
}
|
|
||||||
++i;
|
|
||||||
--j;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Double-check loop completion.
|
|
||||||
if (i != wait) {
|
|
||||||
handle_fault("loop completion check");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static void derive_kek(uint32_t pin, const uint8_t *random_salt,
|
static void derive_kek(uint32_t pin, const uint8_t *random_salt,
|
||||||
uint8_t kek[SHA256_DIGEST_LENGTH],
|
uint8_t kek[SHA256_DIGEST_LENGTH],
|
||||||
uint8_t keiv[SHA256_DIGEST_LENGTH]) {
|
uint8_t keiv[SHA256_DIGEST_LENGTH]) {
|
||||||
|
@ -1,24 +1,36 @@
|
|||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS = -Wall -Wshadow -Wextra -Wpedantic -Werror -fPIC -DTREZOR_STORAGE_TEST
|
CFLAGS = -Wall -Wshadow -Wextra -Wpedantic -Werror -fPIC
|
||||||
LIBS =
|
LIBS =
|
||||||
INC = -I ../../../crypto -I ../../../storage -I .
|
INC = -I ../../../crypto -I ../.. -I .
|
||||||
OBJ = flash.o common.o
|
BASE = ../../../
|
||||||
OBJ += ../../../storage/storage.o ../../../storage/norcow.o
|
|
||||||
OBJ += ../../../crypto/pbkdf2.o
|
SRC = storage/tests/c/flash.c
|
||||||
OBJ += ../../../crypto/rand.o
|
SRC += storage/tests/c/common.c
|
||||||
OBJ += ../../../crypto/chacha20poly1305/rfc7539.o
|
SRC += storage/storage.c
|
||||||
OBJ += ../../../crypto/chacha20poly1305/chacha20poly1305.o
|
SRC += storage/norcow.c
|
||||||
OBJ += ../../../crypto/chacha20poly1305/poly1305-donna.o
|
SRC += crypto/pbkdf2.c
|
||||||
OBJ += ../../../crypto/chacha20poly1305/chacha_merged.o
|
SRC += crypto/rand.c
|
||||||
OBJ += ../../../crypto/hmac.o
|
SRC += crypto/chacha20poly1305/rfc7539.c
|
||||||
OBJ += ../../../crypto/sha2.o
|
SRC += crypto/chacha20poly1305/chacha20poly1305.c
|
||||||
OBJ += ../../../crypto/memzero.o
|
SRC += crypto/chacha20poly1305/poly1305-donna.c
|
||||||
|
SRC += crypto/chacha20poly1305/chacha_merged.c
|
||||||
|
SRC += crypto/hmac.c
|
||||||
|
SRC += crypto/sha2.c
|
||||||
|
SRC += crypto/memzero.c
|
||||||
|
|
||||||
|
OBJ = $(SRC:%.c=build/%.o)
|
||||||
|
|
||||||
OUT = libtrezor-storage.so
|
OUT = libtrezor-storage.so
|
||||||
|
|
||||||
$(OUT): $(OBJ)
|
$(OUT): $(OBJ)
|
||||||
$(CC) $(CFLAGS) $(LIBS) $(OBJ) -shared -o $(OUT)
|
$(CC) $(CFLAGS) $(LIBS) $(OBJ) -shared -o $(OUT)
|
||||||
|
|
||||||
%.o: %.c %.h
|
build/crypto/chacha20poly1305/chacha_merged.o: $(BASE)crypto/chacha20poly1305/chacha_merged.c
|
||||||
|
mkdir -p $(@D)
|
||||||
|
$(CC) $(CFLAGS) $(INC) -c $< -o $@
|
||||||
|
|
||||||
|
build/%.o: $(BASE)%.c $(BASE)%.h
|
||||||
|
mkdir -p $(@D)
|
||||||
$(CC) $(CFLAGS) $(INC) -c $< -o $@
|
$(CC) $(CFLAGS) $(INC) -c $< -o $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
void wait_random(void) {}
|
||||||
|
|
||||||
void __shutdown(void) {
|
void __shutdown(void) {
|
||||||
printf("SHUTDOWN\n");
|
printf("SHUTDOWN\n");
|
||||||
exit(3);
|
exit(3);
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#include "secbool.h"
|
#include "secbool.h"
|
||||||
|
|
||||||
|
void wait_random(void);
|
||||||
|
|
||||||
void __fatal_error(const char *expr, const char *msg, const char *file,
|
void __fatal_error(const char *expr, const char *msg, const char *file,
|
||||||
int line, const char *func);
|
int line, const char *func);
|
||||||
void error_shutdown(const char *line1, const char *line2, const char *line3,
|
void error_shutdown(const char *line1, const char *line2, const char *line3,
|
||||||
|
Loading…
Reference in New Issue
Block a user