Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Cherry pick for API_LEVEL_15 #538

Merged
merged 15 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 26 additions & 28 deletions Makefile.defines
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ ifeq ($(filter $(TARGET),$(TARGETS)),)
$(error TARGET not set to a valid value (possible values: $(TARGETS)))
endif

# for Stax, NBGL must be used
ifeq ($(TARGET),stax)
USE_NBGL ?= 1
endif

API_LEVEL := 15
TARGET_PATH := $(BOLOS_SDK)/target/$(TARGET)
TARGET_ID := $(shell cat $(TARGET_PATH)/include/bolos_target.h | grep TARGET_ID | cut -f3 -d' ')
Expand Down Expand Up @@ -169,9 +164,9 @@ LDFLAGS += -L$(BOLOS_SDK)/arch/st33k1/lib/
AFLAGS += -mcpu=cortex-m35p+nodsp -mthumb
endif

DISABLE_UI ?= 0
ifeq ($(DISABLE_UI),0)
ifeq ($(TARGET_NAME),TARGET_STAX)
# For Stax NBGL must be used
USE_NBGL = 1
DEFINES += HAVE_BAGL_FONT_INTER_REGULAR_24PX
DEFINES += HAVE_BAGL_FONT_INTER_SEMIBOLD_24PX
DEFINES += HAVE_BAGL_FONT_INTER_MEDIUM_32PX
Expand All @@ -182,32 +177,37 @@ DEFINES += HAVE_SE_TOUCH
DEFINES += NBGL_PAGE
DEFINES += NBGL_USE_CASE
DEFINES += SCREEN_SIZE_WALLET
#DEFINES += HAVE_DISPLAY_FAST_MODE
else
endif # TARGET_STAX

# For other devices, by default NBGL is not used
USE_NBGL ?= 0

ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOX TARGET_NANOS2))
DEFINES += BAGL_HEIGHT=64
DEFINES += BAGL_WIDTH=128
DEFINES += HAVE_BAGL_ELLIPSIS
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 += SCREEN_SIZE_NANO
ifdef USE_NBGL

ifeq ($(USE_NBGL),0)
DEFINES += HAVE_BAGL
DEFINES += HAVE_UX_FLOW
else
DEFINES += HAVE_NBGL
DEFINES += NBGL_STEP
DEFINES += NBGL_USE_CASE
else
DEFINES += HAVE_BAGL
endif
endif # USE_NBGL

endif # TARGET_NANOX / TARGET_NANOS2

ifeq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += BAGL_HEIGHT=32
endif
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOX TARGET_NANOS2))
ifndef USE_NBGL
DEFINES += HAVE_UX_FLOW
endif
DEFINES += BAGL_HEIGHT=64
DEFINES += HAVE_BAGL_ELLIPSIS
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_REGULAR_11PX
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_EXTRABOLD_11PX
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_LIGHT_16PX
endif
endif
endif
DEFINES += BAGL_WIDTH=128
DEFINES += SCREEN_SIZE_NANO
DEFINES += HAVE_BAGL
endif # TARGET_NANOS

ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOX TARGET_NANOS2))
# Screen is directly connected to the SE
Expand All @@ -217,8 +217,6 @@ DEFINES += HAVE_SE_BUTTON
# MCU serial is stored on board of the SE
DEFINES += HAVE_MCU_SERIAL_STORAGE
DEFINES += HAVE_FONTS
# already defined within apps
# DEFINES += HAVE_BLE
DEFINES += HAVE_INAPP_BLE_PAIRING
DEFINES += HAVE_BATTERY
endif
Expand Down
2 changes: 1 addition & 1 deletion Makefile.glyphs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ GLYPH_DESTH := $(GLYPH_SRC_DIR)/glyphs.h
# search icons (glyphs) in glyphs folder of the app first
GLYPH_FILES += $(addprefix glyphs/,$(sort $(notdir $(shell find glyphs/))))

ifdef USE_NBGL
ifneq ($(USE_NBGL),0)
# NBGL glyphs files and generation script
#
# search icons (glyphs) in lib_nbgl/glyphs(_nano) folder of the SDK
Expand Down
10 changes: 4 additions & 6 deletions Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
#*******************************************************************************

