Skip to content

Commit

Permalink
wolfBoot TPM improvements:
Browse files Browse the repository at this point in the history
* Added TPM SPI wait state support and debug logging.
* Added platform auth ownership (change platform password to random value before boot).
* Added parameter encryption support.
* Removed the TPM hashing feature (not practical).
* Fixed RSA with wolfTPM build.
* Fixed cleanup wolfTPM objects on make clean.
* Start of TPM based root of trust.
  • Loading branch information
dgarske committed Aug 3, 2023
1 parent 7638bfb commit a632d9d
Show file tree
Hide file tree
Showing 6 changed files with 248 additions and 145 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ src/keystore.c: $(PRIVATE_KEY)
keys: $(PRIVATE_KEY)

clean:
$(Q)rm -f src/*.o hal/*.o hal/spi/*.o lib/wolfssl/wolfcrypt/src/*.o test-app/*.o
$(Q)rm -f *.bin *.elf wolfboot.map test-update.rom *.hex $(LSCRIPT)
$(Q)rm -f src/x86/*.o $(MACHINE_OBJ) $(MAIN_TARGET)
$(Q)rm -f lib/wolfTPM/src/*.o
$(Q)rm -f src/*.o hal/*.o hal/spi/*.o test-app/*.o src/x86/*.o
$(Q)rm -f lib/wolfssl/wolfcrypt/src/*.o lib/wolfTPM/src/*.o
$(Q)rm -f wolfboot.bin wolfboot.elf wolfboot.map test-update.rom wolfboot.hex
$(Q)rm -f $(MACHINE_OBJ) $(MAIN_TARGET) $(LSCRIPT)
$(Q)$(MAKE) -C test-app -s clean
$(Q)$(MAKE) -C tools/check_config -s clean
$(Q)$(MAKE) -C stage1 -s clean
Expand Down
52 changes: 34 additions & 18 deletions include/user_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ extern int tolower(int c);

#ifdef WOLFBOOT_SIGN_RSA2048
# define RSA_LOW_MEM
# define WOLFSSL_RSA_VERIFY_INLINE
# define WOLFSSL_RSA_VERIFY_ONLY
# ifndef WOLFBOOT_TPM
# define WOLFSSL_RSA_VERIFY_INLINE
# define WOLFSSL_RSA_VERIFY_ONLY
# endif
# define WC_NO_RSA_OAEP
# define FP_MAX_BITS (2048 * 2)
/* sp math */
Expand Down Expand Up @@ -223,12 +225,35 @@ extern int tolower(int c);
# define NO_PWDBASED
#endif

/* Disables - For minimum wolfCrypt build */
#ifndef WOLFBOOT_TPM
# if !defined(ENCRYPT_WITH_AES128) && !defined(ENCRYPT_WITH_AES256)
# define NO_AES
# endif
# define NO_HMAC
#ifdef WOLFBOOT_TPM
/* Enable AES CFB (parameter encryption) and HMAC (for KDF) */
#define WOLFSSL_AES_CFB

#ifdef WOLFTPM_MMIO
/* IO callback it above TIS and includes Address and if read/write */
#define WOLFTPM_ADV_IO
#endif

/* add delay */
#if !defined(XTPM_WAIT) && defined(WOLFTPM_MMIO)
void delay(int msec);
#define XTPM_WAIT() delay(1000);
#endif
#ifndef XTPM_WAIT
#define XTPM_WAIT() /* no delay */
#endif

/* TPM remap printf */
#if defined(DEBUG_WOLFTPM) && !defined(ARCH_SIM)
#include "printf.h"
#define printf wolfBoot_printf
#endif
#else
/* Disables - For minimum wolfCrypt build */
#if !defined(ENCRYPT_WITH_AES128) && !defined(ENCRYPT_WITH_AES256)
#define NO_AES
#endif
#define NO_HMAC
#endif

#define NO_CMAC
Expand Down Expand Up @@ -258,6 +283,7 @@ extern int tolower(int c);
#define WOLFSSL_NO_SOCK
#define WOLFSSL_IGNORE_FILE_WARN
#define NO_ERROR_STRINGS
#define NO_AES_CBC

