Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small static psk TLS 1.2 build for microchip #7894

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
86 changes: 86 additions & 0 deletions mplabx/small-psk-build/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Set to @ if you want to suppress command echo
CMD_ECHO =

# Important directories
BUILD_DIR = ./Build

# Toolchain location and prefix
TOOLCHAIN ?=

# Tools selection
CC = $(TOOLCHAIN)gcc
AS = $(CC)
LD = $(CC)
AR = $(TOOLCHAIN)ar
NM = $(TOOLCHAIN)nm
OBJCOPY ?= $(TOOLCHAIN)objcopy
OBJDUMP ?= $(TOOLCHAIN)objdump
SIZE ?= $(TOOLCHAIN)size

# Includes
USER_SETTINGS_DIR ?= .
INC = -I$(USER_SETTINGS_DIR) \
-I../..

# Defines
DEF = -DWOLFSSL_USER_SETTINGS -DWOLFSSL_GENSEED_FORTEST
#DEF += -DUSE_LIBFUZZER
#CFLAGS = -fsanitize=fuzzer,address -g

# LD: generate map
LDFLAGS += -Wl,-Map=$(BUILD_DIR)/$(BIN).map

# LD: Entry point
LDFLAGS += -Wl,-ereset_handler

# Math lib (for DH)
LIBS = -lm

# Optimization level and place functions / data into separate sections to allow dead code removal
CFLAGS += -Os -ffunction-sections -fdata-sections -fno-builtin
# Remove unused sections and link time optimizations
LDFLAGS += -Wl,--gc-sections -flto

# Debugging
#DBGFLAGS = -ggdb -g3
CFLAGS += $(DBGFLAGS)
LDFLAGS += $(DBGFLAGS)


# FILES
SRC_C += ../../wolfcrypt/src/aes.c
SRC_C += ../../wolfcrypt/src/hmac.c
SRC_C += ../../wolfcrypt/src/random.c
SRC_C += ../../wolfcrypt/src/sha256.c
SRC_C += ../../wolfcrypt/src/misc.c
SRC_C += psk-ssl.c
SRC_C += psk-tls.c
SRC_C += example-client-psk.c


FILENAMES_C = $(notdir $(SRC_C))
FILENAMES_C := $(filter-out evp.c, $(FILENAMES_C))
OBJS_C = $(addprefix $(BUILD_DIR)/, $(FILENAMES_C:.c=.o))
vpath %.c $(dir $(SRC_C))

APP = example-client-psk

all: $(BUILD_DIR) $(BUILD_DIR)/$(APP)
@echo ""
$(CMD_ECHO) $(SIZE) $(BUILD_DIR)/$(APP)

$(BUILD_DIR):
$(CMD_ECHO) mkdir -p $(BUILD_DIR)

$(BUILD_DIR)/%.o: %.c
@echo "Compiling C file: $(notdir $<)"
$(CMD_ECHO) $(CC) $(CFLAGS) $(DEF) $(INC) -c -o $@ $<

$(BUILD_DIR)/$(APP): $(OBJS_C)
@echo "Linking object files:"
$(CMD_ECHO) $(CC) $(CFLAGS) $(DEF) $(INC) -o $@ $(OBJS_C)


clean:
rm -f $(BUILD_DIR)/*.o $(BUILD_DIR)/$(APP)

14 changes: 14 additions & 0 deletions mplabx/small-psk-build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
NOT intended for general use!

Crafted for a specific static PSK build using an AES-CBC 128 cipher suite with
TLS 1.2 client. When compiling with the Microchip toolchain additional source
files consumed a small amount of DATA memory. psk-tls.c and psk-ssl.c are the
combination of; src/ssl.c, src/tls.c, src/internal.c, src/keys.c, src/wolfio.c,
and wolfcrypt/src/kdf.c. The code has then been trimmed for the specific use
case and adjusted to flatten the call stack. The compiler used had a limit of
around 32 function calls deep for the call stack. The linker used also was
unable to effectivily trim out unused functions, hence a lot of the unused
functions were removed in psk-tls.c and psk-ssl.c.

To build the example client using the gcc compiler run `make` from this
directory and then `./Build/example-client-psk`.
Loading