# temporary redef, to ensure wider compliance of the SDK with pre-1.6 apps
ifeq ($(DISABLE_UI),0)
ifndef USE_NBGL
SDK_SOURCE_PATH += lib_bagl lib_ux
else
SDK_SOURCE_PATH += lib_nbgl lib_ux_stax
endif
ifeq ($(USE_NBGL),0)
SDK_SOURCE_PATH += lib_bagl lib_ux
else
SDK_SOURCE_PATH += lib_nbgl lib_ux_nbgl
endif

define uniq =
Expand Down
8 changes: 7 additions & 1 deletion Makefile.standard_app
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ ifneq ($(DISABLE_STANDARD_WEBUSB), 1)
endif

ifneq ($(DISABLE_STANDARD_BAGL_UX_FLOW), 1)
ifndef USE_NBGL
ifeq ($(USE_NBGL),0)
DEFINES += HAVE_UX_FLOW
endif
endif
Expand All @@ -124,6 +124,12 @@ ifneq ($(DISABLE_STANDARD_APP_FILES), 1)
SDK_SOURCE_PATH += lib_standard_app
endif

ifneq ($(DISABLE_STANDARD_APP_SYNC_RAPDU), 1)
ifneq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += STANDARD_APP_SYNC_RAPDU
endif
endif

#####################################################################
# NBGL #
#####################################################################
Expand Down
4 changes: 2 additions & 2 deletions doc/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -855,8 +855,8 @@ INPUT = \
lib_ux/doc \
lib_ux/include \
lib_ux/src \
lib_ux_stax/doc \
lib_ux_stax
lib_ux_nbgl/doc \
lib_ux_nbgl

# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
Expand Down
3 changes: 2 additions & 1 deletion include/os_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ extern unsigned char G_io_apdu_buffer[IO_APDU_BUFFER_SIZE];
#define IO_RETURN_AFTER_TX 0x20
#define IO_ASYNCH_REPLY 0x10 // avoid apdu state reset if tx_len == 0 when we're expected to reply
#define IO_FINISHED 0x08 // inter task communication value
#define IO_FLAGS 0xF8
#define IO_CONTINUE_RX 0x04
#define IO_FLAGS 0xFC
unsigned short io_exchange(unsigned char channel_and_flags, unsigned short tx_len);