#define BENCH_EMBEDDED
#define NO_CRYPT_TEST
Expand Down Expand Up @@ -289,14 +315,4 @@ extern int tolower(int c);
# define WOLFSSL_SMALL_STACK
#endif


#ifdef WOLFTPM_MMIO
void delay(int msec);
#define XTPM_WAIT() delay(1000);
#define DEBUG_WOLFTPM
#define WOLFTPM_ADV_IO
void uart_printf(const char* fmt, ...);
#define XPRINTF uart_printf
#endif

#endif /* !H_USER_SETTINGS_ */
10 changes: 7 additions & 3 deletions options.mk
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ ifeq ($(SIGN),RSA2048)
./lib/wolfssl/wolfcrypt/src/rsa.o \
./lib/wolfssl/wolfcrypt/src/asn.o \
./lib/wolfssl/wolfcrypt/src/hash.o \
./lib/wolfssl/wolfcrypt/src/wolfmath.o \
./lib/wolfssl/wolfcrypt/src/wc_port.o
CFLAGS+=-D"WOLFBOOT_SIGN_RSA2048" $(RSA_EXTRA_CFLAGS)
ifeq ($(WOLFBOOT_SMALL_STACK),1)
Expand Down Expand Up @@ -210,6 +211,7 @@ ifeq ($(SIGN),RSA3072)
./lib/wolfssl/wolfcrypt/src/rsa.o \
./lib/wolfssl/wolfcrypt/src/asn.o \
./lib/wolfssl/wolfcrypt/src/hash.o \
./lib/wolfssl/wolfcrypt/src/wolfmath.o \
./lib/wolfssl/wolfcrypt/src/wc_port.o
CFLAGS+=-D"WOLFBOOT_SIGN_RSA3072" $(RSA_EXTRA_CFLAGS)
ifeq ($(WOLFBOOT_SMALL_STACK),1)
Expand Down Expand Up @@ -246,6 +248,7 @@ ifeq ($(SIGN),RSA4096)
./lib/wolfssl/wolfcrypt/src/rsa.o \
./lib/wolfssl/wolfcrypt/src/asn.o \
./lib/wolfssl/wolfcrypt/src/hash.o \
./lib/wolfssl/wolfcrypt/src/wolfmath.o \
./lib/wolfssl/wolfcrypt/src/wc_port.o
CFLAGS+=-D"WOLFBOOT_SIGN_RSA4096" $(RSA_EXTRA_CFLAGS)
ifeq ($(WOLFBOOT_SMALL_STACK),1)
Expand Down Expand Up @@ -438,15 +441,16 @@ ifeq ($(WOLFTPM),1)
-D"MAX_SESSION_NUM=2" -D"MAX_DIGEST_BUFFER=973" \
-D"WOLFTPM_SMALL_STACK"
CFLAGS+=-D"WOLFTPM_AUTODETECT"
# Use TPM for hashing (slow)
#CFLAGS+=-D"WOLFBOOT_HASH_TPM"
ifneq ($(SPI_FLASH),1)
# don't use spi if we're using simulator
ifeq ($(TARGET),sim)
SIM_TPM=1
endif
ifeq ($(SIM_TPM),1)
CFLAGS+=-DWOLFTPM_SWTPM -DTPM_TIMEOUT_TRIES=0
OBJS+=./lib/wolfTPM/src/tpm2_swtpm.o
# Use memory-mapped WOLFTPM on x86-64
else
# Use memory-mapped WOLFTPM on x86-64
ifeq ($(ARCH),x86_64)
CFLAGS+=-DWOLFTPM_MMIO -DWOLFTPM_EXAMPLE_HAL -DWOLFTPM_INCLUDE_IO_FILE
OBJS+=./lib/wolfTPM/hal/tpm_io_mmio.o
Expand Down
Loading

0 comments on commit a632d9d

Please sign in to comment.