storage: Use wait_random() from common.h. Fix build for tests.

pull/239/head
Andrew Kozlik 5 years ago
parent d95756ccf3
commit 531c610a17

@ -330,30 +330,6 @@ static secbool auth_get(uint16_t key, const void **val, uint16_t *len) {
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,
uint8_t kek[SHA256_DIGEST_LENGTH],
uint8_t keiv[SHA256_DIGEST_LENGTH]) {

@ -1,24 +1,36 @@
CC = gcc
CFLAGS = -Wall -Wshadow -Wextra -Wpedantic -Werror -fPIC -DTREZOR_STORAGE_TEST
CFLAGS = -Wall -Wshadow -Wextra -Wpedantic -Werror -fPIC
LIBS =
INC = -I ../../../crypto -I ../../../storage -I .
OBJ = flash.o common.o
OBJ += ../../../storage/storage.o ../../../storage/norcow.o
OBJ += ../../../crypto/pbkdf2.o
OBJ += ../../../crypto/rand.o
OBJ += ../../../crypto/chacha20poly1305/rfc7539.o
OBJ += ../../../crypto/chacha20poly1305/chacha20poly1305.o
OBJ += ../../../crypto/chacha20poly1305/poly1305-donna.o
OBJ += ../../../crypto/chacha20poly1305/chacha_merged.o
OBJ += ../../../crypto/hmac.o
OBJ += ../../../crypto/sha2.o
OBJ += ../../../crypto/memzero.o
INC = -I ../../../crypto -I ../.. -I .
BASE = ../../../
SRC = storage/tests/c/flash.c
SRC += storage/tests/c/common.c
SRC += storage/storage.c
SRC += storage/norcow.c
SRC += crypto/pbkdf2.c
SRC += crypto/rand.c
SRC += crypto/chacha20poly1305/rfc7539.c
SRC += crypto/chacha20poly1305/chacha20poly1305.c
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): $(OBJ)
$(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 $@
clean:

@ -23,6 +23,8 @@
#include "common.h"
void wait_random(void) {}
void __shutdown(void) {
printf("SHUTDOWN\n");
exit(3);

@ -22,6 +22,8 @@
#include "secbool.h"
void wait_random(void);
void __fatal_error(const char *expr, const char *msg, const char *file,
int line, const char *func);
void error_shutdown(const char *line1, const char *line2, const char *line3,

Loading…
Cancel
Save