typedef enum {
Expand Down
26 changes: 26 additions & 0 deletions include/ux.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

/*****************************************************************************
* (c) 2024 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
*
* 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

#ifdef HAVE_BAGL
#include "ux_bagl.h"
#endif

#ifdef HAVE_NBGL
#include "ux_nbgl.h"
#endif
26 changes: 26 additions & 0 deletions include/ux_loc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

/*****************************************************************************
* (c) 2024 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
*
* 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

#ifdef HAVE_BAGL
#include "ux_loc_bagl.h"
#endif

#ifdef HAVE_NBGL
#include "ux_loc_nbgl.h"
#endif
80 changes: 80 additions & 0 deletions lib_cxng/include/lcx_blake2.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
#include <stddef.h>
#include <stdint.h>

/** BLAKE2B_256 message digest size */
#define CX_BLAKE2B_256_SIZE 32

/** BLAKE2B_512 message digest size */
#define CX_BLAKE2B_512_SIZE 64

/** @private BLAKE2b constants */
enum blake2b_constant {
BLAKE2B_BLOCKBYTES = 128, ///< Size of a block
Expand Down Expand Up @@ -91,6 +97,80 @@ DEPRECATED static inline int cx_blake2b_init(cx_blake2b_t *hash, unsigned int ou
return CX_BLAKE2B;
}

/**
* @brief Computes a standalone one shot BLAKE2B_256 digest.
*
* @param[in] iovec Input data in the form of an array of cx_iovec_t.
*
* @param[in] iovec_len Length of the iovec array.
*
* @param[out] digest Buffer where to store the digest.
*
* @return Error code:
* - CX_OK on success
*/
cx_err_t cx_blake2b_256_hash_iovec(const cx_iovec_t *iovec,
size_t iovec_len,
uint8_t digest[static CX_BLAKE2B_256_SIZE]);

/**
* @brief Computes a standalone one shot BLAKE2B_256 digest.
*
* @param[in] in Input data.
*
* @param[in] len Length of the input data.
*
* @param[out] digest Buffer where to store the digest.
*
* @return Error code:
* - CX_OK on success
*/
static inline cx_err_t cx_blake2b_256_hash(const uint8_t *in,
size_t in_len,
uint8_t digest[static CX_BLAKE2B_256_SIZE])
{
const cx_iovec_t iovec = {.iov_base = in, .iov_len = in_len};

return cx_blake2b_256_hash_iovec(&iovec, 1, digest);
}

/**
* @brief Computes a standalone one shot BLAKE2B_512 digest.
*
* @param[in] iovec Input data in the form of an array of cx_iovec_t.
*
* @param[in] iovec_len Length of the iovec array.
*
* @param[out] digest Buffer where to store the digest.
*
* @return Error code:
* - CX_OK on success
*/
cx_err_t cx_blake2b_512_hash_iovec(const cx_iovec_t *iovec,
size_t iovec_len,
uint8_t digest[static CX_BLAKE2B_512_SIZE]);

/**
* @brief Computes a standalone one shot BLAKE2B_512 digest.
*
* @param[in] in Input data.
*
* @param[in] len Length of the input data.
*
* @param[out] digest Buffer where to store the digest.
*
* @return Error code:
* - CX_OK on success
*/
static inline cx_err_t cx_blake2b_512_hash(const uint8_t *in,
size_t in_len,
uint8_t digest[static CX_BLAKE2B_512_SIZE])
{
const cx_iovec_t iovec = {.iov_base = in, .iov_len = in_len};

return cx_blake2b_512_hash_iovec(&iovec, 1, digest);
}

/**
* @brief Initializes BLAKE2b message digest context with
* salt and personnalization string.
Expand Down
9 changes: 9 additions & 0 deletions lib_cxng/include/lcx_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#define LCX_COMMON_H

#include <stdint.h>
#include <stddef.h>

#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define ARCH_LITTLE_ENDIAN
Expand Down Expand Up @@ -59,6 +60,14 @@ typedef struct uint64_s uint64bits_t;
typedef uint64_t uint64bits_t;
#endif

/**
* @brief Similar to libc iovec type
*/
typedef struct {
const uint8_t *iov_base;
size_t iov_len;
} cx_iovec_t;

// clang-format off
/**
* @brief Cryptography flags
Expand Down
37 changes: 37 additions & 0 deletions lib_cxng/include/lcx_ripemd160.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,43 @@ static inline int cx_ripemd160_init(cx_ripemd160_t *hash)
return CX_RIPEMD160;
}

/**
* @brief Computes a standalone one shot Ripemd-160 digest.
*
* @param[in] iovec Input data in the form of an array of cx_iovec_t.
*
* @param[in] iovec_len Length of the iovec array.
*
* @param[out] digest Buffer where to store the digest.
*
* @return Error code:
* - CX_OK on success
*/
cx_err_t cx_ripemd160_hash_iovec(const cx_iovec_t *iovec,
size_t iovec_len,
uint8_t digest[static CX_RIPEMD160_SIZE]);

/**
* @brief Computes a standalone one shot Ripemd-160 digest.
*
* @param[in] in Input data.
*
* @param[in] len Length of the input data.
*
* @param[out] digest Buffer where to store the digest.
*
* @return Error code:
* - CX_OK on success
*/
static inline cx_err_t cx_ripemd160_hash(const uint8_t *in,
size_t in_len,
uint8_t digest[static CX_RIPEMD160_SIZE])
{
const cx_iovec_t iovec = {.iov_base = in, .iov_len = in_len};

return cx_ripemd160_hash_iovec(&iovec, 1, digest);
}

/**
* @brief Computes a one shot Ripemd-160 digest.
*
Expand Down
Loading
Loading