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

Modify to work with new toolchain, fix x509 decode #64

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ script:
# Copy the library into Arduino core
- cp bin/libaxtls.a $ESP8266_ARDUINO_DIR/tools/sdk/lib/libaxtls.a
# Try building examples in ESP8266WiFi library from the ESP8266 Arduino core
- /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16
# - /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16
- sleep 3
- export DISPLAY=:1.0
- export PATH="$HOME/arduino_ide:$PATH"
Expand All @@ -36,7 +36,8 @@ script:
- source tests/common.sh
- arduino --board esp8266com:esp8266:generic --save-prefs
- arduino --get-pref sketchbook.path
- build_sketches $HOME/arduino_ide $ESP8266_ARDUINO_DIR/libraries/ESP8266WiFi/examples/HTTPSRequest "-l $ESP8266_ARDUINO_DIR/libraries" 1 0
- mkdir /tmp/cache
- cache_dir=/tmp/cache build_sketches $HOME/arduino_ide $ESP8266_ARDUINO_DIR/libraries/ESP8266WiFi/examples/HTTPSRequest "-l $ESP8266_ARDUINO_DIR/libraries" 1 0 lm2f
# Feel free to add more test cases (for other environments) here

notifications:
Expand Down
17 changes: 14 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,36 @@ LDFLAGS += -L$(XTENSA_LIBS)/lib \
-L$(XTENSA_LIBS)/arch/lib \


CFLAGS+=-std=c99 -DESP8266
CFLAGS +=-std=gnu99 -DESP8266

CFLAGS += -Wall -Os -g -O2 -Wpointer-arith -Wl,-EL -nostdlib -mlongcalls -mno-text-section-literals -D__ets__ -DICACHE_FLASH

CFLAGS += -ffunction-sections -fdata-sections

CFLAGS += -fdebug-prefix-map=$(PWD)= -fdebug-prefix-map=$(TOOLCHAIN_DIR)=xtensa-lx106-elf -gno-record-gcc-switches

WITH_PGM_READ_HELPER ?= 0

MFORCE32 := $(shell $(CC) --help=target | grep mforce-l32)
ifneq ($(MFORCE32),)
# If the compiler supports the -mforce-l32 flag, the compiler will generate correct code for loading
# 16- and 8-bit constants from program memory. So in the code we can directly access the arrays
# placed into program memory.
CFLAGS += -mforce-l32
ifeq ($(WITH_PGM_READ_HELPER),0)
CFLAGS += -mforce-l32
else
# Ignore the mforge flag, the user forded this off
CFLAGS += -DWITH_PGM_READ_HELPER
endif
else
# Otherwise we need to use a helper function to load 16- and 8-bit constants from program memory.
# Otherwise we need to use a helper function to load 16- and 8-bit constants from program memory.
CFLAGS += -DWITH_PGM_READ_HELPER
endif

# Check to see if memcpy_P/etc. are already defined in the standard libraries by seeing if build fails
HAS_PROGMEM_FCNS :=$(shell $(CC) -std=gnu99 $(CFLAGS) $(CPPFLAGS) -c ssl/os_port.c -o /dev/null 2>/dev/null; echo $$?)
CFLAGS += -DHAS_PROGMEM_FCNS=$(HAS_PROGMEM_FCNS)

BIN_DIR := bin
AXTLS_AR := $(BIN_DIR)/libaxtls.a

Expand Down
2 changes: 1 addition & 1 deletion crypto/sha256.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ void SHA256_Final(uint8_t *digest, SHA256_CTX *ctx)
uint8_t msglen[8];
#ifdef WITH_PGM_READ_HELPER
uint8_t sha256_padding_ram[64];
memcpy(sha256_padding_ram, sha256_padding, 64);
memcpy_P(sha256_padding_ram, sha256_padding, 64);
#endif

high = (ctx->total[0] >> 29)
Expand Down
8 changes: 7 additions & 1 deletion ssl/os_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ void ax_wdt_feed();
#define ax_array_read_u8(x, y) x[y]
#else

#if (HAS_PROGMEM_FCNS==0)
static inline uint8_t pgm_read_byte(const void* addr) {
register uint32_t res;
__asm__("extui %0, %1, 0, 2\n" /* Extract offset within word (in bytes) */
Expand All @@ -115,6 +116,7 @@ static inline uint8_t pgm_read_byte(const void* addr) {
:);
return (uint8_t) res; /* This masks the lower byte from the returned word */
}
#endif

#define ax_array_read_u8(x, y) pgm_read_byte((x)+(y))
#endif //WITH_PGM_READ_HELPER
Expand All @@ -123,8 +125,11 @@ static inline uint8_t pgm_read_byte(const void* addr) {
#undef printf
#endif
//#define printf(...) ets_printf(__VA_ARGS__)
#undef PSTR // Defined in Arduino core
#define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0];}))
#define PGM_VOID_P const void *

#if (HAS_PROGMEM_FCNS==0)
static inline void* memcpy_P(void* dest, PGM_VOID_P src, size_t count) {
const uint8_t* read = (const uint8_t*)(src);
uint8_t* write = (uint8_t*)(dest);
Expand Down Expand Up @@ -153,9 +158,10 @@ static inline int memcmp_P(const void *a1, const void *b1, size_t len) {
}
return 0;
}
#define strcpy_P(dst, src) do { static const char fstr[] PROGMEM = src; memcpy_P(dst, fstr, sizeof(src)); } while (0)
#endif

#define printf(fmt, ...) do { static const char fstr[] PROGMEM = fmt; char rstr[sizeof(fmt)]; memcpy_P(rstr, fstr, sizeof(rstr)); ets_printf(rstr, ##__VA_ARGS__); } while (0)
#define strcpy_P(dst, src) do { static const char fstr[] PROGMEM = src; memcpy_P(dst, fstr, sizeof(src)); } while (0)

// Copied from ets_sys.h to avoid compile warnings
extern int ets_printf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
Expand Down
2 changes: 1 addition & 1 deletion ssl/x509.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ static bigint *sig_verify(BI_CTX *ctx, const uint8_t *sig, int sig_len, uint8_t
break;
}
if (sig_prefix)
hash_len = sig_prefix[sig_prefix_size - 1];
hash_len = pgm_read_byte(&sig_prefix[sig_prefix_size - 1]);

/* check length (#A) */
if (sig_len < 2 + 8 + 1 + sig_prefix_size + hash_len)
Expand Down