diff --git a/.gitmodules b/.gitmodules index ff5aff640..abca705b7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,9 +4,6 @@ [submodule "trezor-common"] path = vendor/trezor-common url = https://github.com/trezor/trezor-common.git -[submodule "trezor-qrenc"] - path = vendor/trezor-qrenc - url = https://github.com/trezor/trezor-qrenc.git [submodule "libopencm3"] path = vendor/libopencm3 url = https://github.com/libopencm3/libopencm3.git @@ -16,3 +13,6 @@ [submodule "vendor/trezor-storage"] path = vendor/trezor-storage url = https://github.com/trezor/trezor-storage.git +[submodule "vendor/QR-Code-generator"] + path = vendor/QR-Code-generator + url = https://github.com/nayuki/QR-Code-generator.git diff --git a/Makefile.include b/Makefile.include index 11e922652..fdf6b5fca 100644 --- a/Makefile.include +++ b/Makefile.include @@ -72,7 +72,7 @@ CFLAGS += $(OPTFLAGS) \ -I$(TOP_DIR) \ -I$(TOP_DIR)gen \ -I$(TOP_DIR)vendor/trezor-crypto \ - -I$(TOP_DIR)vendor/trezor-qrenc \ + -I$(TOP_DIR)vendor/QR-Code-generator/c \ -I$(TOP_DIR)vendor/trezor-storage LDFLAGS += -L$(TOP_DIR) \ diff --git a/firmware/Makefile b/firmware/Makefile index 90e136324..672a063a4 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -82,7 +82,7 @@ OBJS += ../vendor/trezor-crypto/chacha20poly1305/rfc7539.o OBJS += ../vendor/trezor-crypto/nem.o -OBJS += ../vendor/trezor-qrenc/qr_encode.o +OBJS += ../vendor/QR-Code-generator/c/qrcodegen.o OBJS += ../vendor/trezor-storage/storage.o OBJS += ../vendor/trezor-storage/norcow.o @@ -117,7 +117,6 @@ DEBUG_LOG ?= 0 CFLAGS += -Wno-sequence-point CFLAGS += -I../vendor/nanopb -Iprotob -DPB_FIELD_16BIT=1 -CFLAGS += -DQR_MAX_VERSION=0 CFLAGS += -DDEBUG_LINK=$(DEBUG_LINK) CFLAGS += -DDEBUG_LOG=$(DEBUG_LOG) CFLAGS += -DSCM_REVISION='"$(shell git rev-parse HEAD | sed 's:\(..\):\\x\1:g')"' diff --git a/firmware/layout2.c b/firmware/layout2.c index 1080ef278..1a5b98004 100644 --- a/firmware/layout2.c +++ b/firmware/layout2.c @@ -27,7 +27,7 @@ #include "bitmaps.h" #include "string.h" #include "util.h" -#include "qr_encode.h" +#include "qrcodegen.h" #include "timer.h" #include "bignum.h" #include "secp256k1.h" @@ -553,6 +553,8 @@ void layoutResetWord(const char *word, int pass, int word_pos, bool last) oledRefresh(); } +#define QR_MAX_VERSION 9 + void layoutAddress(const char *address, const char *desc, bool qrcode, bool ignorecase, const uint32_t *address_n, size_t address_n_count, bool address_is_account) { if (layoutLast != layoutAddress) { @@ -564,7 +566,6 @@ void layoutAddress(const char *address, const char *desc, bool qrcode, bool igno uint32_t addrlen = strlen(address); if (qrcode) { - static unsigned char bitdata[QR_MAX_BITDATA]; char address_upcase[addrlen + 1]; if (ignorecase) { for (uint32_t i = 0; i < addrlen + 1; i++) { @@ -572,16 +573,28 @@ void layoutAddress(const char *address, const char *desc, bool qrcode, bool igno address[i] + 'A' - 'a' : address[i]; } } - int side = qr_encode(addrlen <= (ignorecase ? 60 : 40) ? QR_LEVEL_M : QR_LEVEL_L, 0, - ignorecase ? address_upcase : address, 0, bitdata); + uint8_t codedata[qrcodegen_BUFFER_LEN_FOR_VERSION(QR_MAX_VERSION)]; + uint8_t tempdata[qrcodegen_BUFFER_LEN_FOR_VERSION(QR_MAX_VERSION)]; + + int side = 0; + if (qrcodegen_encodeText( + ignorecase ? address_upcase : address, + tempdata, + codedata, + qrcodegen_Ecc_LOW, + qrcodegen_VERSION_MIN, + QR_MAX_VERSION, + qrcodegen_Mask_AUTO, + true)) { + side = qrcodegen_getSize(codedata); + } oledInvert(0, 0, 63, 63); if (side > 0 && side <= 29) { int offset = 32 - side; for (int i = 0; i < side; i++) { for (int j = 0; j< side; j++) { - int a = j * side + i; - if (bitdata[a / 8] & (1 << (7 - a % 8))) { + if (qrcodegen_getModule(codedata, i, j)) { oledBox(offset + i * 2, offset + j * 2, offset + 1 + i * 2, offset + 1 + j * 2, false); } @@ -591,8 +604,7 @@ void layoutAddress(const char *address, const char *desc, bool qrcode, bool igno int offset = 32 - (side / 2); for (int i = 0; i < side; i++) { for (int j = 0; j< side; j++) { - int a = j * side + i; - if (bitdata[a / 8] & (1 << (7 - a % 8))) { + if (qrcodegen_getModule(codedata, i, j)) { oledClearPixel(offset + i, offset + j); } } diff --git a/vendor/QR-Code-generator b/vendor/QR-Code-generator new file mode 160000 index 000000000..40d24f38a --- /dev/null +++ b/vendor/QR-Code-generator @@ -0,0 +1 @@ +Subproject commit 40d24f38aa0a8180b271b6c88be8633f842ed9d4 diff --git a/vendor/trezor-qrenc b/vendor/trezor-qrenc deleted file mode 160000 index 4da44cacb..000000000 --- a/vendor/trezor-qrenc +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4da44cacb7bd69aa297bafe4a41c498a050225a4