diff --git a/storage/storage.c b/storage/storage.c index fa6e90ca38..14d4114c50 100644 --- a/storage/storage.c +++ b/storage/storage.c @@ -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]) { diff --git a/storage/tests/c/Makefile b/storage/tests/c/Makefile index a1fc96c2e3..610c2d1e9e 100644 --- a/storage/tests/c/Makefile +++ b/storage/tests/c/Makefile @@ -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: diff --git a/storage/tests/c/common.c b/storage/tests/c/common.c index b3f9b7ffce..b53e1c34d4 100644 --- a/storage/tests/c/common.c +++ b/storage/tests/c/common.c @@ -23,6 +23,8 @@ #include "common.h" +void wait_random(void) {} + void __shutdown(void) { printf("SHUTDOWN\n"); exit(3); diff --git a/storage/tests/c/common.h b/storage/tests/c/common.h index eaa0773790..cfab1fcf85 100644 --- a/storage/tests/c/common.h +++ b/storage/tests/c/common.h @@ -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,