diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..d65f1ce --- /dev/null +++ b/.clang-format @@ -0,0 +1,18 @@ +--- +BasedOnStyle: Google +IndentWidth: 4 +Language: Cpp +ColumnLimit: 100 +PointerAlignment: Right +AlignAfterOpenBracket: Align +AlignConsecutiveMacros: true +AllowAllParametersOfDeclarationOnNextLine: false +SortIncludes: false +SpaceAfterCStyleCast: true +AllowShortCaseLabelsOnASingleLine: false +AllowAllArgumentsOnNextLine: false +AllowShortBlocksOnASingleLine: Never +AllowShortFunctionsOnASingleLine: None +BinPackArguments: false +BinPackParameters: false +--- diff --git a/.github/workflows/build_and_functional_tests.yml b/.github/workflows/build_and_functional_tests.yml new file mode 100644 index 0000000..4d300d0 --- /dev/null +++ b/.github/workflows/build_and_functional_tests.yml @@ -0,0 +1,35 @@ +name: Build and run functional tests using ragger through reusable workflow + +# This workflow will build the app and then run functional tests using the Ragger framework upon Speculos emulation. +# It calls a reusable workflow developed by Ledger's internal developer team to build the application and upload the +# resulting binaries. +# It then calls another reusable workflow to run the Ragger tests on the compiled application binary. +# +# The build part of this workflow is mandatory, this ensures that the app will be deployable in the Ledger App Store. +# While the test part of this workflow is optional, having functional testing on your application is mandatory and this workflow and +# tooling environment is meant to be easy to use and adapt after forking your application + +on: + workflow_dispatch: + inputs: + golden_run: + type: choice + required: true + default: "Raise an error (default)" + description: CI behavior if the test snapshots are different than expected. + options: + - "Raise an error (default)" + - "Open a PR" + push: + branches: + - master + - main + - develop + pull_request: + +jobs: + build_application: + name: Build application using the reusable workflow + uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_build.yml@v1 + with: + upload_app_binaries_artifact: "app_boilerplate_binaries" diff --git a/.github/workflows/coding_style_checks.yml b/.github/workflows/coding_style_checks.yml new file mode 100644 index 0000000..0667c34 --- /dev/null +++ b/.github/workflows/coding_style_checks.yml @@ -0,0 +1,25 @@ +name: Run coding style check through reusable workflow + +# This workflow will run linting checks to ensure a level of uniformization among all Ledger applications. +# +# The presence of this workflow is mandatory as a minimal level of linting is required. +# You are however free to modify the content of the .clang-format file and thus the coding style of your application. +# We simply ask you to not diverge too much from the linting of the Boilerplate application. + +on: + workflow_dispatch: + push: + branches: + - master + - main + - develop + pull_request: + +jobs: + check_linting: + name: Check linting using the reusable workflow + uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_lint.yml@v1 + with: + source: "./src" + extensions: "h,c" + version: 18 diff --git a/.gitignore b/.gitignore index fc1a335..808ff7f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,10 @@ bin +build debug dep obj +output-scan-build +.vscode src/glyphs.c src/glyphs.h customCA.key diff --git a/Makefile b/Makefile index 75cd78c..0d5e7a4 100644 --- a/Makefile +++ b/Makefile @@ -1,243 +1,171 @@ -#******************************************************************************* -# Ledger App -# (c) 2017 Ledger +# **************************************************************************** +# Ledger App Boilerplate +# (c) 2023 Ledger SAS. # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#******************************************************************************* - -ifeq ($(BOLOS_SDK),) -$(error Environment variable BOLOS_SDK is not set) -endif -ifeq (customCA.key,$(wildcard customCA.key)) - SCP_PRIVKEY=`cat customCA.key` -endif -include $(BOLOS_SDK)/Makefile.defines - -# Default to shared app -ifeq ($(APP_TYPE),) -APP_TYPE=shared -endif - -# Default to library app -ifndef COIN -COIN=nano -endif - -APP_LOAD_PARAMS = --curve ed25519 $(COMMON_LOAD_PARAMS) -ALL_PATH_PARAMS = - -# Nano coin config -NANO_APP_NAME = "Nano" -NANO_PATH_PARAM = --path "44'/165'" -NANO_COIN_TYPE = LIBN_COIN_TYPE_NANO -ALL_PATH_PARAMS += $(NANO_PATH_PARAM) - -# Banano coin config -BANANO_APP_NAME = "Banano" -BANANO_PATH_PARAM = --path "44'/198'" -BANANO_COIN_TYPE = LIBN_COIN_TYPE_BANANO -ALL_PATH_PARAMS += $(BANANO_PATH_PARAM) - -# NOS coin config -NOS_APP_NAME = "NOS" -NOS_PATH_PARAM = --path "44'/229'" -NOS_COIN_TYPE = LIBN_COIN_TYPE_NOS -ALL_PATH_PARAMS += $(NOS_PATH_PARAM) - -ifeq ($(APP_TYPE), standalone) - ifeq ($(TARGET_NAME),TARGET_NANOX) -LIB_LOAD_FLAGS = --appFlags 0x200 -APP_LOAD_FLAGS = --appFlags 0x200 - else -LIB_LOAD_FLAGS = --appFlags 0x00 -APP_LOAD_FLAGS = --appFlags 0x00 - endif -DEFINES += IS_STANDALONE_APP - -else ifeq ($(APP_TYPE), shared) - ifeq ($(TARGET_NAME),TARGET_NANOX) -LIB_LOAD_FLAGS = --appFlags 0xA00 -APP_LOAD_FLAGS = --appFlags 0x200 --dep Nano - else -LIB_LOAD_FLAGS = --appFlags 0x800 -APP_LOAD_FLAGS = --appFlags 0x00 --dep Nano - endif -DEFINES += SHARED_LIBRARY_NAME=\"$(NANO_APP_NAME)\" -DEFINES += HAVE_COIN_NANO -DEFINES += HAVE_COIN_BANANO -DEFINES += HAVE_COIN_NOS - -else -ifneq ($(MAKECMDGOALS),listvariants) -$(error Unsupported APP_TYPE - use standalone, shared) -endif -endif - -ifeq ($(COIN),nano) -APPNAME = $(NANO_APP_NAME) -ifeq ($(APP_TYPE), shared) -APP_LOAD_PARAMS += $(LIB_LOAD_FLAGS) $(ALL_PATH_PARAMS) -DEFINES += IS_SHARED_LIBRARY -else -APP_LOAD_PARAMS += $(LIB_LOAD_FLAGS) $(NANO_PATH_PARAM) -endif -DEFINES += HAVE_COIN_NANO -DEFINES += DEFAULT_COIN_TYPE=$(NANO_COIN_TYPE) - -else ifeq ($(COIN),banano) -APPNAME = $(BANANO_APP_NAME) -APP_LOAD_PARAMS += $(APP_LOAD_FLAGS) $(BANANO_PATH_PARAM) -DEFINES += HAVE_COIN_BANANO -DEFINES += DEFAULT_COIN_TYPE=$(BANANO_COIN_TYPE) - -else ifeq ($(COIN),nos) -APPNAME = $(NOS_APP_NAME) -APP_LOAD_PARAMS += $(APP_LOAD_FLAGS) $(NOS_PATH_PARAM) -DEFINES += HAVE_COIN_NOS -DEFINES += DEFAULT_COIN_TYPE=$(NOS_COIN_TYPE) - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# **************************************************************************** + +######################################## +# Coin configuration # +######################################## +NANO_COIN_NAME = nano +BANANO_COIN_NAME = banano +NOS_COIN_NAME = nos + +COIN ?= $(NANO_COIN_NAME) + +ifeq ($(COIN),$(NANO_COIN_NAME)) + COIN_NAME = Nano + COIN_PATH = "44'/165'" + DEFINES += COIN_TYPE=LIBN_COIN_TYPE_NANO +else ifeq ($(COIN),$(BANANO_COIN_NAME)) + COIN_NAME = Banano + COIN_PATH = "44'/198'" + DEFINES += COIN_TYPE=LIBN_COIN_TYPE_BANANO +else ifeq ($(COIN),$(NOS_COIN_NAME)) + COIN_NAME = NOS + COIN_PATH = "44'/229'" + DEFINES += COIN_TYPE=LIBN_COIN_TYPE_NOS else ifeq ($(filter clean listvariants,$(MAKECMDGOALS)),) -$(error Unsupported COIN - use nano, banano, nos) + $(error unsupported COIN $(COIN); expected nano, banano, or nos) endif -APPVERSION_M=1 -APPVERSION_N=2 -APPVERSION_P=8 -APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P) - -MAX_ADPU_INPUT_SIZE=217 -MAX_ADPU_OUTPUT_SIZE=98 - -ifeq ($(TARGET_NAME),TARGET_BLUE) -ICONNAME=blue_icon_$(COIN).gif -else ifeq ($(TARGET_NAME),TARGET_NANOS) -ICONNAME=nanos_icon_$(COIN).gif +######################################## +# Boilerplate # +######################################## +ifeq ($(BOLOS_SDK),) + $(error Environment variable BOLOS_SDK is not set) +endif + +include $(BOLOS_SDK)/Makefile.target + +######################################## +# Mandatory configuration # +######################################## +# Application name +APPNAME = $(COIN_NAME) + +# Application version +APPVERSION_M = 1 +APPVERSION_N = 3 +APPVERSION_P = 0 +APPVERSION = "$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)" + +# Application source files +APP_SOURCE_PATH += src + +# Application icons following guidelines: +# https://developers.ledger.com/docs/embedded-app/design-requirements/#device-icon +ICON_NANOX = icons/$(COIN)_14px.gif +ICON_NANOSP = icons/$(COIN)_14px.gif +ICON_NANOS = icons/$(COIN)_16px.gif +#ICON_STAX = icons/app_boilerplate_32px.gif +#ICON_FLEX = icons/app_boilerplate_40px.gif +ICON_BLUE = icons/${COIN}_50px.gif +#ICON_APEX_P = icons/app_boilerplate_32px_apex.png + +# Application allowed derivation curves. +# Possibles curves are: secp256k1, secp256r1, ed25519 and bls12381g1 +# If your app needs it, you can specify multiple curves by using: +# `CURVE_APP_LOAD_PARAMS = ` +CURVE_APP_LOAD_PARAMS = ed25519 + +# Application allowed derivation paths. +# You should request a specific path for your app. +# This serve as an isolation mechanism. +# Most application will have to request a path according to the BIP-0044 +# and SLIP-0044 standards. +# If your app needs it, you can specify multiple path by using: +# `PATH_APP_LOAD_PARAMS = "44'/1'" "45'/1'"` +PATH_APP_LOAD_PARAMS = $(COIN_PATH) + +# Setting to allow building variant applications +# - is the name of the parameter which should be set +# to specify the variant that should be build. +# - a list of variant that can be build using this app code. +# * It must at least contains one value. +# * Values can be the app ticker or anything else but should be unique. +VARIANT_PARAM = COIN +VARIANT_VALUES = $(NANO_COIN_NAME) $(BANANO_COIN_NAME) $(NOS_COIN_NAME) + +# Enabling DEBUG flag will enable PRINTF and disable optimizations +#DEBUG = 1 + +######################################## +# Application custom permissions # +######################################## +# See SDK `include/appflags.h` for the purpose of each permission +#HAVE_APPLICATION_FLAG_DERIVE_MASTER = 1 +#HAVE_APPLICATION_FLAG_GLOBAL_PIN = 1 +#HAVE_APPLICATION_FLAG_BOLOS_SETTINGS = 1 +#HAVE_APPLICATION_FLAG_LIBRARY = 1 + +######################################## +# Application communication interfaces # +######################################## +ENABLE_BLUETOOTH = 1 +#ENABLE_NFC = 1 +ENABLE_NBGL_FOR_NANO_DEVICES = 0 + +######################################## +# NBGL custom features # +######################################## +#ENABLE_NBGL_QRCODE = 1 +#ENABLE_NBGL_KEYBOARD = 1 +#ENABLE_NBGL_KEYPAD = 1 + +######################################## +# Features disablers # +######################################## +# These advanced settings allow to disable some feature that are by +# default enabled in the SDK `Makefile.standard_app`. +#DISABLE_STANDARD_APP_FILES = 1 +#DISABLE_DEFAULT_IO_SEPROXY_BUFFER_SIZE = 1 # To allow custom size declaration +#DISABLE_STANDARD_APP_DEFINES = 1 # Will set all the following disablers +#DISABLE_STANDARD_SNPRINTF = 1 +#DISABLE_STANDARD_USB = 1 +#DISABLE_STANDARD_WEBUSB = 1 +#DISABLE_DEBUG_LEDGER_ASSERT = 1 +#DISABLE_DEBUG_THROW = 1 + +######################################## +# Nano S (Legacy) # +######################################## +ifeq ($(TARGET_NAME),TARGET_NANOS) + DEFINES += HAVE_UX_LEGACY else -ICONNAME=nanox_icon_$(COIN).gif -endif - -################ -# Default rule # -################ - -all: default - -############ -# Platform # -############ - -DEFINES += OS_IO_SEPROXYHAL IO_SEPROXYHAL_BUFFER_SIZE_B=300 -DEFINES += HAVE_BAGL HAVE_SPRINTF -DEFINES += HAVE_IO_USB HAVE_L4_USBLIB IO_USB_MAX_ENDPOINTS=4 IO_HID_EP_LENGTH=64 HAVE_USB_APDU -DEFINES += APP_MAJOR_VERSION=$(APPVERSION_M) APP_MINOR_VERSION=$(APPVERSION_N) APP_PATCH_VERSION=$(APPVERSION_P) -DEFINES += MAX_ADPU_OUTPUT_SIZE=$(MAX_ADPU_OUTPUT_SIZE) - -# U2F -DEFINES += HAVE_IO_U2F -DEFINES += U2F_PROXY_MAGIC=\"mRB\" -DEFINES += USB_SEGMENT_SIZE=64 -DEFINES += BLE_SEGMENT_SIZE=32 #max MTU, min 20 -DEFINES += U2F_REQUEST_TIMEOUT=10000 # 10 seconds -DEFINES += UNUSED\(x\)=\(void\)x -DEFINES += APPVERSION=\"$(APPVERSION)\" - -# WebUSB -#WEBUSB_URL = www.ledgerwallet.com -#DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=$(shell echo -n $(WEBUSB_URL) | wc -c) WEBUSB_URL=$(shell echo -n $(WEBUSB_URL) | sed -e "s/./\\\'\0\\\',/g") -DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=0 WEBUSB_URL="" - -ifneq ($(TARGET_NAME),TARGET_NANOS) -DEFINES += HAVE_GLO096 -DEFINES += HAVE_BAGL BAGL_WIDTH=128 BAGL_HEIGHT=64 -DEFINES += HAVE_BAGL_ELLIPSIS # long label truncation feature -DEFINES += HAVE_BAGL_FONT_OPEN_SANS_REGULAR_11PX -DEFINES += HAVE_BAGL_FONT_OPEN_SANS_EXTRABOLD_11PX -DEFINES += HAVE_BAGL_FONT_OPEN_SANS_LIGHT_16PX -DEFINES += HAVE_UX_FLOW + DEFINES += HAVE_UX_FLOW endif -ifeq ($(TARGET_NAME),TARGET_NANOX) -# BLE -DEFINES += HAVE_BLE BLE_COMMAND_TIMEOUT_MS=2000 -DEFINES += HAVE_BLE_APDU # basic ledger apdu transport over BLE +ifeq (customCA.key,$(wildcard customCA.key)) + SCP_PRIVKEY=`cat customCA.key` endif -# Enabling debug PRINTF -DEBUG = 0 -ifneq ($(DEBUG),0) +##################################################################### +# MISC # +##################################################################### - ifeq ($(TARGET_NAME),TARGET_NANOS) - DEFINES += HAVE_PRINTF PRINTF=screen_printf - else - DEFINES += HAVE_PRINTF PRINTF=mcu_usb_printf - endif -else - DEFINES += PRINTF\(...\)= -endif - -############## -# Compiler # -############## -ifneq ($(BOLOS_ENV),) -$(info BOLOS_ENV=$(BOLOS_ENV)) -CLANGPATH := $(BOLOS_ENV)/clang-arm-fropi/bin/ -GCCPATH := $(BOLOS_ENV)/gcc-arm-none-eabi-5_3-2016q1/bin/ -else -$(info BOLOS_ENV is not set: falling back to CLANGPATH and GCCPATH) -endif -ifeq ($(CLANGPATH),) -$(info CLANGPATH is not set: clang will be used from PATH) +ifeq ($(TARGET_NAME),TARGET_BLUE) +ICONNAME ?= $(ICON_BLUE) endif -ifeq ($(GCCPATH),) -$(info GCCPATH is not set: arm-none-eabi-* will be used from PATH) +ifeq ($(TARGET_NAME),TARGET_NANOS) +ICONNAME ?= $(ICON_NANOS) endif -CC := $(CLANGPATH)clang - -#CFLAGS += -O0 -CFLAGS += -O3 -Os -Wno-typedef-redefinition - -AS := $(GCCPATH)arm-none-eabi-gcc - -LD := $(GCCPATH)arm-none-eabi-gcc -LDFLAGS += -O3 -Os -LDLIBS += -lm -lgcc -lc - -# import rules to compile glyphs(/pone) -include $(BOLOS_SDK)/Makefile.glyphs - -### variables processed by the common makefile.rules of the SDK to grab source files and include dirs -APP_SOURCE_PATH += src -SDK_SOURCE_PATH += lib_stusb -SDK_SOURCE_PATH += lib_stusb_impl -SDK_SOURCE_PATH += lib_u2f -SDK_SOURCE_PATH += lib_ux - -ifeq ($(TARGET_NAME),TARGET_NANOX) -SDK_SOURCE_PATH += lib_blewbxx lib_blewbxx_impl -endif - -load: all - python -m ledgerblue.loadApp $(APP_LOAD_PARAMS) - -delete: - python -m ledgerblue.deleteApp $(COMMON_DELETE_PARAMS) - -# import generic rules from the sdk -include $(BOLOS_SDK)/Makefile.rules +# variables processed by the common makefile.rules of the SDK to grab source files and include dirs +SDK_SOURCE_PATH += lib_ux -#add dependency on custom makefile filename +# add dependency on custom makefile filename dep/%.d: %.c Makefile -listvariants: - @echo VARIANTS COIN nano banano nos +include $(BOLOS_SDK)/Makefile.standard_app diff --git a/README.md b/README.md index b4d5cc2..b3a5148 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,19 @@ -# blue-app-nano +# ledger-app-nano -$NANO wallet application for Ledger Nano S & Ledger Blue devices. +Nano ($XNO) wallet application for Ledger Nano S, Ledger Nano S+, and Ledger Blue devices. ## For users -You can install the Nano app from the Ledger Manager. If it doesn't show up for you in Ledger Manager, make sure that your Ledger device firmware has been upgraded to the latest version. See also the Ledger own [guide on installing and using the app](https://support.ledgerwallet.com/hc/en-us/articles/360005459013-Install-and-use-Nano). +Install the Nano app from the Ledger Live device manager. See Ledger's [guide on installing apps](https://support.ledger.com/article/4404382258961-zd). -To interact with the Nano network, you need to use a wallet software that has integrated Ledger support. Currently the following wallets have integrated Ledger support: +Interacting with the Nano network requires wallet software with integrated Ledger support. - [Nault.cc](https://nault.cc/) ([user guide](https://docs.nault.cc/2020/08/04/ledger-guide.html)) -_If a wallet is missing from above, please [create an issue](https://github.com/roosmaa/blue-app-nano/issues/new) and it will be added to this list._ +_If a wallet should be added to this list, please [create an issue](https://github.com/LedgerHQ/app-nano/issues/new)._ -## For wallet developers +## For developers -If you wish to integrate your $NANO web wallet with Ledger, then you can use the [hw-app-nano](https://github.com/roosmaa/hw-app-nano/) JavaScript library that works in tandem with [ledgerjs](https://github.com/LedgerHQ/ledgerjs) library. +Browser-based wallets can integrate Ledger device support using the [hw-app-nano](https://github.com/roosmaa/hw-app-nano/) JavaScript library built using [LedgerJS](https://github.com/LedgerHQ/ledger-live/tree/develop/libs/ledgerjs). -For desktop wallet apps, there is no integration library at the time. But you can still interact with the device using the binary protocol detailed in [the ADPU documentation](https://github.com/roosmaa/blue-app-nano/blob/master/doc/nano.md). +Wallets of any type can interact with the device directly using the binary protocol detailed in the [APDU documentation](https://github.com/LedgerHQ/app-nano/blob/master/doc/nano.md). diff --git a/banano.png b/banano.png deleted file mode 100644 index b3bf723..0000000 Binary files a/banano.png and /dev/null differ diff --git a/glyphs/blue_badge_nano.gif b/glyphs/blue_badge_nano.gif index 732e511..27759cb 100644 Binary files a/glyphs/blue_badge_nano.gif and b/glyphs/blue_badge_nano.gif differ diff --git a/glyphs/blue_icon_toggle_on.gif b/glyphs/blue_icon_toggle_on.gif new file mode 100644 index 0000000..6de4adf Binary files /dev/null and b/glyphs/blue_icon_toggle_on.gif differ diff --git a/glyphs/blue_icon_toggle_on_banano.gif b/glyphs/blue_icon_toggle_on_banano.gif deleted file mode 100644 index fe517dd..0000000 Binary files a/glyphs/blue_icon_toggle_on_banano.gif and /dev/null differ diff --git a/glyphs/blue_icon_toggle_on_nano.gif b/glyphs/blue_icon_toggle_on_nano.gif deleted file mode 100644 index 2d3ff05..0000000 Binary files a/glyphs/blue_icon_toggle_on_nano.gif and /dev/null differ diff --git a/glyphs/blue_icon_toggle_on_nos.gif b/glyphs/blue_icon_toggle_on_nos.gif deleted file mode 100644 index a58dc9e..0000000 Binary files a/glyphs/blue_icon_toggle_on_nos.gif and /dev/null differ diff --git a/glyphs/nanos_badge_nano.gif b/glyphs/nanos_badge_nano.gif index 9541b57..a73a0a1 100644 Binary files a/glyphs/nanos_badge_nano.gif and b/glyphs/nanos_badge_nano.gif differ diff --git a/icons/banano_100px.png b/icons/banano_100px.png new file mode 100644 index 0000000..1a24019 Binary files /dev/null and b/icons/banano_100px.png differ diff --git a/nanox_icon_banano.gif b/icons/banano_14px.gif similarity index 100% rename from nanox_icon_banano.gif rename to icons/banano_14px.gif diff --git a/nanos_icon_banano.gif b/icons/banano_16px.gif similarity index 100% rename from nanos_icon_banano.gif rename to icons/banano_16px.gif diff --git a/blue_icon_banano.gif b/icons/blue_icon_banano_50px.gif similarity index 100% rename from blue_icon_banano.gif rename to icons/blue_icon_banano_50px.gif diff --git a/blue_icon_nano.gif b/icons/blue_icon_nano_50px.gif similarity index 100% rename from blue_icon_nano.gif rename to icons/blue_icon_nano_50px.gif diff --git a/blue_icon_nos.gif b/icons/blue_icon_nos_50px.gif similarity index 100% rename from blue_icon_nos.gif rename to icons/blue_icon_nos_50px.gif diff --git a/icons/nano_100px.png b/icons/nano_100px.png new file mode 100644 index 0000000..d925e17 Binary files /dev/null and b/icons/nano_100px.png differ diff --git a/icons/nano_14px.gif b/icons/nano_14px.gif new file mode 100644 index 0000000..8f2d974 Binary files /dev/null and b/icons/nano_14px.gif differ diff --git a/icons/nano_16px.gif b/icons/nano_16px.gif new file mode 100644 index 0000000..26af64f Binary files /dev/null and b/icons/nano_16px.gif differ diff --git a/icons/nano_50px.gif b/icons/nano_50px.gif new file mode 100644 index 0000000..15c7e25 Binary files /dev/null and b/icons/nano_50px.gif differ diff --git a/nos.png b/icons/nos_100px.png similarity index 100% rename from nos.png rename to icons/nos_100px.png diff --git a/nanox_icon_nos.gif b/icons/nos_14px.gif similarity index 100% rename from nanox_icon_nos.gif rename to icons/nos_14px.gif diff --git a/nanos_icon_nos.gif b/icons/nos_16px.gif similarity index 100% rename from nanos_icon_nos.gif rename to icons/nos_16px.gif diff --git a/nano.png b/nano.png deleted file mode 100644 index 305f522..0000000 Binary files a/nano.png and /dev/null differ diff --git a/nanos_icon_nano.gif b/nanos_icon_nano.gif deleted file mode 100644 index ca5c254..0000000 Binary files a/nanos_icon_nano.gif and /dev/null differ diff --git a/nanox_icon_nano.gif b/nanox_icon_nano.gif deleted file mode 100644 index f707c29..0000000 Binary files a/nanox_icon_nano.gif and /dev/null differ diff --git a/src/blake2b.h b/src/blake2b.h index a4e7518..b3cc85d 100644 --- a/src/blake2b.h +++ b/src/blake2b.h @@ -1,17 +1,12 @@ -#ifndef BLAKE2B_H -#define BLAKE2B_H +#pragma once -#include "os.h" #include "cx.h" +#include "os.h" typedef cx_blake2b_t blake2b_ctx; -int blake2b_init(blake2b_ctx *ctx, size_t outlen, - const void *key, size_t keylen); - -void blake2b_update(blake2b_ctx *ctx, - const void *in, size_t inlen); +cx_err_t blake2b_init(blake2b_ctx *ctx, size_t outlen); -void blake2b_final(blake2b_ctx *ctx, void *out); +cx_err_t blake2b_update(blake2b_ctx *ctx, const void *in, size_t inlen); -#endif // BLAKE2B_H +cx_err_t blake2b_final(blake2b_ctx *ctx, void *out); diff --git a/src/blake2b_shim.c b/src/blake2b_shim.c index b11ac08..6bd0e4d 100644 --- a/src/blake2b_shim.c +++ b/src/blake2b_shim.c @@ -2,17 +2,14 @@ #include "os.h" #include "cx.h" -int blake2b_init(blake2b_ctx *ctx, size_t outlen, - const void *key, size_t keylen) { - cx_blake2b_init(ctx, outlen * 8); - return 0; +cx_err_t blake2b_init(blake2b_ctx *ctx, size_t outlen) { + return cx_blake2b_init_no_throw(ctx, outlen * 8); } -void blake2b_update(blake2b_ctx *ctx, - const void *in, size_t inlen) { - cx_hash(&ctx->header, 0, (void *)in, inlen, NULL, 0); +cx_err_t blake2b_update(blake2b_ctx *ctx, const void *in, size_t inlen) { + return cx_hash_no_throw(&ctx->header, 0, (void *) in, inlen, NULL, 0); } -void blake2b_final(blake2b_ctx *ctx, void *out) { - cx_hash(&ctx->header, CX_LAST, NULL, 0, out, ctx->ctx.outlen); +cx_err_t blake2b_final(blake2b_ctx *ctx, void *out) { + return cx_hash_no_throw(&ctx->header, CX_LAST, NULL, 0, out, ctx->ctx.outlen); } diff --git a/src/coins.c b/src/coins.c index ca63e47..8ea7dd8 100644 --- a/src/coins.c +++ b/src/coins.c @@ -3,103 +3,98 @@ libn_coin_conf_t libn_coin_conf_D; -REGISTER_COINS( - #if defined(HAVE_COIN_NANO) - COIN(LIBN_COIN_TYPE_NANO, { - .coinName = "Nano", - #if defined(TARGET_BLUE) - .coinBadge = &C_blue_badge_nano, - #else - .coinBadge = &C_nanos_badge_nano, - #endif - .bip32Prefix = { HARDENED(44), HARDENED(165) }, - .addressPrimaryPrefix = "nano_", - .addressSecondaryPrefix = "xrb_", - .addressDefaultPrefix = LIBN_PRIMARY_PREFIX, - .defaultUnit = "NANO", - .defaultUnitScale = 30, // 1 Mnano = 10^30 raw - #if defined(TARGET_BLUE) - .colorBackground = 0xF9F9F9, - .colorForeground = 0x000000, - .colorAltBackground = 0x4A90E2, - .colorAltForeground = 0xE0FFFF, - .colorRejectBackground = 0xC6C6C6, - .colorRejectForeground = 0x000000, - .colorRejectOverBackground = 0xADADAD, - .colorRejectOverForeground = 0x000000, - .colorConfirmBackground = 0x4A90E2, - .colorConfirmForeground = 0xE0FFFF, - .colorConfirmOverBackground = 0x3177C9, - .colorConfirmOverForeground = 0xFFFFFF, - .iconToggleOff = &C_blue_icon_toggle_off, - .iconToggleOn = &C_blue_icon_toggle_on_nano, - #endif // TARGET_BLUE - }) - #endif +REGISTER_COINS(COIN(LIBN_COIN_TYPE_NANO, + { + .coinName = "Nano", +#if defined(TARGET_BLUE) + .coinBadge = &C_blue_badge_nano, +#else + .coinBadge = &C_nanos_badge_nano, +#endif + .bip32Prefix = {HARDENED(44), HARDENED(165)}, + .addressPrimaryPrefix = "nano_", + .addressSecondaryPrefix = "xrb_", + .addressDefaultPrefix = LIBN_PRIMARY_PREFIX, + .defaultUnit = "NANO", + .defaultUnitScale = 30, // 1 nano = 10^30 raw +#if defined(TARGET_BLUE) + .colorBackground = 0xF9F9F9, + .colorForeground = 0x000000, + .colorAltBackground = 0x4A90E2, + .colorAltForeground = 0xE0FFFF, + .colorRejectBackground = 0xC6C6C6, + .colorRejectForeground = 0x000000, + .colorRejectOverBackground = 0xADADAD, + .colorRejectOverForeground = 0x000000, + .colorConfirmBackground = 0x4A90E2, + .colorConfirmForeground = 0xE0FFFF, + .colorConfirmOverBackground = 0x3177C9, + .colorConfirmOverForeground = 0xFFFFFF, + .iconToggleOff = &C_blue_icon_toggle_off, + .iconToggleOn = &C_blue_icon_toggle_on, +#endif // TARGET_BLUE + }) - #if defined(HAVE_COIN_BANANO) - COIN(LIBN_COIN_TYPE_BANANO, { - .coinName = "Banano", - #if defined(TARGET_BLUE) - .coinBadge = &C_blue_badge_banano, - #else - .coinBadge = &C_nanos_badge_banano, - #endif - .bip32Prefix = { HARDENED(44), HARDENED(198) }, - .addressPrimaryPrefix = "ban_", - .addressSecondaryPrefix = "ban_", - .addressDefaultPrefix = LIBN_PRIMARY_PREFIX, - .defaultUnit = "BANANO", - .defaultUnitScale = 29, // 1 BANANO = 10^29 raw - #if defined(TARGET_BLUE) - .colorBackground = 0xF9F9F9, - .colorForeground = 0x000000, - .colorAltBackground = 0xFBDD11, - .colorAltForeground = 0xFF6058, - .colorRejectBackground = 0xC6C6C6, - .colorRejectForeground = 0x000000, - .colorRejectOverBackground = 0xADADAD, - .colorRejectOverForeground = 0x000000, - .colorConfirmBackground = 0xFBDD11, - .colorConfirmForeground = 0xFF6058, - .colorConfirmOverBackground = 0xE2C400, - .colorConfirmOverForeground = 0xE6473F, - .iconToggleOff = &C_blue_icon_toggle_off, - .iconToggleOn = &C_blue_icon_toggle_on_banano, - #endif // TARGET_BLUE - }) - #endif + COIN(LIBN_COIN_TYPE_BANANO, + { + .coinName = "Banano", +#if defined(TARGET_BLUE) + .coinBadge = &C_blue_badge_banano, +#else + .coinBadge = &C_nanos_badge_banano, +#endif + .bip32Prefix = {HARDENED(44), HARDENED(198)}, + .addressPrimaryPrefix = "ban_", + .addressSecondaryPrefix = "ban_", + .addressDefaultPrefix = LIBN_PRIMARY_PREFIX, + .defaultUnit = "BANANO", + .defaultUnitScale = 29, // 1 BANANO = 10^29 raw +#if defined(TARGET_BLUE) + .colorBackground = 0xF9F9F9, + .colorForeground = 0x000000, + .colorAltBackground = 0xFBDD11, + .colorAltForeground = 0xFF6058, + .colorRejectBackground = 0xC6C6C6, + .colorRejectForeground = 0x000000, + .colorRejectOverBackground = 0xADADAD, + .colorRejectOverForeground = 0x000000, + .colorConfirmBackground = 0xFBDD11, + .colorConfirmForeground = 0xFF6058, + .colorConfirmOverBackground = 0xE2C400, + .colorConfirmOverForeground = 0xE6473F, + .iconToggleOff = &C_blue_icon_toggle_off, + .iconToggleOn = &C_blue_icon_toggle_on, +#endif // TARGET_BLUE + }) - #if defined(HAVE_COIN_NOS) - COIN(LIBN_COIN_TYPE_NOS, { - .coinName = "NOS", - #if defined(TARGET_BLUE) - .coinBadge = &C_blue_badge_nos, - #else - .coinBadge = &C_nanos_badge_nos, - #endif - .bip32Prefix = { HARDENED(44), HARDENED(229) }, - .addressPrimaryPrefix = "nos_", - .addressSecondaryPrefix = "nos_", - .addressDefaultPrefix = LIBN_PRIMARY_PREFIX, - .defaultUnit = "NOS", - .defaultUnitScale = 19, // 1 NOS = 10^19 raw - #if defined(TARGET_BLUE) - .colorBackground = 0xF9F9F9, - .colorForeground = 0x000000, - .colorAltBackground = 0x4A90E2, - .colorAltForeground = 0xE0FFFF, - .colorRejectBackground = 0xC6C6C6, - .colorRejectForeground = 0x000000, - .colorRejectOverBackground = 0xADADAD, - .colorRejectOverForeground = 0x000000, - .colorConfirmBackground = 0x4A90E2, - .colorConfirmForeground = 0xE0FFFF, - .colorConfirmOverBackground = 0x3177C9, - .colorConfirmOverForeground = 0xFFFFFF, - .iconToggleOff = &C_blue_icon_toggle_off, - .iconToggleOn = &C_blue_icon_toggle_on_nos, - #endif // TARGET_BLUE - }) - #endif -) + COIN(LIBN_COIN_TYPE_NOS, + { + .coinName = "NOS", +#if defined(TARGET_BLUE) + .coinBadge = &C_blue_badge_nos, +#else + .coinBadge = &C_nanos_badge_nos, +#endif + .bip32Prefix = {HARDENED(44), HARDENED(229)}, + .addressPrimaryPrefix = "nos_", + .addressSecondaryPrefix = "nos_", + .addressDefaultPrefix = LIBN_PRIMARY_PREFIX, + .defaultUnit = "NOS", + .defaultUnitScale = 19, // 1 NOS = 10^19 raw +#if defined(TARGET_BLUE) + .colorBackground = 0xF9F9F9, + .colorForeground = 0x000000, + .colorAltBackground = 0x4A90E2, + .colorAltForeground = 0xE0FFFF, + .colorRejectBackground = 0xC6C6C6, + .colorRejectForeground = 0x000000, + .colorRejectOverBackground = 0xADADAD, + .colorRejectOverForeground = 0x000000, + .colorConfirmBackground = 0x4A90E2, + .colorConfirmForeground = 0xE0FFFF, + .colorConfirmOverBackground = 0x3177C9, + .colorConfirmOverForeground = 0xFFFFFF, + .iconToggleOff = &C_blue_icon_toggle_off, + .iconToggleOn = &C_blue_icon_toggle_on, +#endif // TARGET_BLUE + })) diff --git a/src/coins.h b/src/coins.h index f9248a0..250d0da 100644 --- a/src/coins.h +++ b/src/coins.h @@ -1,22 +1,20 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2018 Mart Roosmaa -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ - -#ifndef COINS_H -#define COINS_H + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2018 Mart Roosmaa + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +#pragma once #include "libn_types.h" @@ -26,29 +24,28 @@ extern libn_coin_conf_t libn_coin_conf_D; void init_coin_config(libn_coin_type_t coin_type); -#define COIN_NAME libn_coin_conf_D.coinName -#define COIN_BADGE libn_coin_conf_D.coinBadge -#define COIN_BIP32_PREFIX libn_coin_conf_D.bip32Prefix -#define COIN_PRIMARY_PREFIX libn_coin_conf_D.addressPrimaryPrefix +#define COIN_NAME libn_coin_conf_D.coinName +#define COIN_BADGE libn_coin_conf_D.coinBadge +#define COIN_BIP32_PREFIX libn_coin_conf_D.bip32Prefix +#define COIN_PRIMARY_PREFIX libn_coin_conf_D.addressPrimaryPrefix #define COIN_SECONDARY_PREFIX libn_coin_conf_D.addressSecondaryPrefix -#define COIN_DEFAULT_PREFIX libn_coin_conf_D.addressDefaultPrefix -#define COIN_UNIT libn_coin_conf_D.defaultUnit -#define COIN_UNIT_SCALE libn_coin_conf_D.defaultUnitScale +#define COIN_DEFAULT_PREFIX libn_coin_conf_D.addressDefaultPrefix +#define COIN_UNIT libn_coin_conf_D.defaultUnit +#define COIN_UNIT_SCALE libn_coin_conf_D.defaultUnitScale + #if defined(TARGET_BLUE) -#define COIN_COLOR_BG libn_coin_conf_D.colorBackground -#define COIN_COLOR_FG libn_coin_conf_D.colorForeground -#define COIN_COLOR_ALT_BG libn_coin_conf_D.colorAltBackground -#define COIN_COLOR_ALT_FG libn_coin_conf_D.colorAltForeground -#define COIN_COLOR_REJECT_BG libn_coin_conf_D.colorRejectBackground -#define COIN_COLOR_REJECT_FG libn_coin_conf_D.colorRejectForeground -#define COIN_COLOR_REJECT_OVER_BG libn_coin_conf_D.colorRejectOverBackground -#define COIN_COLOR_REJECT_OVER_FG libn_coin_conf_D.colorRejectOverForeground -#define COIN_COLOR_CONFIRM_BG libn_coin_conf_D.colorConfirmBackground -#define COIN_COLOR_CONFIRM_FG libn_coin_conf_D.colorConfirmForeground +#define COIN_COLOR_BG libn_coin_conf_D.colorBackground +#define COIN_COLOR_FG libn_coin_conf_D.colorForeground +#define COIN_COLOR_ALT_BG libn_coin_conf_D.colorAltBackground +#define COIN_COLOR_ALT_FG libn_coin_conf_D.colorAltForeground +#define COIN_COLOR_REJECT_BG libn_coin_conf_D.colorRejectBackground +#define COIN_COLOR_REJECT_FG libn_coin_conf_D.colorRejectForeground +#define COIN_COLOR_REJECT_OVER_BG libn_coin_conf_D.colorRejectOverBackground +#define COIN_COLOR_REJECT_OVER_FG libn_coin_conf_D.colorRejectOverForeground +#define COIN_COLOR_CONFIRM_BG libn_coin_conf_D.colorConfirmBackground +#define COIN_COLOR_CONFIRM_FG libn_coin_conf_D.colorConfirmForeground #define COIN_COLOR_CONFIRM_OVER_BG libn_coin_conf_D.colorConfirmOverBackground #define COIN_COLOR_CONFIRM_OVER_FG libn_coin_conf_D.colorConfirmOverForeground -#define COIN_ICON_TOGGLE_OFF libn_coin_conf_D.iconToggleOff -#define COIN_ICON_TOGGLE_ON libn_coin_conf_D.iconToggleOn -#endif // TARGET_BLUE - -#endif // COINS_H \ No newline at end of file +#define COIN_ICON_TOGGLE_OFF libn_coin_conf_D.iconToggleOff +#define COIN_ICON_TOGGLE_ON libn_coin_conf_D.iconToggleOn +#endif // TARGET_BLUE diff --git a/src/coins_dsl.h b/src/coins_dsl.h index c8ec75f..71aa60b 100644 --- a/src/coins_dsl.h +++ b/src/coins_dsl.h @@ -1,41 +1,36 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2018 Mart Roosmaa -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2018 Mart Roosmaa + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +#pragma once -#ifndef COINS_DSL_H -#define COINS_DSL_H +#include "glyphs.h" #include "coins.h" #include "libn_internal.h" -#include "glyphs.h" -#define REGISTER_COINS(...) \ - void init_coin_config(libn_coin_type_t coin_type) { \ - switch (coin_type) { \ - __VA_ARGS__ \ - } \ - /* avoid default statement to get warnings when a case was missed */ \ - app_exit(); \ +#define REGISTER_COINS(...) \ + void init_coin_config(libn_coin_type_t coin_type) { \ + switch (coin_type) { __VA_ARGS__ } \ + /* avoid default statement to get warnings when a case was missed */ \ + app_exit(); \ } -#define COIN(type, ...) \ - case type: { \ - libn_coin_conf_t conf = __VA_ARGS__; \ - os_memmove(&libn_coin_conf_D, &conf, sizeof(libn_coin_conf_t)); \ - return; \ +#define COIN(type, ...) \ + case type: { \ + libn_coin_conf_t conf = __VA_ARGS__; \ + memmove(&libn_coin_conf_D, &conf, sizeof(libn_coin_conf_t)); \ + return; \ } - -#endif // COINS_DSL_H \ No newline at end of file diff --git a/src/ed25519.h b/src/ed25519.h index 5d34d1b..7a5c72f 100644 --- a/src/ed25519.h +++ b/src/ed25519.h @@ -1,19 +1,17 @@ -#ifndef ED25519_H -#define ED25519_H +#pragma once #include -#include "libn_types.h" -void ed25519_publickey(const libn_private_key_t privateKey, - libn_public_key_t publicKey); +#include "libn_types.h" -void ed25519_sign(const uint8_t *m, size_t mlen, - const libn_private_key_t privateKey, - const libn_public_key_t publicKey, - libn_signature_t signature); +cx_err_t ed25519_publickey(const libn_private_key_t prv, libn_public_key_t pub); -int ed25519_sign_open(const uint8_t *m, size_t mlen, - const libn_public_key_t publicKey, - const libn_signature_t signature); +cx_err_t ed25519_sign(const uint8_t *m, + size_t mlen, + const libn_private_key_t prv, + libn_signature_t sig); -#endif // ED25519_H +bool ed25519_sign_open(const uint8_t *m, + size_t mlen, + const libn_public_key_t pub, + const libn_signature_t sig); diff --git a/src/ed25519_shim.c b/src/ed25519_shim.c index 57b4ed0..a209ea0 100644 --- a/src/ed25519_shim.c +++ b/src/ed25519_shim.c @@ -2,57 +2,71 @@ #include "os.h" #include "cx.h" -void ed25519_publickey(const libn_private_key_t privateKey, - libn_public_key_t publicKey) { - cx_ecfp_private_key_t sdkPrivateKey; - cx_ecfp_public_key_t sdkPublicKey; +cx_err_t ed25519_publickey(const libn_private_key_t prv, libn_public_key_t pub) { + cx_ecfp_private_key_t sdkPrv; + cx_ecfp_public_key_t sdkPub; + cx_err_t error; - cx_ecfp_init_private_key(CX_CURVE_Ed25519, - (uint8_t *)privateKey, sizeof(libn_private_key_t), - &sdkPrivateKey); - cx_ecfp_init_public_key(CX_CURVE_Ed25519, NULL, 0, &sdkPublicKey); + CX_CHECK(cx_ecfp_init_private_key_no_throw(CX_CURVE_Ed25519, + (uint8_t *) prv, + sizeof(libn_private_key_t), + &sdkPrv)); + CX_CHECK(cx_ecfp_init_public_key_no_throw(CX_CURVE_Ed25519, NULL, 0, &sdkPub)); - cx_ecfp_generate_pair2(CX_CURVE_Ed25519, &sdkPublicKey, &sdkPrivateKey, true, CX_BLAKE2B); - os_memset(&sdkPrivateKey, 0, sizeof(sdkPrivateKey)); + CX_CHECK(cx_ecfp_generate_pair2_no_throw(CX_CURVE_Ed25519, &sdkPub, &sdkPrv, true, CX_BLAKE2B)); + memset(&sdkPrv, 0, sizeof(sdkPrv)); - cx_edward_compress_point(CX_CURVE_Ed25519, sdkPublicKey.W, sdkPublicKey.W_len); - os_memmove(publicKey, sdkPublicKey.W+1, sizeof(libn_public_key_t)); + CX_CHECK(cx_edwards_compress_point_no_throw(CX_CURVE_Ed25519, sdkPub.W, sdkPub.W_len)); + memmove(pub, sdkPub.W + 1, sizeof(libn_public_key_t)); + +end: + return error; } -void ed25519_sign(const uint8_t *m, size_t mlen, - const libn_private_key_t privateKey, - const libn_public_key_t publicKey, - libn_signature_t signature) { - cx_ecfp_private_key_t sdkPrivateKey; - cx_ecfp_init_private_key(CX_CURVE_Ed25519, - (uint8_t *)privateKey, sizeof(libn_private_key_t), - &sdkPrivateKey); - - cx_eddsa_sign( - &sdkPrivateKey, - 0, CX_BLAKE2B, - (uint8_t *)m, mlen, - NULL, 0, - signature, sizeof(libn_signature_t), - 0); - os_memset(&sdkPrivateKey, 0, sizeof(sdkPrivateKey)); +cx_err_t ed25519_sign(const uint8_t *m, + size_t mlen, + const libn_private_key_t prv, + libn_signature_t sig) { + cx_ecfp_private_key_t sdkPrv; + cx_err_t error; + + CX_CHECK(cx_ecfp_init_private_key_no_throw(CX_CURVE_Ed25519, + (uint8_t *) prv, + sizeof(libn_private_key_t), + &sdkPrv)); + + CX_CHECK(cx_eddsa_sign_no_throw(&sdkPrv, + CX_BLAKE2B, + (uint8_t *) m, + mlen, + sig, + sizeof(libn_signature_t))); + memset(&sdkPrv, 0, sizeof(sdkPrv)); + +end: + return error; } -int ed25519_sign_open(const uint8_t *m, size_t mlen, - const libn_public_key_t publicKey, - const libn_signature_t signature) { - cx_ecfp_public_key_t sdkPublicKey; - cx_ecfp_init_public_key(CX_CURVE_Ed25519, NULL, 0, &sdkPublicKey); - - sdkPublicKey.W[0] = 0x02; - os_memmove(sdkPublicKey.W+1, publicKey, sizeof(libn_public_key_t)); - cx_edward_decompress_point(CX_CURVE_Ed25519, sdkPublicKey.W, sdkPublicKey.W_len); - sdkPublicKey.W_len = 65; - - return cx_eddsa_verify( - &sdkPublicKey, - 0, CX_BLAKE2B, - (uint8_t *)m, mlen, - NULL, 0, - (uint8_t *)signature, sizeof(libn_signature_t)); +bool ed25519_sign_open(const uint8_t *m, + size_t mlen, + const libn_public_key_t pub, + const libn_signature_t sig) { + cx_ecfp_public_key_t sdkPub; + cx_err_t error; + + CX_CHECK(cx_ecfp_init_public_key_no_throw(CX_CURVE_Ed25519, NULL, 0, &sdkPub)); + + sdkPub.W[0] = 0x02; + memmove(sdkPub.W + 1, pub, sizeof(libn_public_key_t)); + + CX_CHECK(cx_edwards_decompress_point_no_throw(CX_CURVE_Ed25519, sdkPub.W, sdkPub.W_len)); + sdkPub.W_len = 65; + +end: + return cx_eddsa_verify_no_throw(&sdkPub, + CX_BLAKE2B, + (uint8_t *) m, + mlen, + (uint8_t *) sig, + sizeof(libn_signature_t)); } diff --git a/src/libn_apdu_cache_block.c b/src/libn_apdu_cache_block.c index 1f706d4..548e5a0 100644 --- a/src/libn_apdu_cache_block.c +++ b/src/libn_apdu_cache_block.c @@ -1,19 +1,19 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2018 Mart Roosmaa -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2018 Mart Roosmaa + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ #include "libn_internal.h" #include "libn_apdu_constants.h" @@ -23,9 +23,7 @@ #define P1_UNUSED 0x00 #define P2_UNUSED 0x00 -uint16_t libn_apdu_cache_block_output(libn_apdu_response_t *resp, libn_apdu_cache_block_request_t *req); - -uint16_t libn_apdu_cache_block(libn_apdu_response_t *resp) { +uint16_t libn_apdu_cache_block() { libn_apdu_cache_block_request_t req; uint8_t keyPath[MAX_BIP32_PATH_LENGTH]; libn_private_key_t privateKey; @@ -33,17 +31,17 @@ uint16_t libn_apdu_cache_block(libn_apdu_response_t *resp) { uint8_t readLen; switch (G_io_apdu_buffer[ISO_OFFSET_P1]) { - case P1_UNUSED: - break; - default: - return LIBN_SW_INCORRECT_P1_P2; + case P1_UNUSED: + break; + default: + return LIBN_SW_INCORRECT_P1_P2; } switch (G_io_apdu_buffer[ISO_OFFSET_P2]) { - case P2_UNUSED: - break; - default: - return LIBN_SW_INCORRECT_P1_P2; + case P2_UNUSED: + break; + default: + return LIBN_SW_INCORRECT_P1_P2; } // Verify the minimum size @@ -53,7 +51,7 @@ uint16_t libn_apdu_cache_block(libn_apdu_response_t *resp) { inPtr = G_io_apdu_buffer + ISO_OFFSET_CDATA; readLen = 1 + (*inPtr) * 4; - os_memmove(keyPath, inPtr, MIN(readLen, sizeof(keyPath))); + memmove(keyPath, inPtr, MIN(readLen, sizeof(keyPath))); inPtr += readLen; if (os_global_pin_is_validated() != BOLOS_UX_OK) { @@ -66,49 +64,51 @@ uint16_t libn_apdu_cache_block(libn_apdu_response_t *resp) { // Derive public key for hashing libn_derive_keypair(keyPath, privateKey, req.publicKey); - os_memset(privateKey, 0, sizeof(privateKey)); // sanitise private key - os_memset(&keyPath, 0, sizeof(keyPath)); + memset(privateKey, 0, sizeof(privateKey)); // sanitise private key + memset(&keyPath, 0, sizeof(keyPath)); // Reset block state - os_memset(&req.block, 0, sizeof(req.block)); + memset(&req.block, 0, sizeof(req.block)); // Parse input data readLen = sizeof(req.block.parent); - os_memmove(req.block.parent, inPtr, readLen); + memmove(req.block.parent, inPtr, readLen); inPtr += readLen; readLen = sizeof(req.block.link); - os_memmove(req.block.link, inPtr, readLen); + memmove(req.block.link, inPtr, readLen); inPtr += readLen; readLen = sizeof(req.block.representative); - os_memmove(req.block.representative, inPtr, readLen); + memmove(req.block.representative, inPtr, readLen); inPtr += readLen; readLen = sizeof(req.block.balance); - os_memmove(req.block.balance, inPtr, readLen); + memmove(req.block.balance, inPtr, readLen); inPtr += readLen; readLen = sizeof(req.signature); - os_memmove(req.signature, inPtr, readLen); - inPtr += readLen; + memmove(req.signature, inPtr, readLen); libn_hash_block(req.blockHash, &req.block, req.publicKey); - uint16_t statusWord = libn_apdu_cache_block_output(resp, &req); - os_memset(&req, 0, sizeof(req)); // sanitise request data + uint16_t statusWord = libn_apdu_cache_block_output(&req); + memset(&req, 0, sizeof(req)); // sanitise request data return statusWord; } -uint16_t libn_apdu_cache_block_output(libn_apdu_response_t *resp, libn_apdu_cache_block_request_t *req) { +uint16_t libn_apdu_cache_block_output(libn_apdu_cache_block_request_t *req) { // Copy the data over to the cache - os_memset(&libn_context_D.cachedBlock, 0, sizeof(libn_context_D.cachedBlock)); - os_memmove(libn_context_D.cachedBlock.representative, req->block.representative, - sizeof(libn_context_D.cachedBlock.representative)); - os_memmove(libn_context_D.cachedBlock.balance, req->block.balance, - sizeof(libn_context_D.cachedBlock.balance)); - os_memmove(libn_context_D.cachedBlock.hash, req->blockHash, - sizeof(libn_context_D.cachedBlock.hash)); + memset(&libn_context_D.cachedBlock, 0, sizeof(libn_context_D.cachedBlock)); + memmove(libn_context_D.cachedBlock.representative, + req->block.representative, + sizeof(libn_context_D.cachedBlock.representative)); + memmove(libn_context_D.cachedBlock.balance, + req->block.balance, + sizeof(libn_context_D.cachedBlock.balance)); + memmove(libn_context_D.cachedBlock.hash, + req->blockHash, + sizeof(libn_context_D.cachedBlock.hash)); return LIBN_SW_OK; } diff --git a/src/libn_apdu_cache_block.h b/src/libn_apdu_cache_block.h index 7140711..9edadc6 100644 --- a/src/libn_apdu_cache_block.h +++ b/src/libn_apdu_cache_block.h @@ -1,26 +1,24 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2018 Mart Roosmaa -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2018 Mart Roosmaa + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +#pragma once -#ifndef LIBN_APDU_CACHE_BLOCK_H - -#define LIBN_APDU_CACHE_BLOCK_H +#include "libn_helpers.h" #include "libn_types.h" -#include "libn_helpers.h" typedef struct { libn_public_key_t publicKey; @@ -29,6 +27,6 @@ typedef struct { libn_signature_t signature; } libn_apdu_cache_block_request_t; -uint16_t libn_apdu_cache_block(libn_apdu_response_t *resp); +uint16_t libn_apdu_cache_block(); -#endif // LIBN_APDU_CACHE_BLOCK_H +uint16_t libn_apdu_cache_block_output(libn_apdu_cache_block_request_t *req); diff --git a/src/libn_apdu_constants.h b/src/libn_apdu_constants.h index 30626ea..8ac6bfa 100644 --- a/src/libn_apdu_constants.h +++ b/src/libn_apdu_constants.h @@ -1,54 +1,50 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2016 Ledger -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ - -#ifndef LIBN_APDU_CONSTANTS_H - -#define LIBN_APDU_CONSTANTS_H + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2016 Ledger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +#pragma once #define LIBN_CLA 0xA1 #define LIBN_INS_GET_APP_CONF 0x01 -#define LIBN_INS_GET_ADDRESS 0x02 -#define LIBN_INS_CACHE_BLOCK 0x03 -#define LIBN_INS_SIGN_BLOCK 0x04 -#define LIBN_INS_SIGN_NONCE 0x05 +#define LIBN_INS_GET_ADDRESS 0x02 +#define LIBN_INS_CACHE_BLOCK 0x03 +#define LIBN_INS_SIGN_BLOCK 0x04 +#define LIBN_INS_SIGN_NONCE 0x05 -#define LIBN_SW_INCORRECT_LENGTH 0x6700 -#define LIBN_SW_SECURITY_STATUS_NOT_SATISFIED 0x6982 +#define LIBN_SW_INCORRECT_LENGTH 0x6700 +#define LIBN_SW_SECURITY_STATUS_NOT_SATISFIED 0x6982 #define LIBN_SW_CONDITIONS_OF_USE_NOT_SATISFIED 0x6985 -#define LIBN_SW_INCORRECT_DATA 0x6A80 -#define LIBN_SW_INVALID_SIGNATURE 0x6A81 -#define LIBN_SW_PARENT_BLOCK_CACHE_MISS 0x6A82 -#define LIBN_SW_INCORRECT_P1_P2 0x6B00 -#define LIBN_SW_INS_NOT_SUPPORTED 0x6D00 -#define LIBN_SW_CLA_NOT_SUPPORTED 0x6E00 -#define LIBN_SW_TECHNICAL_PROBLEM 0x6F00 -#define LIBN_SW_OK 0x9000 -#define LIBN_SW_HALTED 0x6FAA -#define LIBN_SW_APP_HALTED LIBN_SW_CONDITIONS_OF_USE_NOT_SATISFIED - -#define ISO_OFFSET_CLA 0x00 -#define ISO_OFFSET_INS 0x01 -#define ISO_OFFSET_P1 0x02 -#define ISO_OFFSET_P2 0x03 -#define ISO_OFFSET_LC 0x04 +#define LIBN_SW_INCORRECT_DATA 0x6A80 +#define LIBN_SW_INVALID_SIGNATURE 0x6A81 +#define LIBN_SW_PARENT_BLOCK_CACHE_MISS 0x6A82 +#define LIBN_SW_INCORRECT_P1_P2 0x6B00 +#define LIBN_SW_INS_NOT_SUPPORTED 0x6D00 +#define LIBN_SW_CLA_NOT_SUPPORTED 0x6E00 +#define LIBN_SW_TECHNICAL_PROBLEM 0x6F00 +#define LIBN_SW_OK 0x9000 +#define LIBN_SW_HALTED 0x6FAA +#define LIBN_SW_APP_HALTED LIBN_SW_CONDITIONS_OF_USE_NOT_SATISFIED + +#define ISO_OFFSET_CLA 0x00 +#define ISO_OFFSET_INS 0x01 +#define ISO_OFFSET_P1 0x02 +#define ISO_OFFSET_P2 0x03 +#define ISO_OFFSET_LC 0x04 #define ISO_OFFSET_CDATA 0x05 #include "os.h" -#include "libn_secure_value.h" -#endif +#include "libn_secure_value.h" diff --git a/src/libn_apdu_get_address.c b/src/libn_apdu_get_address.c index 367ce73..2e9a056 100644 --- a/src/libn_apdu_get_address.c +++ b/src/libn_apdu_get_address.c @@ -1,20 +1,20 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2018 Mart Roosmaa -* (c) 2016 Ledger -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2018 Mart Roosmaa + * (c) 2016 Ledger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ #include "coins.h" #include "libn_internal.h" @@ -24,11 +24,12 @@ #include "libn_bagl.h" #define P1_NO_DISPLAY 0x00 -#define P1_DISPLAY 0x01 +#define P1_DISPLAY 0x01 #define P2_UNUSED 0x00 -uint16_t libn_apdu_get_address_output(libn_apdu_response_t *resp, libn_apdu_get_address_request_t *req); +uint16_t libn_apdu_get_address_output(libn_apdu_response_t *resp, + libn_apdu_get_address_request_t *req); uint16_t libn_apdu_get_address(libn_apdu_response_t *resp) { libn_apdu_get_address_request_t req; @@ -38,18 +39,18 @@ uint16_t libn_apdu_get_address(libn_apdu_response_t *resp) { bool display = (G_io_apdu_buffer[ISO_OFFSET_P1] == P1_DISPLAY); switch (G_io_apdu_buffer[ISO_OFFSET_P1]) { - case P1_NO_DISPLAY: - case P1_DISPLAY: - break; - default: - return LIBN_SW_INCORRECT_P1_P2; + case P1_NO_DISPLAY: + case P1_DISPLAY: + break; + default: + return LIBN_SW_INCORRECT_P1_P2; } switch (G_io_apdu_buffer[ISO_OFFSET_P2]) { - case P2_UNUSED: - break; - default: - return LIBN_SW_INCORRECT_P1_P2; + case P2_UNUSED: + break; + default: + return LIBN_SW_INCORRECT_P1_P2; } if (G_io_apdu_buffer[ISO_OFFSET_LC] < 0x01) { @@ -70,31 +71,32 @@ uint16_t libn_apdu_get_address(libn_apdu_response_t *resp) { // Retrieve the public key for the path libn_derive_keypair(keyPathPtr, privateKey, req.publicKey); - os_memset(privateKey, 0, sizeof(privateKey)); // sanitise private key + memset(privateKey, 0, sizeof(privateKey)); // sanitise private key if (display) { // Update app state to confirm the address libn_context_D.state = LIBN_STATE_CONFIRM_ADDRESS; - os_memmove(&libn_context_D.stateData.getAddressRequest, &req, sizeof(req)); - os_memset(&req, 0, sizeof(req)); // sanitise request data + memmove(&libn_context_D.stateData.getAddressRequest, &req, sizeof(req)); + memset(&req, 0, sizeof(req)); // sanitise request data app_apply_state(); resp->ioFlags |= IO_ASYNCH_REPLY; return LIBN_SW_OK; } else { uint16_t statusWord = libn_apdu_get_address_output(resp, &req); - os_memset(&req, 0, sizeof(req)); // sanitise request data + memset(&req, 0, sizeof(req)); // sanitise request data return statusWord; } } -uint16_t libn_apdu_get_address_output(libn_apdu_response_t *resp, libn_apdu_get_address_request_t *req) { +uint16_t libn_apdu_get_address_output(libn_apdu_response_t *resp, + libn_apdu_get_address_request_t *req) { uint8_t length; uint8_t *outPtr = resp->buffer; // Output raw public key length = sizeof(req->publicKey); - os_memmove(outPtr, req->publicKey, length); + memmove(outPtr, req->publicKey, length); outPtr += length; // Encode & output account address @@ -121,6 +123,6 @@ void libn_bagl_display_address_callback(bool confirmed) { } else { statusWord = LIBN_SW_CONDITIONS_OF_USE_NOT_SATISFIED; } - os_memset(req, 0, sizeof(req)); // sanitise request data + memset(req, 0, sizeof(*req)); // sanitise request data app_async_response(&resp, statusWord); } diff --git a/src/libn_apdu_get_address.h b/src/libn_apdu_get_address.h index 5aaf6b6..4946afa 100644 --- a/src/libn_apdu_get_address.h +++ b/src/libn_apdu_get_address.h @@ -1,23 +1,20 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2018 Mart Roosmaa -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ - -#ifndef LIBN_APDU_GET_ADDRESS_H - -#define LIBN_APDU_GET_ADDRESS_H + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2018 Mart Roosmaa + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +#pragma once #include "libn_types.h" @@ -27,5 +24,3 @@ typedef struct { } libn_apdu_get_address_request_t; uint16_t libn_apdu_get_address(libn_apdu_response_t *resp); - -#endif // LIBN_APDU_GET_ADDRESS_H diff --git a/src/libn_apdu_get_app_conf.c b/src/libn_apdu_get_app_conf.c index 38eef6c..63e470c 100644 --- a/src/libn_apdu_get_app_conf.c +++ b/src/libn_apdu_get_app_conf.c @@ -1,19 +1,19 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2018 Mart Roosmaa -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2018 Mart Roosmaa + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ #include "coins.h" #include "libn_internal.h" @@ -28,17 +28,17 @@ uint16_t libn_apdu_get_app_conf_output(libn_apdu_response_t *resp); uint16_t libn_apdu_get_app_conf(libn_apdu_response_t *resp) { switch (G_io_apdu_buffer[ISO_OFFSET_P1]) { - case P1_UNUSED: - break; - default: - return LIBN_SW_INCORRECT_P1_P2; + case P1_UNUSED: + break; + default: + return LIBN_SW_INCORRECT_P1_P2; } switch (G_io_apdu_buffer[ISO_OFFSET_P2]) { - case P2_UNUSED: - break; - default: - return LIBN_SW_INCORRECT_P1_P2; + case P2_UNUSED: + break; + default: + return LIBN_SW_INCORRECT_P1_P2; } if (G_io_apdu_buffer[ISO_OFFSET_LC] > 0x00) { @@ -53,17 +53,17 @@ uint16_t libn_apdu_get_app_conf_output(libn_apdu_response_t *resp) { uint8_t length; // Output app version - *outPtr = APP_MAJOR_VERSION; + *outPtr = MAJOR_VERSION; outPtr += 1; - *outPtr = APP_MINOR_VERSION; + *outPtr = MINOR_VERSION; outPtr += 1; - *outPtr = APP_PATCH_VERSION; + *outPtr = PATCH_VERSION; outPtr += 1; // Output coin name length = strnlen(COIN_NAME, sizeof(COIN_NAME)); *outPtr = length; - os_memmove(outPtr + 1, COIN_NAME, length); + memmove(outPtr + 1, COIN_NAME, length); outPtr += 1 + length; resp->outLength = outPtr - resp->buffer; diff --git a/src/libn_apdu_get_app_conf.h b/src/libn_apdu_get_app_conf.h index ad6a066..9dccc07 100644 --- a/src/libn_apdu_get_app_conf.h +++ b/src/libn_apdu_get_app_conf.h @@ -1,26 +1,21 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2018 Mart Roosmaa -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ - -#ifndef LIBN_APDU_GET_APP_CONF_H - -#define LIBN_APDU_GET_APP_CONF_H + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2018 Mart Roosmaa + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ +#pragma once #include "libn_types.h" uint16_t libn_apdu_get_app_conf(libn_apdu_response_t *resp); - -#endif // LIBN_APDU_GET_APP_CONF_H diff --git a/src/libn_apdu_sign_block.c b/src/libn_apdu_sign_block.c index dd2449d..1d970e7 100644 --- a/src/libn_apdu_sign_block.c +++ b/src/libn_apdu_sign_block.c @@ -1,19 +1,19 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2018 Mart Roosmaa -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2018 Mart Roosmaa + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ #include "libn_internal.h" #include "libn_apdu_constants.h" @@ -23,10 +23,11 @@ #define P1_UNUSED 0x00 -#define P2_RECIPIENT_SECONDARY_PREFIX_FLAG 0x01 +#define P2_RECIPIENT_SECONDARY_PREFIX_FLAG 0x01 #define P2_REPRESENTATIVE_SECONDARY_PREFIX_FLAG 0x02 -uint16_t libn_apdu_sign_block_output(libn_apdu_response_t *resp, libn_apdu_sign_block_request_t *req); +uint16_t libn_apdu_sign_block_output(libn_apdu_response_t *resp, + libn_apdu_sign_block_request_t *req); uint16_t libn_apdu_sign_block(libn_apdu_response_t *resp) { libn_apdu_sign_block_request_t req; @@ -38,10 +39,10 @@ uint16_t libn_apdu_sign_block(libn_apdu_response_t *resp) { bool balanceDecreased; switch (G_io_apdu_buffer[ISO_OFFSET_P1]) { - case P1_UNUSED: - break; - default: - return LIBN_SW_INCORRECT_P1_P2; + case P1_UNUSED: + break; + default: + return LIBN_SW_INCORRECT_P1_P2; } // Verify the minimum size @@ -51,7 +52,7 @@ uint16_t libn_apdu_sign_block(libn_apdu_response_t *resp) { inPtr = G_io_apdu_buffer + ISO_OFFSET_CDATA; readLen = 1 + (*inPtr) * 4; - os_memmove(req.keyPath, inPtr, MIN(readLen, sizeof(req.keyPath))); + memmove(req.keyPath, inPtr, MIN(readLen, sizeof(req.keyPath))); inPtr += readLen; if (os_global_pin_is_validated() != BOLOS_UX_OK) { @@ -83,27 +84,26 @@ uint16_t libn_apdu_sign_block(libn_apdu_response_t *resp) { // Derive public key for hashing libn_derive_keypair(req.keyPath, privateKey, req.publicKey); - os_memset(privateKey, 0, sizeof(privateKey)); // sanitise private key + memset(privateKey, 0, sizeof(privateKey)); // sanitise private key // Reset block state - os_memset(&block, 0, sizeof(block)); + memset(&block, 0, sizeof(block)); // Parse input data readLen = sizeof(block.parent); - os_memmove(block.parent, inPtr, readLen); + memmove(block.parent, inPtr, readLen); inPtr += readLen; readLen = sizeof(block.link); - os_memmove(block.link, inPtr, readLen); + memmove(block.link, inPtr, readLen); inPtr += readLen; readLen = sizeof(block.representative); - os_memmove(block.representative, inPtr, readLen); + memmove(block.representative, inPtr, readLen); inPtr += readLen; readLen = sizeof(block.balance); - os_memmove(block.balance, inPtr, readLen); - inPtr += readLen; + memmove(block.balance, inPtr, readLen); libn_hash_block(req.blockHash, &block, req.publicKey); @@ -111,62 +111,52 @@ uint16_t libn_apdu_sign_block(libn_apdu_response_t *resp) { bool isFirstBlock = libn_is_zero(block.parent, sizeof(block.parent)); if (isFirstBlock) { representativeChanged = true; - os_memmove(req.representative, block.representative, - sizeof(block.representative)); + memmove(req.representative, block.representative, sizeof(block.representative)); // For first block the balance must have increased balanceDecreased = false; - os_memmove(req.amount, block.balance, sizeof(req.amount)); + memmove(req.amount, block.balance, sizeof(req.amount)); } else { // Make sure that the parent block data is cached and available - if (os_memcmp(block.parent, - libn_context_D.cachedBlock.hash, - sizeof(block.parent)) != 0) { + if (memcmp(block.parent, libn_context_D.cachedBlock.hash, sizeof(block.parent)) != 0) { return LIBN_SW_PARENT_BLOCK_CACHE_MISS; } - representativeChanged = os_memcmp( - block.representative, - libn_context_D.cachedBlock.representative, - sizeof(block.representative)) != 0; + representativeChanged = memcmp(block.representative, + libn_context_D.cachedBlock.representative, + sizeof(block.representative)) != 0; if (representativeChanged) { - os_memmove(req.representative, block.representative, - sizeof(block.representative)); + memmove(req.representative, block.representative, sizeof(block.representative)); } else { - os_memset(req.representative, 0, - sizeof(block.representative)); + memset(req.representative, 0, sizeof(block.representative)); } - balanceDecreased = libn_amount_cmp( - block.balance, - libn_context_D.cachedBlock.balance) < 0; + balanceDecreased = libn_amount_cmp(block.balance, libn_context_D.cachedBlock.balance) < 0; if (balanceDecreased) { - os_memmove(req.amount, libn_context_D.cachedBlock.balance, sizeof(req.amount)); + memmove(req.amount, libn_context_D.cachedBlock.balance, sizeof(req.amount)); libn_amount_subtract(req.amount, block.balance); } else { - os_memmove(req.amount, block.balance, sizeof(req.amount)); + memmove(req.amount, block.balance, sizeof(req.amount)); libn_amount_subtract(req.amount, libn_context_D.cachedBlock.balance); } } if (balanceDecreased) { - os_memmove(req.recipient, block.link, - sizeof(req.recipient)); + memmove(req.recipient, block.link, sizeof(req.recipient)); } else { - os_memset(req.recipient, 0, - sizeof(req.recipient)); + memset(req.recipient, 0, sizeof(req.recipient)); } // When auto receive is enabled, skip the prompt if (N_libn.autoReceive && !balanceDecreased && !representativeChanged) { uint16_t statusWord = libn_apdu_sign_block_output(resp, &req); - os_memset(&req, 0, sizeof(req)); // sanitise request data + memset(&req, 0, sizeof(req)); // sanitise request data return statusWord; } else { // Update app state to confirm the address libn_context_D.state = LIBN_STATE_CONFIRM_SIGNATURE; - os_memmove(&libn_context_D.stateData.signBlockRequest, &req, sizeof(req)); - os_memset(&req, 0, sizeof(req)); // sanitise request data + memmove(&libn_context_D.stateData.signBlockRequest, &req, sizeof(req)); + memset(&req, 0, sizeof(req)); // sanitise request data app_apply_state(); resp->ioFlags |= IO_ASYNCH_REPLY; @@ -174,22 +164,23 @@ uint16_t libn_apdu_sign_block(libn_apdu_response_t *resp) { } } -uint16_t libn_apdu_sign_block_output(libn_apdu_response_t *resp, libn_apdu_sign_block_request_t *req) { +uint16_t libn_apdu_sign_block_output(libn_apdu_response_t *resp, + libn_apdu_sign_block_request_t *req) { libn_private_key_t privateKey; libn_signature_t signature; uint8_t *outPtr = resp->buffer; // Derive key and sign the block libn_derive_keypair(req->keyPath, privateKey, NULL); - libn_sign_hash(signature, req->blockHash, privateKey, req->publicKey); - os_memset(privateKey, 0, sizeof(privateKey)); + libn_sign_hash(signature, req->blockHash, privateKey); + memset(privateKey, 0, sizeof(privateKey)); // Output block hash - os_memmove(outPtr, req->blockHash, sizeof(req->blockHash)); + memmove(outPtr, req->blockHash, sizeof(req->blockHash)); outPtr += sizeof(req->blockHash); // Output signature - os_memmove(outPtr, signature, sizeof(signature)); + memmove(outPtr, signature, sizeof(signature)); outPtr += sizeof(signature); resp->outLength = outPtr - resp->buffer; @@ -211,6 +202,6 @@ void libn_bagl_confirm_sign_block_callback(bool confirmed) { } else { statusWord = LIBN_SW_CONDITIONS_OF_USE_NOT_SATISFIED; } - os_memset(req, 0, sizeof(req)); // sanitise request data + memset(req, 0, sizeof(*req)); // sanitise request data app_async_response(&resp, statusWord); } diff --git a/src/libn_apdu_sign_block.h b/src/libn_apdu_sign_block.h index c35ebe1..1cb823d 100644 --- a/src/libn_apdu_sign_block.h +++ b/src/libn_apdu_sign_block.h @@ -1,26 +1,24 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2018 Mart Roosmaa -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2018 Mart Roosmaa + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +#pragma once -#ifndef LIBN_APDU_SIGN_BLOCK_H - -#define LIBN_APDU_SIGN_BLOCK_H +#include "libn_helpers.h" #include "libn_types.h" -#include "libn_helpers.h" typedef struct { uint8_t keyPath[MAX_BIP32_PATH_LENGTH]; @@ -36,5 +34,3 @@ typedef struct { } libn_apdu_sign_block_request_t; uint16_t libn_apdu_sign_block(libn_apdu_response_t *resp); - -#endif // LIBN_APDU_SIGN_BLOCK_H diff --git a/src/libn_apdu_sign_nonce.c b/src/libn_apdu_sign_nonce.c index da05d5f..99a9dfa 100644 --- a/src/libn_apdu_sign_nonce.c +++ b/src/libn_apdu_sign_nonce.c @@ -1,19 +1,19 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2018 Mart Roosmaa -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2018 Mart Roosmaa + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ #include "libn_internal.h" #include "libn_apdu_constants.h" @@ -22,7 +22,8 @@ #define P1_UNUSED 0x00 #define P2_UNUSED 0x00 -uint16_t libn_apdu_sign_nonce_output(libn_apdu_response_t *resp, libn_apdu_sign_nonce_request_t *req); +uint16_t libn_apdu_sign_nonce_output(libn_apdu_response_t *resp, + libn_apdu_sign_nonce_request_t *req); uint16_t libn_apdu_sign_nonce(libn_apdu_response_t *resp) { libn_apdu_sign_nonce_request_t req; @@ -30,17 +31,17 @@ uint16_t libn_apdu_sign_nonce(libn_apdu_response_t *resp) { uint8_t readLen; switch (G_io_apdu_buffer[ISO_OFFSET_P1]) { - case P1_UNUSED: - break; - default: - return LIBN_SW_INCORRECT_P1_P2; + case P1_UNUSED: + break; + default: + return LIBN_SW_INCORRECT_P1_P2; } switch (G_io_apdu_buffer[ISO_OFFSET_P2]) { - case P2_UNUSED: - break; - default: - return LIBN_SW_INCORRECT_P1_P2; + case P2_UNUSED: + break; + default: + return LIBN_SW_INCORRECT_P1_P2; } // Verify the minimum size @@ -50,7 +51,7 @@ uint16_t libn_apdu_sign_nonce(libn_apdu_response_t *resp) { inPtr = G_io_apdu_buffer + ISO_OFFSET_CDATA; readLen = 1 + (*inPtr) * 4; - os_memmove(req.keyPath, inPtr, MIN(readLen, sizeof(req.keyPath))); + memmove(req.keyPath, inPtr, MIN(readLen, sizeof(req.keyPath))); inPtr += readLen; if (os_global_pin_is_validated() != BOLOS_UX_OK) { @@ -58,15 +59,15 @@ uint16_t libn_apdu_sign_nonce(libn_apdu_response_t *resp) { } readLen = sizeof(req.nonce); - os_memmove(req.nonce, inPtr, readLen); - inPtr += readLen; + memmove(req.nonce, inPtr, readLen); uint16_t statusWord = libn_apdu_sign_nonce_output(resp, &req); - os_memset(&req, 0, sizeof(req)); // sanitise request data + memset(&req, 0, sizeof(req)); // sanitise request data return statusWord; } -uint16_t libn_apdu_sign_nonce_output(libn_apdu_response_t *resp, libn_apdu_sign_nonce_request_t *req) { +uint16_t libn_apdu_sign_nonce_output(libn_apdu_response_t *resp, + libn_apdu_sign_nonce_request_t *req) { libn_private_key_t privateKey; libn_public_key_t publicKey; libn_signature_t signature; @@ -74,11 +75,11 @@ uint16_t libn_apdu_sign_nonce_output(libn_apdu_response_t *resp, libn_apdu_sign_ // Derive key and sign the block libn_derive_keypair(req->keyPath, privateKey, publicKey); - libn_sign_nonce(signature, req->nonce, privateKey, publicKey); - os_memset(privateKey, 0, sizeof(privateKey)); + libn_sign_nonce(signature, req->nonce, privateKey); + memset(privateKey, 0, sizeof(privateKey)); // Output signature - os_memmove(outPtr, signature, sizeof(signature)); + memmove(outPtr, signature, sizeof(signature)); outPtr += sizeof(signature); resp->outLength = outPtr - resp->buffer; diff --git a/src/libn_apdu_sign_nonce.h b/src/libn_apdu_sign_nonce.h index a9b74cc..9068981 100644 --- a/src/libn_apdu_sign_nonce.h +++ b/src/libn_apdu_sign_nonce.h @@ -1,26 +1,24 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2018 Mart Roosmaa -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2018 Mart Roosmaa + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +#pragma once -#ifndef LIBN_APDU_SIGN_NONCE_H - -#define LIBN_APDU_SIGN_NONCE_H +#include "libn_helpers.h" #include "libn_types.h" -#include "libn_helpers.h" typedef struct { uint8_t keyPath[MAX_BIP32_PATH_LENGTH]; @@ -28,5 +26,3 @@ typedef struct { } libn_apdu_sign_nonce_request_t; uint16_t libn_apdu_sign_nonce(libn_apdu_response_t *resp); - -#endif // LIBN_APDU_SIGN_NONCE_H diff --git a/src/libn_app.c b/src/libn_app.c index 1ede11e..2cb1808 100644 --- a/src/libn_app.c +++ b/src/libn_app.c @@ -1,19 +1,19 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2016 Ledger -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2016 Ledger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ #include "os.h" #include "os_io_seproxyhal.h" @@ -22,13 +22,6 @@ #include "libn_apdu_constants.h" #include "libn_bagl.h" -#ifdef HAVE_IO_U2F - -#include "u2f_transport.h" -#include "u2f_processing.h" -extern u2f_service_t G_io_u2f; -#endif // HAVE_IO_U2F - void libn_bagl_idle(void); void ui_ticker_event(bool uxAllowed); @@ -37,7 +30,6 @@ void app_dispatch(void) { uint8_t ins; uint8_t dispatched; uint16_t statusWord; - uint32_t apduHash; libn_apdu_response_t *resp = &libn_context_D.response; // nothing to reply for now @@ -53,32 +45,10 @@ void app_dispatch(void) { goto sendSW; } -#ifdef HAVE_IO_U2F - if (G_io_apdu_state == APDU_U2F) { - apduHash = libn_simple_hash(G_io_apdu_buffer, libn_context_D.inLength); - if (apduHash == libn_context_D.u2fRequestHash) { - if (libn_context_D.state != LIBN_STATE_READY) { - // Request ongoing, setup a timeout - libn_context_D.u2fTimeout = U2F_REQUEST_TIMEOUT; - - resp->ioFlags |= IO_ASYNCH_REPLY; - statusWord = LIBN_SW_OK; - goto sendSW; - - } else if (libn_context_D.stateData.asyncResponse.outLength > 0) { - // Immediately return the previous response to this request - libn_context_move_async_response(); - goto sendBuffer; - } - } - } -#endif // HAVE_IO_U2F - cla = G_io_apdu_buffer[ISO_OFFSET_CLA]; ins = G_io_apdu_buffer[ISO_OFFSET_INS]; for (dispatched = 0; dispatched < DISPATCHER_APDUS; dispatched++) { - if ((cla == DISPATCHER_CLA[dispatched]) && - (ins == DISPATCHER_INS[dispatched])) { + if ((cla == DISPATCHER_CLA[dispatched]) && (ins == DISPATCHER_INS[dispatched])) { break; } } @@ -87,8 +57,7 @@ void app_dispatch(void) { goto sendSW; } if (DISPATCHER_DATA_IN[dispatched]) { - if (G_io_apdu_buffer[ISO_OFFSET_LC] == 0x00 || - libn_context_D.inLength - 5 == 0) { + if (G_io_apdu_buffer[ISO_OFFSET_LC] == 0x00 || libn_context_D.inLength - 5 == 0) { statusWord = LIBN_SW_INCORRECT_LENGTH; goto sendSW; } @@ -96,23 +65,13 @@ void app_dispatch(void) { // io_exchange(CHANNEL_APDU | IO_RECEIVE_DATA, 0); } // call the apdu handler - statusWord = ((apduProcessingFunction)PIC( - DISPATCHER_FUNCTIONS[dispatched]))(resp); - -#ifdef HAVE_IO_U2F - if (G_io_apdu_state == APDU_U2F && (resp->ioFlags & IO_ASYNCH_REPLY) != 0) { - // Setup the timeout and request details - libn_context_D.u2fRequestHash = apduHash; - libn_context_D.u2fTimeout = U2F_REQUEST_TIMEOUT; - } -#endif // HAVE_IO_U2F + statusWord = ((apduProcessingFunction) PIC(DISPATCHER_FUNCTIONS[dispatched]))(resp); sendSW: // prepare SW after replied data resp->buffer[resp->outLength] = (statusWord >> 8); resp->buffer[resp->outLength + 1] = (statusWord & 0xff); resp->outLength += 2; - sendBuffer: {} } CATCH_L(dispatch, EXCEPTION_IO_RESET) { THROW(EXCEPTION_IO_RESET); @@ -137,29 +96,19 @@ void app_async_response(libn_apdu_response_t *resp, uint16_t statusWord) { // Queue up the response to be sent when convenient libn_context_D.state = LIBN_STATE_READY; - os_memmove(&libn_context_D.stateData.asyncResponse, resp, sizeof(libn_apdu_response_t)); + memmove(&libn_context_D.stateData.asyncResponse, resp, sizeof(libn_apdu_response_t)); app_apply_state(); } -bool app_send_async_response(libn_apdu_response_t *resp) { -#ifdef HAVE_IO_U2F - if (G_io_apdu_state == APDU_IDLE) { - return false; - } - - libn_context_D.u2fTimeout = 0; -#endif // HAVE_IO_U2F - +bool app_send_async_response() { // Move the async result data to sync buffer libn_context_move_async_response(); - - io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, - libn_context_D.response.outLength); + io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, libn_context_D.response.outLength); return true; } bool app_apply_state(void) { - if (!UX_DISPLAYED() || io_seproxyhal_spi_is_status_sent()) { + if (!UX_DISPLAYED()) { return false; } @@ -172,7 +121,7 @@ bool app_apply_state(void) { // In READY state, try to return the queued asyncResponse if (libn_context_D.state == LIBN_STATE_READY && libn_context_D.stateData.asyncResponse.outLength > 0) { - bool responseSent = app_send_async_response(&libn_context_D.stateData.asyncResponse); + bool responseSent = app_send_async_response(); if (responseSent) { return true; } @@ -202,7 +151,7 @@ void app_init(void) { } void app_main(void) { - os_memset(libn_context_D.response.buffer, 0, 255); // paranoia + memset(libn_context_D.response.buffer, 0, 255); // paranoia // Process the incoming APDUs @@ -212,13 +161,12 @@ void app_main(void) { for (;;) { L_DEBUG_APP(("Main Loop\n")); - // os_memset(G_io_apdu_buffer, 0, 255); // paranoia + // memset(G_io_apdu_buffer, 0, 255); // paranoia // receive the whole apdu using the 7 bytes headers (ledger transport) - libn_context_D.inLength = - io_exchange(CHANNEL_APDU | libn_context_D.response.ioFlags, - // use the previous outlength as the reply - libn_context_D.response.outLength); + libn_context_D.inLength = io_exchange(CHANNEL_APDU | libn_context_D.response.ioFlags, + // use the previous outlength as the reply + libn_context_D.response.outLength); app_dispatch(); @@ -242,115 +190,73 @@ void app_exit(void) { END_TRY_L(exit); } -#ifdef HAVE_IO_U2F - -void u2f_message_timeout() { - libn_context_D.u2fTimeout = 0; - - G_io_apdu_buffer[0] = 0x69; - G_io_apdu_buffer[1] = 0x85; - u2f_message_reply(&G_io_u2f, U2F_CMD_MSG, G_io_apdu_buffer, 2); - - // reset apdu state - #if defined(TARGET_NANOX) || defined(TARGET_NANOS2) - G_io_app.apdu_state = APDU_IDLE; - G_io_app.apdu_length = 0; - G_io_app.apdu_media = IO_APDU_MEDIA_NONE; - #else - G_io_apdu_state = APDU_IDLE; -#if CX_APILEVEL < 10 - G_io_apdu_length = 0; -#else - G_io_app.apdu_length = 0; -#endif - G_io_apdu_media = IO_APDU_MEDIA_NONE; - #endif -} - -#endif // HAVE_IO_U2F - // override point, but nothing more to do void io_seproxyhal_display(const bagl_element_t *element) { - io_seproxyhal_display_default((bagl_element_t *)element); + io_seproxyhal_display_default((bagl_element_t *) element); } uint16_t io_exchange_al(uint8_t channel, uint16_t tx_len) { switch (channel & ~(IO_FLAGS)) { - case CHANNEL_KEYBOARD: - break; + case CHANNEL_KEYBOARD: + break; - // multiplexed io exchange over a SPI channel and TLV encapsulated protocol - case CHANNEL_SPI: - if (tx_len) { - io_seproxyhal_spi_send(G_io_apdu_buffer, tx_len); + // multiplexed io exchange over a SPI channel and TLV encapsulated protocol + case CHANNEL_SPI: + if (tx_len) { + io_seproxyhal_spi_send(G_io_apdu_buffer, tx_len); - if (channel & IO_RESET_AFTER_REPLIED) { - reset(); + if (channel & IO_RESET_AFTER_REPLIED) { + reset(); + } + return 0; // nothing received from the master so far (it's a tx + // transaction) + } else { + return io_seproxyhal_spi_recv(G_io_apdu_buffer, sizeof(G_io_apdu_buffer), 0); } - return 0; // nothing received from the master so far (it's a tx - // transaction) - } else { - return io_seproxyhal_spi_recv(G_io_apdu_buffer, - sizeof(G_io_apdu_buffer), 0); - } - default: - THROW(INVALID_PARAMETER); + default: + THROW(INVALID_PARAMETER); } return 0; } uint8_t io_event(uint8_t channel) { - // nothing done with the event, throw an error on the transport layer if - // needed + // nothing done with event, throw error on transport layer if needed + UNUSED(channel); - // can't have more than one tag in the reply, not supported yet. + // no more than one tag in the reply, not yet supported switch (G_io_seproxyhal_spi_buffer[0]) { - case SEPROXYHAL_TAG_FINGER_EVENT: - UX_FINGER_EVENT(G_io_seproxyhal_spi_buffer); - break; - - case SEPROXYHAL_TAG_BUTTON_PUSH_EVENT: - UX_BUTTON_PUSH_EVENT(G_io_seproxyhal_spi_buffer); - break; - - case SEPROXYHAL_TAG_STATUS_EVENT: - if (G_io_apdu_media == IO_APDU_MEDIA_USB_HID && - !(U4BE(G_io_seproxyhal_spi_buffer, 3) & - SEPROXYHAL_TAG_STATUS_EVENT_FLAG_USB_POWERED)) { - THROW(EXCEPTION_IO_RESET); - } - // no break is intentional - default: - UX_DEFAULT_EVENT(); - break; - - case SEPROXYHAL_TAG_DISPLAY_PROCESSED_EVENT: - UX_DISPLAYED_EVENT({ - app_apply_state(); - }); - break; - - case SEPROXYHAL_TAG_TICKER_EVENT: - if (app_apply_state()) { - // Apply caused changed, nothing else to do this cycle + case SEPROXYHAL_TAG_FINGER_EVENT: + UX_FINGER_EVENT(G_io_seproxyhal_spi_buffer); break; - } -#ifdef HAVE_IO_U2F - if (libn_context_D.u2fTimeout > 0) { - libn_context_D.u2fTimeout -= MIN(100, libn_context_D.u2fTimeout); - if (libn_context_D.u2fTimeout == 0) { - u2f_message_timeout(); - break; + case SEPROXYHAL_TAG_BUTTON_PUSH_EVENT: + UX_BUTTON_PUSH_EVENT(G_io_seproxyhal_spi_buffer); + break; + + case SEPROXYHAL_TAG_STATUS_EVENT: + if (G_io_apdu_media == IO_APDU_MEDIA_USB_HID && + !(U4BE(G_io_seproxyhal_spi_buffer, 3) & + SEPROXYHAL_TAG_STATUS_EVENT_FLAG_USB_POWERED)) { + THROW(EXCEPTION_IO_RESET); } - } -#endif // HAVE_IO_U2F + __attribute__((fallthrough)); + // no break is intentional + default: + UX_DEFAULT_EVENT(); + break; + + case SEPROXYHAL_TAG_DISPLAY_PROCESSED_EVENT: + UX_DISPLAYED_EVENT({ app_apply_state(); }); + break; - UX_TICKER_EVENT(G_io_seproxyhal_spi_buffer, { - ui_ticker_event(UX_ALLOWED); - }); - break; + case SEPROXYHAL_TAG_TICKER_EVENT: + if (app_apply_state()) { + // Apply caused changed, nothing else to do this cycle + break; + } + UX_TICKER_EVENT(G_io_seproxyhal_spi_buffer, { ui_ticker_event(UX_ALLOWED); }); + break; } // close the event if not done previously (by a display or whatever) diff --git a/src/libn_app.h b/src/libn_app.h index b03c4d5..7cd5e96 100644 --- a/src/libn_app.h +++ b/src/libn_app.h @@ -1,23 +1,20 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2016 Ledger -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ - -#ifndef LIBN_H - -#define LIBN_H + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2016 Ledger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +#pragma once #include "os.h" @@ -28,6 +25,7 @@ #define SW_TECHNICAL_DETAILS(x) LIBN_SW_TECHNICAL_PROBLEM #include "libn_secure_value.h" + #include "libn_types.h" void app_async_response(libn_apdu_response_t *resp, uint16_t statusWord); @@ -36,5 +34,3 @@ bool app_apply_state(void); void app_init(void); void app_main(void); void app_exit(void); - -#endif diff --git a/src/libn_bagl.h b/src/libn_bagl.h index a3c0862..52e0e70 100644 --- a/src/libn_bagl.h +++ b/src/libn_bagl.h @@ -1,33 +1,29 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2018 Mart Roosmaa -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ - -#ifndef LIBN_BAGL_H - -#define LIBN_BAGL_H + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2018 Mart Roosmaa + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +#pragma once #include "libn_app.h" #define LIBN_BAGL_COLOR_APP 0xFCB653 void libn_bagl_display_address_callback(bool confirmed); + void libn_bagl_confirm_sign_block_callback(bool confirmed); /** Apply current global state to UX. Returns true if UX was updated, false if the UX is already in the correct state and nothing was done. **/ bool libn_bagl_apply_state(); - -#endif // LIBN_BAGL_H diff --git a/src/libn_bagl_blue.c b/src/libn_bagl_blue.c index 73e1b74..0ba92f5 100644 --- a/src/libn_bagl_blue.c +++ b/src/libn_bagl_blue.c @@ -1,19 +1,19 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2018 Mart Roosmaa -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2018 Mart Roosmaa + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ #include @@ -39,15 +39,8 @@ extern ux_state_t ux; libn_state_t bagl_state; libn_idle_state_t bagl_idle_state; -#define COIN_MAX_PREFIX ( \ - MAX(sizeof(COIN_PRIMARY_PREFIX), \ - sizeof(COIN_SECONDARY_PREFIX)) \ -) -#define ACCOUNT_BUF_LEN ( \ - LIBN_ACCOUNT_STRING_BASE_LEN \ - + COIN_MAX_PREFIX \ - + 1 \ -) +#define COIN_MAX_PREFIX (MAX(sizeof(COIN_PRIMARY_PREFIX), sizeof(COIN_SECONDARY_PREFIX))) +#define ACCOUNT_BUF_LEN (LIBN_ACCOUNT_STRING_BASE_LEN + COIN_MAX_PREFIX + 1) #define OPEN_LABEL_PREFIX "Open " #define OPEN_LABEL_SUFFIX " wallet" @@ -84,10 +77,10 @@ void ui_write_address_truncated(const libn_address_formatter_t *fmt, const size_t addressLen = libn_address_format(fmt, buf, publicKey); const size_t prefixLen = addressLen - LIBN_ACCOUNT_STRING_BASE_LEN; - os_memmove(label, buf, prefixLen + 5); - os_memset(label + prefixLen + 5, '.', 2); - os_memmove(label + prefixLen + 7, buf + addressLen - 5, 5); - label[prefixLen+12] = '\0'; + memmove(label, buf, prefixLen + 5); + memset(label + prefixLen + 5, '.', 2); + memmove(label + prefixLen + 7, buf + addressLen - 5, 5); + label[prefixLen + 12] = '\0'; } typedef char ui_truncated_hash_t[13]; @@ -96,24 +89,22 @@ void ui_write_hash_truncated(ui_truncated_hash_t label, libn_hash_t hash) { uint8_t buf[sizeof(libn_hash_t) * 2]; libn_write_hex_string(buf, hash, sizeof(libn_hash_t)); // Truncate hash to 12345..67890 format - os_memmove(label, buf, 5); - os_memset(label+5, '.', 2); - os_memmove(label+7, buf+sizeof(buf)-5, 5); + memmove(label, buf, 5); + memset(label + 5, '.', 2); + memmove(label + 7, buf + sizeof(buf) - 5, 5); label[12] = '\0'; } -#define SEND_AMOUNT_LABEL "Send amount" +#define SEND_AMOUNT_LABEL "Send amount" #define RECEIVE_AMOUNT_LABEL "Receive amount" bagl_element_t mutableElement; union { struct { - char appTitle[sizeof(COIN_NAME)+1]; - char openLabel[sizeof(OPEN_LABEL_PREFIX) - + sizeof(COIN_NAME) - + sizeof(OPEN_LABEL_SUFFIX) - + 1]; + char appTitle[sizeof(COIN_NAME) + 1]; + char openLabel[sizeof(OPEN_LABEL_PREFIX) + sizeof(COIN_NAME) + sizeof(OPEN_LABEL_SUFFIX) + + 1]; } idle; struct { } settings; @@ -139,103 +130,215 @@ const bagl_element_t *ui_touch_confirm(const bagl_element_t *e); const bagl_element_t ui_idle[] = { // Header background - {{/* type */ BAGL_RECTANGLE, /* userid */ 0x00, - /* x */ 0, /* y */ 20, /* width */ 320, /* height */ 48, - /* stroke */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_ALT_BG, /* bgcolor */ COIN_COLOR_ALT_BG, - /* font_id */ 0, /* icon_id */ 0}, - /* text */ NULL, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, + {{/* type */ BAGL_RECTANGLE, + /* userid */ 0x00, + /* x */ 0, + /* y */ 20, + /* width */ 320, + /* height */ 48, + /* stroke */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_ALT_BG, + /* bgcolor */ COIN_COLOR_ALT_BG, + /* font_id */ 0, + /* icon_id */ 0}, + /* text */ NULL, + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, // Content background - {{/* type */ BAGL_RECTANGLE, /* userid */ 0x00, - /* x */ 0, /* y */ 68, /* width */ 320, /* height */ 413, - /* stroke */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_BG, /* bgcolor */ COIN_COLOR_BG, - /* font_id */ 0, /* icon_id */ 0}, - /* text */ NULL, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, + {{/* type */ BAGL_RECTANGLE, + /* userid */ 0x00, + /* x */ 0, + /* y */ 68, + /* width */ 320, + /* height */ 413, + /* stroke */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_BG, + /* bgcolor */ COIN_COLOR_BG, + /* font_id */ 0, + /* icon_id */ 0}, + /* text */ NULL, + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, // Header views - {{/* type */ BAGL_LABELINE, /* userid */ 0x00, - /* x */ 0, /* y */ 45, /* width */ 320, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ 0, - /* fgcolor */ COIN_COLOR_ALT_FG, /* bgcolor */ COIN_COLOR_ALT_BG, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x00, + /* x */ 0, + /* y */ 45, + /* width */ 320, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ 0, + /* fgcolor */ COIN_COLOR_ALT_FG, + /* bgcolor */ COIN_COLOR_ALT_BG, /* font_id */ BAGL_FONT_OPEN_SANS_SEMIBOLD_10_13PX | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, - /* text */ vars.idle.appTitle, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_RECTANGLE | BAGL_FLAG_TOUCHABLE, /* userid */ 0x00, - /* x */ 0, /* y */ 19, /* width */ 56, /* height */ 44, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_ALT_BG, /* bgcolor */ COIN_COLOR_ALT_FG, + /* text */ vars.idle.appTitle, + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + {{/* type */ BAGL_RECTANGLE | BAGL_FLAG_TOUCHABLE, + /* userid */ 0x00, + /* x */ 0, + /* y */ 19, + /* width */ 56, + /* height */ 44, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_ALT_BG, + /* bgcolor */ COIN_COLOR_ALT_FG, /* font_id */ BAGL_FONT_SYMBOLS_0 | BAGL_FONT_ALIGNMENT_CENTER | BAGL_FONT_ALIGNMENT_MIDDLE, /* scrollspeed */ 0}, - /* text */ BAGL_FONT_SYMBOLS_0_SETTINGS, /* touch_area_brim */ 0, - /* overfgcolor */ COIN_COLOR_ALT_BG, /* overbgcolor */ COIN_COLOR_ALT_FG, - /* tap */ ui_touch_settings, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_RECTANGLE | BAGL_FLAG_TOUCHABLE, /* userid */ 0x00, - /* x */ 264, /* y */ 19, /* width */ 56, /* height */ 44, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_ALT_BG, /* bgcolor */ COIN_COLOR_ALT_FG, + /* text */ BAGL_FONT_SYMBOLS_0_SETTINGS, + /* touch_area_brim */ 0, + /* overfgcolor */ COIN_COLOR_ALT_BG, + /* overbgcolor */ COIN_COLOR_ALT_FG, + /* tap */ ui_touch_settings, + /* out */ NULL, + /* over */ NULL}, + {{/* type */ BAGL_RECTANGLE | BAGL_FLAG_TOUCHABLE, + /* userid */ 0x00, + /* x */ 264, + /* y */ 19, + /* width */ 56, + /* height */ 44, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_ALT_BG, + /* bgcolor */ COIN_COLOR_ALT_FG, /* font_id */ BAGL_FONT_SYMBOLS_0 | BAGL_FONT_ALIGNMENT_CENTER | BAGL_FONT_ALIGNMENT_MIDDLE, /* scrollspeed */ 0}, - /* text */ BAGL_FONT_SYMBOLS_0_DASHBOARD, /* touch_area_brim */ 0, - /* overfgcolor */ COIN_COLOR_ALT_BG, /* overbgcolor */ COIN_COLOR_ALT_FG, - /* tap */ ui_touch_exit, /* out */ NULL, /* over */ NULL}, + /* text */ BAGL_FONT_SYMBOLS_0_DASHBOARD, + /* touch_area_brim */ 0, + /* overfgcolor */ COIN_COLOR_ALT_BG, + /* overbgcolor */ COIN_COLOR_ALT_FG, + /* tap */ ui_touch_exit, + /* out */ NULL, + /* over */ NULL}, // Content views - {{/* type */ BAGL_ICON, /* userid */ 0x00, - /* x */ 135, /* y */ 178, /* width */ 50, /* height */ 50, - /* stroke */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, - /* font_id */ 0, /* icon_id */ 0}, - /* text */ (char *)COIN_BADGE, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_LABELINE, /* userid */ 0x00, - /* x */ 0, /* y */ 270, /* width */ 320, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, + {{/* type */ BAGL_ICON, + /* userid */ 0x00, + /* x */ 135, + /* y */ 178, + /* width */ 50, + /* height */ 50, + /* stroke */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, + /* font_id */ 0, + /* icon_id */ 0}, + /* text */ (char *) COIN_BADGE, + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x00, + /* x */ 0, + /* y */ 270, + /* width */ 320, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, /* font_id */ BAGL_FONT_OPEN_SANS_LIGHT_16_22PX | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, - /* text */ vars.idle.openLabel, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_LABELINE, /* userid */ 0x00, - /* x */ 0, /* y */ 308, /* width */ 320, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, + /* text */ vars.idle.openLabel, + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x00, + /* x */ 0, + /* y */ 308, + /* width */ 320, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_10_13PX | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, - /* text */ "Connect the Ledger Blue and open your", /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_LABELINE, /* userid */ 0x00, - /* x */ 0, /* y */ 331, /* width */ 320, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, + /* text */ "Connect the Ledger Blue and open your", + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x00, + /* x */ 0, + /* y */ 331, + /* width */ 320, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_10_13PX | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, - /* text */ "preferred wallet to view your accounts.", /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_LABELINE, /* userid */ 0x00, - /* x */ 0, /* y */ 450, /* width */ 320, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, + /* text */ "preferred wallet to view your accounts.", + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x00, + /* x */ 0, + /* y */ 450, + /* width */ 320, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_8_11PX | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, - /* text */ "Approval requests will show automatically.", /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, + /* text */ "Approval requests will show automatically.", + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, }; -uint32_t ui_idle_button(uint32_t button_mask, - uint32_t button_mask_counter) { +uint32_t ui_idle_button(uint32_t button_mask, uint32_t button_mask_counter) { return 0; } @@ -245,8 +348,8 @@ void libn_bagl_idle(void) { UX_SET_STATUS_BAR_COLOR(COIN_COLOR_ALT_FG, COIN_COLOR_ALT_BG); // Uppercase the coin name - os_memset(vars.idle.appTitle, 0, sizeof(vars.idle.appTitle)); - strncpy(vars.idle.appTitle, COIN_NAME, MIN(sizeof(vars.idle.appTitle)-1, sizeof(COIN_NAME))); + memset(vars.idle.appTitle, 0, sizeof(vars.idle.appTitle)); + strncpy(vars.idle.appTitle, COIN_NAME, MIN(sizeof(vars.idle.appTitle) - 1, sizeof(COIN_NAME))); for (size_t i = 0; i < sizeof(vars.idle.appTitle); i++) { if (vars.idle.appTitle[i] >= 'a' && vars.idle.appTitle[i] <= 'z') { vars.idle.appTitle[i] = 'A' + vars.idle.appTitle[i] - 'a'; @@ -254,7 +357,7 @@ void libn_bagl_idle(void) { } // Concat OPEN_LABEL_PREFIX + COIN_NAME + OPEN_LABEL_SUFFIX - os_memset(vars.idle.openLabel, 0, sizeof(vars.idle.openLabel)); + memset(vars.idle.openLabel, 0, sizeof(vars.idle.openLabel)); size_t max = sizeof(vars.idle.openLabel) - 1; char *ptr = vars.idle.openLabel; @@ -273,141 +376,298 @@ void libn_bagl_idle(void) { const bagl_element_t ui_settings[] = { // Header background - {{/* type */ BAGL_RECTANGLE, /* userid */ 0x00, - /* x */ 0, /* y */ 20, /* width */ 320, /* height */ 48, - /* stroke */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_ALT_BG, /* bgcolor */ COIN_COLOR_ALT_BG, - /* font_id */ 0, /* icon_id */ 0}, - /* text */ NULL, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, + {{/* type */ BAGL_RECTANGLE, + /* userid */ 0x00, + /* x */ 0, + /* y */ 20, + /* width */ 320, + /* height */ 48, + /* stroke */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_ALT_BG, + /* bgcolor */ COIN_COLOR_ALT_BG, + /* font_id */ 0, + /* icon_id */ 0}, + /* text */ NULL, + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, // Content background - {{/* type */ BAGL_RECTANGLE, /* userid */ 0x00, - /* x */ 0, /* y */ 68, /* width */ 320, /* height */ 413, - /* stroke */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_BG, /* bgcolor */ COIN_COLOR_BG, - /* font_id */ 0, /* icon_id */ 0}, - /* text */ NULL, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, + {{/* type */ BAGL_RECTANGLE, + /* userid */ 0x00, + /* x */ 0, + /* y */ 68, + /* width */ 320, + /* height */ 413, + /* stroke */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_BG, + /* bgcolor */ COIN_COLOR_BG, + /* font_id */ 0, + /* icon_id */ 0}, + /* text */ NULL, + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, // Header views - {{/* type */ BAGL_LABELINE, /* userid */ 0x00, - /* x */ 0, /* y */ 45, /* width */ 320, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ 0, - /* fgcolor */ COIN_COLOR_ALT_FG, /* bgcolor */ COIN_COLOR_ALT_BG, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x00, + /* x */ 0, + /* y */ 45, + /* width */ 320, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ 0, + /* fgcolor */ COIN_COLOR_ALT_FG, + /* bgcolor */ COIN_COLOR_ALT_BG, /* font_id */ BAGL_FONT_OPEN_SANS_SEMIBOLD_10_13PX | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, - /* text */ "SETTINGS", /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_RECTANGLE | BAGL_FLAG_TOUCHABLE, /* userid */ 0x00, - /* x */ 0, /* y */ 19, /* width */ 50, /* height */ 44, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_ALT_BG, /* bgcolor */ COIN_COLOR_ALT_FG, + /* text */ "SETTINGS", + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + {{/* type */ BAGL_RECTANGLE | BAGL_FLAG_TOUCHABLE, + /* userid */ 0x00, + /* x */ 0, + /* y */ 19, + /* width */ 50, + /* height */ 44, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_ALT_BG, + /* bgcolor */ COIN_COLOR_ALT_FG, /* font_id */ BAGL_FONT_SYMBOLS_0 | BAGL_FONT_ALIGNMENT_CENTER | BAGL_FONT_ALIGNMENT_MIDDLE, /* scrollspeed */ 0}, - /* text */ BAGL_FONT_SYMBOLS_0_LEFT, /* touch_area_brim */ 0, - /* overfgcolor */ COIN_COLOR_ALT_BG, /* overbgcolor */ COIN_COLOR_ALT_FG, - /* tap */ ui_touch_back, /* out */ NULL, /* over */ NULL}, + /* text */ BAGL_FONT_SYMBOLS_0_LEFT, + /* touch_area_brim */ 0, + /* overfgcolor */ COIN_COLOR_ALT_BG, + /* overbgcolor */ COIN_COLOR_ALT_FG, + /* tap */ ui_touch_back, + /* out */ NULL, + /* over */ NULL}, // Content views - {{/* type */ BAGL_LABELINE, /* userid */ 0x00, - /* x */ 30, /* y */ 105, /* width */ 260, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x00, + /* x */ 30, + /* y */ 105, + /* width */ 260, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_10_13PX, /* scrollspeed */ 0}, - /* text */ "Auto-receive", /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_LABELINE, /* userid */ 0x00, - /* x */ 30, /* y */ 126, /* width */ 260, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, + /* text */ "Auto-receive", + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x00, + /* x */ 30, + /* y */ 126, + /* width */ 260, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_8_11PX, /* scrollspeed */ 0}, - /* text */ "No confirmation for receive transactions", /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_NONE | BAGL_FLAG_TOUCHABLE, /* userid */ 0x00, - /* x */ 0, /* y */ 78, /* width */ 320, /* height */ 68, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, - /* font_id */ 0, /* scrollspeed */ 0}, - /* text */ NULL, /* touch_area_brim */ 0, - /* overfgcolor */ COIN_COLOR_ALT_BG, /* overbgcolor */ COIN_COLOR_ALT_FG, - /* tap */ ui_touch_auto_receive, /* out */ NULL, /* over */ NULL}, - - {{/* type */ BAGL_LABELINE, /* userid */ 0x00, - /* x */ 30, /* y */ 329, /* width */ 260, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, + /* text */ "No confirmation for receive transactions", + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + {{/* type */ BAGL_NONE | BAGL_FLAG_TOUCHABLE, + /* userid */ 0x00, + /* x */ 0, + /* y */ 78, + /* width */ 320, + /* height */ 68, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, + /* font_id */ 0, + /* scrollspeed */ 0}, + /* text */ NULL, + /* touch_area_brim */ 0, + /* overfgcolor */ COIN_COLOR_ALT_BG, + /* overbgcolor */ COIN_COLOR_ALT_FG, + /* tap */ ui_touch_auto_receive, + /* out */ NULL, + /* over */ NULL}, + + {{/* type */ BAGL_LABELINE, + /* userid */ 0x00, + /* x */ 30, + /* y */ 329, + /* width */ 260, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_10_13PX, /* scrollspeed */ 0}, - /* text */ "Version", /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_LABELINE, /* userid */ 0x00, - /* x */ 30, /* y */ 350, /* width */ 260, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, + /* text */ "Version", + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x00, + /* x */ 30, + /* y */ 350, + /* width */ 260, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_8_11PX, /* scrollspeed */ 0}, - /* text */ APPVERSION, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_LABELINE, /* userid */ 0x00, - /* x */ 30, /* y */ 379, /* width */ 260, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, + /* text */ APPVERSION, + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x00, + /* x */ 30, + /* y */ 379, + /* width */ 260, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_10_13PX, /* scrollspeed */ 0}, - /* text */ "Developer", /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_LABELINE, /* userid */ 0x00, - /* x */ 30, /* y */ 400, /* width */ 260, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, + /* text */ "Developer", + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x00, + /* x */ 30, + /* y */ 400, + /* width */ 260, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_8_11PX, /* scrollspeed */ 0}, - /* text */ "Mart Roosmaa", /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_LABELINE, /* userid */ 0x00, - /* x */ 30, /* y */ 429, /* width */ 260, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, + /* text */ "Mart Roosmaa", + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x00, + /* x */ 30, + /* y */ 429, + /* width */ 260, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_10_13PX, /* scrollspeed */ 0}, - /* text */ "Source code", /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_LABELINE, /* userid */ 0x00, - /* x */ 30, /* y */ 450, /* width */ 260, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, + /* text */ "Source code", + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x00, + /* x */ 30, + /* y */ 450, + /* width */ 260, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_8_11PX, /* scrollspeed */ 0}, - /* text */ "https://github.com/roosmaa/blue-app-nano", /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, + /* text */ "https://github.com/LedgerHQ/app-nano", + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, // Quick-redrawable icons - {{/* type */ BAGL_ICON, /* userid */ 0x01, - /* x */ 258, /* y */ 98, /* width */ 32, /* height */ 18, - /* stroke */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, - /* font_id */ 0, /* icon_id */ 0}, - /* text */ (char *)COIN_ICON_TOGGLE_OFF, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, + {{/* type */ BAGL_ICON, + /* userid */ 0x01, + /* x */ 258, + /* y */ 98, + /* width */ 32, + /* height */ 18, + /* stroke */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, + /* font_id */ 0, + /* icon_id */ 0}, + /* text */ (char *) COIN_ICON_TOGGLE_OFF, + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, }; -uint32_t ui_settings_button(uint32_t button_mask, - uint32_t button_mask_counter) { +uint32_t ui_settings_button(uint32_t button_mask, uint32_t button_mask_counter) { return 0; } @@ -417,12 +677,11 @@ const bagl_element_t *ui_settings_prepro(const bagl_element_t *e) { } switch (e->component.userid) { - case 0x01: - os_memmove(&mutableElement, e, sizeof(bagl_element_t)); - mutableElement.text = (const char *)(N_libn.autoReceive - ? COIN_ICON_TOGGLE_ON - : COIN_ICON_TOGGLE_OFF); - return &mutableElement; + case 0x01: + memmove(&mutableElement, e, sizeof(bagl_element_t)); + mutableElement.text = + (const char *) (N_libn.autoReceive ? COIN_ICON_TOGGLE_ON : COIN_ICON_TOGGLE_OFF); + return &mutableElement; } return e; @@ -436,9 +695,8 @@ void libn_bagl_settings(void) { bagl_state = LIBN_STATE_READY; bagl_idle_state = LIBN_IDLE_STATE_SETTINGS; - const bool quickRedaw = UX_DISPLAYED() - && ux.elements == ui_settings - && ux.elements_preprocessor == ui_settings_prepro; + const bool quickRedaw = UX_DISPLAYED() && ux.elements == ui_settings && + ux.elements_preprocessor == ui_settings_prepro; if (!quickRedaw) { UX_DISPLAY(ui_settings, ui_settings_prepro); @@ -451,86 +709,177 @@ void libn_bagl_settings(void) { const bagl_element_t ui_confirm_address[] = { // Header background - {{/* type */ BAGL_RECTANGLE, /* userid */ 0x00, - /* x */ 0, /* y */ 20, /* width */ 320, /* height */ 48, - /* stroke */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_ALT_BG, /* bgcolor */ COIN_COLOR_ALT_BG, - /* font_id */ 0, /* icon_id */ 0}, - /* text */ NULL, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, + {{/* type */ BAGL_RECTANGLE, + /* userid */ 0x00, + /* x */ 0, + /* y */ 20, + /* width */ 320, + /* height */ 48, + /* stroke */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_ALT_BG, + /* bgcolor */ COIN_COLOR_ALT_BG, + /* font_id */ 0, + /* icon_id */ 0}, + /* text */ NULL, + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, // Content background - {{/* type */ BAGL_RECTANGLE, /* userid */ 0x00, - /* x */ 0, /* y */ 68, /* width */ 320, /* height */ 413, - /* stroke */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_BG, /* bgcolor */ COIN_COLOR_BG, - /* font_id */ 0, /* icon_id */ 0}, - /* text */ NULL, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, + {{/* type */ BAGL_RECTANGLE, + /* userid */ 0x00, + /* x */ 0, + /* y */ 68, + /* width */ 320, + /* height */ 413, + /* stroke */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_BG, + /* bgcolor */ COIN_COLOR_BG, + /* font_id */ 0, + /* icon_id */ 0}, + /* text */ NULL, + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, // Header views - {{/* type */ BAGL_LABELINE, /* userid */ 0x00, - /* x */ 0, /* y */ 45, /* width */ 320, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ 0, - /* fgcolor */ COIN_COLOR_ALT_FG, /* bgcolor */ COIN_COLOR_ALT_BG, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x00, + /* x */ 0, + /* y */ 45, + /* width */ 320, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ 0, + /* fgcolor */ COIN_COLOR_ALT_FG, + /* bgcolor */ COIN_COLOR_ALT_BG, /* font_id */ BAGL_FONT_OPEN_SANS_SEMIBOLD_10_13PX | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, - /* text */ "CONFIRM ADDRESS", /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, + /* text */ "CONFIRM ADDRESS", + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, // Content views - {{/* type */ BAGL_LABELINE, /* userid */ 0x00, - /* x */ 30, /* y */ 105, /* width */ 260, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x00, + /* x */ 30, + /* y */ 105, + /* width */ 260, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, /* font_id */ BAGL_FONT_OPEN_SANS_SEMIBOLD_8_11PX | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, - /* text */ "Account address", /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_LABELINE, /* userid */ 0x00, - /* x */ 30, /* y */ 131, /* width */ 260, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, + /* text */ "Account address", + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x00, + /* x */ 30, + /* y */ 131, + /* width */ 260, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_10_13PX | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, - /* text */ vars.displayAddress.address.lines.first, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_LABELINE, /* userid */ 0x00, - /* x */ 30, /* y */ 157, /* width */ 260, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, + /* text */ vars.displayAddress.address.lines.first, + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x00, + /* x */ 30, + /* y */ 157, + /* width */ 260, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_10_13PX | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, - /* text */ vars.displayAddress.address.lines.second, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_RECTANGLE | BAGL_FLAG_TOUCHABLE, /* userid */ 0x00, - /* x */ 40, /* y */ 414, /* width */ 115, /* height */ 36, - /* stroke */ 0, /* radius */ 18, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_REJECT_BG, /* bgcolor */ COIN_COLOR_REJECT_FG, - /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_11_14PX | BAGL_FONT_ALIGNMENT_CENTER | BAGL_FONT_ALIGNMENT_MIDDLE, + /* text */ vars.displayAddress.address.lines.second, + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + {{/* type */ BAGL_RECTANGLE | BAGL_FLAG_TOUCHABLE, + /* userid */ 0x00, + /* x */ 40, + /* y */ 414, + /* width */ 115, + /* height */ 36, + /* stroke */ 0, + /* radius */ 18, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_REJECT_BG, + /* bgcolor */ COIN_COLOR_REJECT_FG, + /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_11_14PX | BAGL_FONT_ALIGNMENT_CENTER | + BAGL_FONT_ALIGNMENT_MIDDLE, /* icon_id */ 0}, - /* text */ "REJECT", /* touch_area_brim */ 0, - /* overfgcolor */ COIN_COLOR_REJECT_OVER_BG, /* overbgcolor */ COIN_COLOR_REJECT_OVER_FG, - /* tap */ ui_touch_reject, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_RECTANGLE | BAGL_FLAG_TOUCHABLE, /* userid */ 0x00, - /* x */ 165, /* y */ 414, /* width */ 115, /* height */ 36, - /* stroke */ 0, /* radius */ 18, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_CONFIRM_BG, /* bgcolor */ COIN_COLOR_CONFIRM_FG, - /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_11_14PX | BAGL_FONT_ALIGNMENT_CENTER | BAGL_FONT_ALIGNMENT_MIDDLE, + /* text */ "REJECT", + /* touch_area_brim */ 0, + /* overfgcolor */ COIN_COLOR_REJECT_OVER_BG, + /* overbgcolor */ COIN_COLOR_REJECT_OVER_FG, + /* tap */ ui_touch_reject, + /* out */ NULL, + /* over */ NULL}, + {{/* type */ BAGL_RECTANGLE | BAGL_FLAG_TOUCHABLE, + /* userid */ 0x00, + /* x */ 165, + /* y */ 414, + /* width */ 115, + /* height */ 36, + /* stroke */ 0, + /* radius */ 18, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_CONFIRM_BG, + /* bgcolor */ COIN_COLOR_CONFIRM_FG, + /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_11_14PX | BAGL_FONT_ALIGNMENT_CENTER | + BAGL_FONT_ALIGNMENT_MIDDLE, /* icon_id */ 0}, - /* text */ "CONFIRM", /* touch_area_brim */ 0, - /* overfgcolor */ COIN_COLOR_CONFIRM_OVER_BG, /* overbgcolor */ COIN_COLOR_CONFIRM_OVER_FG, - /* tap */ ui_touch_confirm, /* out */ NULL, /* over */ NULL}, + /* text */ "CONFIRM", + /* touch_area_brim */ 0, + /* overfgcolor */ COIN_COLOR_CONFIRM_OVER_BG, + /* overbgcolor */ COIN_COLOR_CONFIRM_OVER_FG, + /* tap */ ui_touch_confirm, + /* out */ NULL, + /* over */ NULL}, }; -uint32_t ui_confirm_address_button(uint32_t button_mask, - uint32_t button_mask_counter) { +uint32_t ui_confirm_address_button(uint32_t button_mask, uint32_t button_mask_counter) { return 0; } @@ -540,12 +889,9 @@ void libn_bagl_confirm_address(void) { } libn_apdu_get_address_request_t *req = &libn_context_D.stateData.getAddressRequest; - os_memset(&vars.displayAddress, 0, sizeof(vars.displayAddress)); + memset(&vars.displayAddress, 0, sizeof(vars.displayAddress)); // Encode public key into an address string - ui_write_split_address( - &req->addressFormatter, - &vars.displayAddress.address, - req->publicKey); + ui_write_split_address(&req->addressFormatter, &vars.displayAddress.address, req->publicKey); bagl_state = LIBN_STATE_CONFIRM_ADDRESS; UX_DISPLAY(ui_confirm_address, NULL); @@ -553,176 +899,362 @@ void libn_bagl_confirm_address(void) { const bagl_element_t ui_confirm_block[] = { // Header background - {{/* type */ BAGL_RECTANGLE, /* userid */ 0x00, - /* x */ 0, /* y */ 20, /* width */ 320, /* height */ 48, - /* stroke */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_ALT_BG, /* bgcolor */ COIN_COLOR_ALT_BG, - /* font_id */ 0, /* icon_id */ 0}, - /* text */ NULL, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, + {{/* type */ BAGL_RECTANGLE, + /* userid */ 0x00, + /* x */ 0, + /* y */ 20, + /* width */ 320, + /* height */ 48, + /* stroke */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_ALT_BG, + /* bgcolor */ COIN_COLOR_ALT_BG, + /* font_id */ 0, + /* icon_id */ 0}, + /* text */ NULL, + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, // Content background - {{/* type */ BAGL_RECTANGLE, /* userid */ 0x00, - /* x */ 0, /* y */ 68, /* width */ 320, /* height */ 413, - /* stroke */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_BG, /* bgcolor */ COIN_COLOR_BG, - /* font_id */ 0, /* icon_id */ 0}, - /* text */ NULL, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, + {{/* type */ BAGL_RECTANGLE, + /* userid */ 0x00, + /* x */ 0, + /* y */ 68, + /* width */ 320, + /* height */ 413, + /* stroke */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_BG, + /* bgcolor */ COIN_COLOR_BG, + /* font_id */ 0, + /* icon_id */ 0}, + /* text */ NULL, + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, // Header views - {{/* type */ BAGL_LABELINE, /* userid */ 0x00, - /* x */ 0, /* y */ 45, /* width */ 320, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ 0, - /* fgcolor */ COIN_COLOR_ALT_FG, /* bgcolor */ COIN_COLOR_ALT_BG, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x00, + /* x */ 0, + /* y */ 45, + /* width */ 320, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ 0, + /* fgcolor */ COIN_COLOR_ALT_FG, + /* bgcolor */ COIN_COLOR_ALT_BG, /* font_id */ BAGL_FONT_OPEN_SANS_SEMIBOLD_10_13PX | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, - /* text */ "CONFIRM BLOCK", /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, + /* text */ "CONFIRM BLOCK", + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, // Content views - {{/* type */ BAGL_LABELINE, /* userid */ 0x10, - /* x */ 30, /* y */ 105, /* width */ 260, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x10, + /* x */ 30, + /* y */ 105, + /* width */ 260, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, /* font_id */ BAGL_FONT_OPEN_SANS_SEMIBOLD_8_11PX | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, - /* text */ "Your account", /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_LABELINE, /* userid */ 0x11, - /* x */ 30, /* y */ 131, /* width */ 260, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, + /* text */ "Your account", + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x11, + /* x */ 30, + /* y */ 131, + /* width */ 260, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_10_13PX | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, - /* text */ vars.confirmSignBlock.accountAddress, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - - {{/* type */ BAGL_LABELINE, /* userid */ 0x20, - /* x */ 30, /* y */ 160, /* width */ 260, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, + /* text */ vars.confirmSignBlock.accountAddress, + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + + {{/* type */ BAGL_LABELINE, + /* userid */ 0x20, + /* x */ 30, + /* y */ 160, + /* width */ 260, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, /* font_id */ BAGL_FONT_OPEN_SANS_SEMIBOLD_8_11PX | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, - /* text */ vars.confirmSignBlock.amountLabel, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_LABELINE, /* userid */ 0x21, - /* x */ 30, /* y */ 186, /* width */ 260, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, + /* text */ vars.confirmSignBlock.amountLabel, + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x21, + /* x */ 30, + /* y */ 186, + /* width */ 260, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_10_13PX | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, - /* text */ vars.confirmSignBlock.amountValue, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - - {{/* type */ BAGL_LABELINE, /* userid */ 0x30, - /* x */ 30, /* y */ 215, /* width */ 260, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, + /* text */ vars.confirmSignBlock.amountValue, + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + + {{/* type */ BAGL_LABELINE, + /* userid */ 0x30, + /* x */ 30, + /* y */ 215, + /* width */ 260, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, /* font_id */ BAGL_FONT_OPEN_SANS_SEMIBOLD_8_11PX | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, - /* text */ "Send to", /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_LABELINE, /* userid */ 0x31, - /* x */ 30, /* y */ 241, /* width */ 260, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, + /* text */ "Send to", + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x31, + /* x */ 30, + /* y */ 241, + /* width */ 260, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_10_13PX | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, /* text */ vars.confirmSignBlock.recipientAddress.lines.first, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_LABELINE, /* userid */ 0x32, - /* x */ 30, /* y */ 262, /* width */ 260, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x32, + /* x */ 30, + /* y */ 262, + /* width */ 260, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_10_13PX | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, /* text */ vars.confirmSignBlock.recipientAddress.lines.second, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - - {{/* type */ BAGL_LABELINE, /* userid */ 0x40, - /* x */ 30, /* y */ 291, /* width */ 260, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + + {{/* type */ BAGL_LABELINE, + /* userid */ 0x40, + /* x */ 30, + /* y */ 291, + /* width */ 260, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, /* font_id */ BAGL_FONT_OPEN_SANS_SEMIBOLD_8_11PX | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, - /* text */ "Representative", /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_LABELINE, /* userid */ 0x41, - /* x */ 30, /* y */ 317, /* width */ 260, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, + /* text */ "Representative", + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x41, + /* x */ 30, + /* y */ 317, + /* width */ 260, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_10_13PX | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, /* text */ vars.confirmSignBlock.representativeAddress.lines.first, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_LABELINE, /* userid */ 0x42, - /* x */ 30, /* y */ 338, /* width */ 260, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x42, + /* x */ 30, + /* y */ 338, + /* width */ 260, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_10_13PX | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, /* text */ vars.confirmSignBlock.representativeAddress.lines.second, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - - {{/* type */ BAGL_LABELINE, /* userid */ 0x50, - /* x */ 30, /* y */ 367, /* width */ 260, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + + {{/* type */ BAGL_LABELINE, + /* userid */ 0x50, + /* x */ 30, + /* y */ 367, + /* width */ 260, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, /* font_id */ BAGL_FONT_OPEN_SANS_SEMIBOLD_8_11PX | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, - /* text */ "Block hash", /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_LABELINE, /* userid */ 0x51, - /* x */ 30, /* y */ 393, /* width */ 260, /* height */ 30, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_FG, /* bgcolor */ COIN_COLOR_BG, + /* text */ "Block hash", + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x51, + /* x */ 30, + /* y */ 393, + /* width */ 260, + /* height */ 30, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_FG, + /* bgcolor */ COIN_COLOR_BG, /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_10_13PX | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, - /* text */ vars.confirmSignBlock.blockHash, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - - {{/* type */ BAGL_RECTANGLE | BAGL_FLAG_TOUCHABLE, /* userid */ 0x00, - /* x */ 40, /* y */ 414, /* width */ 115, /* height */ 36, - /* stroke */ 0, /* radius */ 18, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_REJECT_BG, /* bgcolor */ COIN_COLOR_REJECT_FG, - /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_11_14PX | BAGL_FONT_ALIGNMENT_CENTER | BAGL_FONT_ALIGNMENT_MIDDLE, + /* text */ vars.confirmSignBlock.blockHash, + /* touch_area_brim */ 0, + /* overfgcolor */ 0, + /* overbgcolor */ 0, + /* tap */ NULL, + /* out */ NULL, + /* over */ NULL}, + + {{/* type */ BAGL_RECTANGLE | BAGL_FLAG_TOUCHABLE, + /* userid */ 0x00, + /* x */ 40, + /* y */ 414, + /* width */ 115, + /* height */ 36, + /* stroke */ 0, + /* radius */ 18, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_REJECT_BG, + /* bgcolor */ COIN_COLOR_REJECT_FG, + /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_11_14PX | BAGL_FONT_ALIGNMENT_CENTER | + BAGL_FONT_ALIGNMENT_MIDDLE, /* icon_id */ 0}, - /* text */ "REJECT", /* touch_area_brim */ 0, - /* overfgcolor */ COIN_COLOR_REJECT_OVER_BG, /* overbgcolor */ COIN_COLOR_REJECT_OVER_FG, - /* tap */ ui_touch_reject, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_RECTANGLE | BAGL_FLAG_TOUCHABLE, /* userid */ 0x00, - /* x */ 165, /* y */ 414, /* width */ 115, /* height */ 36, - /* stroke */ 0, /* radius */ 18, /* fill */ BAGL_FILL, - /* fgcolor */ COIN_COLOR_CONFIRM_BG, /* bgcolor */ COIN_COLOR_CONFIRM_FG, - /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_11_14PX | BAGL_FONT_ALIGNMENT_CENTER | BAGL_FONT_ALIGNMENT_MIDDLE, + /* text */ "REJECT", + /* touch_area_brim */ 0, + /* overfgcolor */ COIN_COLOR_REJECT_OVER_BG, + /* overbgcolor */ COIN_COLOR_REJECT_OVER_FG, + /* tap */ ui_touch_reject, + /* out */ NULL, + /* over */ NULL}, + {{/* type */ BAGL_RECTANGLE | BAGL_FLAG_TOUCHABLE, + /* userid */ 0x00, + /* x */ 165, + /* y */ 414, + /* width */ 115, + /* height */ 36, + /* stroke */ 0, + /* radius */ 18, + /* fill */ BAGL_FILL, + /* fgcolor */ COIN_COLOR_CONFIRM_BG, + /* bgcolor */ COIN_COLOR_CONFIRM_FG, + /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_11_14PX | BAGL_FONT_ALIGNMENT_CENTER | + BAGL_FONT_ALIGNMENT_MIDDLE, /* icon_id */ 0}, - /* text */ "CONFIRM", /* touch_area_brim */ 0, - /* overfgcolor */ COIN_COLOR_CONFIRM_OVER_BG, /* overbgcolor */ COIN_COLOR_CONFIRM_OVER_FG, - /* tap */ ui_touch_confirm, /* out */ NULL, /* over */ NULL}, + /* text */ "CONFIRM", + /* touch_area_brim */ 0, + /* overfgcolor */ COIN_COLOR_CONFIRM_OVER_BG, + /* overbgcolor */ COIN_COLOR_CONFIRM_OVER_FG, + /* tap */ ui_touch_confirm, + /* out */ NULL, + /* over */ NULL}, }; -uint32_t ui_confirm_block_button(uint32_t button_mask, - uint32_t button_mask_counter) { +uint32_t ui_confirm_block_button(uint32_t button_mask, uint32_t button_mask_counter) { return 0; } @@ -733,20 +1265,20 @@ const bagl_element_t *ui_confirm_block_prepro(const bagl_element_t *e) { uint16_t y = 97; - #define LAYOUT(el_uid, el_vis) { \ - if (el_vis) { \ - const bool isHeader = (el_uid & 0x0F) == 0; \ - y += isHeader ? 8 : 0; \ - if (e->component.userid == el_uid) { \ - os_memmove(&mutableElement, e, \ - sizeof(bagl_element_t)); \ - mutableElement.component.y = y; \ - return &mutableElement; \ - } \ - y += (isHeader ? 5 : 0) + 21; \ - } else if (e->component.userid == el_uid) { \ - return NULL; \ - } \ +#define LAYOUT(el_uid, el_vis) \ + { \ + if (el_vis) { \ + const bool isHeader = (el_uid & 0x0F) == 0; \ + y += isHeader ? 8 : 0; \ + if (e->component.userid == el_uid) { \ + memmove(&mutableElement, e, sizeof(bagl_element_t)); \ + mutableElement.component.y = y; \ + return &mutableElement; \ + } \ + y += (isHeader ? 5 : 0) + 21; \ + } else if (e->component.userid == el_uid) { \ + return NULL; \ + } \ } // Account @@ -767,7 +1299,7 @@ const bagl_element_t *ui_confirm_block_prepro(const bagl_element_t *e) { LAYOUT(0x50, true); LAYOUT(0x51, true); - #undef LAYOUT +#undef LAYOUT return e; } @@ -778,41 +1310,35 @@ void libn_bagl_confirm_block(void) { } libn_apdu_sign_block_request_t *req = &libn_context_D.stateData.signBlockRequest; - os_memset(&vars.confirmSignBlock, 0, sizeof(vars.confirmSignBlock)); + memset(&vars.confirmSignBlock, 0, sizeof(vars.confirmSignBlock)); - ui_write_address_truncated( - &req->addressFormatter, - vars.confirmSignBlock.accountAddress, - req->publicKey); + ui_write_address_truncated(&req->addressFormatter, + vars.confirmSignBlock.accountAddress, + req->publicKey); if (!libn_is_zero(req->amount, sizeof(req->amount))) { - libn_amount_format( - &req->amountFormatter, - vars.confirmSignBlock.amountValue, - sizeof(vars.confirmSignBlock.amountValue), - req->amount); + libn_amount_format(&req->amountFormatter, + vars.confirmSignBlock.amountValue, + sizeof(vars.confirmSignBlock.amountValue), + req->amount); if (!libn_is_zero(req->recipient, sizeof(req->recipient))) { strcpy(vars.confirmSignBlock.amountLabel, SEND_AMOUNT_LABEL); - ui_write_split_address( - &req->recipientFormatter, - &vars.confirmSignBlock.recipientAddress, - req->recipient); + ui_write_split_address(&req->recipientFormatter, + &vars.confirmSignBlock.recipientAddress, + req->recipient); } else { strcpy(vars.confirmSignBlock.amountLabel, RECEIVE_AMOUNT_LABEL); } } if (!libn_is_zero(req->representative, sizeof(req->representative))) { - ui_write_split_address( - &req->representativeFormatter, - &vars.confirmSignBlock.representativeAddress, - req->representative); + ui_write_split_address(&req->representativeFormatter, + &vars.confirmSignBlock.representativeAddress, + req->representative); } - ui_write_hash_truncated( - vars.confirmSignBlock.blockHash, - req->blockHash); + ui_write_hash_truncated(vars.confirmSignBlock.blockHash, req->blockHash); bagl_state = LIBN_STATE_CONFIRM_SIGNATURE; UX_DISPLAY(ui_confirm_block, ui_confirm_block_prepro); @@ -827,30 +1353,30 @@ bool libn_bagl_apply_state() { } switch (libn_context_D.state) { - case LIBN_STATE_READY: - if (bagl_state != LIBN_STATE_READY) { - switch (bagl_idle_state) { - case LIBN_IDLE_STATE_HOME: - libn_bagl_idle(); + case LIBN_STATE_READY: + if (bagl_state != LIBN_STATE_READY) { + switch (bagl_idle_state) { + case LIBN_IDLE_STATE_HOME: + libn_bagl_idle(); + return true; + case LIBN_IDLE_STATE_SETTINGS: + libn_bagl_settings(); + return true; + } + } + break; + case LIBN_STATE_CONFIRM_ADDRESS: + if (bagl_state != LIBN_STATE_CONFIRM_ADDRESS) { + libn_bagl_confirm_address(); return true; - case LIBN_IDLE_STATE_SETTINGS: - libn_bagl_settings(); + } + break; + case LIBN_STATE_CONFIRM_SIGNATURE: + if (bagl_state != LIBN_STATE_CONFIRM_SIGNATURE) { + libn_bagl_confirm_block(); return true; } - } - break; - case LIBN_STATE_CONFIRM_ADDRESS: - if (bagl_state != LIBN_STATE_CONFIRM_ADDRESS) { - libn_bagl_confirm_address(); - return true; - } - break; - case LIBN_STATE_CONFIRM_SIGNATURE: - if (bagl_state != LIBN_STATE_CONFIRM_SIGNATURE) { - libn_bagl_confirm_block(); - return true; - } - break; + break; } return false; @@ -881,26 +1407,28 @@ const bagl_element_t *ui_touch_auto_receive(const bagl_element_t *e) { const bagl_element_t *ui_touch_reject(const bagl_element_t *e) { switch (bagl_state) { - case LIBN_STATE_READY: break; - case LIBN_STATE_CONFIRM_ADDRESS: - libn_bagl_display_address_callback(false); - break; - case LIBN_STATE_CONFIRM_SIGNATURE: - libn_bagl_confirm_sign_block_callback(false); - break; + case LIBN_STATE_READY: + break; + case LIBN_STATE_CONFIRM_ADDRESS: + libn_bagl_display_address_callback(false); + break; + case LIBN_STATE_CONFIRM_SIGNATURE: + libn_bagl_confirm_sign_block_callback(false); + break; } return NULL; } const bagl_element_t *ui_touch_confirm(const bagl_element_t *e) { switch (bagl_state) { - case LIBN_STATE_READY: break; - case LIBN_STATE_CONFIRM_ADDRESS: - libn_bagl_display_address_callback(true); - break; - case LIBN_STATE_CONFIRM_SIGNATURE: - libn_bagl_confirm_sign_block_callback(true); - break; + case LIBN_STATE_READY: + break; + case LIBN_STATE_CONFIRM_ADDRESS: + libn_bagl_display_address_callback(true); + break; + case LIBN_STATE_CONFIRM_SIGNATURE: + libn_bagl_confirm_sign_block_callback(true); + break; } return NULL; } diff --git a/src/libn_bagl_nanos.c b/src/libn_bagl_nanos.c index 7b622fd..e296530 100644 --- a/src/libn_bagl_nanos.c +++ b/src/libn_bagl_nanos.c @@ -1,19 +1,19 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2018 Mart Roosmaa -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2018 Mart Roosmaa + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ #include @@ -34,12 +34,9 @@ libn_state_t bagl_state; uint16_t ux_step; uint16_t ux_step_count; -#define ACCOUNT_BUF_LEN ( \ - LIBN_ACCOUNT_STRING_BASE_LEN \ - + MAX(sizeof(COIN_PRIMARY_PREFIX), \ - sizeof(COIN_SECONDARY_PREFIX)) \ - + 1 \ -) +#define ACCOUNT_BUF_LEN \ + (LIBN_ACCOUNT_STRING_BASE_LEN + \ + MAX(sizeof(COIN_PRIMARY_PREFIX), sizeof(COIN_SECONDARY_PREFIX)) + 1) union { struct { @@ -50,37 +47,36 @@ union { bool showRecipient; bool showRepresentative; char confirmLabel[20]; - char confirmValue[MAX(ACCOUNT_BUF_LEN, 2*sizeof(libn_hash_t)+1)]; + char confirmValue[MAX(ACCOUNT_BUF_LEN, 2 * sizeof(libn_hash_t) + 1)]; } confirmSignBlock; } vars; void ui_write_address_truncated(const libn_address_formatter_t *fmt, char *label, const libn_public_key_t publicKey) { - const size_t addressLen = libn_address_format(fmt, (uint8_t *)label, publicKey); + const size_t addressLen = libn_address_format(fmt, (uint8_t *) label, publicKey); const size_t prefixLen = addressLen - LIBN_ACCOUNT_STRING_BASE_LEN; - os_memset(label + prefixLen + 5, '.', 2); - os_memmove(label + prefixLen + 7, label + addressLen - 5, 5); - label[prefixLen+12] = '\0'; + memset(label + prefixLen + 5, '.', 2); + memmove(label + prefixLen + 7, label + addressLen - 5, 5); + label[prefixLen + 12] = '\0'; } void ui_write_address_full(const libn_address_formatter_t *fmt, char *label, const libn_public_key_t publicKey) { - const size_t addressLen = libn_address_format(fmt, (uint8_t *)label, publicKey); + const size_t addressLen = libn_address_format(fmt, (uint8_t *) label, publicKey); label[addressLen] = '\0'; } void ui_write_hash_truncated(char *label, libn_hash_t hash) { - libn_write_hex_string((uint8_t *)label, hash, sizeof(libn_hash_t)); + libn_write_hex_string((uint8_t *) label, hash, sizeof(libn_hash_t)); // Truncate hash to 12345..67890 format - os_memset(label+5, '.', 2); - os_memmove(label+7, label+2*sizeof(libn_hash_t)-5, 5); + memset(label + 5, '.', 2); + memmove(label + 7, label + 2 * sizeof(libn_hash_t) - 5, 5); label[12] = '\0'; } - const ux_menu_entry_t menu_main[]; const ux_menu_entry_t menu_settings[]; const ux_menu_entry_t menu_settings_autoreceive[]; @@ -89,20 +85,21 @@ const bagl_element_t *menu_prepro(const ux_menu_entry_t *menu_entry, bagl_elemen // Customise the about menu appearance if (menu_entry->userid == 0xAB) { switch (element->component.userid) { - case 0x21: // 1st line - element->component.font_id = BAGL_FONT_OPEN_SANS_REGULAR_11px | BAGL_FONT_ALIGNMENT_CENTER; - break; - case 0x22: // 2nd line - element->component.stroke = 10; // scrolldelay - element->component.icon_id = 26; // scrollspeed - break; + case 0x21: // 1st line + element->component.font_id = + BAGL_FONT_OPEN_SANS_REGULAR_11px | BAGL_FONT_ALIGNMENT_CENTER; + break; + case 0x22: // 2nd line + element->component.stroke = 10; // scrolldelay + element->component.icon_id = 26; // scrollspeed + break; } } else if (menu_entry->userid == 0xBA) { // Customise the badge for the coin switch (element->component.userid) { - case 0x10: // icon - element->text = (const char *)COIN_BADGE; - break; + case 0x10: // icon + element->text = (const char *) COIN_BADGE; + break; } } return element; @@ -116,8 +113,12 @@ void menu_settings_autoreceive_change(uint32_t enabled) { void menu_settings_autoreceive_init(uint32_t ignored) { UNUSED(ignored); - UX_MENU_DISPLAY(N_libn.autoReceive ? 1 : 0, - menu_settings_autoreceive, NULL); + UX_MENU_DISPLAY(N_libn.autoReceive ? 1 : 0, menu_settings_autoreceive, NULL); +} + +void menu_quit_app(unsigned int ignored) { + UNUSED(ignored); + os_sched_exit(0); } const ux_menu_entry_t menu_settings_autoreceive[] = { @@ -134,16 +135,15 @@ const ux_menu_entry_t menu_about[] = { {NULL, NULL, 0xAB, NULL, "Version", APPVERSION, 0, 0}, {NULL, NULL, 0xAB, NULL, "Developer", "Mart Roosmaa", 0, 0}, // URL with trailing spaces to avoid render artifacts when scrolling - {NULL, NULL, 0xAB, NULL, "Source code", " github.com/roosmaa/blue-app-nano ", 0, 0}, + {NULL, NULL, 0xAB, NULL, "Source code", " github.com/LedgerHQ/app-nano ", 0, 0}, {menu_main, NULL, 2, &C_nanos_icon_back, "Back", NULL, 61, 40}, UX_MENU_END}; const ux_menu_entry_t menu_main[] = { - {NULL, NULL, 0xBA, &C_nanos_badge_nano, "Use wallet to", - "view accounts", 33, 12}, + {NULL, NULL, 0xBA, &C_nanos_badge_nano, "Use wallet to", "view accounts", 33, 12}, {menu_settings, NULL, 0, NULL, "Settings", NULL, 0, 0}, {menu_about, NULL, 0, NULL, "About", NULL, 0, 0}, - {NULL, os_sched_exit, 0, &C_nanos_icon_dashboard, "Quit app", NULL, 50, 29}, + {NULL, menu_quit_app, 0, &C_nanos_icon_dashboard, "Quit app", NULL, 50, 29}, UX_MENU_END}; void libn_bagl_idle(void) { @@ -168,71 +168,104 @@ void ui_ticker_event(bool uxAllowed) { */ const bagl_element_t ui_display_address[] = { - {{/* type */ BAGL_RECTANGLE, /* userid */ 0x00, - /* x */ 0, /* y */ 0, /* width */ 128, /* height */ 32, - /* stroke */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ 0x000000, /* bgcolor */ 0xFFFFFF, - /* font_id */ 0, /* icon_id */ 0}, - /* text */ NULL, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - - {{/* type */ BAGL_ICON, /* userid */ 0x00, - /* x */ 3, /* y */ 12, /* width */ 7, /* height */ 7, - /* stroke */ 0, /* radius */ 0, /* fill */ 0, - /* fgcolor */ 0xFFFFFF, /* bgcolor */ 0x000000, - /* font_id */ 0, /* icon_id */ BAGL_GLYPH_ICON_CROSS}, - /* text */ NULL, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - - {{/* type */ BAGL_ICON, /* userid */ 0x00, - /* x */ 117, /* y */ 13, /* width */ 8, /* height */ 6, - /* stroke */ 0, /* radius */ 0, /* fill */ 0, - /* fgcolor */ 0xFFFFFF, /* bgcolor */ 0x000000, - /* font_id */ 0, /* icon_id */ BAGL_GLYPH_ICON_CHECK}, - /* text */ NULL, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - - {{/* type */ BAGL_LABELINE, /* userid */ 0x01, - /* x */ 0, /* y */ 12, /* width */ 128, /* height */ 12, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ 0, - /* fgcolor */ 0xFFFFFF, /* bgcolor */ 0x000000, + {{/* type */ BAGL_RECTANGLE, + /* userid */ 0x00, + /* x */ 0, + /* y */ 0, + /* width */ 128, + /* height */ 32, + /* stroke */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ 0x000000, + /* bgcolor */ 0xFFFFFF, + /* font_id */ 0, + /* icon_id */ 0}, + /* text */ NULL}, + {{/* type */ BAGL_ICON, + /* userid */ 0x00, + /* x */ 3, + /* y */ 12, + /* width */ 7, + /* height */ 7, + /* stroke */ 0, + /* radius */ 0, + /* fill */ 0, + /* fgcolor */ 0xFFFFFF, + /* bgcolor */ 0x000000, + /* font_id */ 0, + /* icon_id */ BAGL_GLYPH_ICON_CROSS}, + /* text */ NULL}, + {{/* type */ BAGL_ICON, + /* userid */ 0x00, + /* x */ 117, + /* y */ 13, + /* width */ 8, + /* height */ 6, + /* stroke */ 0, + /* radius */ 0, + /* fill */ 0, + /* fgcolor */ 0xFFFFFF, + /* bgcolor */ 0x000000, + /* font_id */ 0, + /* icon_id */ BAGL_GLYPH_ICON_CHECK}, + /* text */ NULL}, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x01, + /* x */ 0, + /* y */ 12, + /* width */ 128, + /* height */ 12, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ 0, + /* fgcolor */ 0xFFFFFF, + /* bgcolor */ 0x000000, /* font_id */ BAGL_FONT_OPEN_SANS_EXTRABOLD_11px | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, - /* text */ "Confirm", /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_LABELINE, /* userid */ 0x01, - /* x */ 0, /* y */ 26, /* width */ 128, /* height */ 12, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ 0, - /* fgcolor */ 0xFFFFFF, /* bgcolor */ 0x000000, + /* text */ "Confirm"}, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x01, + /* x */ 0, + /* y */ 26, + /* width */ 128, + /* height */ 12, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ 0, + /* fgcolor */ 0xFFFFFF, + /* bgcolor */ 0x000000, /* font_id */ BAGL_FONT_OPEN_SANS_EXTRABOLD_11px | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, - /* text */ "address", /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - - {{/* type */ BAGL_LABELINE, /* userid */ 0x02, - /* x */ 0, /* y */ 12, /* width */ 128, /* height */ 12, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ 0, - /* fgcolor */ 0xFFFFFF, /* bgcolor */ 0x000000, + /* text */ "address"}, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x02, + /* x */ 0, + /* y */ 12, + /* width */ 128, + /* height */ 12, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ 0, + /* fgcolor */ 0xFFFFFF, + /* bgcolor */ 0x000000, /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_11px | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, - /* text */ "Address", /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_LABELINE, /* userid */ 0x02, - /* x */ 23, /* y */ 26, /* width */ 82, /* height */ 12, + /* text */ "Address"}, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x02, + /* x */ 23, + /* y */ 26, + /* width */ 82, + /* height */ 12, /* scrolldelay */ 10 | BAGL_STROKE_FLAG_ONESHOT, - /* radius */ 0, /* fill */ 0, - /* fgcolor */ 0xFFFFFF, /* bgcolor */ 0x000000, + /* radius */ 0, + /* fill */ 0, + /* fgcolor */ 0xFFFFFF, + /* bgcolor */ 0x000000, /* font_id */ BAGL_FONT_OPEN_SANS_EXTRABOLD_11px | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 26}, - /* text */ vars.displayAddress.account, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, + /* text */ vars.displayAddress.account}, }; const bagl_element_t *ui_display_address_prepro(const bagl_element_t *element) { @@ -243,32 +276,31 @@ const bagl_element_t *ui_display_address_prepro(const bagl_element_t *element) { } switch (element->component.userid) { - case 1: - UX_CALLBACK_SET_INTERVAL(2000); - break; - case 2: - UX_CALLBACK_SET_INTERVAL(MAX( - 3000, 1000 + bagl_label_roundtrip_duration_ms(element, 7))); - break; + case 1: + UX_CALLBACK_SET_INTERVAL(2000); + break; + case 2: + UX_CALLBACK_SET_INTERVAL( + MAX(3000, 1000 + bagl_label_roundtrip_duration_ms(element, 7))); + break; } } return element; } -uint32_t ui_display_address_button(uint32_t button_mask, - uint32_t button_mask_counter) { - switch (button_mask) { - case BUTTON_EVT_RELEASED | BUTTON_LEFT: - libn_bagl_display_address_callback(false); - break; - - case BUTTON_EVT_RELEASED | BUTTON_RIGHT: - libn_bagl_display_address_callback(true); - break; +uint32_t ui_display_address_button(uint32_t button_mask, uint32_t button_mask_counter) { + UNUSED(button_mask_counter); - // For other button combinations return early and do nothing - default: - return 0; + switch (button_mask) { + case BUTTON_EVT_RELEASED | BUTTON_LEFT: + libn_bagl_display_address_callback(false); + break; + case BUTTON_EVT_RELEASED | BUTTON_RIGHT: + libn_bagl_display_address_callback(true); + break; + // For other button combinations return early and do nothing + default: + return 0; } libn_bagl_idle(); @@ -281,12 +313,9 @@ void libn_bagl_display_address(void) { } libn_apdu_get_address_request_t *req = &libn_context_D.stateData.getAddressRequest; - os_memset(&vars.displayAddress, 0, sizeof(vars.displayAddress)); + memset(&vars.displayAddress, 0, sizeof(vars.displayAddress)); // Encode public key into an address string - ui_write_address_full( - &req->addressFormatter, - vars.displayAddress.account, - req->publicKey); + ui_write_address_full(&req->addressFormatter, vars.displayAddress.account, req->publicKey); bagl_state = LIBN_STATE_CONFIRM_ADDRESS; ux_step_count = 2; @@ -299,71 +328,104 @@ void libn_bagl_display_address(void) { */ const bagl_element_t ui_confirm_sign_block[] = { - {{/* type */ BAGL_RECTANGLE, /* userid */ 0x00, - /* x */ 0, /* y */ 0, /* width */ 128, /* height */ 32, - /* stroke */ 0, /* radius */ 0, /* fill */ BAGL_FILL, - /* fgcolor */ 0x000000, /* bgcolor */ 0xFFFFFF, - /* font_id */ 0, /* icon_id */ 0}, - /* text */ NULL, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - - {{/* type */ BAGL_ICON, /* userid */ 0x00, - /* x */ 3, /* y */ 12, /* width */ 7, /* height */ 7, - /* stroke */ 0, /* radius */ 0, /* fill */ 0, - /* fgcolor */ 0xFFFFFF, /* bgcolor */ 0x000000, - /* font_id */ 0, /* icon_id */ BAGL_GLYPH_ICON_CROSS}, - /* text */ NULL, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - - {{/* type */ BAGL_ICON, /* userid */ 0x00, - /* x */ 117, /* y */ 13, /* width */ 8, /* height */ 6, - /* stroke */ 0, /* radius */ 0, /* fill */ 0, - /* fgcolor */ 0xFFFFFF, /* bgcolor */ 0x000000, - /* font_id */ 0, /* icon_id */ BAGL_GLYPH_ICON_CHECK}, - /* text */ NULL, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - - {{/* type */ BAGL_LABELINE, /* userid */ 0x01, - /* x */ 0, /* y */ 12, /* width */ 128, /* height */ 12, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ 0, - /* fgcolor */ 0xFFFFFF, /* bgcolor */ 0x000000, + {{/* type */ BAGL_RECTANGLE, + /* userid */ 0x00, + /* x */ 0, + /* y */ 0, + /* width */ 128, + /* height */ 32, + /* stroke */ 0, + /* radius */ 0, + /* fill */ BAGL_FILL, + /* fgcolor */ 0x000000, + /* bgcolor */ 0xFFFFFF, + /* font_id */ 0, + /* icon_id */ 0}, + /* text */ NULL}, + {{/* type */ BAGL_ICON, + /* userid */ 0x00, + /* x */ 3, + /* y */ 12, + /* width */ 7, + /* height */ 7, + /* stroke */ 0, + /* radius */ 0, + /* fill */ 0, + /* fgcolor */ 0xFFFFFF, + /* bgcolor */ 0x000000, + /* font_id */ 0, + /* icon_id */ BAGL_GLYPH_ICON_CROSS}, + /* text */ NULL}, + {{/* type */ BAGL_ICON, + /* userid */ 0x00, + /* x */ 117, + /* y */ 13, + /* width */ 8, + /* height */ 6, + /* stroke */ 0, + /* radius */ 0, + /* fill */ 0, + /* fgcolor */ 0xFFFFFF, + /* bgcolor */ 0x000000, + /* font_id */ 0, + /* icon_id */ BAGL_GLYPH_ICON_CHECK}, + /* text */ NULL}, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x01, + /* x */ 0, + /* y */ 12, + /* width */ 128, + /* height */ 12, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ 0, + /* fgcolor */ 0xFFFFFF, + /* bgcolor */ 0x000000, /* font_id */ BAGL_FONT_OPEN_SANS_EXTRABOLD_11px | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, - /* text */ "Confirm", /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_LABELINE, /* userid */ 0x01, - /* x */ 0, /* y */ 26, /* width */ 128, /* height */ 12, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ 0, - /* fgcolor */ 0xFFFFFF, /* bgcolor */ 0x000000, + /* text */ "Confirm"}, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x01, + /* x */ 0, + /* y */ 26, + /* width */ 128, + /* height */ 12, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ 0, + /* fgcolor */ 0xFFFFFF, + /* bgcolor */ 0x000000, /* font_id */ BAGL_FONT_OPEN_SANS_EXTRABOLD_11px | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, - /* text */ "block", /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - - {{/* type */ BAGL_LABELINE, /* userid */ 0x02, - /* x */ 0, /* y */ 12, /* width */ 128, /* height */ 12, - /* scrolldelay */ 0, /* radius */ 0, /* fill */ 0, - /* fgcolor */ 0xFFFFFF, /* bgcolor */ 0x000000, + /* text */ "block"}, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x02, + /* x */ 0, + /* y */ 12, + /* width */ 128, + /* height */ 12, + /* scrolldelay */ 0, + /* radius */ 0, + /* fill */ 0, + /* fgcolor */ 0xFFFFFF, + /* bgcolor */ 0x000000, /* font_id */ BAGL_FONT_OPEN_SANS_REGULAR_11px | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 0}, - /* text */ vars.confirmSignBlock.confirmLabel, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, - {{/* type */ BAGL_LABELINE, /* userid */ 0x03, - /* x */ 23, /* y */ 26, /* width */ 82, /* height */ 12, + /* text */ vars.confirmSignBlock.confirmLabel}, + {{/* type */ BAGL_LABELINE, + /* userid */ 0x03, + /* x */ 23, + /* y */ 26, + /* width */ 82, + /* height */ 12, /* scrolldelay */ 10 | BAGL_STROKE_FLAG_ONESHOT, - /* radius */ 0, /* fill */ 0, - /* fgcolor */ 0xFFFFFF, /* bgcolor */ 0x000000, + /* radius */ 0, + /* fill */ 0, + /* fgcolor */ 0xFFFFFF, + /* bgcolor */ 0x000000, /* font_id */ BAGL_FONT_OPEN_SANS_EXTRABOLD_11px | BAGL_FONT_ALIGNMENT_CENTER, /* scrollspeed */ 26}, - /* text */ vars.confirmSignBlock.confirmValue, /* touch_area_brim */ 0, - /* overfgcolor */ 0, /* overbgcolor */ 0, - /* tap */ NULL, /* out */ NULL, /* over */ NULL}, + /* text */ vars.confirmSignBlock.confirmValue}, }; void ui_confirm_sign_block_prepare_confirm_step(void) { @@ -375,10 +437,9 @@ void ui_confirm_sign_block_prepare_confirm_step(void) { if (ux_step == step++) { strcpy(vars.confirmSignBlock.confirmLabel, "Your account"); - ui_write_address_truncated( - &req->addressFormatter, - vars.confirmSignBlock.confirmValue, - req->publicKey); + ui_write_address_truncated(&req->addressFormatter, + vars.confirmSignBlock.confirmValue, + req->publicKey); return; } @@ -389,11 +450,10 @@ void ui_confirm_sign_block_prepare_confirm_step(void) { } else { strcpy(vars.confirmSignBlock.confirmLabel, "Receive amount"); } - libn_amount_format( - &req->amountFormatter, - vars.confirmSignBlock.confirmValue, - sizeof(vars.confirmSignBlock.confirmValue), - req->amount); + libn_amount_format(&req->amountFormatter, + vars.confirmSignBlock.confirmValue, + sizeof(vars.confirmSignBlock.confirmValue), + req->amount); return; } } @@ -401,10 +461,9 @@ void ui_confirm_sign_block_prepare_confirm_step(void) { if (vars.confirmSignBlock.showRecipient) { if (ux_step == step++) { strcpy(vars.confirmSignBlock.confirmLabel, "Send to"); - ui_write_address_full( - &req->recipientFormatter, - vars.confirmSignBlock.confirmValue, - req->recipient); + ui_write_address_full(&req->recipientFormatter, + vars.confirmSignBlock.confirmValue, + req->recipient); return; } } @@ -412,19 +471,16 @@ void ui_confirm_sign_block_prepare_confirm_step(void) { if (vars.confirmSignBlock.showRepresentative) { if (ux_step == step++) { strcpy(vars.confirmSignBlock.confirmLabel, "Representative"); - ui_write_address_full( - &req->representativeFormatter, - vars.confirmSignBlock.confirmValue, - req->representative); + ui_write_address_full(&req->representativeFormatter, + vars.confirmSignBlock.confirmValue, + req->representative); return; } } if (ux_step == step++) { strcpy(vars.confirmSignBlock.confirmLabel, "Block hash"); - ui_write_hash_truncated( - vars.confirmSignBlock.confirmValue, - req->blockHash); + ui_write_hash_truncated(vars.confirmSignBlock.confirmValue, req->blockHash); return; } } @@ -449,32 +505,31 @@ const bagl_element_t *ui_confirm_sign_block_prepro(const bagl_element_t *element } switch (element->component.userid) { - case 0x01: - UX_CALLBACK_SET_INTERVAL(2000); - break; - case 0x03: - UX_CALLBACK_SET_INTERVAL(MAX( - 3000, 1000 + bagl_label_roundtrip_duration_ms(element, 7))); - break; + case 0x01: + UX_CALLBACK_SET_INTERVAL(2000); + break; + case 0x03: + UX_CALLBACK_SET_INTERVAL( + MAX(3000, 1000 + bagl_label_roundtrip_duration_ms(element, 7))); + break; } } return element; } -uint32_t ui_confirm_sign_block_button(uint32_t button_mask, - uint32_t button_mask_counter) { - switch (button_mask) { - case BUTTON_EVT_RELEASED | BUTTON_LEFT: - libn_bagl_confirm_sign_block_callback(false); - break; - - case BUTTON_EVT_RELEASED | BUTTON_RIGHT: - libn_bagl_confirm_sign_block_callback(true); - break; +uint32_t ui_confirm_sign_block_button(uint32_t button_mask, uint32_t button_mask_counter) { + UNUSED(button_mask_counter); - // For other button combinations return early and do nothing - default: - return 0; + switch (button_mask) { + case BUTTON_EVT_RELEASED | BUTTON_LEFT: + libn_bagl_confirm_sign_block_callback(false); + break; + case BUTTON_EVT_RELEASED | BUTTON_RIGHT: + libn_bagl_confirm_sign_block_callback(true); + break; + // For other button combinations return early and do nothing + default: + return 0; } libn_bagl_idle(); @@ -487,7 +542,7 @@ void libn_bagl_confirm_sign_block(void) { } libn_apdu_sign_block_request_t *req = &libn_context_D.stateData.signBlockRequest; - os_memset(&vars.confirmSignBlock, 0, sizeof(vars.confirmSignBlock)); + memset(&vars.confirmSignBlock, 0, sizeof(vars.confirmSignBlock)); if (!libn_is_zero(req->amount, sizeof(req->amount))) { vars.confirmSignBlock.showAmount = true; @@ -502,10 +557,9 @@ void libn_bagl_confirm_sign_block(void) { bagl_state = LIBN_STATE_CONFIRM_SIGNATURE; ux_step = 0; - ux_step_count = 3 - + (vars.confirmSignBlock.showAmount ? 1 : 0) - + (vars.confirmSignBlock.showRecipient ? 1 : 0) - + (vars.confirmSignBlock.showRepresentative ? 1 : 0); + ux_step_count = 3 + (vars.confirmSignBlock.showAmount ? 1 : 0) + + (vars.confirmSignBlock.showRecipient ? 1 : 0) + + (vars.confirmSignBlock.showRepresentative ? 1 : 0); UX_DISPLAY(ui_confirm_sign_block, ui_confirm_sign_block_prepro); } @@ -515,27 +569,27 @@ bool libn_bagl_apply_state() { } switch (libn_context_D.state) { - case LIBN_STATE_READY: - if (bagl_state != LIBN_STATE_READY) { - libn_bagl_idle(); - return true; - } - break; - case LIBN_STATE_CONFIRM_ADDRESS: - if (bagl_state != LIBN_STATE_CONFIRM_ADDRESS) { - libn_bagl_display_address(); - return true; - } - break; - case LIBN_STATE_CONFIRM_SIGNATURE: - if (bagl_state != LIBN_STATE_CONFIRM_SIGNATURE) { - libn_bagl_confirm_sign_block(); - return true; - } - break; + case LIBN_STATE_READY: + if (bagl_state != LIBN_STATE_READY) { + libn_bagl_idle(); + return true; + } + break; + case LIBN_STATE_CONFIRM_ADDRESS: + if (bagl_state != LIBN_STATE_CONFIRM_ADDRESS) { + libn_bagl_display_address(); + return true; + } + break; + case LIBN_STATE_CONFIRM_SIGNATURE: + if (bagl_state != LIBN_STATE_CONFIRM_SIGNATURE) { + libn_bagl_confirm_sign_block(); + return true; + } + break; } return false; } -#endif // defined(TARGET_NANOS) +#endif // defined(TARGET_NANOS) diff --git a/src/libn_bagl_nanox.c b/src/libn_bagl_nanox.c index 5b4bf36..f13a225 100644 --- a/src/libn_bagl_nanox.c +++ b/src/libn_bagl_nanox.c @@ -1,19 +1,19 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2018 Mart Roosmaa -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2018 Mart Roosmaa + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ #include @@ -27,12 +27,9 @@ #if defined(TARGET_NANOX) || defined(TARGET_NANOS2) -#define ACCOUNT_BUF_LEN ( \ - LIBN_ACCOUNT_STRING_BASE_LEN \ - + MAX(sizeof(COIN_PRIMARY_PREFIX), \ - sizeof(COIN_SECONDARY_PREFIX)) \ - + 1 \ -) +#define ACCOUNT_BUF_LEN \ + (LIBN_ACCOUNT_STRING_BASE_LEN + \ + MAX(sizeof(COIN_PRIMARY_PREFIX), sizeof(COIN_SECONDARY_PREFIX)) + 1) union { struct { char account[ACCOUNT_BUF_LEN]; @@ -40,7 +37,7 @@ union { struct { bool showRecipient; char titleBuf[20]; - char textBuf[MAX(ACCOUNT_BUF_LEN, 2*sizeof(libn_hash_t)+1)]; + char textBuf[MAX(ACCOUNT_BUF_LEN, 2 * sizeof(libn_hash_t) + 1)]; } confirmSignBlock; } vars; @@ -49,26 +46,26 @@ libn_state_t bagl_state; void ui_write_address_truncated(const libn_address_formatter_t *fmt, char *label, const libn_public_key_t publicKey) { - const size_t addressLen = libn_address_format(fmt, (uint8_t *)label, publicKey); + const size_t addressLen = libn_address_format(fmt, (uint8_t *) label, publicKey); const size_t prefixLen = addressLen - LIBN_ACCOUNT_STRING_BASE_LEN; - os_memset(label + prefixLen + 5, '.', 2); - os_memmove(label + prefixLen + 7, label + addressLen - 5, 5); - label[prefixLen+12] = '\0'; + memset(label + prefixLen + 5, '.', 2); + memmove(label + prefixLen + 7, label + addressLen - 5, 5); + label[prefixLen + 12] = '\0'; } void ui_write_address_full(const libn_address_formatter_t *fmt, char *label, const libn_public_key_t publicKey) { - const size_t addressLen = libn_address_format(fmt, (uint8_t *)label, publicKey); + const size_t addressLen = libn_address_format(fmt, (uint8_t *) label, publicKey); label[addressLen] = '\0'; } void ui_write_hash_truncated(char *label, libn_hash_t hash) { - libn_write_hex_string((uint8_t *)label, hash, sizeof(libn_hash_t)); + libn_write_hex_string((uint8_t *) label, hash, sizeof(libn_hash_t)); // Truncate hash to 12345..67890 format - os_memset(label+5, '.', 2); - os_memmove(label+7, label+2*sizeof(libn_hash_t)-5, 5); + memset(label + 5, '.', 2); + memmove(label + 7, label + 2 * sizeof(libn_hash_t) - 5, 5); label[12] = '\0'; } @@ -79,50 +76,42 @@ const char *settings_auto_receive_getter(unsigned int idx); void settings_auto_receive_selector(unsigned int idx); const char *settings_submenu_getter(unsigned int idx); void settings_submenu_selector(unsigned int idx); -const ux_flow_step_t * const ux_about_flow[]; - -UX_STEP_NOCB( - ux_idle_flow_1_step, - nn, - { - "Application", - "is ready", - }); -UX_STEP_CB( - ux_idle_flow_2_step, - pb, - ux_menulist_init(0, settings_submenu_getter, settings_submenu_selector), - { - &C_icon_coggle, - "Settings", - }); -UX_STEP_CB( - ux_idle_flow_3_step, - bn, - ux_flow_init(0, ux_about_flow, NULL), - { - "Version", - APPVERSION, - }); -UX_STEP_CB( - ux_idle_flow_4_step, - pb, - os_sched_exit(-1), - { - &C_icon_dashboard, - "Quit", - }); +const ux_flow_step_t *const ux_about_flow[]; + +UX_STEP_NOCB(ux_idle_flow_1_step, + nn, + { + "Application", + "is ready", + }); +UX_STEP_CB(ux_idle_flow_2_step, + pb, + ux_menulist_init(0, settings_submenu_getter, settings_submenu_selector), + { + &C_icon_coggle, + "Settings", + }); +UX_STEP_CB(ux_idle_flow_3_step, + bn, + ux_flow_init(0, ux_about_flow, NULL), + { + "Version", + APPVERSION, + }); +UX_STEP_CB(ux_idle_flow_4_step, + pb, + os_sched_exit(-1), + { + &C_icon_dashboard, + "Quit", + }); UX_FLOW(ux_idle_flow, - &ux_idle_flow_1_step, - &ux_idle_flow_2_step, - &ux_idle_flow_3_step, - &ux_idle_flow_4_step); - -const char * const settings_auto_receive_getter_values[] = { - "Disabled", - "Enabled", - "Back" -}; + &ux_idle_flow_1_step, + &ux_idle_flow_2_step, + &ux_idle_flow_3_step, + &ux_idle_flow_4_step); + +const char *const settings_auto_receive_getter_values[] = {"Disabled", "Enabled", "Back"}; const char *settings_auto_receive_getter(unsigned int idx) { if (idx < ARRAYLEN(settings_auto_receive_getter_values)) { @@ -132,20 +121,20 @@ const char *settings_auto_receive_getter(unsigned int idx) { } void settings_auto_receive_selector(unsigned int idx) { - switch(idx) { - case 0: - libn_set_auto_receive(false); - break; - case 1: - libn_set_auto_receive(true); - break; - default: - break; + switch (idx) { + case 0: + libn_set_auto_receive(false); + break; + case 1: + libn_set_auto_receive(true); + break; + default: + break; } ux_menulist_init_select(0, settings_submenu_getter, settings_submenu_selector, 0); } -const char * const settings_submenu_getter_values[] = { +const char *const settings_submenu_getter_values[] = { "Auto-receive", "Back", }; @@ -158,58 +147,57 @@ const char *settings_submenu_getter(unsigned int idx) { } void settings_submenu_selector(unsigned int idx) { - switch(idx) { - case 0: - ux_menulist_init_select(0, settings_auto_receive_getter, settings_auto_receive_selector, N_libn.autoReceive ? 1 : 0); - break; - default: - ux_flow_init(0, ux_idle_flow, &ux_idle_flow_2_step); + switch (idx) { + case 0: + ux_menulist_init_select(0, + settings_auto_receive_getter, + settings_auto_receive_selector, + N_libn.autoReceive ? 1 : 0); + break; + default: + ux_flow_init(0, ux_idle_flow, &ux_idle_flow_2_step); } } -UX_STEP_CB( - ux_about_flow_1_step, - nn, - ux_flow_init(0, ux_idle_flow, &ux_idle_flow_3_step), - { - "About", - "application", - }); -UX_STEP_CB( - ux_about_flow_2_step, - bn, - ux_flow_init(0, ux_idle_flow, &ux_idle_flow_3_step), - { - "Developer", - "Mart Roosmaa", - }); -UX_STEP_CB( - ux_about_flow_3_step, - bnnn, - ux_flow_init(0, ux_idle_flow, &ux_idle_flow_3_step), - { - "Source code", - "github.com/", - "roosmaa/", - "blue-app-nano", - }); -UX_STEP_CB( - ux_about_flow_4_step, - pb, - ux_flow_init(0, ux_idle_flow, &ux_idle_flow_3_step), - { - &C_icon_close, - "Back", - }); +UX_STEP_CB(ux_about_flow_1_step, + nn, + ux_flow_init(0, ux_idle_flow, &ux_idle_flow_3_step), + { + "About", + "application", + }); +UX_STEP_CB(ux_about_flow_2_step, + bn, + ux_flow_init(0, ux_idle_flow, &ux_idle_flow_3_step), + { + "Developer", + "Mart Roosmaa", + }); +UX_STEP_CB(ux_about_flow_3_step, + bnnn, + ux_flow_init(0, ux_idle_flow, &ux_idle_flow_3_step), + { + "Source code", + "github.com/", + "LedgerHQ/", + "app-nano", + }); +UX_STEP_CB(ux_about_flow_4_step, + pb, + ux_flow_init(0, ux_idle_flow, &ux_idle_flow_3_step), + { + &C_icon_close, + "Back", + }); UX_FLOW(ux_about_flow, - &ux_about_flow_1_step, - &ux_about_flow_2_step, - &ux_about_flow_3_step, - &ux_about_flow_4_step); + &ux_about_flow_1_step, + &ux_about_flow_2_step, + &ux_about_flow_3_step, + &ux_about_flow_4_step); void libn_bagl_idle(void) { bagl_state = LIBN_STATE_READY; - if(G_ux.stack_count == 0) { + if (G_ux.stack_count == 0) { ux_stack_push(); } ux_flow_init(0, ux_idle_flow, NULL); @@ -218,42 +206,38 @@ void libn_bagl_idle(void) { /*** * Display address */ -UX_STEP_NOCB( - ux_display_address_flow_1_step, - pnn, - { - &C_icon_eye, - "Confirm", - "address", - }); -UX_STEP_NOCB( - ux_display_address_flow_2_step, - bnnn_paging, - { - "Address", - vars.displayAddress.account, - }); -UX_STEP_CB( - ux_display_address_flow_3_step, - pb, - libn_bagl_display_address_callback(true), - { - &C_icon_validate_14, - "Confirm", - }); -UX_STEP_CB( - ux_display_address_flow_4_step, - pb, - libn_bagl_display_address_callback(false), - { - &C_icon_crossmark, - "Reject", - }); +UX_STEP_NOCB(ux_display_address_flow_1_step, + pnn, + { + &C_icon_eye, + "Confirm", + "address", + }); +UX_STEP_NOCB(ux_display_address_flow_2_step, + bnnn_paging, + { + "Address", + vars.displayAddress.account, + }); +UX_STEP_CB(ux_display_address_flow_3_step, + pb, + libn_bagl_display_address_callback(true), + { + &C_icon_validate_14, + "Confirm", + }); +UX_STEP_CB(ux_display_address_flow_4_step, + pb, + libn_bagl_display_address_callback(false), + { + &C_icon_crossmark, + "Reject", + }); UX_FLOW(ux_display_address_flow, - &ux_display_address_flow_1_step, - &ux_display_address_flow_2_step, - &ux_display_address_flow_3_step, - &ux_display_address_flow_4_step); + &ux_display_address_flow_1_step, + &ux_display_address_flow_2_step, + &ux_display_address_flow_3_step, + &ux_display_address_flow_4_step); void libn_bagl_display_address(void) { if (libn_context_D.state != LIBN_STATE_CONFIRM_ADDRESS) { @@ -261,12 +245,9 @@ void libn_bagl_display_address(void) { } libn_apdu_get_address_request_t *req = &libn_context_D.stateData.getAddressRequest; - os_memset(&vars.displayAddress, 0, sizeof(vars.displayAddress)); + memset(&vars.displayAddress, 0, sizeof(vars.displayAddress)); // Encode public key into an address string - ui_write_address_full( - &req->addressFormatter, - vars.displayAddress.account, - req->publicKey); + ui_write_address_full(&req->addressFormatter, vars.displayAddress.account, req->publicKey); bagl_state = LIBN_STATE_CONFIRM_ADDRESS; ux_flow_init(0, ux_display_address_flow, NULL); @@ -275,107 +256,98 @@ void libn_bagl_display_address(void) { /*** * Confirm sign block */ -UX_STEP_NOCB( - ux_confirm_sign_block_flow_1_step, - pnn, - { - &C_icon_eye, - "Review", - "transaction", - }); -UX_STEP_NOCB_INIT( - ux_confirm_sign_block_flow_2_step, - bn, - { - libn_apdu_sign_block_request_t *req = &libn_context_D.stateData.signBlockRequest; - ui_write_address_truncated( - &req->addressFormatter, - vars.confirmSignBlock.textBuf, - req->publicKey); - }, - { - "Your account", - vars.confirmSignBlock.textBuf, - }); -UX_STEP_NOCB_INIT( - ux_confirm_sign_block_flow_3_step, - bn, - { - libn_apdu_sign_block_request_t *req = &libn_context_D.stateData.signBlockRequest; - if (vars.confirmSignBlock.showRecipient) { - strcpy(vars.confirmSignBlock.titleBuf, "Send amount"); - } else { - strcpy(vars.confirmSignBlock.titleBuf, "Receive amount"); - } - libn_amount_format( - &req->amountFormatter, - vars.confirmSignBlock.textBuf, - sizeof(vars.confirmSignBlock.textBuf), - req->amount); - }, - { - vars.confirmSignBlock.titleBuf, - vars.confirmSignBlock.textBuf, - }); -UX_STEP_NOCB_INIT( - ux_confirm_sign_block_flow_4_step, - bnnn_paging, - { - libn_apdu_sign_block_request_t *req = &libn_context_D.stateData.signBlockRequest; - ui_write_address_full( - &req->recipientFormatter, - vars.confirmSignBlock.textBuf, - req->recipient); - }, - { - "Send to", - vars.confirmSignBlock.textBuf, - }); -UX_STEP_NOCB_INIT( - ux_confirm_sign_block_flow_5_step, - bnnn_paging, - { - libn_apdu_sign_block_request_t *req = &libn_context_D.stateData.signBlockRequest; - ui_write_address_full( - &req->representativeFormatter, - vars.confirmSignBlock.textBuf, - req->representative); - }, - { - "Representative", - vars.confirmSignBlock.textBuf, - }); -UX_STEP_NOCB_INIT( - ux_confirm_sign_block_flow_6_step, - bn, - { - libn_apdu_sign_block_request_t *req = &libn_context_D.stateData.signBlockRequest; - ui_write_hash_truncated( - vars.confirmSignBlock.textBuf, - req->blockHash); - }, - { - "Block hash", - vars.confirmSignBlock.textBuf, - }); -UX_STEP_CB( - ux_confirm_sign_block_flow_7_step, - pbb, - libn_bagl_confirm_sign_block_callback(true), - { - &C_icon_validate_14, - "Accept", - "and sign", - }); -UX_STEP_CB( - ux_confirm_sign_block_flow_8_step, - pb, - libn_bagl_confirm_sign_block_callback(false), - { - &C_icon_crossmark, - "Reject", - }); -const ux_flow_step_t * ux_confirm_sign_block_flow[9]; +UX_STEP_NOCB(ux_confirm_sign_block_flow_1_step, + pnn, + { + &C_icon_eye, + "Review", + "transaction", + }); +UX_STEP_NOCB_INIT(ux_confirm_sign_block_flow_2_step, + bn, + { + libn_apdu_sign_block_request_t *req = + &libn_context_D.stateData.signBlockRequest; + ui_write_address_truncated(&req->addressFormatter, + vars.confirmSignBlock.textBuf, + req->publicKey); + }, + { + "Your account", + vars.confirmSignBlock.textBuf, + }); +UX_STEP_NOCB_INIT(ux_confirm_sign_block_flow_3_step, + bn, + { + libn_apdu_sign_block_request_t *req = + &libn_context_D.stateData.signBlockRequest; + if (vars.confirmSignBlock.showRecipient) { + strcpy(vars.confirmSignBlock.titleBuf, "Send amount"); + } else { + strcpy(vars.confirmSignBlock.titleBuf, "Receive amount"); + } + libn_amount_format(&req->amountFormatter, + vars.confirmSignBlock.textBuf, + sizeof(vars.confirmSignBlock.textBuf), + req->amount); + }, + { + vars.confirmSignBlock.titleBuf, + vars.confirmSignBlock.textBuf, + }); +UX_STEP_NOCB_INIT(ux_confirm_sign_block_flow_4_step, + bnnn_paging, + { + libn_apdu_sign_block_request_t *req = + &libn_context_D.stateData.signBlockRequest; + ui_write_address_full(&req->recipientFormatter, + vars.confirmSignBlock.textBuf, + req->recipient); + }, + { + "Send to", + vars.confirmSignBlock.textBuf, + }); +UX_STEP_NOCB_INIT(ux_confirm_sign_block_flow_5_step, + bnnn_paging, + { + libn_apdu_sign_block_request_t *req = + &libn_context_D.stateData.signBlockRequest; + ui_write_address_full(&req->representativeFormatter, + vars.confirmSignBlock.textBuf, + req->representative); + }, + { + "Representative", + vars.confirmSignBlock.textBuf, + }); +UX_STEP_NOCB_INIT(ux_confirm_sign_block_flow_6_step, + bn, + { + libn_apdu_sign_block_request_t *req = + &libn_context_D.stateData.signBlockRequest; + ui_write_hash_truncated(vars.confirmSignBlock.textBuf, req->blockHash); + }, + { + "Block hash", + vars.confirmSignBlock.textBuf, + }); +UX_STEP_CB(ux_confirm_sign_block_flow_7_step, + pbb, + libn_bagl_confirm_sign_block_callback(true), + { + &C_icon_validate_14, + "Accept", + "and sign", + }); +UX_STEP_CB(ux_confirm_sign_block_flow_8_step, + pb, + libn_bagl_confirm_sign_block_callback(false), + { + &C_icon_crossmark, + "Reject", + }); +const ux_flow_step_t *ux_confirm_sign_block_flow[9]; void libn_bagl_confirm_sign_block(void) { if (libn_context_D.state != LIBN_STATE_CONFIRM_SIGNATURE) { @@ -383,7 +355,7 @@ void libn_bagl_confirm_sign_block(void) { } libn_apdu_sign_block_request_t *req = &libn_context_D.stateData.signBlockRequest; - os_memset(&vars.confirmSignBlock, 0, sizeof(vars.confirmSignBlock)); + memset(&vars.confirmSignBlock, 0, sizeof(vars.confirmSignBlock)); bool showAmount = false; bool showRecipient = false; @@ -418,6 +390,7 @@ void libn_bagl_confirm_sign_block(void) { } void ui_ticker_event(bool uxAllowed) { + UNUSED(uxAllowed); } bool libn_bagl_apply_state() { @@ -426,27 +399,27 @@ bool libn_bagl_apply_state() { } switch (libn_context_D.state) { - case LIBN_STATE_READY: - if (bagl_state != LIBN_STATE_READY) { - libn_bagl_idle(); - return true; - } - break; - case LIBN_STATE_CONFIRM_ADDRESS: - if (bagl_state != LIBN_STATE_CONFIRM_ADDRESS) { - libn_bagl_display_address(); - return true; - } - break; - case LIBN_STATE_CONFIRM_SIGNATURE: - if (bagl_state != LIBN_STATE_CONFIRM_SIGNATURE) { - libn_bagl_confirm_sign_block(); - return true; - } - break; + case LIBN_STATE_READY: + if (bagl_state != LIBN_STATE_READY) { + libn_bagl_idle(); + return true; + } + break; + case LIBN_STATE_CONFIRM_ADDRESS: + if (bagl_state != LIBN_STATE_CONFIRM_ADDRESS) { + libn_bagl_display_address(); + return true; + } + break; + case LIBN_STATE_CONFIRM_SIGNATURE: + if (bagl_state != LIBN_STATE_CONFIRM_SIGNATURE) { + libn_bagl_confirm_sign_block(); + return true; + } + break; } return false; } -#endif // defined(TARGET_NANOS) +#endif // defined(TARGET_NANOS) diff --git a/src/libn_context.c b/src/libn_context.c index 06902d3..43d6d95 100644 --- a/src/libn_context.c +++ b/src/libn_context.c @@ -1,19 +1,19 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2016 Ledger -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2016 Ledger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ #include "libn_internal.h" @@ -22,7 +22,7 @@ */ void libn_context_init() { L_DEBUG_APP(("Context init\n")); - os_memset(&libn_context_D, 0, sizeof(libn_context_D)); + memset(&libn_context_D, 0, sizeof(libn_context_D)); SB_SET(libn_context_D.halted, 0); libn_context_D.response.buffer = G_io_apdu_buffer; } @@ -40,9 +40,9 @@ void libn_context_move_async_response(void) { // Move the async result data to sync buffer libn_context_D.response.outLength = resp->outLength; libn_context_D.response.ioFlags = resp->ioFlags; - os_memmove(libn_context_D.response.buffer, resp->buffer, resp->outLength); + memmove(libn_context_D.response.buffer, resp->buffer, resp->outLength); // Reset the asyncResponse resp->ioFlags = 0; resp->outLength = 0; -} \ No newline at end of file +} diff --git a/src/libn_context.h b/src/libn_context.h index fb96566..ad0251f 100644 --- a/src/libn_context.h +++ b/src/libn_context.h @@ -1,29 +1,28 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2016 Ledger -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ - -#ifndef LIBN_CONTEXT_H - -#define LIBN_CONTEXT_H + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2016 Ledger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +#pragma once #include "os.h" -#include "libn_types.h" -#include "libn_secure_value.h" + #include "libn_apdu_get_address.h" #include "libn_apdu_sign_block.h" +#include "libn_secure_value.h" + +#include "libn_types.h" typedef struct { /** Flag if dongle has been halted */ @@ -50,19 +49,8 @@ typedef struct { // when LIBN_STATE_CONFIRM_SIGNATURE libn_apdu_sign_block_request_t signBlockRequest; } stateData; - -#ifdef HAVE_IO_U2F - /** U2F async request hash that is used to keep track and hook back - into an async operation. **/ - uint32_t u2fRequestHash; - /** U2F timeout tracker, once zero the active connection is dropped - appropriate status code. **/ - uint16_t u2fTimeout; -#endif // HAVE_IO_U2F - } libn_context_t; void libn_context_init(void); -void libn_context_move_async_response(void); -#endif +void libn_context_move_async_response(void); diff --git a/src/libn_filesystem.c b/src/libn_filesystem.c index 066d7d0..2b932b9 100644 --- a/src/libn_filesystem.c +++ b/src/libn_filesystem.c @@ -1,25 +1,24 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2016 Ledger -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2016 Ledger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ #include "libn_internal.h" #include "libn_ram_variables.h" void libn_set_auto_receive(bool enabled) { - nvm_write((void *)&N_libn.autoReceive, &enabled, - sizeof(enabled)); + nvm_write((void *) &N_libn.autoReceive, &enabled, sizeof(enabled)); } diff --git a/src/libn_filesystem.h b/src/libn_filesystem.h index 8910bb1..70a93d1 100644 --- a/src/libn_filesystem.h +++ b/src/libn_filesystem.h @@ -1,27 +1,25 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2016 Ledger -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ - -#ifndef LIBN_FS_H - -#define LIBN_FS_H + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2016 Ledger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +#pragma once #include #include "os.h" + #include "libn_context.h" typedef struct libn_storage_s { @@ -30,8 +28,6 @@ typedef struct libn_storage_s { // the global nvram memory variable extern libn_storage_t const N_libn_real; -#define N_libn (*(volatile libn_storage_t *)PIC(&N_libn_real)) +#define N_libn (*(volatile libn_storage_t *) PIC(&N_libn_real)) void libn_set_auto_receive(bool enabled); - -#endif diff --git a/src/libn_helpers.c b/src/libn_helpers.c index 38df6a9..417f833 100644 --- a/src/libn_helpers.c +++ b/src/libn_helpers.c @@ -1,19 +1,19 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2016 Ledger -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2016 Ledger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ #include "coins.h" #include "libn_internal.h" @@ -21,16 +21,16 @@ #include "ed25519.h" #include "blake2b.h" -#define LIBN_CURVE CX_CURVE_Ed25519 +#define LIBN_CURVE CX_CURVE_Ed25519 #define LIBN_SEED_KEY "ed25519 seed" // Define some binary "literals" for the massive bit manipulation operation // when converting public key to account string. #define B_11111 31 #define B_01111 15 -#define B_00111 7 -#define B_00011 3 -#define B_00001 1 +#define B_00111 7 +#define B_00011 3 +#define B_00001 1 bool libn_is_zero(const uint8_t *ptr, size_t num) { while (num > 0) { @@ -42,17 +42,16 @@ bool libn_is_zero(const uint8_t *ptr, size_t num) { return true; } -uint32_t libn_read_u32(uint8_t *buffer, bool be, - bool skipSign) { +uint32_t libn_read_u32(uint8_t *buffer, bool be, bool skipSign) { uint8_t i; uint32_t result = 0; uint8_t shiftValue = (be ? 24 : 0); for (i = 0; i < 4; i++) { - uint8_t x = (uint8_t)buffer[i]; + uint8_t x = (uint8_t) buffer[i]; if ((i == 0) && skipSign) { x &= 0x7f; } - result += ((uint32_t)x) << shiftValue; + result += ((uint32_t) x) << shiftValue; if (be) { shiftValue -= 8; } else { @@ -79,8 +78,8 @@ void libn_write_u32_le(uint8_t *buffer, uint32_t value) { void libn_write_hex_string(uint8_t *buffer, const uint8_t *bytes, size_t bytesLen) { uint32_t i; for (i = 0; i < bytesLen; i++) { - buffer[2*i] = BASE16_ALPHABET[(bytes[i] >> 4) & 0xF]; - buffer[2*i+1] = BASE16_ALPHABET[bytes[i] & 0xF]; + buffer[2 * i] = BASE16_ALPHABET[(bytes[i] >> 4) & 0xF]; + buffer[2 * i + 1] = BASE16_ALPHABET[bytes[i] & 0xF]; } } @@ -93,39 +92,41 @@ uint32_t libn_bip32_get_component(uint8_t *path, uint8_t n) { return libn_read_u32(&path[1 + 4 * n], 1, 0); } -void libn_address_formatter_for_coin(libn_address_formatter_t *fmt, libn_address_prefix_t prefix, uint8_t *bip32Path) { +void libn_address_formatter_for_coin(libn_address_formatter_t *fmt, + libn_address_prefix_t prefix, + uint8_t *bip32Path) { // NOS multi-currency coin handling if (strcmp(COIN_NAME, "NOS") == 0) { uint32_t currencyComponent = libn_bip32_get_component(bip32Path, 2); - #define SUBCURRENCY(CODE, PREFIX, SUFFIX, SCALE) \ - case HARDENED((CODE)): \ - fmt->prefix = (PREFIX); \ - fmt->prefixLen = strlen((PREFIX)); \ - break +#define SUBCURRENCY(CODE, PREFIX, SUFFIX, SCALE) \ + case HARDENED((CODE)): \ + fmt->prefix = (PREFIX); \ + fmt->prefixLen = strlen((PREFIX)); \ + break switch (currencyComponent) { - #include "nos_subcurrencies.h" - case HARDENED(0): - fmt->prefix = COIN_PRIMARY_PREFIX; - fmt->prefixLen = strnlen(COIN_PRIMARY_PREFIX, sizeof(COIN_PRIMARY_PREFIX)); - break; - default: - THROW(INVALID_PARAMETER); +#include "nos_subcurrencies.h" + case HARDENED(0): + fmt->prefix = COIN_PRIMARY_PREFIX; + fmt->prefixLen = strnlen(COIN_PRIMARY_PREFIX, sizeof(COIN_PRIMARY_PREFIX)); + break; + default: + THROW(INVALID_PARAMETER); } - #undef SUBCURRENCY +#undef SUBCURRENCY return; } // Default prefixes switch (prefix) { - case LIBN_PRIMARY_PREFIX: - fmt->prefix = COIN_PRIMARY_PREFIX; - fmt->prefixLen = strnlen(COIN_PRIMARY_PREFIX, sizeof(COIN_PRIMARY_PREFIX)); - break; - case LIBN_SECONDARY_PREFIX: - fmt->prefix = COIN_SECONDARY_PREFIX; - fmt->prefixLen = strnlen(COIN_SECONDARY_PREFIX, sizeof(COIN_SECONDARY_PREFIX)); - break; + case LIBN_PRIMARY_PREFIX: + fmt->prefix = COIN_PRIMARY_PREFIX; + fmt->prefixLen = strnlen(COIN_PRIMARY_PREFIX, sizeof(COIN_PRIMARY_PREFIX)); + break; + case LIBN_SECONDARY_PREFIX: + fmt->prefix = COIN_SECONDARY_PREFIX; + fmt->prefixLen = strnlen(COIN_SECONDARY_PREFIX, sizeof(COIN_SECONDARY_PREFIX)); + break; } } @@ -134,23 +135,23 @@ void libn_amount_formatter_for_coin(libn_amount_formatter_t *fmt, uint8_t *bip32 if (strcmp(COIN_NAME, "NOS") == 0) { uint32_t currencyComponent = libn_bip32_get_component(bip32Path, 2); - #define SUBCURRENCY(CODE, PREFIX, SUFFIX, SCALE) \ - case HARDENED((CODE)): \ - fmt->suffix = (SUFFIX); \ - fmt->suffixLen = strlen((SUFFIX)); \ - fmt->unitScale = SCALE; \ - break +#define SUBCURRENCY(CODE, PREFIX, SUFFIX, SCALE) \ + case HARDENED((CODE)): \ + fmt->suffix = (SUFFIX); \ + fmt->suffixLen = strlen((SUFFIX)); \ + fmt->unitScale = SCALE; \ + break switch (currencyComponent) { - #include "nos_subcurrencies.h" - case HARDENED(0): - fmt->suffix = COIN_UNIT; - fmt->suffixLen = strnlen(COIN_UNIT, sizeof(COIN_UNIT)); - fmt->unitScale = COIN_UNIT_SCALE; - break; - default: - THROW(INVALID_PARAMETER); +#include "nos_subcurrencies.h" + case HARDENED(0): + fmt->suffix = COIN_UNIT; + fmt->suffixLen = strnlen(COIN_UNIT, sizeof(COIN_UNIT)); + fmt->unitScale = COIN_UNIT_SCALE; + break; + default: + THROW(INVALID_PARAMETER); } - #undef SUBCURRENCY +#undef SUBCURRENCY return; } @@ -162,61 +163,61 @@ void libn_amount_formatter_for_coin(libn_amount_formatter_t *fmt, uint8_t *bip32 size_t libn_address_format(const libn_address_formatter_t *fmt, uint8_t *buffer, - const libn_public_key_t publicKey) { + const libn_public_key_t pub) { uint8_t k, i, c; - uint8_t check[5] = { 0, 0, 0, 0, 0 }; + uint8_t check[5] = {0, 0, 0, 0, 0}; + blake2b_ctx ctx; - blake2b_ctx hash; - blake2b_init(&hash, sizeof(check), NULL, 0); - blake2b_update(&hash, publicKey, sizeof(libn_public_key_t)); - blake2b_final(&hash, check); + blake2b_init(&ctx, sizeof(check)); + blake2b_update(&ctx, pub, sizeof(libn_public_key_t)); + blake2b_final(&ctx, check); // Write prefix - os_memmove(buffer, fmt->prefix, fmt->prefixLen); + memmove(buffer, fmt->prefix, fmt->prefixLen); buffer += fmt->prefixLen; - // Helper macro to create a virtual array of check and publicKey variables - #define accGetByte(x) (uint8_t)( \ - ((x) < sizeof(check)) ? check[(x)] : \ - ((x) - sizeof(check) < sizeof(libn_public_key_t)) ? publicKey[sizeof(libn_public_key_t) - 1 - ((x) - sizeof(check))] : \ - 0 \ - ) +// Helper macro to create a virtual array of check and public key variables +#define accGetByte(x) \ + (uint8_t)(((x) < sizeof(check)) ? check[(x)] \ + : ((x) - sizeof(check) < sizeof(libn_public_key_t)) \ + ? pub[sizeof(libn_public_key_t) - 1 - ((x) - sizeof(check))] \ + : 0) for (k = 0; k < LIBN_ACCOUNT_STRING_BASE_LEN; k++) { i = (k / 8) * 5; c = 0; switch (k % 8) { - case 0: - c = accGetByte(i) & B_11111; - break; - case 1: - c = (accGetByte(i) >> 5) & B_00111; - c |= (accGetByte(i + 1) & B_00011) << 3; - break; - case 2: - c = (accGetByte(i + 1) >> 2) & B_11111; - break; - case 3: - c = (accGetByte(i + 1) >> 7) & B_00001; - c |= (accGetByte(i + 2) & B_01111) << 1; - break; - case 4: - c = (accGetByte(i + 2) >> 4) & B_01111; - c |= (accGetByte(i + 3) & B_00001) << 4; - break; - case 5: - c = (accGetByte(i + 3) >> 1) & B_11111; - break; - case 6: - c = (accGetByte(i + 3) >> 6) & B_00011; - c |= (accGetByte(i + 4) & B_00111) << 2; - break; - case 7: - c = (accGetByte(i + 4) >> 3) & B_11111; - break; + case 0: + c = accGetByte(i) & B_11111; + break; + case 1: + c = (accGetByte(i) >> 5) & B_00111; + c |= (accGetByte(i + 1) & B_00011) << 3; + break; + case 2: + c = (accGetByte(i + 1) >> 2) & B_11111; + break; + case 3: + c = (accGetByte(i + 1) >> 7) & B_00001; + c |= (accGetByte(i + 2) & B_01111) << 1; + break; + case 4: + c = (accGetByte(i + 2) >> 4) & B_01111; + c |= (accGetByte(i + 3) & B_00001) << 4; + break; + case 5: + c = (accGetByte(i + 3) >> 1) & B_11111; + break; + case 6: + c = (accGetByte(i + 3) >> 6) & B_00011; + c |= (accGetByte(i + 4) & B_00111) << 2; + break; + case 7: + c = (accGetByte(i + 4) >> 3) & B_11111; + break; } - buffer[LIBN_ACCOUNT_STRING_BASE_LEN-1-k] = BASE32_ALPHABET[c]; + buffer[LIBN_ACCOUNT_STRING_BASE_LEN - 1 - k] = BASE32_ALPHABET[c]; } - #undef accGetByte +#undef accGetByte return fmt->prefixLen + LIBN_ACCOUNT_STRING_BASE_LEN; } @@ -237,29 +238,29 @@ void libn_amount_subtract(libn_amount_t value, const libn_amount_t other) { while (i > 0) { i -= 1; - uint16_t diff = (uint16_t)value[i] - (other[i] & mask) - borrow; - value[i] = (uint8_t)diff; - borrow = -(uint8_t)(diff >> 8); + uint16_t diff = (uint16_t) value[i] - (other[i] & mask) - borrow; + value[i] = (uint8_t) diff; + borrow = -(uint8_t) (diff >> 8); } } void libn_amount_format(const libn_amount_formatter_t *fmt, - char *dest, size_t destLen, + char *dest, + size_t destLen, const libn_amount_t balance) { // MaxUInt128 = 340282366920938463463374607431768211455 (39 digits) - char buf[39 /* digits */ + char buf[39 /* digits */ + 1 /* period */ + 1 /* " " before unit */ - + sizeof((libn_coin_conf_t){}.defaultUnit) - + 1 /* '\0' NULL terminator */]; + + sizeof((libn_coin_conf_t){}.defaultUnit) + 1 /* '\0' NULL terminator */]; libn_amount_t num; - os_memset(buf, 0, sizeof(buf)); - os_memmove(num, balance, sizeof(num)); + memset(buf, 0, sizeof(buf)); + memmove(num, balance, sizeof(num)); size_t end = sizeof(buf); - end -= 1; // '\0' NULL terminator - end -= 1 + fmt->suffixLen; // len(" " + suffix) + end -= 1; // '\0' NULL terminator + end -= 1 + fmt->suffixLen; // len(" " + suffix) size_t start = end; // Convert the balance into a string by dividing by 10 until @@ -268,27 +269,57 @@ void libn_amount_format(const libn_amount_formatter_t *fmt, uint16_t d; do { r = num[0]; - d = r / 10; r = ((r - d * 10) << 8) + num[1]; num[0] = d; - d = r / 10; r = ((r - d * 10) << 8) + num[2]; num[1] = d; - d = r / 10; r = ((r - d * 10) << 8) + num[3]; num[2] = d; - d = r / 10; r = ((r - d * 10) << 8) + num[4]; num[3] = d; - d = r / 10; r = ((r - d * 10) << 8) + num[5]; num[4] = d; - d = r / 10; r = ((r - d * 10) << 8) + num[6]; num[5] = d; - d = r / 10; r = ((r - d * 10) << 8) + num[7]; num[6] = d; - d = r / 10; r = ((r - d * 10) << 8) + num[8]; num[7] = d; - d = r / 10; r = ((r - d * 10) << 8) + num[9]; num[8] = d; - d = r / 10; r = ((r - d * 10) << 8) + num[10]; num[9] = d; - d = r / 10; r = ((r - d * 10) << 8) + num[11]; num[10] = d; - d = r / 10; r = ((r - d * 10) << 8) + num[12]; num[11] = d; - d = r / 10; r = ((r - d * 10) << 8) + num[13]; num[12] = d; - d = r / 10; r = ((r - d * 10) << 8) + num[14]; num[13] = d; - d = r / 10; r = ((r - d * 10) << 8) + num[15]; num[14] = d; - d = r / 10; r = r - d * 10; num[15] = d; + d = r / 10; + r = ((r - d * 10) << 8) + num[1]; + num[0] = d; + d = r / 10; + r = ((r - d * 10) << 8) + num[2]; + num[1] = d; + d = r / 10; + r = ((r - d * 10) << 8) + num[3]; + num[2] = d; + d = r / 10; + r = ((r - d * 10) << 8) + num[4]; + num[3] = d; + d = r / 10; + r = ((r - d * 10) << 8) + num[5]; + num[4] = d; + d = r / 10; + r = ((r - d * 10) << 8) + num[6]; + num[5] = d; + d = r / 10; + r = ((r - d * 10) << 8) + num[7]; + num[6] = d; + d = r / 10; + r = ((r - d * 10) << 8) + num[8]; + num[7] = d; + d = r / 10; + r = ((r - d * 10) << 8) + num[9]; + num[8] = d; + d = r / 10; + r = ((r - d * 10) << 8) + num[10]; + num[9] = d; + d = r / 10; + r = ((r - d * 10) << 8) + num[11]; + num[10] = d; + d = r / 10; + r = ((r - d * 10) << 8) + num[12]; + num[11] = d; + d = r / 10; + r = ((r - d * 10) << 8) + num[13]; + num[12] = d; + d = r / 10; + r = ((r - d * 10) << 8) + num[14]; + num[13] = d; + d = r / 10; + r = ((r - d * 10) << 8) + num[15]; + num[14] = d; + d = r / 10; + r = r - d * 10; + num[15] = d; buf[--start] = '0' + r; - } while (num[0] || num[1] || num[2] || num[3] || - num[4] || num[5] || num[6] || num[7] || - num[8] || num[9] || num[10] || num[11] || - num[12] || num[13] || num[14] || num[15]); + } while (num[0] || num[1] || num[2] || num[3] || num[4] || num[5] || num[6] || num[7] || + num[8] || num[9] || num[10] || num[11] || num[12] || num[13] || num[14] || num[15]); // Assign the location for the decimal point size_t point = end - 1 - fmt->unitScale; @@ -298,7 +329,7 @@ void libn_amount_format(const libn_amount_formatter_t *fmt, } // Move digits before the point one place to the left for (size_t i = start; i <= point; i++) { - buf[i-1] = buf[i]; + buf[i - 1] = buf[i]; } start -= 1; // It's safe to write out the point now @@ -307,30 +338,31 @@ void libn_amount_format(const libn_amount_formatter_t *fmt, } // Remove as many zeros from the fractional part as possible - while (end > point && (buf[end-1] == '0' || buf[end-1] == '.')) { + while (end > point && (buf[end - 1] == '0' || buf[end - 1] == '.')) { end -= 1; } buf[end] = '\0'; // Append the unit buf[end++] = ' '; - os_memmove(buf + end, fmt->suffix, fmt->suffixLen); + memmove(buf + end, fmt->suffix, fmt->suffixLen); end += fmt->suffixLen; buf[end] = '\0'; // Copy the result to the destination buffer - os_memmove(dest, buf + start, MIN(destLen - 1, end - start + 1)); + memmove(dest, buf + start, MIN(destLen - 1, end - start + 1)); dest[destLen - 1] = '\0'; } void libn_derive_keypair(uint8_t *bip32Path, - libn_private_key_t out_privateKey, - libn_public_key_t out_publicKey) { + libn_private_key_t out_prv, + libn_public_key_t out_pub) { uint32_t bip32PathInt[MAX_BIP32_PATH]; uint8_t chainCode[32]; uint8_t bip32PathLength; uint8_t i; const uint8_t bip32PrefixLength = 2; + cx_err_t result; bip32PathLength = bip32Path[0]; if (bip32PathLength > MAX_BIP32_PATH) { @@ -350,16 +382,21 @@ void libn_derive_keypair(uint8_t *bip32Path, THROW(INVALID_PARAMETER); } } - os_perso_derive_node_bip32_seed_key( - HDW_ED25519_SLIP10, LIBN_CURVE, - bip32PathInt, bip32PathLength, - out_privateKey, chainCode, - (unsigned char *)LIBN_SEED_KEY, sizeof(LIBN_SEED_KEY) - ); - os_memset(chainCode, 0, sizeof(chainCode)); - - if (out_publicKey != NULL) { - ed25519_publickey(out_privateKey, out_publicKey); + result = os_derive_bip32_with_seed_no_throw(HDW_ED25519_SLIP10, + LIBN_CURVE, + bip32PathInt, + bip32PathLength, + out_prv, + chainCode, + (unsigned char *) LIBN_SEED_KEY, + sizeof(LIBN_SEED_KEY)); + if (result != CX_OK) { + THROW(result); + } + memset(chainCode, 0, sizeof(chainCode)); + + if (out_pub != NULL) { + ed25519_publickey(out_prv, out_pub); } } @@ -371,48 +408,31 @@ uint32_t libn_simple_hash(uint8_t *data, size_t dataLen) { return result; } -void libn_hash_block(libn_hash_t blockHash, - const libn_block_data_t *blockData, - const libn_public_key_t publicKey) { - blake2b_ctx hash; - blake2b_init(&hash, sizeof(libn_hash_t), NULL, 0); - - blake2b_update(&hash, BLOCK_HASH_PREAMBLE, sizeof(BLOCK_HASH_PREAMBLE)); - blake2b_update(&hash, publicKey, sizeof(libn_public_key_t)); - blake2b_update(&hash, blockData->parent, sizeof(blockData->parent)); - blake2b_update(&hash, blockData->representative, - sizeof(blockData->representative)); - blake2b_update(&hash, blockData->balance, sizeof(blockData->balance)); - blake2b_update(&hash, blockData->link, sizeof(blockData->link)); - - blake2b_final(&hash, blockHash); +void libn_hash_block(libn_hash_t hash, const libn_block_data_t *data, const libn_public_key_t pub) { + blake2b_ctx ctx; + + blake2b_init(&ctx, sizeof(libn_hash_t)); + blake2b_update(&ctx, BLOCK_HASH_PREAMBLE, sizeof(BLOCK_HASH_PREAMBLE)); + blake2b_update(&ctx, pub, sizeof(libn_public_key_t)); + blake2b_update(&ctx, data->parent, sizeof(data->parent)); + blake2b_update(&ctx, data->representative, sizeof(data->representative)); + blake2b_update(&ctx, data->balance, sizeof(data->balance)); + blake2b_update(&ctx, data->link, sizeof(data->link)); + blake2b_final(&ctx, hash); } -void libn_sign_hash(libn_signature_t signature, - const libn_hash_t hash, - const libn_private_key_t privateKey, - const libn_public_key_t publicKey) { - ed25519_sign( - hash, sizeof(libn_hash_t), - privateKey, publicKey, - signature); +void libn_sign_hash(libn_signature_t sig, const libn_hash_t hash, const libn_private_key_t prv) { + ed25519_sign(hash, sizeof(libn_hash_t), prv, sig); } bool libn_verify_hash_signature(const libn_hash_t hash, - const libn_public_key_t publicKey, - const libn_signature_t signature) { - return ed25519_sign_open( - hash, sizeof(libn_hash_t), - publicKey, signature) == 0; + const libn_public_key_t pub, + const libn_signature_t sig) { + return ed25519_sign_open(hash, sizeof(libn_hash_t), pub, sig); } -void libn_sign_nonce(libn_signature_t signature, - const libn_nonce_t nonce, - const libn_private_key_t privateKey, - const libn_public_key_t publicKey) { - uint8_t msg[sizeof(COIN_NAME) + - sizeof(NONCE_PREAMBLE) + - 2 * sizeof(libn_nonce_t)]; +void libn_sign_nonce(libn_signature_t sig, const libn_nonce_t nonce, const libn_private_key_t prv) { + uint8_t msg[sizeof(COIN_NAME) + sizeof(NONCE_PREAMBLE) + 2 * sizeof(libn_nonce_t)]; size_t len; // Construct the message to contain the preamble with the hex-encoded @@ -420,18 +440,15 @@ void libn_sign_nonce(libn_signature_t signature, uint8_t *ptr = msg; // Append the coin name len = strnlen(COIN_NAME, sizeof(COIN_NAME)); - os_memmove(ptr, COIN_NAME, len); + memmove(ptr, COIN_NAME, len); ptr += len; // Apend the " Signed Nonce:\n" - os_memmove(ptr, NONCE_PREAMBLE, sizeof(NONCE_PREAMBLE)); + memmove(ptr, NONCE_PREAMBLE, sizeof(NONCE_PREAMBLE)); ptr += sizeof(NONCE_PREAMBLE); // Append the nonce libn_write_hex_string(ptr, nonce, sizeof(libn_nonce_t)); ptr += 2 * sizeof(libn_nonce_t); len = ptr - msg; - ed25519_sign( - msg, len, - privateKey, publicKey, - signature); + ed25519_sign(msg, len, prv, sig); } diff --git a/src/libn_helpers.h b/src/libn_helpers.h index a4bf50e..6bb2cf1 100644 --- a/src/libn_helpers.h +++ b/src/libn_helpers.h @@ -1,33 +1,29 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2016 Ledger -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ - -#ifndef LIBN_HELPERS_H - -#define LIBN_HELPERS_H + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2016 Ledger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +#pragma once #include "libn_types.h" -#define MAX_BIP32_PATH 10 +#define MAX_BIP32_PATH 10 #define MAX_BIP32_PATH_LENGTH (4 * MAX_BIP32_PATH) + 1 bool libn_is_zero(const uint8_t *ptr, size_t num); -uint32_t libn_read_u32(uint8_t *buffer, bool be, - bool skipSign); +uint32_t libn_read_u32(uint8_t *buffer, bool be, bool skipSign); void libn_write_u32_be(uint8_t *buffer, uint32_t value); void libn_write_u32_le(uint8_t *buffer, uint32_t value); @@ -37,41 +33,29 @@ void libn_write_hex_string(uint8_t *buffer, const uint8_t *bytes, size_t bytesLe void libn_address_formatter_for_coin(libn_address_formatter_t *fmt, libn_address_prefix_t prefix, uint8_t *bip32Path); -void libn_amount_formatter_for_coin(libn_amount_formatter_t *fmt, - uint8_t *bip32Path); +void libn_amount_formatter_for_coin(libn_amount_formatter_t *fmt, uint8_t *bip32Path); size_t libn_address_format(const libn_address_formatter_t *fmt, uint8_t *buffer, - const libn_public_key_t publicKey); + const libn_public_key_t pub); int8_t libn_amount_cmp(const libn_amount_t a, const libn_amount_t b); void libn_amount_subtract(libn_amount_t value, const libn_amount_t other); void libn_amount_format(const libn_amount_formatter_t *fmt, - char *dest, size_t destLen, + char *dest, + size_t destLen, const libn_amount_t balance); -void libn_derive_keypair(uint8_t *bip32Path, - libn_private_key_t out_privateKey, - libn_public_key_t out_publicKey); +void libn_derive_keypair(uint8_t *bip32Path, libn_private_key_t out_prv, libn_public_key_t out_pub); /** Implement Java hashCode() equivalent hashing of data **/ uint32_t libn_simple_hash(uint8_t *data, size_t dataLen); -void libn_hash_block(libn_hash_t blockHash, - const libn_block_data_t *blockData, - const libn_public_key_t publicKey); - -void libn_sign_hash(libn_signature_t signature, - const libn_hash_t hash, - const libn_private_key_t privateKey, - const libn_public_key_t publicKey); -bool libn_verify_hash_signature(const libn_hash_t blockHash, - const libn_public_key_t publicKey, - const libn_signature_t signature); +void libn_hash_block(libn_hash_t hash, const libn_block_data_t *data, const libn_public_key_t pub); -void libn_sign_nonce(libn_signature_t signature, - const libn_nonce_t nonce, - const libn_private_key_t privateKey, - const libn_public_key_t publicKey); +void libn_sign_hash(libn_signature_t sig, const libn_hash_t hash, const libn_private_key_t prv); +bool libn_verify_hash_signature(const libn_hash_t hash, + const libn_public_key_t pub, + const libn_signature_t sig); -#endif +void libn_sign_nonce(libn_signature_t sig, const libn_nonce_t nonce, const libn_private_key_t prv); diff --git a/src/libn_internal.h b/src/libn_internal.h index 0c1fdc3..148b21d 100644 --- a/src/libn_internal.h +++ b/src/libn_internal.h @@ -1,29 +1,26 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2016 Ledger -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ - -#ifndef LIBN_INTERNAL_H -#define LIBN_INTERNAL_H + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2016 Ledger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +#pragma once #include "libn_app.h" -#include "libn_types.h" #include "libn_context.h" -#include "libn_ram_variables.h" -#include "libn_rom_variables.h" #include "libn_filesystem.h" #include "libn_helpers.h" +#include "libn_ram_variables.h" +#include "libn_rom_variables.h" -#endif +#include "libn_types.h" diff --git a/src/libn_nvram.c b/src/libn_nvram.c index 50bbd8c..6480096 100644 --- a/src/libn_nvram.c +++ b/src/libn_nvram.c @@ -1,19 +1,19 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2016 Ledger -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2016 Ledger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ #include "libn_internal.h" diff --git a/src/libn_ram_variables.c b/src/libn_ram_variables.c index edc0de0..da79fdb 100644 --- a/src/libn_ram_variables.c +++ b/src/libn_ram_variables.c @@ -1,33 +1,27 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2016 Ledger -* (c) 2018 Mart Roosmaa -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2016 Ledger + * (c) 2018 Mart Roosmaa + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ -#include "libn_ram_variables.h" -#include "os_io_seproxyhal.h" +#include "io.h" -// Bolos SDK variables -uint8_t G_io_seproxyhal_spi_buffer[IO_SEPROXYHAL_BUFFER_SIZE_B]; +#include "libn_ram_variables.h" -#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) -ux_state_t G_ux; -bolos_ux_params_t G_ux_params; -#else ux_state_t ux; -#endif -uint8_t libn_async_buffer_D[MAX_ADPU_OUTPUT_SIZE + 2 /* status word */]; +uint8_t libn_async_buffer_D[IO_APDU_BUFFER_SIZE]; + libn_context_t libn_context_D; diff --git a/src/libn_ram_variables.h b/src/libn_ram_variables.h index 29fe939..5365480 100644 --- a/src/libn_ram_variables.h +++ b/src/libn_ram_variables.h @@ -1,31 +1,28 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2016 Ledger -* (c) 2018 Mart Roosmaa -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2016 Ledger + * (c) 2018 Mart Roosmaa + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +#pragma once -#ifndef LIBN_PUBLIC_RAM_VARIABLES_H - -#define LIBN_PUBLIC_RAM_VARIABLES_H +#include "io.h" #include "blake2b.h" - #include "libn_context.h" -/** Buffer used for asynchronous response data **/ -extern uint8_t libn_async_buffer_D[MAX_ADPU_OUTPUT_SIZE + 2 /* status word */]; -extern libn_context_t libn_context_D; +/* Buffer used for asynchronous response data + status word */ +extern uint8_t libn_async_buffer_D[IO_APDU_BUFFER_SIZE]; -#endif // LIBN_PUBLIC_RAM_VARIABLES_H +extern libn_context_t libn_context_D; diff --git a/src/libn_rom_variables.c b/src/libn_rom_variables.c index db25dfa..8e69b31 100644 --- a/src/libn_rom_variables.c +++ b/src/libn_rom_variables.c @@ -1,19 +1,19 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2016 Ledger -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2016 Ledger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ #include "libn_internal.h" #include "libn_apdu_constants.h" @@ -24,27 +24,27 @@ #include "libn_apdu_sign_nonce.h" uint8_t const DISPATCHER_CLA[] = { - LIBN_CLA, // libn_apdu_get_app_conf - LIBN_CLA, // libn_apdu_get_address - LIBN_CLA, // libn_apdu_cache_block - LIBN_CLA, // libn_apdu_sign_block - LIBN_CLA, // libn_apdu_sign_nonce + LIBN_CLA, // libn_apdu_get_app_conf + LIBN_CLA, // libn_apdu_get_address + LIBN_CLA, // libn_apdu_cache_block + LIBN_CLA, // libn_apdu_sign_block + LIBN_CLA, // libn_apdu_sign_nonce }; uint8_t const DISPATCHER_INS[] = { - LIBN_INS_GET_APP_CONF, // libn_apdu_get_app_conf - LIBN_INS_GET_ADDRESS, // libn_apdu_get_address - LIBN_INS_CACHE_BLOCK, // libn_apdu_cache_block - LIBN_INS_SIGN_BLOCK, // libn_apdu_sign_block - LIBN_INS_SIGN_NONCE, // libn_apdu_sign_nonce + LIBN_INS_GET_APP_CONF, // libn_apdu_get_app_conf + LIBN_INS_GET_ADDRESS, // libn_apdu_get_address + LIBN_INS_CACHE_BLOCK, // libn_apdu_cache_block + LIBN_INS_SIGN_BLOCK, // libn_apdu_sign_block + LIBN_INS_SIGN_NONCE, // libn_apdu_sign_nonce }; bool const DISPATCHER_DATA_IN[] = { - false, // libn_apdu_get_app_conf - true, // libn_apdu_get_address - true, // libn_apdu_cache_block - true, // libn_apdu_sign_block - true, // libn_apdu_sign_nonce + false, // libn_apdu_get_app_conf + true, // libn_apdu_get_address + true, // libn_apdu_cache_block + true, // libn_apdu_sign_block + true, // libn_apdu_sign_nonce }; apduProcessingFunction const DISPATCHER_FUNCTIONS[] = { @@ -55,30 +55,23 @@ apduProcessingFunction const DISPATCHER_FUNCTIONS[] = { libn_apdu_sign_nonce, }; -uint8_t const BASE16_ALPHABET[16] = { - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - 'A', 'B', 'C', 'D', 'E', 'F' }; +uint8_t const BASE16_ALPHABET[16] = + {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; -uint8_t const BASE32_ALPHABET[32] = { - '1', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', - 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'm', 'n', 'o', 'p', 'q', - 'r', 's', 't', 'u', 'w', 'x', 'y', 'z' }; +uint8_t const BASE32_ALPHABET[32] = {'1', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', + 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'm', 'n', 'o', + 'p', 'q', 'r', 's', 't', 'u', 'w', 'x', 'y', 'z'}; uint8_t const BASE32_TABLE[75] = { - 0xff, 0x00, 0xff, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x08, 0x09, 0x0a, - 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0xff, 0x13, - 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0xff, 0x1c, - 0x1d, 0x1e, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x08, - 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, - 0xff, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, - 0xff, 0x1c, 0x1d, 0x1e, 0x1f }; + 0xff, 0x00, 0xff, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0xff, 0x13, + 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0xff, 0x1c, 0x1d, 0x1e, 0x1f, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, + 0xff, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0xff, 0x1c, 0x1d, 0x1e, 0x1f}; uint8_t const BLOCK_HASH_PREAMBLE[32] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, }; uint8_t const NONCE_PREAMBLE[15] = " Signed Nonce:\n"; diff --git a/src/libn_rom_variables.h b/src/libn_rom_variables.h index bed01c2..6fc1fef 100644 --- a/src/libn_rom_variables.h +++ b/src/libn_rom_variables.h @@ -1,19 +1,19 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2016 Ledger -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2016 Ledger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ #include "libn_internal.h" diff --git a/src/libn_secure_value.c b/src/libn_secure_value.c index f4e53eb..f21775d 100644 --- a/src/libn_secure_value.c +++ b/src/libn_secure_value.c @@ -1,38 +1,38 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2016 Ledger -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2016 Ledger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ #include "libn_internal.h" void sbSet(secu8 *target, uint8_t source) { - *target = (((uint16_t)~source) << 8) + source; + *target = (((uint16_t) ~source) << 8) + source; } void sbCheck(secu8 source) { - if (((source >> 8) & 0xff) != (uint8_t)(~(source & 0xff))) { + if (((source >> 8) & 0xff) != (uint8_t) (~(source & 0xff))) { reset(); } } void ssSet(secu16 *target, uint16_t source) { - *target = (((uint32_t)~source) << 16) + source; + *target = (((uint32_t) ~source) << 16) + source; } void ssCheck(secu16 source) { - if (((source >> 16) & 0xffff) != (uint16_t)(~(source & 0xffff))) { + if (((source >> 16) & 0xffff) != (uint16_t) (~(source & 0xffff))) { reset(); } } diff --git a/src/libn_secure_value.h b/src/libn_secure_value.h index 73d8367..62fb6c5 100644 --- a/src/libn_secure_value.h +++ b/src/libn_secure_value.h @@ -1,23 +1,20 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2016 Ledger -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ - -#ifndef LIBN_SECURE_VALUE_H - -#define LIBN_SECURE_VALUE_H + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2016 Ledger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +#pragma once #include "os.h" @@ -29,16 +26,14 @@ void sbCheck(secu8 source); void ssSet(secu16 *target, uint16_t source); void ssCheck(secu16 source); -#define SB_GET(x) ((uint8_t)x) +#define SB_GET(x) ((uint8_t) x) #define SB_SET(x, y) sbSet(&x, y); #define SB_CHECK(x) sbCheck(x); -#define SS_GET(x) ((uint16_t)x) +#define SS_GET(x) ((uint16_t) x) #define SS_SET(x, y) ssSet(&x, y); #define SS_CHECK(x) ssCheck(x); - -#endif diff --git a/src/libn_types.h b/src/libn_types.h index 94cb292..285e8ae 100644 --- a/src/libn_types.h +++ b/src/libn_types.h @@ -1,27 +1,25 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2018 Mart Roosmaa -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ - -#ifndef LIBN_TYPES_H - -#define LIBN_TYPES_H + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2018 Mart Roosmaa + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +#pragma once #include #include -#include "os_io_seproxyhal.h" + +#include "io.h" #include "ux.h" typedef struct { @@ -82,16 +80,16 @@ typedef struct { const uint32_t colorConfirmOverForeground; const bagl_icon_details_t *iconToggleOff; const bagl_icon_details_t *iconToggleOn; -#endif // TARGET_BLUE +#endif // TARGET_BLUE } libn_coin_conf_t; typedef struct { - char *prefix; + const char *prefix; uint8_t prefixLen; } libn_address_formatter_t; typedef struct { - char *suffix; + const char *suffix; uint8_t suffixLen; uint8_t unitScale; } libn_amount_formatter_t; @@ -108,5 +106,3 @@ typedef struct { libn_public_key_t representative; libn_amount_t balance; } libn_cached_block_data_t; - -#endif // LIBN_TYPES_H \ No newline at end of file diff --git a/src/main.c b/src/main.c index 9b29068..99dd086 100644 --- a/src/main.c +++ b/src/main.c @@ -1,33 +1,30 @@ /******************************************************************************* -* $NANO Wallet for Ledger Nano S & Blue -* (c) 2018 Mart Roosmaa -* (c) 2016 Ledger -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * $NANO Wallet for Ledger Nano S & Blue + * (c) 2018 Mart Roosmaa + * (c) 2016 Ledger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ -#include "os_io_seproxyhal.h" -#include "libn_internal.h" #include "coins.h" - -#if defined(IS_SHARED_LIBRARY) || defined(IS_STANDALONE_APP) +#include "libn_internal.h" +#include "os_io_seproxyhal.h" __attribute__((section(".boot"))) int main(int arg0) { // exit critical section __asm volatile("cpsie i"); -#ifdef IS_SHARED_LIBRARY - const uint32_t *libcall_args = (uint32_t *)arg0; + const uint32_t* libcall_args = (uint32_t*) arg0; if (libcall_args) { if (libcall_args[0] != 0x100) { @@ -35,13 +32,10 @@ __attribute__((section(".boot"))) int main(int arg0) { return 0; } // grab the coin type from the first parameter - init_coin_config((libn_coin_type_t)libcall_args[1]); + init_coin_config((libn_coin_type_t) libcall_args[1]); } else { - init_coin_config(DEFAULT_COIN_TYPE); + init_coin_config(COIN_TYPE); } -#else - init_coin_config(DEFAULT_COIN_TYPE); -#endif // ensure exception will work as planned os_boot(); @@ -68,29 +62,3 @@ __attribute__((section(".boot"))) int main(int arg0) { app_exit(); return 0; } - -#else // IS_SHARED_LIBRARY || IS_STANDALONE_APP - -__attribute__((section(".boot"))) int main(void) { - // in RAM allocation (on stack), to allow simple simple traversal into the - // main Nano app (separate NVRAM zone) - uint32_t libcall_params[3]; - BEGIN_TRY { - TRY { - // ensure syscall will accept us - check_api_level(CX_COMPAT_APILEVEL); - // delegate to Nano app/lib - libcall_params[0] = SHARED_LIBRARY_NAME; - libcall_params[1] = 0x100; // use the Init call, as we won't exit - libcall_params[2] = DEFAULT_COIN_TYPE; - os_lib_call(&libcall_params); - } - FINALLY { - app_exit(); - } - } - END_TRY; - return 0; -} - -#endif // IS_SHARED_LIBRARY || IS_STANDALONE_APP