diff --git a/deps/ledger-zxlib/app/common/app_main.c b/deps/ledger-zxlib/app/common/app_main.c index 71bc6693..e4fc80b4 100644 --- a/deps/ledger-zxlib/app/common/app_main.c +++ b/deps/ledger-zxlib/app/common/app_main.c @@ -1,43 +1,42 @@ /******************************************************************************* -* (c) 2018 - 2023 Zondax AG -* (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. -********************************************************************************/ + * (c) 2018 - 2024 Zondax AG + * (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 "app_main.h" -#include -#include #include +#include +#include #include -#include "view.h" #include "actions.h" -#include "tx.h" +#include "app_mode.h" #include "coin.h" -#include "zxmacros.h" +#include "tx.h" +#include "view.h" #include "zxcanary.h" -#include "app_mode.h" +#include "zxmacros.h" #ifdef HAVE_SWAP #include "swap.h" -#endif // HAVE_SWAP +#endif // HAVE_SWAP unsigned char G_io_seproxyhal_spi_buffer[IO_SEPROXYHAL_BUFFER_SIZE_B]; unsigned char io_event(__Z_UNUSED unsigned char channel) { switch (G_io_seproxyhal_spi_buffer[0]) { - case SEPROXYHAL_TAG_BUTTON_PUSH_EVENT: // for Nano #ifdef HAVE_BAGL UX_BUTTON_PUSH_EVENT(G_io_seproxyhal_spi_buffer); @@ -51,7 +50,7 @@ unsigned char io_event(__Z_UNUSED unsigned char channel) { THROW(EXCEPTION_IO_RESET); } - __attribute__((fallthrough)); + __attribute__((fallthrough)); case SEPROXYHAL_TAG_DISPLAY_PROCESSED_EVENT: #ifdef HAVE_BAGL UX_DISPLAYED_EVENT({}); @@ -78,7 +77,7 @@ unsigned char io_event(__Z_UNUSED unsigned char channel) { if (!io_seproxyhal_spi_is_status_sent()) { io_seproxyhal_general_status(); } - return 1; // DO NOT reset the current APDU transport + return 1; // DO NOT reset the current APDU transport } unsigned short io_exchange_al(unsigned char channel, unsigned short tx_len) { @@ -94,7 +93,7 @@ unsigned short io_exchange_al(unsigned char channel, unsigned short tx_len) { if (channel & IO_RESET_AFTER_REPLIED) { reset(); } - return 0; // nothing received from the master so far (it's a tx + 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); @@ -138,7 +137,7 @@ void app_init() { #ifdef HAVE_BLE // grab the current plane mode setting G_io_app.plane_mode = os_setting_get(OS_SETTING_PLANEMODE, NULL, 0); -#endif // HAVE_BLE +#endif // HAVE_BLE USB_power(0); USB_power(1); @@ -150,19 +149,18 @@ void app_init() { view_idle_show(0, NULL); } #else - #ifdef SUPPORT_SR25519 +#ifdef SUPPORT_SR25519 zeroize_sr25519_signdata(); - #endif +#endif view_idle_show(0, NULL); -#endif // HAVE_SWAP -#endif // POSTPONE_MAIN_SCREEN_INIT +#endif // HAVE_SWAP +#endif // POSTPONE_MAIN_SCREEN_INIT #ifdef HAVE_BLE // Enable Bluetooth BLE_power(0, NULL); BLE_power(1, NULL); -#endif // HAVE_BLE - +#endif // HAVE_BLE } void app_main() { @@ -185,8 +183,7 @@ void app_main() { flags = 0; CHECK_APP_CANARY() - if (rx == 0) - THROW(APDU_CODE_EMPTY_BUFFER); + if (rx == 0) THROW(APDU_CODE_EMPTY_BUFFER); handle_generic_apdu(&flags, &tx, rx); CHECK_APP_CANARY() @@ -194,8 +191,7 @@ void app_main() { handleApdu(&flags, &tx, rx); CHECK_APP_CANARY() } - CATCH(EXCEPTION_IO_RESET) - { + CATCH(EXCEPTION_IO_RESET) { // reset IO and UX before continuing app_init(); continue; @@ -216,8 +212,7 @@ void app_main() { tx += 2; } FINALLY; - { - } + {} } END_TRY; } diff --git a/deps/ledger-zxlib/app/common/app_main.h b/deps/ledger-zxlib/app/common/app_main.h index cfb1bd77..66fff1d2 100644 --- a/deps/ledger-zxlib/app/common/app_main.h +++ b/deps/ledger-zxlib/app/common/app_main.h @@ -1,45 +1,46 @@ /******************************************************************************* -* (c) 2016 Ledger -* (c) 2018 Zondax GmbH -* -* 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. -********************************************************************************/ + * (c) 2016 Ledger + * (c) 2018 - 2024 Zondax AG + * + * 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 "apdu_codes.h" -#define OFFSET_CLA 0 -#define OFFSET_INS 1 //< Instruction offset -#define OFFSET_P1 2 //< P1 -#define OFFSET_P2 3 //< P2 -#define OFFSET_DATA_LEN 4 //< Data Length -#define OFFSET_DATA 5 //< Data offset +#define OFFSET_CLA 0 +#define OFFSET_INS 1 //< Instruction offset +#define OFFSET_P1 2 //< P1 +#define OFFSET_P2 3 //< P2 +#define OFFSET_DATA_LEN 4 //< Data Length +#define OFFSET_DATA 5 //< Data offset -#define APDU_MIN_LENGTH 5 +#define APDU_MIN_LENGTH 5 -#define P1_INIT 0 //< P1 -#define P1_ADD 1 //< P1 -#define P1_LAST 2 //< P1 +#define P1_INIT 0 //< P1 +#define P1_ADD 1 //< P1 +#define P1_LAST 2 //< P1 -#define OFFSET_PAYLOAD_TYPE OFFSET_P1 +#define OFFSET_PAYLOAD_TYPE OFFSET_P1 -#define INS_GET_VERSION 0x00 -#define INS_GET_ADDR 0x01 -#define INS_SIGN 0x02 +#define INS_GET_VERSION 0x00 +#define INS_GET_ADDR 0x01 +#define INS_SIGN 0x02 #if defined(APP_TESTING) -#define INS_TEST 0xFF +#define INS_TEST 0xFF #endif void app_init(); diff --git a/deps/ledger-zxlib/app/ui/view.c b/deps/ledger-zxlib/app/ui/view.c index 63e5f146..dd18a9fd 100644 --- a/deps/ledger-zxlib/app/ui/view.c +++ b/deps/ledger-zxlib/app/ui/view.c @@ -1,22 +1,22 @@ /******************************************************************************* -* (c) 2018 - 2022 Zondax AG -* (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. -********************************************************************************/ + * (c) 2018 - 2022 Zondax AG + * (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 "view_internal.h" #include "actions.h" +#include "view_internal.h" #include "zxmacros.h" view_t viewdata; @@ -43,26 +43,37 @@ void view_init(void) { #endif } -void view_idle_show(uint8_t item_idx, const char *statusString) { - view_idle_show_impl(item_idx, statusString); -} +void view_idle_show(uint8_t item_idx, const char *statusString) { view_idle_show_impl(item_idx, statusString); } -void view_message_show(const char *title, const char *message) { - view_message_impl(title, message); -} +void view_message_show(const char *title, const char *message) { view_message_impl(title, message); } -void view_review_init(viewfunc_getItem_t viewfuncGetItem, - viewfunc_getNumItems_t viewfuncGetNumItems, +void view_review_init(viewfunc_getItem_t viewfuncGetItem, viewfunc_getNumItems_t viewfuncGetNumItems, viewfunc_accept_t viewfuncAccept) { viewdata.viewfuncGetItem = viewfuncGetItem; viewdata.viewfuncGetNumItems = viewfuncGetNumItems; viewdata.viewfuncAccept = viewfuncAccept; + +#if defined(TARGET_NANOS) || defined(TARGET_NANOS2) || defined(TARGET_NANOX) + viewdata.with_confirmation = false; +#endif + } -void view_initialize_init(viewfunc_initialize_t viewFuncInit) { - viewdata.viewfuncInitialize = viewFuncInit; +void view_review_init_progressive( + viewfunc_getItem_t viewfuncGetItem, + viewfunc_getNumItems_t viewfuncGetNumItems, + viewfunc_accept_t viewfuncAccept) { + + view_review_init(viewfuncGetItem, viewfuncGetNumItems, viewfuncAccept); + +#if defined(TARGET_NANOS) || defined(TARGET_NANOS2) || defined(TARGET_NANOX) + viewdata.with_confirmation = true; +#endif + } +void view_initialize_init(viewfunc_initialize_t viewFuncInit) { viewdata.viewfuncInitialize = viewFuncInit; } + void view_review_show(review_type_e reviewKind) { // Set > 0 to reply apdu message view_review_show_impl((unsigned int)reviewKind, NULL, NULL); diff --git a/deps/ledger-zxlib/app/ui/view.h b/deps/ledger-zxlib/app/ui/view.h index db7ddb7a..e9aeff65 100644 --- a/deps/ledger-zxlib/app/ui/view.h +++ b/deps/ledger-zxlib/app/ui/view.h @@ -81,6 +81,9 @@ typedef void (*viewfunc_accept_t)(); typedef zxerr_t (*viewfunc_initialize_t)(); +// Callback type for continuation confirmation +typedef void (*viewfunc_confirm_continue_t)(char *outKey, uint16_t outKeyLen, char *outVal, uint16_t outValLen); + typedef enum { REVIEW_UI = 0, REVIEW_ADDRESS, @@ -111,9 +114,16 @@ void view_error_show(); void view_custom_error_show(const char *upper, const char *lower); +void view_blindsign_error_show(); + void view_review_init(viewfunc_getItem_t viewfuncGetItem, viewfunc_getNumItems_t viewfuncGetNumItems, viewfunc_accept_t viewfuncAccept); +void view_review_init_progressive( + viewfunc_getItem_t viewfuncGetItem, + viewfunc_getNumItems_t viewfuncGetNumItems, + viewfunc_accept_t viewfuncAccept); + void view_inspect_init(viewfunc_getInnerItem_t view_funcGetInnerItem, viewfunc_getNumItems_t view_funcGetInnerNumItems, viewfunc_canInspectItem_t view_funcCanInspectItem); diff --git a/deps/ledger-zxlib/app/ui/view_inspect_s.c b/deps/ledger-zxlib/app/ui/view_inspect_s.c index d4e1e603..cd314c8e 100644 --- a/deps/ledger-zxlib/app/ui/view_inspect_s.c +++ b/deps/ledger-zxlib/app/ui/view_inspect_s.c @@ -1,26 +1,26 @@ /******************************************************************************* -* (c) 2018 - 2023 Zondax AG -* -* 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. -********************************************************************************/ + * (c) 2018 - 2023 Zondax AG + * + * 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 "bolos_target.h" #if defined(TARGET_NANOS) +#include "bagl.h" +#include "ux.h" #include "view_internal.h" #include "view_nano_inspect.h" #include "view_templates.h" -#include "ux.h" -#include "bagl.h" #include "zxmacros.h" static void h_inspect_button_left(); @@ -40,7 +40,6 @@ static const bagl_element_t view_inspect[] = { UI_LabelLine(UIID_LABEL + 2, 0, 30, UI_SCREEN_WIDTH, UI_11PX, UI_WHITE, UI_BLACK, viewdata.value2), }; - static unsigned int view_inspect_button(unsigned int button_mask, __Z_UNUSED unsigned int button_mask_counter) { switch (button_mask) { case BUTTON_EVT_RELEASED | BUTTON_LEFT | BUTTON_RIGHT: @@ -100,9 +99,8 @@ void h_inspect() { const uint8_t idxOffset = (viewdata.innerField.paging.itemIdx > 0) ? 1 : 0; // Check if we can inspect this element if (viewdata.innerField.level >= MAX_DEPTH || - !viewdata.viewfuncCanInspectItem(viewdata.innerField.level+1, - viewdata.innerField.trace, - viewdata.innerField.paging.itemIdx - idxOffset )) { + !viewdata.viewfuncCanInspectItem(viewdata.innerField.level + 1, viewdata.innerField.trace, + viewdata.innerField.paging.itemIdx - idxOffset)) { h_inspect_update_data(); view_inspect_show_impl(); return; @@ -110,7 +108,8 @@ void h_inspect() { // NanoS counts Go to root screen as an item, adjust offset viewdata.innerField.level++; - viewdata.innerField.trace[viewdata.innerField.level] = viewdata.innerField.paging.itemIdx- idxOffset; viewdata.innerField.paging.itemIdx = 1; + viewdata.innerField.trace[viewdata.innerField.level] = viewdata.innerField.paging.itemIdx - idxOffset; + viewdata.innerField.paging.itemIdx = 1; viewdata.innerField.paging.pageCount = 1; viewdata.innerField.paging.itemCount = 0xFF; @@ -143,22 +142,21 @@ void h_back() { } void inspect_init() { - #ifdef HAVE_INSPECT - h_inspect_init(); - if (!viewdata.viewfuncCanInspectItem(viewdata.innerField.level, - viewdata.innerField.trace, - viewdata.innerField.paging.itemIdx)) { - h_rootTxn(); - return; - } - // Skip first screen for NanoS - viewdata.innerField.paging.itemIdx = 1; - const zxerr_t err = h_inspect_update_data(); - if (err == zxerr_no_data) { - return; - } - view_inspect_show_impl(); - #endif +#ifdef HAVE_INSPECT + h_inspect_init(); + if (!viewdata.viewfuncCanInspectItem(viewdata.innerField.level, viewdata.innerField.trace, + viewdata.innerField.paging.itemIdx)) { + h_rootTxn(); + return; + } + // Skip first screen for NanoS + viewdata.innerField.paging.itemIdx = 1; + const zxerr_t err = h_inspect_update_data(); + if (err == zxerr_no_data) { + return; + } + view_inspect_show_impl(); +#endif } #endif diff --git a/deps/ledger-zxlib/app/ui/view_internal.h b/deps/ledger-zxlib/app/ui/view_internal.h index db808b24..eb0b9aa8 100644 --- a/deps/ledger-zxlib/app/ui/view_internal.h +++ b/deps/ledger-zxlib/app/ui/view_internal.h @@ -33,7 +33,7 @@ #include "nbgl_use_case.h" #define MAX_LINES_PER_PAGE_REVIEW NB_MAX_LINES_IN_REVIEW #define MAX_CHARS_PER_KEY_LINE 64 -#define MAX_CHARS_PER_VALUE1_LINE 120 //we experienced a crash wih 180 +#define MAX_CHARS_PER_VALUE1_LINE 120 #define MAX_CHARS_HEXMESSAGE 160 #else #ifndef MAX_CHARS_PER_VALUE_LINE @@ -47,6 +47,10 @@ // This takes data from G_io_apdu_buffer that is prefilled with the address +#if defined(APP_BLINDSIGN_MODE_ENABLED) +#define APPROVE_LABEL_1 "ACCEPT RISK" +#define APPROVE_LABEL_2 "AND APPROVE" +#endif #define APPROVE_LABEL "APPROVE" #define REJECT_LABEL "REJECT" @@ -61,11 +65,24 @@ #define REVIEW_SCREEN_ADDR_VALUE "review" #endif +#ifdef APP_BLINDSIGN_MODE_ENABLED +#define REVIEW_BLINDSIGN_MESSAGE_TITLE "Warning" +#define REVIEW_BLINDSIGN_MESSAGE_VALUE \ + "Tx details not verifiable. " \ + "Could lose all assets" +#endif + static const char *review_key = REVIEW_SCREEN_TITLE; static const char *review_txvalue = REVIEW_SCREEN_TXN_VALUE; static const char *review_addrvalue = REVIEW_SCREEN_ADDR_VALUE; static const char *review_keyconfig = "Review"; static const char *review_configvalue = "configuration"; +static const char *review_skip_key = "Warning"; +static const char *review_skip_value = "BlindSign"; +static const char *review_skip_key_msg = "Tx details"; +static const char *review_skip_value_msg = "not verifiable"; +static const char *review_skip_key_msg_2 = "Could lose"; +static const char *review_skip_value_msg_2 = "all assets"; // Review msg string can be customizable in each app #if !defined(REVIEW_MSG_TITLE) && !defined(REVIEW_MSG_VALUE) @@ -80,7 +97,9 @@ static const char *shortcut_key = SHORTCUT_TITLE; static const char *shortcut_value = SHORTCUT_VALUE; #if defined(TARGET_NANOS) -#if defined(REVIEW_SCREEN_ENABLED) && defined(SHORTCUT_MODE_ENABLED) +#if defined(APP_BLINDSIGN_MODE_ENABLED) +#define INTRO_PAGES 3 +#elif defined(REVIEW_SCREEN_ENABLED) && defined(SHORTCUT_MODE_ENABLED) #define INTRO_PAGES 2 #elif defined(REVIEW_SCREEN_ENABLED) || defined(SHORTCUT_MODE_ENABLED) #define INTRO_PAGES 1 @@ -133,6 +152,28 @@ typedef struct { uint8_t pageCount; inner_state_t innerField; +#if defined(TARGET_NANOS) || defined(TARGET_NANOS2) || defined(TARGET_NANOX) + /** + * @brief Determines whether to prompt the user for confirmation during the review process. + * + * When `with_confirmation` is set to `true`, the engine will display a confirmation prompt + * to the user after each item review. This allows the user to either continue reviewing items + * or proceed to the final approval step. + * + * If `with_confirmation` is set to `false`, the engine will skip the confirmation prompts + * forcing users to review all items until they get to the approval menu. + * + * **Applicable Targets:** + * - Ledger Nano S (TARGET_NANOS) + * - Ledger Nano S2 (TARGET_NANOS2) + * - Ledger Nano X (TARGET_NANOX) + * + * **Excluded Targets:** + * - Stax + * - Flex + */ + bool with_confirmation; +#endif } view_t; typedef enum { @@ -168,6 +209,8 @@ void view_error_show_impl(); void view_custom_error_show_impl(); +void view_blindsign_error_show_impl(); + void h_paging_init(); void h_inspect_init(); diff --git a/deps/ledger-zxlib/app/ui/view_nano.c b/deps/ledger-zxlib/app/ui/view_nano.c index 72df2b94..fb61f064 100644 --- a/deps/ledger-zxlib/app/ui/view_nano.c +++ b/deps/ledger-zxlib/app/ui/view_nano.c @@ -1,43 +1,40 @@ /******************************************************************************* -* (c) 2018 - 2022 Zondax GmbH -* -* 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. -********************************************************************************/ + * (c) 2018 - 2024 Zondax AG + * + * 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 "bolos_target.h" #if defined(TARGET_NANOS) || defined(TARGET_NANOS2) || defined(TARGET_NANOX) -#include "view_internal.h" -#include "view_nano.h" - -#include "view.h" -#include "coin.h" -#include "view_internal.h" -#include "crypto.h" +#include +#include +#include #include "actions.h" #include "apdu_codes.h" -#include "ux.h" +#include "app_mode.h" #include "bagl.h" -#include "zxmacros.h" -#include "view_templates.h" +#include "coin.h" +#include "crypto.h" #include "tx.h" -#include "app_mode.h" +#include "ux.h" +#include "view.h" +#include "view_internal.h" +#include "view_nano.h" +#include "view_templates.h" #include "zxerror.h" - -#include -#include -#include +#include "zxmacros.h" extern unsigned int review_type; @@ -46,13 +43,16 @@ uint8_t getIntroPages() { if (review_type == REVIEW_ADDRESS || !app_mode_shortcut()) { return INTRO_PAGES ? INTRO_PAGES - 1 : 0; } +#endif +#ifdef APP_BLINDSIGN_MODE_ENABLED + if (!app_mode_blindsign_required() || review_type == REVIEW_ADDRESS) { + return 0; + } #endif return INTRO_PAGES; } -bool h_paging_intro_screen() { - return viewdata.itemIdx < getIntroPages(); -} +bool h_paging_intro_screen() { return viewdata.itemIdx < getIntroPages(); } void h_initialize() { ZEMU_LOGF(50, "Initialize function\n") @@ -75,6 +75,8 @@ void view_custom_error_show(const char *upper, const char *lower) { view_custom_error_show_impl(); } +void view_blindsign_error_show() { view_blindsign_error_show_impl(); } + /////////////////////////////////// // Paging related bool h_paging_can_increase() { @@ -150,18 +152,14 @@ void h_paging_decrease() { } #ifdef INCLUDE_ACTIONS_AS_ITEMS -bool is_accept_item(){ - return viewdata.itemIdx == viewdata.itemCount - 1; -} +bool is_accept_item() { return viewdata.itemIdx == viewdata.itemCount - 1; } -void set_accept_item(){ +void set_accept_item() { viewdata.itemIdx = viewdata.itemCount - 1; viewdata.pageIdx = 0; } -bool is_reject_item(){ - return viewdata.itemIdx == viewdata.itemCount; -} +bool is_reject_item() { return viewdata.itemIdx == viewdata.itemCount; } #endif zxerr_t h_review_update_data() { @@ -179,12 +177,20 @@ zxerr_t h_review_update_data() { #ifdef INCLUDE_ACTIONS_AS_ITEMS viewdata.pageCount = 1; - if( is_accept_item() ){ + if (is_accept_item()) { snprintf(viewdata.key, MAX_CHARS_PER_KEY_LINE, "%s", ""); if (review_type == REVIEW_MSG) { snprintf(viewdata.value, MAX_CHARS_PER_VALUE1_LINE, "Ok"); } else { +#if defined(APP_BLINDSIGN_MODE_ENABLED) + if (app_mode_blindsign_required() && review_type == REVIEW_TXN) { + snprintf(viewdata.value, MAX_CHARS_PER_VALUE1_LINE, "%s %s", APPROVE_LABEL_1, APPROVE_LABEL_2); + } else { + snprintf(viewdata.value, MAX_CHARS_PER_VALUE1_LINE, "%s", APPROVE_LABEL); + } +#else snprintf(viewdata.value, MAX_CHARS_PER_VALUE1_LINE, "%s", APPROVE_LABEL); +#endif } splitValueField(); zemu_log_stack("show_accept_action - accept item"); @@ -192,7 +198,7 @@ zxerr_t h_review_update_data() { return zxerr_ok; } - if( is_reject_item() ){ + if (is_reject_item()) { snprintf(viewdata.key, MAX_CHARS_PER_KEY_LINE, "%s", ""); snprintf(viewdata.value, MAX_CHARS_PER_VALUE1_LINE, "%s", REJECT_LABEL); splitValueField(); @@ -202,45 +208,64 @@ zxerr_t h_review_update_data() { } if (h_paging_intro_screen()) { - char* intro_key = NULL; - char* intro_value = NULL; + char *intro_key = NULL; + char *intro_value = NULL; #if defined(REVIEW_SCREEN_ENABLED) switch (viewdata.itemIdx) { case 0: intro_key = PIC(review_key); switch (review_type) { - case REVIEW_MSG: - return zxerr_unknown; - - case REVIEW_UI: - intro_key = PIC(review_keyconfig); - intro_value = PIC(review_configvalue); - break; - - case REVIEW_ADDRESS: - intro_value = PIC(review_addrvalue); - break; - - case REVIEW_GENERIC: - case REVIEW_TXN: - default: - intro_value = PIC(review_txvalue); - break; + case REVIEW_MSG: + return zxerr_unknown; + + case REVIEW_UI: + intro_key = PIC(review_keyconfig); + intro_value = PIC(review_configvalue); + break; + + case REVIEW_ADDRESS: + intro_value = PIC(review_addrvalue); + break; + + case REVIEW_GENERIC: + case REVIEW_TXN: + default: + intro_value = PIC(review_txvalue); + break; } break; - #if defined(SHORTCUT_MODE_ENABLED) +#if defined(SHORTCUT_MODE_ENABLED) case 1: intro_key = PIC(shortcut_key); intro_value = PIC(shortcut_value); break; - #endif +#endif default: return zxerr_no_data; } #elif defined(SHORTCUT_MODE_ENABLED) intro_key = PIC(shortcut_key); intro_value = PIC(shortcut_value); +#elif defined(APP_BLINDSIGN_MODE_ENABLED) + if (app_mode_blindsign_required() && review_type == REVIEW_TXN) { + switch (viewdata.itemIdx) { + case 0: + intro_key = PIC(review_skip_key); + intro_value = PIC(review_skip_value); + break; + case 1: + intro_key = PIC(review_skip_key_msg); + intro_value = PIC(review_skip_value_msg); + break; + case 2: + intro_key = PIC(review_skip_key_msg_2); + intro_value = PIC(review_skip_value_msg_2); + break; + default: + break; + } + } #else return zxerr_no_data; #endif @@ -258,44 +283,32 @@ zxerr_t h_review_update_data() { viewdata.itemCount += getIntroPages(); if (viewdata.itemIdx - getIntroPages() < 0) { - return zxerr_out_of_bounds; + return zxerr_out_of_bounds; } const uint8_t realItemIdx = viewdata.itemIdx - getIntroPages(); - //Verify how many chars fit in display (nanos) - CHECK_ZXERR(viewdata.viewfuncGetItem( - realItemIdx, - viewdata.key, MAX_CHARS_PER_KEY_LINE, - viewdata.value, MAX_CHARS_PER_VALUE1_LINE, - 0, &viewdata.pageCount)) + // Verify how many chars fit in display (nanos) + CHECK_ZXERR(viewdata.viewfuncGetItem(realItemIdx, viewdata.key, MAX_CHARS_PER_KEY_LINE, viewdata.value, + MAX_CHARS_PER_VALUE1_LINE, 0, &viewdata.pageCount)) viewdata.pageCount = 1; const max_char_display dyn_max_char_per_line1 = get_max_char_per_line(); // be sure we are not out of bounds - CHECK_ZXERR(viewdata.viewfuncGetItem( - realItemIdx, - viewdata.key, MAX_CHARS_PER_KEY_LINE, - viewdata.value, dyn_max_char_per_line1, - 0, &viewdata.pageCount)) + CHECK_ZXERR(viewdata.viewfuncGetItem(realItemIdx, viewdata.key, MAX_CHARS_PER_KEY_LINE, viewdata.value, + dyn_max_char_per_line1, 0, &viewdata.pageCount)) if (viewdata.pageCount != 0 && viewdata.pageIdx > viewdata.pageCount) { // try again and get last page viewdata.pageIdx = viewdata.pageCount - 1; } - CHECK_ZXERR(viewdata.viewfuncGetItem( - realItemIdx, - viewdata.key, MAX_CHARS_PER_KEY_LINE, - viewdata.value, dyn_max_char_per_line1, - viewdata.pageIdx, &viewdata.pageCount)) + CHECK_ZXERR(viewdata.viewfuncGetItem(realItemIdx, viewdata.key, MAX_CHARS_PER_KEY_LINE, viewdata.value, + dyn_max_char_per_line1, viewdata.pageIdx, &viewdata.pageCount)) viewdata.itemCount++; if (viewdata.pageCount > 1) { uint8_t keyLen = strnlen(viewdata.key, MAX_CHARS_PER_KEY_LINE); if (keyLen < MAX_CHARS_PER_KEY_LINE) { - snprintf(viewdata.key + keyLen, - MAX_CHARS_PER_KEY_LINE - keyLen, - " [%d/%d]", - viewdata.pageIdx + 1, + snprintf(viewdata.key + keyLen, MAX_CHARS_PER_KEY_LINE - keyLen, " [%d/%d]", viewdata.pageIdx + 1, viewdata.pageCount); } } @@ -306,13 +319,12 @@ zxerr_t h_review_update_data() { } while (viewdata.pageCount == 0); splitValueAddress(); + return zxerr_ok; } /////////////////////////////////// // General -void io_seproxyhal_display(const bagl_element_t *element) { - io_seproxyhal_display_default(element); -} +void io_seproxyhal_display(const bagl_element_t *element) { io_seproxyhal_display_default(element); } #endif diff --git a/deps/ledger-zxlib/app/ui/view_nano.h b/deps/ledger-zxlib/app/ui/view_nano.h index 83ed1ac2..bfbd45d9 100644 --- a/deps/ledger-zxlib/app/ui/view_nano.h +++ b/deps/ledger-zxlib/app/ui/view_nano.h @@ -1,5 +1,5 @@ /******************************************************************************* -* (c) 2018 - 2022 Zondax GmbH +* (c) 2018 - 2024 Zondax AG * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/deps/ledger-zxlib/app/ui/view_nano_inspect.h b/deps/ledger-zxlib/app/ui/view_nano_inspect.h index 4576dce2..6e2d1c8a 100644 --- a/deps/ledger-zxlib/app/ui/view_nano_inspect.h +++ b/deps/ledger-zxlib/app/ui/view_nano_inspect.h @@ -1,20 +1,21 @@ /******************************************************************************* -* (c) 2018 - 2023 Zondax AG -* -* 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. -********************************************************************************/ + * (c) 2018 - 2023 Zondax AG + * + * 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 "view.h" bool h_can_increase(paging_t *paging, uint8_t actionsCount); diff --git a/deps/ledger-zxlib/app/ui/view_nbgl.c b/deps/ledger-zxlib/app/ui/view_nbgl.c index 2ece8c6d..2b64f363 100644 --- a/deps/ledger-zxlib/app/ui/view_nbgl.c +++ b/deps/ledger-zxlib/app/ui/view_nbgl.c @@ -24,7 +24,6 @@ #include "nbgl_use_case.h" #include "ux.h" #include "view_internal.h" -#include "menu_handler.h" #ifdef APP_SECRET_MODE_ENABLED zxerr_t secret_enabled(); @@ -38,7 +37,8 @@ zxerr_t account_enabled(); #define APPROVE_LABEL_NBGL_GENERIC "Accept operation?" #define CANCEL_LABEL "Cancel" #define VERIFY_TITLE_LABEL_GENERIC "Verify operation" - +#define INFO_LIST_SIZE 4 +#define SETTING_CONTENTS_NB 1 static const char HOME_TEXT[] = "This application enables\nsigning transactions on the\n" MENU_MAIN_APP_LINE1 " network"; @@ -55,8 +55,6 @@ static nbgl_layoutTagValue_t pairs[NB_MAX_DISPLAYED_PAIRS_IN_REVIEW]; static nbgl_layoutTagValue_t pair; static nbgl_layoutTagValueList_t pairList; -static nbgl_layoutSwitch_t settings[4]; - static nbgl_layoutTagValueList_t *extraPagesPtr = NULL; typedef enum { @@ -67,13 +65,17 @@ typedef enum { #ifdef APP_SECRET_MODE_ENABLED SECRET_MODE, #endif +#ifdef APP_BLINDSIGN_MODE_ENABLED + BLINDSIGN_MODE, +#endif + SETTINGS_SWITCHES_NB_LEN } settings_list_e; typedef enum { EXPERT_MODE_TOKEN = FIRST_USER_TOKEN, ACCOUNT_MODE_TOKEN, SECRET_MODE_TOKEN, - REVIEW_ADDRESS_TOKEN, + BLINDSIGN_MODE_TOKEN, } config_token_e; void app_quit(void) { @@ -85,19 +87,25 @@ static void h_reject_internal(void) { h_reject(review_type); } static void h_approve_internal(void) { h_approve(review_type); } -static void view_idle_show_impl_callback() { view_idle_show_impl(0, NULL); } - #ifdef TARGET_STAX #define MAX_INFO_LIST_ITEM_PER_PAGE 3 #else // TARGET_FLEX #define MAX_INFO_LIST_ITEM_PER_PAGE 2 #endif -static const char *const INFO_KEYS_PAGE[] = {"Version", "License"}; -static const char *const INFO_VALUES_PAGE[] = {APPVERSION, "Apache 2.0"}; +static const char *const INFO_KEYS_PAGE[] = {"Version", "Developed by", "Website", "License"}; +static const char *const INFO_VALUES_PAGE[] = {APPVERSION, "Zondax AG", "https://zondax.ch", "Apache 2.0"}; + +static nbgl_contentInfoList_t infoList = {0}; +static nbgl_genericContents_t settingContents = {0}; +static nbgl_contentSwitch_t switches[SETTINGS_SWITCHES_NB_LEN]; static void h_expert_toggle() { app_mode_set_expert(!app_mode_expert()); } +#ifdef APP_BLINDSIGN_MODE_ENABLED +static void h_blindsign_toggle() { app_mode_set_blindsign(!app_mode_blindsign()); } +#endif + static void confirm_error(__Z_UNUSED bool confirm) { h_error_accept(0); } static void reviewAddressChoice(bool confirm) { @@ -116,10 +124,6 @@ static void reviewTransactionChoice(bool confirm) { } } -static void h_view_address() { - handleMenuShowAddress(); -} - static void reviewGenericChoice(bool confirm) { const char *msg = "Operation rejected"; bool isSuccess = false; @@ -163,6 +167,11 @@ void view_custom_error_show(const char *upper, const char *lower) { nbgl_useCaseChoice(&C_Important_Circle_64px, viewdata.key, viewdata.value, "Ok", "", confirm_error); } +void view_blindsign_error_show() { + nbgl_useCaseChoice(&C_Warning_64px, "This message cannot\nbe clear-signed", + "Enable blind-signing in\nthe settings to sign\nthis transaction.", "Exit", "", confirm_error); +} + void view_error_show_impl() { nbgl_useCaseChoice(&C_Important_Circle_64px, viewdata.key, viewdata.value, "Ok", NULL, confirm_setting); } @@ -239,71 +248,10 @@ void h_review_update() { } } -static bool settings_screen_callback(uint8_t page, nbgl_pageContent_t *content) { - const uint16_t infoElements = sizeof(INFO_KEYS_PAGE) / sizeof(INFO_KEYS_PAGE[0]); - switch (page) { - case 0: { - // Config - content->type = SWITCHES_LIST; - content->switchesList.nbSwitches = 1; - content->switchesList.switches = settings; - - settings[0].initState = app_mode_expert(); - settings[0].text = "Expert mode"; - settings[0].tuneId = TUNE_TAP_CASUAL; - settings[0].token = EXPERT_MODE_TOKEN; - -#ifdef APP_ACCOUNT_MODE_ENABLED - if (app_mode_expert() || app_mode_account()) { - settings[ACCOUNT_MODE].initState = app_mode_account(); - settings[ACCOUNT_MODE].text = "Crowdloan account"; - settings[ACCOUNT_MODE].tuneId = TUNE_TAP_CASUAL; - settings[ACCOUNT_MODE].token = ACCOUNT_MODE_TOKEN; - content->switchesList.nbSwitches++; - } -#endif - -#ifdef APP_SECRET_MODE_ENABLED - if (app_mode_expert() || app_mode_secret()) { - settings[SECRET_MODE].initState = app_mode_secret(); - settings[SECRET_MODE].text = "Secret mode"; - settings[SECRET_MODE].tuneId = TUNE_TAP_CASUAL; - settings[SECRET_MODE].token = SECRET_MODE_TOKEN; - content->switchesList.nbSwitches++; - } -#endif - break; - } - - // Info page 1 - // We have just two elements, which fits one screen. - // It allows to keep three setting pages, while adding "Show address" - case 1: { - content->type = INFOS_LIST; - content->infosList.nbInfos = infoElements; - content->infosList.infoContents = INFO_VALUES_PAGE; - content->infosList.infoTypes = INFO_KEYS_PAGE; - break; - } - - case 2: { - content->type = INFO_BUTTON; - content->infoButton.text = "Show address"; - content->infoButton.icon = NULL; - content->infoButton.buttonText = "Review address"; - content->infoButton.buttonToken = REVIEW_ADDRESS_TOKEN; - break; - } +void settings_toggle_callback(int token, uint8_t index, int page) { + UNUSED(index); + UNUSED(page); - default: - ZEMU_LOGF(50, "Incorrect settings page: %d\n", page) - return false; - } - - return true; -} - -static void settings_toggle_callback(int token, __Z_UNUSED uint8_t index) { switch (token) { case EXPERT_MODE_TOKEN: h_expert_toggle(); @@ -321,9 +269,11 @@ static void settings_toggle_callback(int token, __Z_UNUSED uint8_t index) { break; #endif - case REVIEW_ADDRESS_TOKEN: - h_view_address(); +#ifdef APP_BLINDSIGN_MODE_ENABLED + case BLINDSIGN_MODE_TOKEN: + h_blindsign_toggle(); break; +#endif default: ZEMU_LOGF(50, "Toggling setting not found\n") @@ -331,13 +281,46 @@ static void settings_toggle_callback(int token, __Z_UNUSED uint8_t index) { } } -void setting_screen() { - // Set return button top-left (true) botton-left (false) - const bool return_button_top_left = false; - const uint8_t init_page = 0; - const uint8_t settings_pages = 3; - nbgl_useCaseSettings(MENU_MAIN_APP_LINE1, init_page, settings_pages, return_button_top_left, - view_idle_show_impl_callback, settings_screen_callback, settings_toggle_callback); +static void settings_screen_callback(uint8_t index, nbgl_content_t *content) { + UNUSED(index); + switches[EXPERT_MODE].initState = app_mode_expert(); + switches[EXPERT_MODE].text = "Expert mode"; + switches[EXPERT_MODE].subText = ""; + switches[EXPERT_MODE].tuneId = TUNE_TAP_CASUAL; + switches[EXPERT_MODE].token = EXPERT_MODE_TOKEN; + +#ifdef APP_BLINDSIGN_MODE_ENABLED + switches[BLINDSIGN_MODE].initState = app_mode_blindsign(); + switches[BLINDSIGN_MODE].text = "Blind sign"; + switches[BLINDSIGN_MODE].subText = ""; + switches[BLINDSIGN_MODE].tuneId = TUNE_TAP_CASUAL; + switches[BLINDSIGN_MODE].token = BLINDSIGN_MODE_TOKEN; +#endif + +#ifdef APP_ACCOUNT_MODE_ENABLED + if (app_mode_expert() || app_mode_account()) { + switches[ACCOUNT_MODE].initState = app_mode_account(); + switches[ACCOUNT_MODE].text = "Crowdloan account"; + switches[ACCOUNT_MODE].subText = ""; + switches[ACCOUNT_MODE].tuneId = TUNE_TAP_CASUAL; + switches[ACCOUNT_MODE].token = ACCOUNT_MODE_TOKEN; + } +#endif + +#ifdef APP_SECRET_MODE_ENABLED + if (app_mode_expert() || app_mode_secret()) { + switches[SECRET_MODE].initState = app_mode_secret(); + switches[SECRET_MODE].text = "Secret mode"; + switches[SECRET_MODE].subText = ""; + switches[SECRET_MODE].tuneId = TUNE_TAP_CASUAL; + switches[SECRET_MODE].token = SECRET_MODE_TOKEN; + } +#endif + + content->type = SWITCHES_LIST; + content->content.switchesList.nbSwitches = SETTINGS_SWITCHES_NB_LEN; + content->content.switchesList.switches = switches; + content->contentActionCallback = settings_toggle_callback; } void view_idle_show_impl(__Z_UNUSED uint8_t item_idx, const char *statusString) { @@ -353,8 +336,17 @@ void view_idle_show_impl(__Z_UNUSED uint8_t item_idx, const char *statusString) } else { snprintf(viewdata.key, MAX_CHARS_PER_KEY_LINE, "%s", statusString); } - const bool settings_icon = true; - nbgl_useCaseHome(MENU_MAIN_APP_LINE1, &C_icon_stax_64, home_text, settings_icon, setting_screen, app_quit); + + settingContents.callbackCallNeeded = true; + settingContents.nbContents = SETTING_CONTENTS_NB; + settingContents.contentGetterCallback = settings_screen_callback; + + infoList.nbInfos = INFO_LIST_SIZE; + infoList.infoContents = INFO_VALUES_PAGE; + infoList.infoTypes = INFO_KEYS_PAGE; + + nbgl_useCaseHomeAndSettings(MENU_MAIN_APP_LINE1, &C_icon_stax_64, home_text, INIT_HOME_PAGE, &settingContents, + &infoList, NULL, app_quit); } void view_message_impl(const char *title, const char *message) { @@ -448,9 +440,15 @@ static void config_useCaseReview(nbgl_operationType_t type) { pairList.pairs = NULL; // to indicate that callback should be used pairList.callback = update_item_callback; pairList.startIndex = 0; - - nbgl_useCaseReview(type, &pairList, &C_icon_stax_64, (intro_message == NULL ? "Review transaction" : intro_message), - NULL, APPROVE_LABEL_NBGL, reviewTransactionChoice); + if (app_mode_blindsign_required()) { + nbgl_useCaseReviewBlindSigning(type, &pairList, &C_icon_stax_64, + (intro_message == NULL ? "Review transaction" : intro_message), NULL, + "Accept risk and sign transaction ?", NULL, reviewTransactionChoice); + } else { + nbgl_useCaseReview(type, &pairList, &C_icon_stax_64, + (intro_message == NULL ? "Review transaction" : intro_message), NULL, APPROVE_LABEL_NBGL, + reviewTransactionChoice); + } } static void config_useCaseReviewLight(const char *title, const char *validate) { diff --git a/deps/ledger-zxlib/app/ui/view_s.c b/deps/ledger-zxlib/app/ui/view_s.c index c9f6aed7..19cf2a43 100644 --- a/deps/ledger-zxlib/app/ui/view_s.c +++ b/deps/ledger-zxlib/app/ui/view_s.c @@ -50,6 +50,9 @@ static void h_view_address(); bool is_accept_item(); void set_accept_item(); bool is_reject_item(); +bool should_show_skip_menu_right(); +bool should_show_skip_menu_left(); + #ifdef APP_SECRET_MODE_ENABLED static void h_secret_click(); @@ -65,6 +68,14 @@ static void h_shortcut_toggle(); static void h_shortcut_update(); #endif +#ifdef APP_BLINDSIGN_MODE_ENABLED +static void h_blindsign_toggle(); +static void h_blindsign_update(); +#endif + +// Keep track of whether we're in skip menu view +static bool is_in_skip_menu = false; + enum MAINMENU_SCREENS { SCREEN_HOME = 0, SCREEN_EXPERT, @@ -74,6 +85,9 @@ enum MAINMENU_SCREENS { #ifdef SHORTCUT_MODE_ENABLED SCREEN_SHORTCUT, #endif +#ifdef APP_BLINDSIGN_MODE_ENABLED + SCREEN_BLINDSIGN, +#endif }; ux_state_t ux; @@ -84,11 +98,26 @@ void os_exit(uint32_t id) { (void)id; os_sched_exit(0); } +static unsigned int view_skip_button(unsigned int button_mask, __Z_UNUSED unsigned int button_mask_counter); +const bagl_element_t *view_prepro(const bagl_element_t *element); + +// Add new view state for skip screen +static const bagl_element_t view_skip[] = { + UI_BACKGROUND_LEFT_RIGHT_ICONS, + UI_LabelLine(UIID_LABEL + 0, 0, 8, UI_SCREEN_WIDTH, UI_11PX, UI_WHITE, UI_BLACK, + "Press right to read"), + UI_LabelLine(UIID_LABEL + 1, 0, 19, UI_SCREEN_WIDTH, UI_11PX, UI_WHITE, UI_BLACK, + "Double-press to skip"), +}; const ux_menu_entry_t menu_main[] = { {NULL, NULL, 0, &C_icon_app, MENU_MAIN_APP_LINE1, viewdata.key, 33, 12}, {NULL, h_expert_toggle, 0, &C_icon_app, "Expert mode:", viewdata.value, 33, 12}, +#ifdef APP_BLINDSIGN_MODE_ENABLED + {NULL, h_blindsign_toggle, 0, &C_icon_app, "Blind sign:", viewdata.value, 33, 12}, +#endif + #ifdef APP_ACCOUNT_MODE_ENABLED {NULL, h_account_toggle, 0, &C_icon_app, "Account:", viewdata.value, 33, 12}, #endif @@ -108,7 +137,7 @@ const ux_menu_entry_t menu_main[] = { #endif 0, &C_icon_app, "License: ", "Apache 2.0", 33, 12}, - {NULL, os_exit, 0, &C_icon_dashboard, "Quit", NULL, 50, 29}, + {NULL, os_exit, 0, &C_icon_dashboard, "Quit", NULL, 50, 29}, UX_MENU_END }; @@ -127,6 +156,12 @@ const ux_menu_entry_t menu_custom_error[] = { UX_MENU_END }; +const ux_menu_entry_t blindsign_error[] = { + {NULL, NULL, 0, &C_icon_warning, "Blindsing Mode", " Required", 33, 12}, + {NULL, h_error_accept, 0, &C_icon_validate_14, "Exit", NULL, 50, 29}, + UX_MENU_END +}; + static const bagl_element_t view_message[] = { UI_BACKGROUND, UI_LabelLine(UIID_LABEL + 0, 0, 8, UI_SCREEN_WIDTH, UI_11PX, UI_WHITE, UI_BLACK, viewdata.key), @@ -170,19 +205,66 @@ static unsigned int view_message_button(unsigned int button_mask, __Z_UNUSED uns return 0; } +// Helper to check if we've completed reviewing an item +bool should_show_skip_menu_right() { + // When going forwards: we're at last page of current item + // When going backwards: we're at first page of current item + return viewdata.with_confirmation && + (review_type == REVIEW_TXN || review_type == REVIEW_MSG) && + // To enable left arrow rendering + viewdata.pageIdx > 0 && + // only if all item's pages has been rendered + viewdata.pageIdx == viewdata.pageCount - 1 && + // Not in approve screen + // Not in reject screen + !is_accept_item() && + !is_reject_item() && + // if we are not in the skip menu already + !is_in_skip_menu; +} + +// Helper to check if we should show skip menu +bool should_show_skip_menu_left() { + return viewdata.with_confirmation && + (review_type == REVIEW_TXN || review_type == REVIEW_MSG) && + viewdata.itemIdx > 0 && // Not the first item + // if all pages have been rendered + // Reached first page of current item + viewdata.pageIdx == 0 && + // Not in approve screen + // Not in reject screen + !is_accept_item() && + !is_reject_item() && + // if we are not in the skip menu already + !is_in_skip_menu; +} + static unsigned int view_review_button(unsigned int button_mask, __Z_UNUSED unsigned int button_mask_counter) { switch (button_mask) { case BUTTON_EVT_RELEASED | BUTTON_LEFT | BUTTON_RIGHT: - h_review_button_both(); + // Only handle double-click if we're in skip menu or approve/reject screens + if (is_in_skip_menu || is_accept_item() || is_reject_item()) { + h_review_button_both(); + } break; case BUTTON_EVT_RELEASED | BUTTON_LEFT: - // Press left to progress to the previous element - h_review_button_left(); + // Check if we should show skip menu before moving back + if (should_show_skip_menu_left()) { + is_in_skip_menu = true; + UX_DISPLAY(view_skip, view_prepro); + } else { + is_in_skip_menu = false; + h_review_button_left(); + } break; - case BUTTON_EVT_RELEASED | BUTTON_RIGHT: - // Press right to progress to the next element - h_review_button_right(); + if (should_show_skip_menu_right()) { + is_in_skip_menu = true; // Entering skip menu + UX_DISPLAY(view_skip, view_prepro); + } else { + is_in_skip_menu = false; + h_review_button_right(); + } break; } return 0; @@ -195,6 +277,11 @@ const bagl_element_t* idle_preprocessor(__Z_UNUSED const ux_menu_entry_t* entry, case SCREEN_EXPERT: h_expert_update(); break; +#ifdef APP_BLINDSIGN_MODE_ENABLED + case SCREEN_BLINDSIGN: + h_blindsign_update(); + break; +#endif #ifdef APP_ACCOUNT_MODE_ENABLED case SCREEN_ACCOUNT: h_account_update(); @@ -279,6 +366,16 @@ void h_review_button_right() { } static void h_review_action(unsigned int requireReply) { + if (is_in_skip_menu) { + // Force jump to approval screen + set_accept_item(); + + is_in_skip_menu = false; // Reset the flag after handling + h_review_update(); + + return; + } + if( is_accept_item() ){ zemu_log_stack("action_accept"); h_approve(1); @@ -303,7 +400,12 @@ static void h_review_action(unsigned int requireReply) { void h_review_button_both() { zemu_log_stack("h_review_button_both"); - h_review_action(review_type); + + // Handle double-click when in skip menu or approve/reject screens + if (is_in_skip_menu || is_accept_item() || is_reject_item()) { + is_in_skip_menu = false; + h_review_action(review_type); + } } ////////////////////////// @@ -349,6 +451,10 @@ void view_custom_error_show_impl() { UX_MENU_DISPLAY(0, menu_custom_error, NULL); } +void view_blindsign_error_show_impl() { + UX_MENU_DISPLAY(0, blindsign_error, NULL); +} + void h_expert_toggle() { app_mode_set_expert(!app_mode_expert()); view_idle_show(1, NULL); @@ -361,6 +467,20 @@ void h_expert_update() { } } +#ifdef APP_BLINDSIGN_MODE_ENABLED +void h_blindsign_toggle() { + app_mode_set_blindsign(!app_mode_blindsign()); + view_idle_show(SCREEN_BLINDSIGN, NULL); +} + +void h_blindsign_update() { + snprintf(viewdata.value, MAX_CHARS_PER_VALUE_LINE, "disabled"); + if (app_mode_blindsign()) { + snprintf(viewdata.value, MAX_CHARS_PER_VALUE_LINE, "enabled"); + } +} +#endif + #ifdef APP_ACCOUNT_MODE_ENABLED void h_account_toggle() { if(app_mode_expert()) { @@ -472,4 +592,25 @@ bool exceed_pixel_in_display(const uint8_t length) { const unsigned short strWidth = zx_compute_line_width_light(viewdata.value, length); return (strWidth >= (BAGL_WIDTH - BAGL_WIDTH_MARGIN)); } + +static unsigned int view_skip_button(unsigned int button_mask, __Z_UNUSED unsigned int button_mask_counter) { + switch (button_mask) { + case BUTTON_EVT_RELEASED | BUTTON_LEFT | BUTTON_RIGHT: + // Skip to approve + h_review_action(review_type); + break; + case BUTTON_EVT_RELEASED | BUTTON_RIGHT: + // Continue review + is_in_skip_menu = false; + h_review_button_right(); + break; + case BUTTON_EVT_RELEASED | BUTTON_LEFT: + // Go back + is_in_skip_menu = false; + h_review_button_left(); + break; + } + return 0; +} + #endif diff --git a/deps/ledger-zxlib/app/ui/view_x.c b/deps/ledger-zxlib/app/ui/view_x.c index 37abb12b..474f2d2c 100644 --- a/deps/ledger-zxlib/app/ui/view_x.c +++ b/deps/ledger-zxlib/app/ui/view_x.c @@ -1,45 +1,48 @@ /******************************************************************************* -* (c) 2018 - 2023 Zondax AG -* (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. -********************************************************************************/ + * (c) 2018 - 2023 Zondax AG + * (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 "bolos_target.h" #if defined(TARGET_NANOX) || defined(TARGET_NANOS2) -#include "app_mode.h" -#include "view.h" -#include "view_internal.h" #include "actions.h" #include "apdu_codes.h" -#include "glyphs.h" +#include "app_mode.h" #include "bagl.h" -#include "zxmacros.h" -#include "view_templates.h" +#include "glyphs.h" #include "tx.h" +#include "view.h" +#include "view_internal.h" #include "view_nano.h" #include "view_nano_inspect.h" +#include "view_templates.h" +#include "zxmacros.h" #include "menu_handler.h" #ifdef APP_SECRET_MODE_ENABLED #include "secret.h" #endif - -#include #include +#include + +bool custom_callback_active = false; +// Add global variable to store original callback at the top with other globals +unsigned int (*original_button_callback)(unsigned int button_mask, unsigned int button_mask_counter) = NULL; void account_enabled(); void shortcut_enabled(); @@ -49,6 +52,8 @@ static void h_expert_update(); static void h_review_loop_start(); static void h_review_loop_inside(); static void h_review_loop_end(); +static unsigned int handle_button_push(unsigned int button_mask, unsigned int button_mask_counter); +static void set_button_callback(unsigned int slot); static void h_view_address(); #ifdef APP_SECRET_MODE_ENABLED @@ -65,8 +70,13 @@ static void h_shortcut_toggle(); static void h_shortcut_update(); #endif +#ifdef APP_BLINDSIGN_MODE_ENABLED +static void h_blindsign_toggle(); +static void h_blindsign_update(); +#endif + static void h_shortcut(unsigned int); -static void run_ux_review_flow(review_type_e reviewType, const ux_flow_step_t* const start_step); +static void run_ux_review_flow(review_type_e reviewType, const ux_flow_step_t *const start_step); const ux_flow_step_t *ux_review_flow[MAX_REVIEW_UX_SCREENS]; #include "ux.h" @@ -75,109 +85,219 @@ bolos_ux_params_t G_ux_params; uint8_t flow_inside_loop; extern unsigned int review_type; - -UX_STEP_NOCB(ux_idle_flow_1_step, pbb, { &C_icon_app, MENU_MAIN_APP_LINE1, viewdata.key,}); -UX_STEP_CB_INIT(ux_idle_flow_2_step, bn, h_expert_update(), h_expert_toggle(), { "Expert mode:", viewdata.value, }); -UX_STEP_NOCB(ux_idle_flow_3_step, bn, { APPVERSION_LINE1, APPVERSION_LINE2, }); -UX_STEP_CB(ux_idle_flow_4_step, bn, h_view_address(), { "View", "address", }); - -#ifdef APP_SECRET_MODE_ENABLED -UX_STEP_CB(ux_idle_flow_5_step, bn, h_secret_click(), { "License:", "Apache 2.0", }); -#else -UX_STEP_NOCB(ux_idle_flow_5_step, bn, { "License:", "Apache 2.0", }); -#endif - -UX_STEP_CB(ux_idle_flow_6_step, pb, os_sched_exit(-1), { &C_icon_dashboard, "Quit",}); +UX_STEP_NOCB(ux_idle_flow_1_step, pbb, + { + &C_icon_app, + MENU_MAIN_APP_LINE1, + viewdata.key, + }); +UX_STEP_CB_INIT(ux_idle_flow_2_step, bn, h_expert_update(), h_expert_toggle(), + { + "Expert mode:", + viewdata.value, + }); +UX_STEP_NOCB(ux_idle_flow_3_step, bn, + { + APPVERSION_LINE1, + APPVERSION_LINE2, + }); + +UX_STEP_NOCB_INIT( + ux_review_skip_step, + nn, + { + // This will execute during initialization without requiring validation + custom_callback_active = true; + set_button_callback(stack_slot); + }, + { + "Press right to read", + "Double-press to skip" + }); + +UX_STEP_CB(ux_idle_flow_4_step, bn, h_view_address(), + { + "View", + "address", + }); + +UX_STEP_NOCB(ux_idle_flow_5_step, bn, + { + "License:", + "Apache 2.0", + }); +UX_STEP_CB(ux_idle_flow_6_step, pb, os_sched_exit(-1), + { + &C_icon_dashboard, + "Quit", + }); #ifdef APP_ACCOUNT_MODE_ENABLED -UX_STEP_CB_INIT(ux_idle_flow_7_step, bn, h_account_update(), h_account_toggle(), { "Account:", viewdata.value, }); +UX_STEP_CB_INIT(ux_idle_flow_7_step, bn, h_account_update(), h_account_toggle(), + { + "Account:", + viewdata.value, + }); #endif #ifdef SHORTCUT_MODE_ENABLED -UX_STEP_CB_INIT(ux_idle_flow_8_step, bn, h_shortcut_update(), h_shortcut_toggle(), { "Shortcut mode:", viewdata.value, }); +UX_STEP_CB_INIT(ux_idle_flow_8_step, bn, h_shortcut_update(), h_shortcut_toggle(), + { + "Shortcut mode:", + viewdata.value, + }); +#endif + +#ifdef APP_BLINDSIGN_MODE_ENABLED +UX_STEP_CB_INIT(ux_idle_flow_9_step, bn, h_blindsign_update(), h_blindsign_toggle(), + { + "Blind sign:", + viewdata.value, + }); #endif -const ux_flow_step_t *const ux_idle_flow [] = { - &ux_idle_flow_1_step, - &ux_idle_flow_2_step, +const ux_flow_step_t *const ux_idle_flow[] = { + &ux_idle_flow_1_step, &ux_idle_flow_2_step, +#ifdef APP_BLINDSIGN_MODE_ENABLED + &ux_idle_flow_9_step, +#endif #ifdef APP_ACCOUNT_MODE_ENABLED - &ux_idle_flow_7_step, + &ux_idle_flow_7_step, #endif #ifdef SHORTCUT_MODE_ENABLED - &ux_idle_flow_8_step, + &ux_idle_flow_8_step, #endif - &ux_idle_flow_3_step, - &ux_idle_flow_4_step, - &ux_idle_flow_5_step, - &ux_idle_flow_6_step, - FLOW_END_STEP, + &ux_idle_flow_3_step, &ux_idle_flow_4_step, &ux_idle_flow_5_step, &ux_idle_flow_6_step, FLOW_END_STEP, }; /////////// -UX_STEP_CB_INIT(ux_menu_init_flow_2_step, bn, NULL, h_initialize(), { "Click to", "Initialize", }); -UX_STEP_NOCB(ux_menu_init_flow_4_step, bn, { "Developed by:", "Zondax.ch", }); - -const ux_flow_step_t *const ux_menu_initialize [] = { - &ux_idle_flow_1_step, - &ux_menu_init_flow_2_step, - &ux_idle_flow_3_step, - &ux_menu_init_flow_4_step, - &ux_idle_flow_5_step, - &ux_idle_flow_6_step, - - FLOW_END_STEP, +UX_STEP_CB_INIT(ux_menu_init_flow_2_step, bn, NULL, h_initialize(), + { + "Click to", + "Initialize", + }); +UX_STEP_NOCB(ux_menu_init_flow_4_step, bn, + { + "Developed by:", + "Zondax.ch", + }); + +const ux_flow_step_t *const ux_menu_initialize[] = { + &ux_idle_flow_1_step, &ux_menu_init_flow_2_step, &ux_idle_flow_3_step, &ux_menu_init_flow_4_step, + &ux_idle_flow_5_step, &ux_idle_flow_6_step, + + FLOW_END_STEP, }; /////////// -UX_STEP_NOCB(ux_message_flow_1_step, pbb, { &C_icon_app, viewdata.key, viewdata.value,}); +UX_STEP_NOCB(ux_message_flow_1_step, pbb, + { + &C_icon_app, + viewdata.key, + viewdata.value, + }); -UX_FLOW( - ux_message_flow, - &ux_message_flow_1_step -); +UX_FLOW(ux_message_flow, &ux_message_flow_1_step); /////////// -UX_STEP_NOCB(ux_error_flow_1_step, bnnn_paging, { .title = viewdata.key, .text = viewdata.value, }); -UX_STEP_VALID(ux_error_flow_2_step, pb, h_error_accept(0), { &C_icon_validate_14, "Ok"}); +UX_STEP_NOCB(ux_error_flow_1_step, bnnn_paging, + { + .title = viewdata.key, + .text = viewdata.value, + }); +UX_STEP_VALID(ux_error_flow_2_step, pb, h_error_accept(0), {&C_icon_validate_14, "Ok"}); -UX_FLOW( - ux_error_flow, - &ux_error_flow_1_step, - &ux_error_flow_2_step -); +UX_FLOW(ux_error_flow, &ux_error_flow_1_step, &ux_error_flow_2_step); /////////// -UX_STEP_NOCB(ux_custom_error_flow_1_step, pbb, { &C_icon_warning, viewdata.key, viewdata.value,}); -UX_STEP_VALID(ux_custom_error_flow_2_step, pb, h_error_accept(0), { &C_icon_validate_14, "Ok"}); +UX_STEP_NOCB(ux_custom_error_flow_1_step, pbb, + { + &C_icon_warning, + viewdata.key, + viewdata.value, + }); +UX_STEP_VALID(ux_custom_error_flow_2_step, pb, h_error_accept(0), {&C_icon_validate_14, "Ok"}); -UX_FLOW( - ux_custom_error_flow, - &ux_custom_error_flow_1_step, - &ux_custom_error_flow_2_step -); +UX_FLOW(ux_custom_error_flow, &ux_custom_error_flow_1_step, &ux_custom_error_flow_2_step); +/////////// +UX_STEP_CB(ux_warning_blind_sign_step, pnn, h_error_accept(0), + { + &C_icon_crossmark, + "Blind signing must be", + "enabled in Settings", + }); +UX_FLOW(ux_warning_blind_sign_flow, &ux_warning_blind_sign_step); + +UX_STEP_NOCB(ux_approval_blind_signing_warning_step, pbb, + { + &C_icon_warning, + "Blind", + "Signing", + }); + +#ifdef APP_BLINDSIGN_MODE_ENABLED +UX_STEP_NOCB(ux_approval_blind_signing_message_step, bnnn_paging, + { + REVIEW_BLINDSIGN_MESSAGE_TITLE, + REVIEW_BLINDSIGN_MESSAGE_VALUE, + }); +#endif /////////// -UX_FLOW_DEF_NOCB(ux_review_flow_1_review_title, pbb, { &C_icon_app, REVIEW_SCREEN_TITLE, REVIEW_SCREEN_TXN_VALUE,}); -UX_FLOW_DEF_NOCB(ux_review_flow_2_review_title, pbb, { &C_icon_app, REVIEW_SCREEN_TITLE, REVIEW_SCREEN_ADDR_VALUE,}); -UX_FLOW_DEF_NOCB(ux_review_flow_3_review_title, pbb, { &C_icon_app, "Review", "configuration",}); -UX_FLOW_DEF_NOCB(ux_review_flow_4_review_title, pbb, { &C_icon_app, REVIEW_MSG_TITLE, REVIEW_MSG_VALUE, }); +UX_FLOW_DEF_NOCB(ux_review_flow_1_review_title, pbb, + { + &C_icon_app, + REVIEW_SCREEN_TITLE, + REVIEW_SCREEN_TXN_VALUE, + }); +UX_FLOW_DEF_NOCB(ux_review_flow_2_review_title, pbb, + { + &C_icon_app, + REVIEW_SCREEN_TITLE, + REVIEW_SCREEN_ADDR_VALUE, + }); +UX_FLOW_DEF_NOCB(ux_review_flow_3_review_title, pbb, + { + &C_icon_app, + "Review", + "configuration", + }); +UX_FLOW_DEF_NOCB(ux_review_flow_4_review_title, pbb, + { + &C_icon_app, + REVIEW_MSG_TITLE, + REVIEW_MSG_VALUE, + }); UX_STEP_INIT(ux_review_flow_2_start_step, NULL, NULL, { h_review_loop_start(); }); #ifdef HAVE_INSPECT -UX_STEP_CB_INIT(ux_review_flow_2_step, bnnn_paging, h_review_loop_inside(), inspect_init(), { .title = viewdata.key, .text = viewdata.value, }); +UX_STEP_CB_INIT(ux_review_flow_2_step, bnnn_paging, h_review_loop_inside(), inspect_init(), + { + .title = viewdata.key, + .text = viewdata.value, + }); #else -UX_STEP_NOCB_INIT(ux_review_flow_2_step, bnnn_paging, { h_review_loop_inside(); }, { .title = viewdata.key, .text = viewdata.value, }); +UX_STEP_NOCB_INIT(ux_review_flow_2_step, bnnn_paging, { h_review_loop_inside(); }, + { + .title = viewdata.key, + .text = viewdata.value, + }); #endif UX_STEP_INIT(ux_review_flow_2_end_step, NULL, NULL, { h_review_loop_end(); }); -UX_STEP_VALID(ux_review_flow_3_step, pb, h_approve(0), { &C_icon_validate_14, APPROVE_LABEL }); -UX_STEP_VALID(ux_review_flow_4_step, pb, h_reject(review_type), { &C_icon_crossmark, REJECT_LABEL }); +#if defined(APP_BLINDSIGN_MODE_ENABLED) +UX_STEP_VALID(ux_review_flow_3_step_blindsign, pnn, h_approve(0), + {&C_icon_validate_14, APPROVE_LABEL_1, APPROVE_LABEL_2}); +#endif +UX_STEP_VALID(ux_review_flow_3_step, pb, h_approve(0), {&C_icon_validate_14, APPROVE_LABEL}); + +UX_STEP_VALID(ux_review_flow_4_step, pb, h_reject(review_type), {&C_icon_crossmark, REJECT_LABEL}); UX_STEP_VALID(ux_review_flow_6_step, pb, h_approve(0), {&C_icon_validate_14, "Ok"}); -UX_STEP_CB_INIT(ux_review_flow_5_step, pb, NULL, h_shortcut(0), { &C_icon_eye, SHORTCUT_STR }); +UX_STEP_CB_INIT(ux_review_flow_5_step, pb, NULL, h_shortcut(0), {&C_icon_eye, SHORTCUT_STR}); ////////////////////////// ////////////////////////// @@ -192,7 +312,7 @@ static void h_view_address() { void h_review_update() { zxerr_t err = h_review_update_data(); - switch(err) { + switch (err) { case zxerr_ok: case zxerr_no_data: break; @@ -215,7 +335,7 @@ void h_review_loop_start() { h_paging_decrease(); } else { - // coming from left + // coming from left h_paging_init(); } @@ -224,9 +344,7 @@ void h_review_loop_start() { ux_flow_next(); } -void h_review_loop_inside() { - flow_inside_loop = 1; -} +void h_review_loop_inside() { flow_inside_loop = 1; } void h_review_loop_end() { if (flow_inside_loop) { @@ -234,10 +352,38 @@ void h_review_loop_end() { h_paging_increase(); zxerr_t err = h_review_update_data(); - switch(err) { + switch (err) { case zxerr_ok: ux_layout_bnnn_paging_reset(); + // If we're at the end of current item and there's more to show + if (viewdata.with_confirmation && + (review_type == REVIEW_TXN || review_type == REVIEW_MSG) && + viewdata.pageIdx == viewdata.pageCount - 1 && + // Ensure that at least the first item is displayed. + // The UI design may vary between applications. For example, item 0 might + // serve as a title for the transaction type rather than a regular item. + // In this implementation, we check if there is more than one item (>1). + // If so, we treat item 0 as a title and display the skip menu after it. + // This approach allows for flexible UI designs while maintaining essential functionality. + viewdata.itemIdx > 1 && + viewdata.itemIdx < viewdata.itemCount - 1) { + + // Show skip screen and enable button handler + uint8_t index = 0; + + ux_review_flow[index++] = &ux_review_skip_step; + ux_review_flow[index++] = FLOW_END_STEP; + + + unsigned int current_slot = G_ux.stack_count - 1; + ux_flow_init(current_slot, ux_review_flow, NULL); + // set the callback after flow initialization, otherwise + // it would be overwritten + set_button_callback(current_slot); + return; + } break; + case zxerr_no_data: { flow_inside_loop = 0; ux_flow_next(); @@ -248,31 +394,27 @@ void h_review_loop_end() { break; } } else { - // coming from right + // coming from right h_paging_decrease(); h_review_update(); } // move to prev flow but trick paging to show first page - CUR_FLOW.prev_index = CUR_FLOW.index-2; + CUR_FLOW.prev_index = CUR_FLOW.index - 2; CUR_FLOW.index--; ux_flow_relayout(); } void splitValueField() { uint16_t vlen = strlen(viewdata.value); - if (vlen == 0 ) { + if (vlen == 0) { snprintf(viewdata.value, MAX_CHARS_PER_VALUE1_LINE, " "); } } -void splitValueAddress() { - splitValueField(); -} +void splitValueAddress() { splitValueField(); } -max_char_display get_max_char_per_line() { - return MAX_CHARS_PER_VALUE1_LINE; -} +max_char_display get_max_char_per_line() { return MAX_CHARS_PER_VALUE1_LINE; } void h_expert_toggle() { app_mode_set_expert(!app_mode_expert()); @@ -286,9 +428,23 @@ void h_expert_update() { } } +#ifdef APP_BLINDSIGN_MODE_ENABLED +void h_blindsign_toggle() { + app_mode_set_blindsign(!app_mode_blindsign()); + ux_flow_init(0, ux_idle_flow, &ux_idle_flow_9_step); +} + +void h_blindsign_update() { + snprintf(viewdata.value, MAX_CHARS_PER_VALUE1_LINE, "disabled"); + if (app_mode_blindsign()) { + snprintf(viewdata.value, MAX_CHARS_PER_VALUE1_LINE, "enabled"); + } +} +#endif + #ifdef APP_ACCOUNT_MODE_ENABLED void h_account_toggle() { - if(app_mode_expert()) { + if (app_mode_expert()) { account_enabled(); } else { ux_flow_init(0, ux_idle_flow, &ux_idle_flow_7_step); @@ -344,9 +500,7 @@ void h_secret_click() { } #endif -static void h_shortcut(__Z_UNUSED unsigned int _) { - run_ux_review_flow(REVIEW_TXN, &ux_review_flow_3_step); -} +static void h_shortcut(__Z_UNUSED unsigned int _) { run_ux_review_flow(REVIEW_TXN, &ux_review_flow_3_step); } ////////////////////////// ////////////////////////// @@ -355,7 +509,7 @@ static void h_shortcut(__Z_UNUSED unsigned int _) { ////////////////////////// void view_idle_show_impl(__Z_UNUSED uint8_t item_idx, const char *statusString) { - if (statusString == NULL ) { + if (statusString == NULL) { snprintf(viewdata.key, MAX_CHARS_PER_KEY_LINE, "%s", MENU_MAIN_APP_LINE2); #ifdef APP_SECRET_MODE_ENABLED if (app_mode_secret()) { @@ -366,26 +520,26 @@ void view_idle_show_impl(__Z_UNUSED uint8_t item_idx, const char *statusString) snprintf(viewdata.key, MAX_CHARS_PER_KEY_LINE, "%s", statusString); } - if(G_ux.stack_count == 0) { + if (G_ux.stack_count == 0) { ux_stack_push(); } ux_flow_init(0, ux_idle_flow, NULL); } void view_initialize_show_impl(__Z_UNUSED uint8_t item_idx, const char *statusString) { - if (statusString == NULL ) { + if (statusString == NULL) { snprintf(viewdata.key, MAX_CHARS_PER_KEY_LINE, "%s", "Not Ready"); } else { snprintf(viewdata.key, MAX_CHARS_PER_KEY_LINE, "%s", statusString); } - if(G_ux.stack_count == 0) { + if (G_ux.stack_count == 0) { ux_stack_push(); } - ux_flow_init(0, ux_menu_initialize, NULL); + ux_flow_init(0, ux_menu_initialize, NULL); } -void view_review_show_impl(unsigned int requireReply, const char *title, const char *validate){ +void view_review_show_impl(unsigned int requireReply, const char *title, const char *validate) { UNUSED(title); UNUSED(validate); review_type = requireReply; @@ -393,19 +547,17 @@ void view_review_show_impl(unsigned int requireReply, const char *title, const c h_paging_decrease(); //// flow_inside_loop = 0; - if(G_ux.stack_count == 0) { + if (G_ux.stack_count == 0) { ux_stack_push(); } run_ux_review_flow((review_type_e)review_type, NULL); } -void run_root_txn_flow() { - run_ux_review_flow(review_type, &ux_review_flow_2_start_step); -} +void run_root_txn_flow() { run_ux_review_flow(review_type, &ux_review_flow_2_start_step); } // Build review UX flow and run it -void run_ux_review_flow(review_type_e reviewType, const ux_flow_step_t* const start_step) { +void run_ux_review_flow(review_type_e reviewType, const ux_flow_step_t *const start_step) { uint8_t index = 0; switch (reviewType) { @@ -424,8 +576,14 @@ void run_ux_review_flow(review_type_e reviewType, const ux_flow_step_t* const st case REVIEW_GENERIC: case REVIEW_TXN: default: +#ifdef APP_BLINDSIGN_MODE_ENABLED + if (app_mode_blindsign_required()) { + ux_review_flow[index++] = &ux_approval_blind_signing_warning_step; + ux_review_flow[index++] = &ux_approval_blind_signing_message_step; + } +#endif ux_review_flow[index++] = &ux_review_flow_1_review_title; - if(app_mode_shortcut()) { + if (app_mode_shortcut()) { ux_review_flow[index++] = &ux_review_flow_5_step; } break; @@ -434,10 +592,19 @@ void run_ux_review_flow(review_type_e reviewType, const ux_flow_step_t* const st ux_review_flow[index++] = &ux_review_flow_2_start_step; ux_review_flow[index++] = &ux_review_flow_2_step; ux_review_flow[index++] = &ux_review_flow_2_end_step; + if (reviewType == REVIEW_MSG) { ux_review_flow[index++] = &ux_review_flow_6_step; } else { +#ifdef APP_BLINDSIGN_MODE_ENABLED + if (app_mode_blindsign_required() && reviewType == REVIEW_TXN) { + ux_review_flow[index++] = &ux_review_flow_3_step_blindsign; + } else { + ux_review_flow[index++] = &ux_review_flow_3_step; + } +#else ux_review_flow[index++] = &ux_review_flow_3_step; +#endif ux_review_flow[index++] = &ux_review_flow_4_step; } ux_review_flow[index++] = FLOW_END_STEP; @@ -449,7 +616,7 @@ void view_message_impl(const char *title, const char *message) { snprintf(viewdata.key, MAX_CHARS_PER_KEY_LINE, "%s", title); snprintf(viewdata.value, MAX_CHARS_PER_VALUE1_LINE, "%s", message); ux_layout_bnnn_paging_reset(); - if(G_ux.stack_count == 0) { + if (G_ux.stack_count == 0) { ux_stack_push(); } ux_flow_init(0, ux_message_flow, NULL); @@ -457,7 +624,7 @@ void view_message_impl(const char *title, const char *message) { void view_error_show_impl() { ux_layout_bnnn_paging_reset(); - if(G_ux.stack_count == 0) { + if (G_ux.stack_count == 0) { ux_stack_push(); } ux_flow_init(0, ux_error_flow, NULL); @@ -465,9 +632,55 @@ void view_error_show_impl() { void view_custom_error_show_impl() { ux_layout_bnnn_paging_reset(); - if(G_ux.stack_count == 0) { + if (G_ux.stack_count == 0) { ux_stack_push(); } ux_flow_init(0, ux_custom_error_flow, NULL); } + +void view_blindsign_error_show_impl() { ux_flow_init(0, ux_warning_blind_sign_flow, NULL); } + +static unsigned int handle_button_push(unsigned int button_mask, unsigned int button_mask_counter) { + UNUSED(button_mask_counter); + + if (!custom_callback_active) { + if (original_button_callback != NULL) { + // Just pass through to original callback + return original_button_callback(button_mask, button_mask_counter); + } + return 0; + } + + // This is meant to handle the button interactions + // over the skip_step screen + switch (button_mask) { + // Handle skip to approve + case BUTTON_EVT_RELEASED | BUTTON_LEFT | BUTTON_RIGHT: + if (review_type == REVIEW_MSG) { + run_ux_review_flow((review_type_e)review_type, &ux_review_flow_6_step); + } else { + run_ux_review_flow((review_type_e)review_type, &ux_review_flow_3_step); + } + return 1; + + // Handle continue review + case BUTTON_EVT_RELEASED | BUTTON_RIGHT: + viewdata.itemIdx++; + run_ux_review_flow((review_type_e)review_type, &ux_review_flow_2_start_step); + return 1; + + case BUTTON_EVT_RELEASED | BUTTON_LEFT: + // h_paging_init(); + run_ux_review_flow((review_type_e)review_type, &ux_review_flow_2_start_step); + return 1; + } + return 0; +} + +static void set_button_callback(unsigned int slot) { + // Store default callback to restablish later + original_button_callback = G_ux.stack[slot].button_push_callback; + G_ux.stack[slot].button_push_callback = handle_button_push; +} + #endif diff --git a/deps/ledger-zxlib/dockerized_build.mk b/deps/ledger-zxlib/dockerized_build.mk index 244718d9..e7e32c44 100644 --- a/deps/ledger-zxlib/dockerized_build.mk +++ b/deps/ledger-zxlib/dockerized_build.mk @@ -49,7 +49,7 @@ $(info TESTS_ZEMU_DIR : $(TESTS_ZEMU_DIR)) $(info TESTS_JS_DIR : $(TESTS_JS_DIR)) $(info TESTS_JS_PACKAGE : $(TESTS_JS_PACKAGE)) -DOCKER_IMAGE_ZONDAX=zondax/ledger-app-builder:ledger-ec93499de7f17076ee90caaca5953fdb9d3daf6c +DOCKER_IMAGE_ZONDAX=zondax/ledger-app-builder:ledger-493c1c105dc3e78415c25b3a292e2577ce183615 DOCKER_IMAGE_LEDGER=ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest ifdef INTERACTIVE diff --git a/deps/ledger-zxlib/include/apdu_codes.h b/deps/ledger-zxlib/include/apdu_codes.h index 5f552651..7a1453f7 100644 --- a/deps/ledger-zxlib/include/apdu_codes.h +++ b/deps/ledger-zxlib/include/apdu_codes.h @@ -1,18 +1,18 @@ /******************************************************************************* -* (c) 2018 Zondax GmbH -* -* 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. -********************************************************************************/ + * (c) 2018 - 2024 Zondax AG + * + * 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 @@ -21,30 +21,29 @@ // Based on ISO7816 -#define APDU_CODE_OK 0x9000 -#define APDU_CODE_BUSY 0x9001 +#define APDU_CODE_OK 0x9000 +#define APDU_CODE_BUSY 0x9001 -#define APDU_CODE_EXECUTION_ERROR 0x6400 +#define APDU_CODE_EXECUTION_ERROR 0x6400 -#define APDU_CODE_WRONG_LENGTH 0x6700 +#define APDU_CODE_WRONG_LENGTH 0x6700 -#define APDU_CODE_EMPTY_BUFFER 0x6982 -#define APDU_CODE_OUTPUT_BUFFER_TOO_SMALL 0x6983 -#define APDU_CODE_DATA_INVALID 0x6984 -#define APDU_CODE_CONDITIONS_NOT_SATISFIED 0x6985 -#define APDU_CODE_COMMAND_NOT_ALLOWED 0x6986 -#define APDU_CODE_TX_NOT_INITIALIZED 0x6987 +#define APDU_CODE_EMPTY_BUFFER 0x6982 +#define APDU_CODE_OUTPUT_BUFFER_TOO_SMALL 0x6983 +#define APDU_CODE_DATA_INVALID 0x6984 +#define APDU_CODE_CONDITIONS_NOT_SATISFIED 0x6985 +#define APDU_CODE_COMMAND_NOT_ALLOWED 0x6986 +#define APDU_CODE_TX_NOT_INITIALIZED 0x6987 -#define APDU_CODE_BAD_KEY_HANDLE 0x6A80 -#define APDU_CODE_INVALIDP1P2 0x6B00 -#define APDU_CODE_INS_NOT_SUPPORTED 0x6D00 -#define APDU_CODE_CLA_NOT_SUPPORTED 0x6E00 - -#define APDU_CODE_UNKNOWN 0x6F00 -#define APDU_CODE_SIGN_VERIFY_ERROR 0x6F01 +#define APDU_CODE_BAD_KEY_HANDLE 0x6A80 +#define APDU_CODE_INVALIDP1P2 0x6B00 +#define APDU_CODE_INS_NOT_SUPPORTED 0x6D00 +#define APDU_CODE_CLA_NOT_SUPPORTED 0x6E00 +#define APDU_CODE_UNKNOWN 0x6F00 +#define APDU_CODE_SIGN_VERIFY_ERROR 0x6F01 __Z_INLINE void set_code(uint8_t *buffer, uint8_t offset, uint16_t value) { - *(buffer + offset) = (uint8_t) (value >> 8); - *(buffer + offset + 1) = (uint8_t) (value & 0xFF); + *(buffer + offset) = (uint8_t)(value >> 8); + *(buffer + offset + 1) = (uint8_t)(value & 0xFF); } diff --git a/deps/ledger-zxlib/include/app_mode.h b/deps/ledger-zxlib/include/app_mode.h index b6722ebd..144db713 100644 --- a/deps/ledger-zxlib/include/app_mode.h +++ b/deps/ledger-zxlib/include/app_mode.h @@ -1,22 +1,22 @@ /******************************************************************************* -* (c) 2016 Ledger -* (c) 2018 Zondax GmbH -* -* 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. -********************************************************************************/ + * (c) 2016 Ledger + * (c) 2018 - 2024 Zondax AG + * + * 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 "zxmacros.h" #include "stdbool.h" +#include "zxmacros.h" #ifdef __cplusplus extern "C" { @@ -40,6 +40,13 @@ bool app_mode_shortcut(); void app_mode_set_shortcut(uint8_t val); +bool app_mode_blindsign(); + +void app_mode_set_blindsign(uint8_t val); + +bool app_mode_blindsign_required(); + +void app_mode_skip_blindsign_ui(); #ifdef __cplusplus } #endif diff --git a/deps/ledger-zxlib/include/base64.h b/deps/ledger-zxlib/include/base64.h index 99bc7c0a..e805765c 100644 --- a/deps/ledger-zxlib/include/base64.h +++ b/deps/ledger-zxlib/include/base64.h @@ -1,5 +1,5 @@ /******************************************************************************* -* (c) 2020 Zondax GmbH +* (c) 2018 - 2024 Zondax AG * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/deps/ledger-zxlib/include/bech32.h b/deps/ledger-zxlib/include/bech32.h index a1c42245..f4d77c09 100644 --- a/deps/ledger-zxlib/include/bech32.h +++ b/deps/ledger-zxlib/include/bech32.h @@ -1,5 +1,5 @@ /******************************************************************************* -* (c) 2019 Zondax GmbH +* (c) 2018 - 2024 Zondax AG * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/deps/ledger-zxlib/include/bignum.h b/deps/ledger-zxlib/include/bignum.h index 9bf31f8f..4bca3385 100644 --- a/deps/ledger-zxlib/include/bignum.h +++ b/deps/ledger-zxlib/include/bignum.h @@ -1,5 +1,5 @@ /******************************************************************************* -* (c) 2019 Zondax GmbH +* (c) 2018 - 2024 Zondax AG * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/deps/ledger-zxlib/include/bittools.h b/deps/ledger-zxlib/include/bittools.h index 1903878d..ae501e03 100644 --- a/deps/ledger-zxlib/include/bittools.h +++ b/deps/ledger-zxlib/include/bittools.h @@ -25,12 +25,7 @@ extern "C" { #endif -int convert_bits(uint8_t *out, - size_t *outlen, - int outBits, - const uint8_t *in, - size_t inLen, - int inBits, int pad); +int convert_bits(uint8_t *out, size_t *outlen, int outBits, const uint8_t *in, size_t inLen, int inBits, int pad); #ifdef __cplusplus } diff --git a/deps/ledger-zxlib/include/buffering.h b/deps/ledger-zxlib/include/buffering.h index 121ba278..6e73539f 100644 --- a/deps/ledger-zxlib/include/buffering.h +++ b/deps/ledger-zxlib/include/buffering.h @@ -1,19 +1,19 @@ /******************************************************************************* -* (c) 2016 Ledger -* (c) 2018 Zondax GmbH -* -* 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. -********************************************************************************/ + * (c) 2016 Ledger + * (c) 2018 - 2024 Zondax AG + * + * 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 @@ -28,7 +28,7 @@ typedef struct { uint8_t *data; size_t size; size_t pos; - uint8_t in_use: 1; + uint8_t in_use : 1; } buffer_state_t; /// Initialize buffer @@ -36,10 +36,7 @@ typedef struct { /// \param ram_buffer_size /// \param flash_buffer /// \param flash_buffer_size -void buffering_init(uint8_t *ram_buffer, - size_t ram_buffer_size, - uint8_t *flash_buffer, - size_t flash_buffer_size); +void buffering_init(uint8_t *ram_buffer, size_t ram_buffer_size, uint8_t *flash_buffer, size_t flash_buffer_size); /// Reset buffer void buffering_reset(); diff --git a/deps/ledger-zxlib/include/hexutils.h b/deps/ledger-zxlib/include/hexutils.h index 3cbaad8e..22d60302 100644 --- a/deps/ledger-zxlib/include/hexutils.h +++ b/deps/ledger-zxlib/include/hexutils.h @@ -1,23 +1,23 @@ /******************************************************************************* -* (c) 2018 Zondax GmbH -* -* 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. -********************************************************************************/ + * (c) 2018 - 2024 Zondax AG + * + * 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 #ifdef __cplusplus extern "C" { diff --git a/deps/ledger-zxlib/include/segwit_addr.h b/deps/ledger-zxlib/include/segwit_addr.h index 1683b625..92ce073c 100644 --- a/deps/ledger-zxlib/include/segwit_addr.h +++ b/deps/ledger-zxlib/include/segwit_addr.h @@ -22,8 +22,8 @@ #ifndef _SEGWIT_ADDR_H_ #define _SEGWIT_ADDR_H_ 1 -#include #include +#include /** Encode a SegWit address * @@ -36,13 +36,7 @@ * prog_len: Number of data bytes in prog. * Returns 1 if successful. */ -int segwit_addr_encode( - char *output, - const char *hrp, - int ver, - const uint8_t *prog, - size_t prog_len -); +int segwit_addr_encode(char *output, const char *hrp, int ver, const uint8_t *prog, size_t prog_len); /** Decode a SegWit address * @@ -57,23 +51,13 @@ int segwit_addr_encode( * addr: Pointer to the null-terminated address. * Returns 1 if successful. */ -int segwit_addr_decode( - int *ver, - uint8_t *prog, - size_t *prog_len, - const char *hrp, - const char *addr -); +int segwit_addr_decode(int *ver, uint8_t *prog, size_t *prog_len, const char *hrp, const char *addr); /** Supported encodings. */ -typedef enum { - BECH32_ENCODING_NONE, - BECH32_ENCODING_BECH32, - BECH32_ENCODING_BECH32M -} bech32_encoding; +typedef enum { BECH32_ENCODING_NONE, BECH32_ENCODING_BECH32, BECH32_ENCODING_BECH32M } bech32_encoding; -#define BECH32M_CONST 0x2bc830a3 -#define BECH32_CONST 1 +#define BECH32M_CONST 0x2bc830a3 +#define BECH32_CONST 1 /** Encode a Bech32 or Bech32m string * @@ -86,13 +70,7 @@ typedef enum { * Returns 1 if successful. */ -int bech32_encode( - char *output, - const char *hrp, - const uint8_t *data, - size_t data_len, - bech32_encoding enc -); +int bech32_encode(char *output, const char *hrp, const uint8_t *data, size_t data_len, bech32_encoding enc); /** Decode a Bech32 or Bech32m string * @@ -107,11 +85,6 @@ int bech32_encode( * with the specified encoding standard. BECH32_ENCODING_NONE is returned if * decoding failed. */ -bech32_encoding bech32_decode( - char *hrp, - uint8_t *data, - size_t *data_len, - const char *input -); +bech32_encoding bech32_decode(char *hrp, uint8_t *data, size_t *data_len, const char *input); #endif diff --git a/deps/ledger-zxlib/include/sigutils.h b/deps/ledger-zxlib/include/sigutils.h index 76346c8b..49862d09 100644 --- a/deps/ledger-zxlib/include/sigutils.h +++ b/deps/ledger-zxlib/include/sigutils.h @@ -1,18 +1,18 @@ /******************************************************************************* -* (c) 2020 Zondax GmbH -* -* 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. -********************************************************************************/ + * (c) 2018 - 2024 Zondax AG + * + * 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 @@ -30,10 +30,7 @@ typedef enum { invalid_sLen, } err_convert_e; -err_convert_e convertDERtoRSV(const uint8_t *inSignatureDER, - unsigned int inInfo, - uint8_t *outR, - uint8_t *outS, +err_convert_e convertDERtoRSV(const uint8_t *inSignatureDER, unsigned int inInfo, uint8_t *outR, uint8_t *outS, uint8_t *outV); #ifdef __cplusplus diff --git a/deps/ledger-zxlib/include/timeutils.h b/deps/ledger-zxlib/include/timeutils.h index 8d5d617b..e2371fa5 100644 --- a/deps/ledger-zxlib/include/timeutils.h +++ b/deps/ledger-zxlib/include/timeutils.h @@ -1,28 +1,29 @@ /******************************************************************************* -* (c) 2018 Zondax GmbH -* -* 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. -********************************************************************************/ + * (c) 2018 - 2024 Zondax AG + * + * 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 __cplusplus extern "C" { #endif -#include #include -#include "zxmacros.h" +#include + #include "zxerror.h" +#include "zxmacros.h" __Z_INLINE const char *getMonth(uint8_t tm_mon) { switch (tm_mon) { diff --git a/deps/ledger-zxlib/include/utf8.h b/deps/ledger-zxlib/include/utf8.h index fc7eecd7..7c4ab677 100644 --- a/deps/ledger-zxlib/include/utf8.h +++ b/deps/ledger-zxlib/include/utf8.h @@ -104,30 +104,24 @@ typedef char utf8_int8_t; /* Return less than 0, 0, greater than 0 if src1 < src2, src1 == src2, src1 > * src2 respectively, case insensitive. */ -utf8_constexpr14 utf8_nonnull utf8_pure int -utf8casecmp(const utf8_int8_t *src1, const utf8_int8_t *src2); +utf8_constexpr14 utf8_nonnull utf8_pure int utf8casecmp(const utf8_int8_t *src1, const utf8_int8_t *src2); /* Append the utf8 string src onto the utf8 string dst. */ -utf8_nonnull utf8_weak utf8_int8_t * -utf8cat(utf8_int8_t *utf8_restrict dst, const utf8_int8_t *utf8_restrict src); +utf8_nonnull utf8_weak utf8_int8_t *utf8cat(utf8_int8_t *utf8_restrict dst, const utf8_int8_t *utf8_restrict src); /* Find the first match of the utf8 codepoint chr in the utf8 string src. */ -utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t * -utf8chr(const utf8_int8_t *src, utf8_int32_t chr); +utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t *utf8chr(const utf8_int8_t *src, utf8_int32_t chr); /* Return less than 0, 0, greater than 0 if src1 < src2, * src1 == src2, src1 > src2 respectively. */ -utf8_constexpr14 utf8_nonnull utf8_pure int utf8cmp(const utf8_int8_t *src1, - const utf8_int8_t *src2); +utf8_constexpr14 utf8_nonnull utf8_pure int utf8cmp(const utf8_int8_t *src1, const utf8_int8_t *src2); /* Copy the utf8 string src onto the memory allocated in dst. */ -utf8_nonnull utf8_weak utf8_int8_t * - utf8cpy(utf8_int8_t *utf8_restrict dst, const utf8_int8_t *utf8_restrict src); +utf8_nonnull utf8_weak utf8_int8_t *utf8cpy(utf8_int8_t *utf8_restrict dst, const utf8_int8_t *utf8_restrict src); /* Number of utf8 codepoints in the utf8 string src that consists entirely * of utf8 codepoints not from the utf8 string reject. */ -utf8_constexpr14 utf8_nonnull utf8_pure size_t -utf8cspn(const utf8_int8_t *src, const utf8_int8_t *reject); +utf8_constexpr14 utf8_nonnull utf8_pure size_t utf8cspn(const utf8_int8_t *src, const utf8_int8_t *reject); /* Duplicate the utf8 string src by getting its size, malloc'ing a new buffer * copying over the data, and returning that. Or 0 if malloc failed. */ @@ -138,27 +132,23 @@ utf8_weak utf8_int8_t *utf8dup(const utf8_int8_t *src); utf8_constexpr14 utf8_nonnull utf8_pure size_t utf8len(const utf8_int8_t *str); /* Similar to utf8len, except that only at most n bytes of src are looked. */ -utf8_constexpr14 utf8_nonnull utf8_pure size_t utf8nlen(const utf8_int8_t *str, - size_t n); +utf8_constexpr14 utf8_nonnull utf8_pure size_t utf8nlen(const utf8_int8_t *str, size_t n); /* Return less than 0, 0, greater than 0 if src1 < src2, src1 == src2, src1 > * src2 respectively, case insensitive. Checking at most n bytes of each utf8 * string. */ -utf8_constexpr14 utf8_nonnull utf8_pure int -utf8ncasecmp(const utf8_int8_t *src1, const utf8_int8_t *src2, size_t n); +utf8_constexpr14 utf8_nonnull utf8_pure int utf8ncasecmp(const utf8_int8_t *src1, const utf8_int8_t *src2, size_t n); /* Append the utf8 string src onto the utf8 string dst, * writing at most n+1 bytes. Can produce an invalid utf8 * string if n falls partway through a utf8 codepoint. */ -utf8_nonnull utf8_weak utf8_int8_t * - utf8ncat(utf8_int8_t *utf8_restrict dst, const utf8_int8_t *utf8_restrict src, -size_t n); +utf8_nonnull utf8_weak utf8_int8_t *utf8ncat(utf8_int8_t *utf8_restrict dst, const utf8_int8_t *utf8_restrict src, + size_t n); /* Return less than 0, 0, greater than 0 if src1 < src2, * src1 == src2, src1 > src2 respectively. Checking at most n * bytes of each utf8 string. */ -utf8_constexpr14 utf8_nonnull utf8_pure int -utf8ncmp(const utf8_int8_t *src1, const utf8_int8_t *src2, size_t n); +utf8_constexpr14 utf8_nonnull utf8_pure int utf8ncmp(const utf8_int8_t *src1, const utf8_int8_t *src2, size_t n); /* Copy the utf8 string src onto the memory allocated in dst. * Copies at most n bytes. If n falls partway through a utf8 @@ -166,9 +156,8 @@ utf8ncmp(const utf8_int8_t *src1, const utf8_int8_t *src2, size_t n); * terminator, the final string will be cut short to preserve * utf8 validity. */ -utf8_nonnull utf8_weak utf8_int8_t * - utf8ncpy(utf8_int8_t *utf8_restrict dst, const utf8_int8_t *utf8_restrict src, -size_t n); +utf8_nonnull utf8_weak utf8_int8_t *utf8ncpy(utf8_int8_t *utf8_restrict dst, const utf8_int8_t *utf8_restrict src, + size_t n); /* Similar to utf8dup, except that at most n bytes of src are copied. If src is * longer than n, only n bytes are copied and a null byte is added. @@ -178,63 +167,52 @@ utf8_weak utf8_int8_t *utf8ndup(const utf8_int8_t *src, size_t n); /* Locates the first occurrence in the utf8 string str of any byte in the * utf8 string accept, or 0 if no match was found. */ -utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t * -utf8pbrk(const utf8_int8_t *str, const utf8_int8_t *accept); +utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t *utf8pbrk(const utf8_int8_t *str, const utf8_int8_t *accept); /* Find the last match of the utf8 codepoint chr in the utf8 string src. */ -utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t * -utf8rchr(const utf8_int8_t *src, int chr); +utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t *utf8rchr(const utf8_int8_t *src, int chr); /* Number of bytes in the utf8 string str, * including the null terminating byte. */ utf8_constexpr14 utf8_nonnull utf8_pure size_t utf8size(const utf8_int8_t *str); /* Similar to utf8size, except that the null terminating byte is excluded. */ -utf8_constexpr14 utf8_nonnull utf8_pure size_t -utf8size_lazy(const utf8_int8_t *str); +utf8_constexpr14 utf8_nonnull utf8_pure size_t utf8size_lazy(const utf8_int8_t *str); /* Similar to utf8size, except that only at most n bytes of src are looked and * the null terminating byte is excluded. */ -utf8_constexpr14 utf8_nonnull utf8_pure size_t -utf8nsize_lazy(const utf8_int8_t *str, size_t n); +utf8_constexpr14 utf8_nonnull utf8_pure size_t utf8nsize_lazy(const utf8_int8_t *str, size_t n); /* Number of utf8 codepoints in the utf8 string src that consists entirely * of utf8 codepoints from the utf8 string accept. */ -utf8_constexpr14 utf8_nonnull utf8_pure size_t -utf8spn(const utf8_int8_t *src, const utf8_int8_t *accept); +utf8_constexpr14 utf8_nonnull utf8_pure size_t utf8spn(const utf8_int8_t *src, const utf8_int8_t *accept); /* The position of the utf8 string needle in the utf8 string haystack. */ -utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t * -utf8str(const utf8_int8_t *haystack, const utf8_int8_t *needle); +utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t *utf8str(const utf8_int8_t *haystack, const utf8_int8_t *needle); /* The position of the utf8 string needle in the utf8 string haystack, case * insensitive. */ -utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t * -utf8casestr(const utf8_int8_t *haystack, const utf8_int8_t *needle); +utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t *utf8casestr(const utf8_int8_t *haystack, + const utf8_int8_t *needle); /* Return 0 on success, or the position of the invalid * utf8 codepoint on failure. */ -utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t * -utf8valid(const utf8_int8_t *str); +utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t *utf8valid(const utf8_int8_t *str); /* Similar to utf8valid, except that only at most n bytes of src are looked. */ -utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t * -utf8nvalid(const utf8_int8_t *str, size_t n); +utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t *utf8nvalid(const utf8_int8_t *str, size_t n); /* Given a null-terminated string, makes the string valid by replacing invalid * codepoints with a 1-byte replacement. Returns 0 on success. */ -utf8_nonnull utf8_weak int utf8makevalid(utf8_int8_t *str, -const utf8_int32_t replacement); +utf8_nonnull utf8_weak int utf8makevalid(utf8_int8_t *str, const utf8_int32_t replacement); /* Sets out_codepoint to the current utf8 codepoint in str, and returns the * address of the next utf8 codepoint after the current one in str. */ -utf8_constexpr14 utf8_nonnull utf8_int8_t * -utf8codepoint(const utf8_int8_t *utf8_restrict str, - utf8_int32_t *utf8_restrict out_codepoint); +utf8_constexpr14 utf8_nonnull utf8_int8_t *utf8codepoint(const utf8_int8_t *utf8_restrict str, + utf8_int32_t *utf8_restrict out_codepoint); /* Calculates the size of the next utf8 codepoint in str. */ -utf8_constexpr14 utf8_nonnull size_t -utf8codepointcalcsize(const utf8_int8_t *str); +utf8_constexpr14 utf8_nonnull size_t utf8codepointcalcsize(const utf8_int8_t *str); /* Returns the size of the given codepoint in bytes. */ utf8_constexpr14 size_t utf8codepointsize(utf8_int32_t chr); @@ -243,8 +221,7 @@ utf8_constexpr14 size_t utf8codepointsize(utf8_int32_t chr); * place after the written codepoint. Pass how many bytes left in the buffer to * n. If there is not enough space for the codepoint, this function returns * null. */ -utf8_nonnull utf8_weak utf8_int8_t * - utf8catcodepoint(utf8_int8_t *str, utf8_int32_t chr, size_t n); +utf8_nonnull utf8_weak utf8_int8_t *utf8catcodepoint(utf8_int8_t *str, utf8_int32_t chr, size_t n); /* Returns 1 if the given character is lowercase, or 0 if it is not. */ utf8_constexpr14 int utf8islower(utf8_int32_t chr); @@ -266,35 +243,28 @@ utf8_constexpr14 utf8_int32_t utf8uprcodepoint(utf8_int32_t cp); /* Sets out_codepoint to the current utf8 codepoint in str, and returns the * address of the previous utf8 codepoint before the current one in str. */ -utf8_constexpr14 utf8_nonnull utf8_int8_t * -utf8rcodepoint(const utf8_int8_t *utf8_restrict str, - utf8_int32_t *utf8_restrict out_codepoint); +utf8_constexpr14 utf8_nonnull utf8_int8_t *utf8rcodepoint(const utf8_int8_t *utf8_restrict str, + utf8_int32_t *utf8_restrict out_codepoint); /* Duplicate the utf8 string src by getting its size, calling alloc_func_ptr to * copy over data to a new buffer, and returning that. Or 0 if alloc_func_ptr * returned null. */ -utf8_weak utf8_int8_t *utf8dup_ex(const utf8_int8_t *src, - utf8_int8_t *(*alloc_func_ptr)(utf8_int8_t *, - size_t), - utf8_int8_t *user_data); +utf8_weak utf8_int8_t *utf8dup_ex(const utf8_int8_t *src, utf8_int8_t *(*alloc_func_ptr)(utf8_int8_t *, size_t), + utf8_int8_t *user_data); /* Similar to utf8dup, except that at most n bytes of src are copied. If src is * longer than n, only n bytes are copied and a null byte is added. * * Returns a new string if successful, 0 otherwise. */ utf8_weak utf8_int8_t *utf8ndup_ex(const utf8_int8_t *src, size_t n, - utf8_int8_t *(*alloc_func_ptr)(utf8_int8_t *, - size_t), - utf8_int8_t *user_data); + utf8_int8_t *(*alloc_func_ptr)(utf8_int8_t *, size_t), utf8_int8_t *user_data); #undef utf8_weak #undef utf8_pure #undef utf8_nonnull -utf8_constexpr14_impl int utf8casecmp(const utf8_int8_t *src1, - const utf8_int8_t *src2) { - utf8_int32_t src1_lwr_cp = 0, src2_lwr_cp = 0, src1_upr_cp = 0, - src2_upr_cp = 0, src1_orig_cp = 0, src2_orig_cp = 0; +utf8_constexpr14_impl int utf8casecmp(const utf8_int8_t *src1, const utf8_int8_t *src2) { + utf8_int32_t src1_lwr_cp = 0, src2_lwr_cp = 0, src1_upr_cp = 0, src2_upr_cp = 0, src1_orig_cp = 0, src2_orig_cp = 0; for (;;) { src1 = utf8codepoint(src1, &src1_orig_cp); @@ -321,27 +291,25 @@ utf8_constexpr14_impl int utf8casecmp(const utf8_int8_t *src1, } } -utf8_int8_t *utf8cat(utf8_int8_t *utf8_restrict dst, -const utf8_int8_t *utf8_restrict src) { -utf8_int8_t *d = dst; -/* find the null terminating byte in dst */ -while ('\0' != *d) { -d++; -} +utf8_int8_t *utf8cat(utf8_int8_t *utf8_restrict dst, const utf8_int8_t *utf8_restrict src) { + utf8_int8_t *d = dst; + /* find the null terminating byte in dst */ + while ('\0' != *d) { + d++; + } -/* overwriting the null terminating byte in dst, append src byte-by-byte */ -while ('\0' != *src) { -*d++ = *src++; -} + /* overwriting the null terminating byte in dst, append src byte-by-byte */ + while ('\0' != *src) { + *d++ = *src++; + } -/* write out a new null terminating byte into dst */ -*d = '\0'; + /* write out a new null terminating byte into dst */ + *d = '\0'; -return dst; + return dst; } -utf8_constexpr14_impl utf8_int8_t *utf8chr(const utf8_int8_t *src, - utf8_int32_t chr) { +utf8_constexpr14_impl utf8_int8_t *utf8chr(const utf8_int8_t *src, utf8_int32_t chr) { utf8_int8_t c[5] = {'\0', '\0', '\0', '\0', '\0'}; if (0 == chr) { @@ -381,8 +349,7 @@ utf8_constexpr14_impl utf8_int8_t *utf8chr(const utf8_int8_t *src, return utf8str(src, c); } -utf8_constexpr14_impl int utf8cmp(const utf8_int8_t *src1, - const utf8_int8_t *src2) { +utf8_constexpr14_impl int utf8cmp(const utf8_int8_t *src1, const utf8_int8_t *src2) { while (('\0' != *src1) || ('\0' != *src2)) { if (*src1 < *src2) { return -1; @@ -398,27 +365,24 @@ utf8_constexpr14_impl int utf8cmp(const utf8_int8_t *src1, return 0; } -utf8_constexpr14_impl int utf8coll(const utf8_int8_t *src1, - const utf8_int8_t *src2); +utf8_constexpr14_impl int utf8coll(const utf8_int8_t *src1, const utf8_int8_t *src2); -utf8_int8_t *utf8cpy(utf8_int8_t *utf8_restrict dst, -const utf8_int8_t *utf8_restrict src) { -utf8_int8_t *d = dst; +utf8_int8_t *utf8cpy(utf8_int8_t *utf8_restrict dst, const utf8_int8_t *utf8_restrict src) { + utf8_int8_t *d = dst; -/* overwriting anything previously in dst, write byte-by-byte - * from src */ -while ('\0' != *src) { -*d++ = *src++; -} + /* overwriting anything previously in dst, write byte-by-byte + * from src */ + while ('\0' != *src) { + *d++ = *src++; + } -/* append null terminating byte */ -*d = '\0'; + /* append null terminating byte */ + *d = '\0'; -return dst; + return dst; } -utf8_constexpr14_impl size_t utf8cspn(const utf8_int8_t *src, - const utf8_int8_t *reject) { +utf8_constexpr14_impl size_t utf8cspn(const utf8_int8_t *src, const utf8_int8_t *reject) { size_t chars = 0; while ('\0' != *src) { @@ -468,48 +432,43 @@ utf8_constexpr14_impl size_t utf8cspn(const utf8_int8_t *src, return chars; } -utf8_int8_t *utf8dup(const utf8_int8_t *src) { - return utf8dup_ex(src, utf8_null, utf8_null); -} +utf8_int8_t *utf8dup(const utf8_int8_t *src) { return utf8dup_ex(src, utf8_null, utf8_null); } -utf8_int8_t *utf8dup_ex(const utf8_int8_t *src, - utf8_int8_t *(*alloc_func_ptr)(utf8_int8_t *, size_t), - utf8_int8_t *user_data) { -utf8_int8_t *n = utf8_null; +utf8_int8_t *utf8dup_ex(const utf8_int8_t *src, utf8_int8_t *(*alloc_func_ptr)(utf8_int8_t *, size_t), + utf8_int8_t *user_data) { + utf8_int8_t *n = utf8_null; -/* figure out how many bytes (including the terminator) we need to copy first - */ -size_t bytes = utf8size(src); + /* figure out how many bytes (including the terminator) we need to copy first + */ + size_t bytes = utf8size(src); -if (alloc_func_ptr) { -n = alloc_func_ptr(user_data, bytes); -} else { -n = (utf8_int8_t *)malloc(bytes); -} + if (alloc_func_ptr) { + n = alloc_func_ptr(user_data, bytes); + } else { + n = (utf8_int8_t *)malloc(bytes); + } -if (utf8_null == n) { -/* out of memory so we bail */ -return utf8_null; -} else { -bytes = 0; + if (utf8_null == n) { + /* out of memory so we bail */ + return utf8_null; + } else { + bytes = 0; -/* copy src byte-by-byte into our new utf8 string */ -while ('\0' != src[bytes]) { -n[bytes] = src[bytes]; -bytes++; -} + /* copy src byte-by-byte into our new utf8 string */ + while ('\0' != src[bytes]) { + n[bytes] = src[bytes]; + bytes++; + } -/* append null terminating byte */ -n[bytes] = '\0'; -return n; -} + /* append null terminating byte */ + n[bytes] = '\0'; + return n; + } } utf8_constexpr14_impl utf8_int8_t *utf8fry(const utf8_int8_t *str); -utf8_constexpr14_impl size_t utf8len(const utf8_int8_t *str) { - return utf8nlen(str, SIZE_MAX); -} +utf8_constexpr14_impl size_t utf8len(const utf8_int8_t *str) { return utf8nlen(str, SIZE_MAX); } utf8_constexpr14_impl size_t utf8nlen(const utf8_int8_t *str, size_t n) { const utf8_int8_t *t = str; @@ -541,10 +500,8 @@ utf8_constexpr14_impl size_t utf8nlen(const utf8_int8_t *str, size_t n) { return length; } -utf8_constexpr14_impl int utf8ncasecmp(const utf8_int8_t *src1, - const utf8_int8_t *src2, size_t n) { - utf8_int32_t src1_lwr_cp = 0, src2_lwr_cp = 0, src1_upr_cp = 0, - src2_upr_cp = 0, src1_orig_cp = 0, src2_orig_cp = 0; +utf8_constexpr14_impl int utf8ncasecmp(const utf8_int8_t *src1, const utf8_int8_t *src2, size_t n) { + utf8_int32_t src1_lwr_cp = 0, src2_lwr_cp = 0, src1_upr_cp = 0, src2_upr_cp = 0, src1_orig_cp = 0, src2_orig_cp = 0; do { const utf8_int8_t *const s1 = src1; @@ -615,29 +572,27 @@ utf8_constexpr14_impl int utf8ncasecmp(const utf8_int8_t *src1, return 0; } -utf8_int8_t *utf8ncat(utf8_int8_t *utf8_restrict dst, -const utf8_int8_t *utf8_restrict src, size_t n) { -utf8_int8_t *d = dst; +utf8_int8_t *utf8ncat(utf8_int8_t *utf8_restrict dst, const utf8_int8_t *utf8_restrict src, size_t n) { + utf8_int8_t *d = dst; -/* find the null terminating byte in dst */ -while ('\0' != *d) { -d++; -} + /* find the null terminating byte in dst */ + while ('\0' != *d) { + d++; + } -/* overwriting the null terminating byte in dst, append src byte-by-byte - * stopping if we run out of space */ -do { -*d++ = *src++; -} while (('\0' != *src) && (0 != --n)); + /* overwriting the null terminating byte in dst, append src byte-by-byte + * stopping if we run out of space */ + do { + *d++ = *src++; + } while (('\0' != *src) && (0 != --n)); -/* write out a new null terminating byte into dst */ -*d = '\0'; + /* write out a new null terminating byte into dst */ + *d = '\0'; -return dst; + return dst; } -utf8_constexpr14_impl int utf8ncmp(const utf8_int8_t *src1, - const utf8_int8_t *src2, size_t n) { +utf8_constexpr14_impl int utf8ncmp(const utf8_int8_t *src1, const utf8_int8_t *src2, size_t n) { while ((0 != n--) && (('\0' != *src1) || ('\0' != *src2))) { if (*src1 < *src2) { return -1; @@ -653,87 +608,80 @@ utf8_constexpr14_impl int utf8ncmp(const utf8_int8_t *src1, return 0; } -utf8_int8_t *utf8ncpy(utf8_int8_t *utf8_restrict dst, -const utf8_int8_t *utf8_restrict src, size_t n) { -utf8_int8_t *d = dst; -size_t index = 0, check_index = 0; +utf8_int8_t *utf8ncpy(utf8_int8_t *utf8_restrict dst, const utf8_int8_t *utf8_restrict src, size_t n) { + utf8_int8_t *d = dst; + size_t index = 0, check_index = 0; -if (n == 0) { -return dst; -} + if (n == 0) { + return dst; + } -/* overwriting anything previously in dst, write byte-by-byte - * from src */ -for (index = 0; index < n; index++) { -d[index] = src[index]; -if ('\0' == src[index]) { -break; -} -} + /* overwriting anything previously in dst, write byte-by-byte + * from src */ + for (index = 0; index < n; index++) { + d[index] = src[index]; + if ('\0' == src[index]) { + break; + } + } -for (check_index = index - 1; -check_index > 0 && 0x80 == (0xc0 & d[check_index]); check_index--) { -/* just moving the index */ -} + for (check_index = index - 1; check_index > 0 && 0x80 == (0xc0 & d[check_index]); check_index--) { + /* just moving the index */ + } -if (check_index < index && -(index - check_index) < utf8codepointsize(d[check_index])) { -index = check_index; -} + if (check_index < index && (index - check_index) < utf8codepointsize(d[check_index])) { + index = check_index; + } -/* append null terminating byte */ -for (; index < n; index++) { -d[index] = 0; -} + /* append null terminating byte */ + for (; index < n; index++) { + d[index] = 0; + } -return dst; + return dst; } -utf8_int8_t *utf8ndup(const utf8_int8_t *src, size_t n) { - return utf8ndup_ex(src, n, utf8_null, utf8_null); -} +utf8_int8_t *utf8ndup(const utf8_int8_t *src, size_t n) { return utf8ndup_ex(src, n, utf8_null, utf8_null); } -utf8_int8_t *utf8ndup_ex(const utf8_int8_t *src, size_t n, - utf8_int8_t *(*alloc_func_ptr)(utf8_int8_t *, size_t), - utf8_int8_t *user_data) { -utf8_int8_t *c = utf8_null; -size_t bytes = 0; +utf8_int8_t *utf8ndup_ex(const utf8_int8_t *src, size_t n, utf8_int8_t *(*alloc_func_ptr)(utf8_int8_t *, size_t), + utf8_int8_t *user_data) { + utf8_int8_t *c = utf8_null; + size_t bytes = 0; -/* Find the end of the string or stop when n is reached */ -while (bytes < n && '\0' != src[bytes]) { -bytes++; -} + /* Find the end of the string or stop when n is reached */ + while (bytes < n && '\0' != src[bytes]) { + bytes++; + } -/* In case bytes is actually less than n, we need to set it - * to be used later in the copy byte by byte. */ -n = bytes; + /* In case bytes is actually less than n, we need to set it + * to be used later in the copy byte by byte. */ + n = bytes; -if (alloc_func_ptr) { -c = alloc_func_ptr(user_data, bytes + 1); -} else { -c = (utf8_int8_t *)malloc(bytes + 1); -} + if (alloc_func_ptr) { + c = alloc_func_ptr(user_data, bytes + 1); + } else { + c = (utf8_int8_t *)malloc(bytes + 1); + } -if (utf8_null == c) { -/* out of memory so we bail */ -return utf8_null; -} + if (utf8_null == c) { + /* out of memory so we bail */ + return utf8_null; + } -bytes = 0; + bytes = 0; -/* copy src byte-by-byte into our new utf8 string */ -while (bytes < n && '\0' != src[bytes]) { -c[bytes] = src[bytes]; -bytes++; -} + /* copy src byte-by-byte into our new utf8 string */ + while (bytes < n && '\0' != src[bytes]) { + c[bytes] = src[bytes]; + bytes++; + } -/* append null terminating byte */ -c[bytes] = '\0'; -return c; + /* append null terminating byte */ + c[bytes] = '\0'; + return c; } utf8_constexpr14_impl utf8_int8_t *utf8rchr(const utf8_int8_t *src, int chr) { - utf8_int8_t *match = utf8_null; utf8_int8_t c[5] = {'\0', '\0', '\0', '\0', '\0'}; @@ -800,8 +748,7 @@ utf8_constexpr14_impl utf8_int8_t *utf8rchr(const utf8_int8_t *src, int chr) { return match; } -utf8_constexpr14_impl utf8_int8_t *utf8pbrk(const utf8_int8_t *str, - const utf8_int8_t *accept) { +utf8_constexpr14_impl utf8_int8_t *utf8pbrk(const utf8_int8_t *str, const utf8_int8_t *accept) { while ('\0' != *str) { const utf8_int8_t *a = accept; size_t offset = 0; @@ -848,13 +795,9 @@ utf8_constexpr14_impl utf8_int8_t *utf8pbrk(const utf8_int8_t *str, return utf8_null; } -utf8_constexpr14_impl size_t utf8size(const utf8_int8_t *str) { - return utf8size_lazy(str) + 1; -} +utf8_constexpr14_impl size_t utf8size(const utf8_int8_t *str) { return utf8size_lazy(str) + 1; } -utf8_constexpr14_impl size_t utf8size_lazy(const utf8_int8_t *str) { - return utf8nsize_lazy(str, SIZE_MAX); -} +utf8_constexpr14_impl size_t utf8size_lazy(const utf8_int8_t *str) { return utf8nsize_lazy(str, SIZE_MAX); } utf8_constexpr14_impl size_t utf8nsize_lazy(const utf8_int8_t *str, size_t n) { size_t size = 0; @@ -864,8 +807,7 @@ utf8_constexpr14_impl size_t utf8nsize_lazy(const utf8_int8_t *str, size_t n) { return size; } -utf8_constexpr14_impl size_t utf8spn(const utf8_int8_t *src, - const utf8_int8_t *accept) { +utf8_constexpr14_impl size_t utf8spn(const utf8_int8_t *src, const utf8_int8_t *accept) { size_t chars = 0; while ('\0' != *src) { @@ -918,8 +860,7 @@ utf8_constexpr14_impl size_t utf8spn(const utf8_int8_t *src, return chars; } -utf8_constexpr14_impl utf8_int8_t *utf8str(const utf8_int8_t *haystack, - const utf8_int8_t *needle) { +utf8_constexpr14_impl utf8_int8_t *utf8str(const utf8_int8_t *haystack, const utf8_int8_t *needle) { utf8_int32_t throwaway_codepoint = 0; /* if needle has no utf8 codepoints before the null terminating @@ -953,8 +894,7 @@ utf8_constexpr14_impl utf8_int8_t *utf8str(const utf8_int8_t *haystack, return utf8_null; } -utf8_constexpr14_impl utf8_int8_t *utf8casestr(const utf8_int8_t *haystack, - const utf8_int8_t *needle) { +utf8_constexpr14_impl utf8_int8_t *utf8casestr(const utf8_int8_t *haystack, const utf8_int8_t *needle) { /* if needle has no utf8 codepoints before the null terminating * byte then return haystack */ if ('\0' == *needle) { @@ -999,12 +939,9 @@ utf8_constexpr14_impl utf8_int8_t *utf8casestr(const utf8_int8_t *haystack, } } -utf8_constexpr14_impl utf8_int8_t *utf8valid(const utf8_int8_t *str) { - return utf8nvalid(str, SIZE_MAX); -} +utf8_constexpr14_impl utf8_int8_t *utf8valid(const utf8_int8_t *str) { return utf8nvalid(str, SIZE_MAX); } -utf8_constexpr14_impl utf8_int8_t *utf8nvalid(const utf8_int8_t *str, - size_t n) { +utf8_constexpr14_impl utf8_int8_t *utf8nvalid(const utf8_int8_t *str, size_t n) { const utf8_int8_t *t = str; size_t consumed = 0, remained = 0; @@ -1019,8 +956,7 @@ utf8_constexpr14_impl utf8_int8_t *utf8nvalid(const utf8_int8_t *str, /* ensure each of the 3 following bytes in this 4-byte * utf8 codepoint began with 0b10xxxxxx */ - if ((0x80 != (0xc0 & str[1])) || (0x80 != (0xc0 & str[2])) || - (0x80 != (0xc0 & str[3]))) { + if ((0x80 != (0xc0 & str[1])) || (0x80 != (0xc0 & str[2])) || (0x80 != (0xc0 & str[3]))) { return (utf8_int8_t *)str; } @@ -1103,82 +1039,78 @@ utf8_constexpr14_impl utf8_int8_t *utf8nvalid(const utf8_int8_t *str, } int utf8makevalid(utf8_int8_t *str, const utf8_int32_t replacement) { -utf8_int8_t *read = str; -utf8_int8_t *write = read; -const utf8_int8_t r = (utf8_int8_t)replacement; -utf8_int32_t codepoint = 0; + utf8_int8_t *read = str; + utf8_int8_t *write = read; + const utf8_int8_t r = (utf8_int8_t)replacement; + utf8_int32_t codepoint = 0; -if (replacement > 0x7f) { -return -1; -} + if (replacement > 0x7f) { + return -1; + } -while ('\0' != *read) { -if (0xf0 == (0xf8 & *read)) { -/* ensure each of the 3 following bytes in this 4-byte - * utf8 codepoint began with 0b10xxxxxx */ -if ((0x80 != (0xc0 & read[1])) || (0x80 != (0xc0 & read[2])) || -(0x80 != (0xc0 & read[3]))) { -*write++ = r; -read++; -continue; -} + while ('\0' != *read) { + if (0xf0 == (0xf8 & *read)) { + /* ensure each of the 3 following bytes in this 4-byte + * utf8 codepoint began with 0b10xxxxxx */ + if ((0x80 != (0xc0 & read[1])) || (0x80 != (0xc0 & read[2])) || (0x80 != (0xc0 & read[3]))) { + *write++ = r; + read++; + continue; + } -/* 4-byte utf8 code point (began with 0b11110xxx) */ -read = utf8codepoint(read, &codepoint); -write = utf8catcodepoint(write, codepoint, 4); -} else if (0xe0 == (0xf0 & *read)) { -/* ensure each of the 2 following bytes in this 3-byte - * utf8 codepoint began with 0b10xxxxxx */ -if ((0x80 != (0xc0 & read[1])) || (0x80 != (0xc0 & read[2]))) { -*write++ = r; -read++; -continue; -} + /* 4-byte utf8 code point (began with 0b11110xxx) */ + read = utf8codepoint(read, &codepoint); + write = utf8catcodepoint(write, codepoint, 4); + } else if (0xe0 == (0xf0 & *read)) { + /* ensure each of the 2 following bytes in this 3-byte + * utf8 codepoint began with 0b10xxxxxx */ + if ((0x80 != (0xc0 & read[1])) || (0x80 != (0xc0 & read[2]))) { + *write++ = r; + read++; + continue; + } -/* 3-byte utf8 code point (began with 0b1110xxxx) */ -read = utf8codepoint(read, &codepoint); -write = utf8catcodepoint(write, codepoint, 3); -} else if (0xc0 == (0xe0 & *read)) { -/* ensure the 1 following byte in this 2-byte - * utf8 codepoint began with 0b10xxxxxx */ -if (0x80 != (0xc0 & read[1])) { -*write++ = r; -read++; -continue; -} + /* 3-byte utf8 code point (began with 0b1110xxxx) */ + read = utf8codepoint(read, &codepoint); + write = utf8catcodepoint(write, codepoint, 3); + } else if (0xc0 == (0xe0 & *read)) { + /* ensure the 1 following byte in this 2-byte + * utf8 codepoint began with 0b10xxxxxx */ + if (0x80 != (0xc0 & read[1])) { + *write++ = r; + read++; + continue; + } -/* 2-byte utf8 code point (began with 0b110xxxxx) */ -read = utf8codepoint(read, &codepoint); -write = utf8catcodepoint(write, codepoint, 2); -} else if (0x00 == (0x80 & *read)) { -/* 1-byte ascii (began with 0b0xxxxxxx) */ -read = utf8codepoint(read, &codepoint); -write = utf8catcodepoint(write, codepoint, 1); -} else { -/* if we got here then we've got a dangling continuation (0b10xxxxxx) */ -*write++ = r; -read++; -continue; -} -} + /* 2-byte utf8 code point (began with 0b110xxxxx) */ + read = utf8codepoint(read, &codepoint); + write = utf8catcodepoint(write, codepoint, 2); + } else if (0x00 == (0x80 & *read)) { + /* 1-byte ascii (began with 0b0xxxxxxx) */ + read = utf8codepoint(read, &codepoint); + write = utf8catcodepoint(write, codepoint, 1); + } else { + /* if we got here then we've got a dangling continuation (0b10xxxxxx) */ + *write++ = r; + read++; + continue; + } + } -*write = '\0'; + *write = '\0'; -return 0; + return 0; } -utf8_constexpr14_impl utf8_int8_t * -utf8codepoint(const utf8_int8_t *utf8_restrict str, - utf8_int32_t *utf8_restrict out_codepoint) { +utf8_constexpr14_impl utf8_int8_t *utf8codepoint(const utf8_int8_t *utf8_restrict str, + utf8_int32_t *utf8_restrict out_codepoint) { if (0xf0 == (0xf8 & str[0])) { /* 4 byte utf8 codepoint */ - *out_codepoint = ((0x07 & str[0]) << 18) | ((0x3f & str[1]) << 12) | - ((0x3f & str[2]) << 6) | (0x3f & str[3]); + *out_codepoint = ((0x07 & str[0]) << 18) | ((0x3f & str[1]) << 12) | ((0x3f & str[2]) << 6) | (0x3f & str[3]); str += 4; } else if (0xe0 == (0xf0 & str[0])) { /* 3 byte utf8 codepoint */ - *out_codepoint = - ((0x0f & str[0]) << 12) | ((0x3f & str[1]) << 6) | (0x3f & str[2]); + *out_codepoint = ((0x0f & str[0]) << 12) | ((0x3f & str[1]) << 6) | (0x3f & str[2]); str += 3; } else if (0xc0 == (0xe0 & str[0])) { /* 2 byte utf8 codepoint */ @@ -1222,118 +1154,103 @@ utf8_constexpr14_impl size_t utf8codepointsize(utf8_int32_t chr) { } utf8_int8_t *utf8catcodepoint(utf8_int8_t *str, utf8_int32_t chr, size_t n) { -if (0 == ((utf8_int32_t)0xffffff80 & chr)) { -/* 1-byte/7-bit ascii - * (0b0xxxxxxx) */ -if (n < 1) { -return utf8_null; -} -str[0] = (utf8_int8_t)chr; -str += 1; -} else if (0 == ((utf8_int32_t)0xfffff800 & chr)) { -/* 2-byte/11-bit utf8 code point - * (0b110xxxxx 0b10xxxxxx) */ -if (n < 2) { -return utf8_null; -} -str[0] = (utf8_int8_t)(0xc0 | (utf8_int8_t)((chr >> 6) & 0x1f)); -str[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); -str += 2; -} else if (0 == ((utf8_int32_t)0xffff0000 & chr)) { -/* 3-byte/16-bit utf8 code point - * (0b1110xxxx 0b10xxxxxx 0b10xxxxxx) */ -if (n < 3) { -return utf8_null; -} -str[0] = (utf8_int8_t)(0xe0 | (utf8_int8_t)((chr >> 12) & 0x0f)); -str[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 6) & 0x3f)); -str[2] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); -str += 3; -} else { /* if (0 == ((int)0xffe00000 & chr)) { */ -/* 4-byte/21-bit utf8 code point - * (0b11110xxx 0b10xxxxxx 0b10xxxxxx 0b10xxxxxx) */ -if (n < 4) { -return utf8_null; -} -str[0] = (utf8_int8_t)(0xf0 | (utf8_int8_t)((chr >> 18) & 0x07)); -str[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 12) & 0x3f)); -str[2] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 6) & 0x3f)); -str[3] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); -str += 4; -} + if (0 == ((utf8_int32_t)0xffffff80 & chr)) { + /* 1-byte/7-bit ascii + * (0b0xxxxxxx) */ + if (n < 1) { + return utf8_null; + } + str[0] = (utf8_int8_t)chr; + str += 1; + } else if (0 == ((utf8_int32_t)0xfffff800 & chr)) { + /* 2-byte/11-bit utf8 code point + * (0b110xxxxx 0b10xxxxxx) */ + if (n < 2) { + return utf8_null; + } + str[0] = (utf8_int8_t)(0xc0 | (utf8_int8_t)((chr >> 6) & 0x1f)); + str[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); + str += 2; + } else if (0 == ((utf8_int32_t)0xffff0000 & chr)) { + /* 3-byte/16-bit utf8 code point + * (0b1110xxxx 0b10xxxxxx 0b10xxxxxx) */ + if (n < 3) { + return utf8_null; + } + str[0] = (utf8_int8_t)(0xe0 | (utf8_int8_t)((chr >> 12) & 0x0f)); + str[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 6) & 0x3f)); + str[2] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); + str += 3; + } else { /* if (0 == ((int)0xffe00000 & chr)) { */ + /* 4-byte/21-bit utf8 code point + * (0b11110xxx 0b10xxxxxx 0b10xxxxxx 0b10xxxxxx) */ + if (n < 4) { + return utf8_null; + } + str[0] = (utf8_int8_t)(0xf0 | (utf8_int8_t)((chr >> 18) & 0x07)); + str[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 12) & 0x3f)); + str[2] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 6) & 0x3f)); + str[3] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); + str += 4; + } -return str; + return str; } -utf8_constexpr14_impl int utf8islower(utf8_int32_t chr) { - return chr != utf8uprcodepoint(chr); -} +utf8_constexpr14_impl int utf8islower(utf8_int32_t chr) { return chr != utf8uprcodepoint(chr); } -utf8_constexpr14_impl int utf8isupper(utf8_int32_t chr) { - return chr != utf8lwrcodepoint(chr); -} +utf8_constexpr14_impl int utf8isupper(utf8_int32_t chr) { return chr != utf8lwrcodepoint(chr); } void utf8lwr(utf8_int8_t *utf8_restrict str) { -utf8_int32_t cp = 0; -utf8_int8_t *pn = utf8codepoint(str, &cp); + utf8_int32_t cp = 0; + utf8_int8_t *pn = utf8codepoint(str, &cp); -while (cp != 0) { -const utf8_int32_t lwr_cp = utf8lwrcodepoint(cp); -const size_t size = utf8codepointsize(lwr_cp); + while (cp != 0) { + const utf8_int32_t lwr_cp = utf8lwrcodepoint(cp); + const size_t size = utf8codepointsize(lwr_cp); -if (lwr_cp != cp) { -utf8catcodepoint(str, lwr_cp, size); -} + if (lwr_cp != cp) { + utf8catcodepoint(str, lwr_cp, size); + } -str = pn; -pn = utf8codepoint(str, &cp); -} + str = pn; + pn = utf8codepoint(str, &cp); + } } void utf8upr(utf8_int8_t *utf8_restrict str) { -utf8_int32_t cp = 0; -utf8_int8_t *pn = utf8codepoint(str, &cp); + utf8_int32_t cp = 0; + utf8_int8_t *pn = utf8codepoint(str, &cp); -while (cp != 0) { -const utf8_int32_t lwr_cp = utf8uprcodepoint(cp); -const size_t size = utf8codepointsize(lwr_cp); + while (cp != 0) { + const utf8_int32_t lwr_cp = utf8uprcodepoint(cp); + const size_t size = utf8codepointsize(lwr_cp); -if (lwr_cp != cp) { -utf8catcodepoint(str, lwr_cp, size); -} + if (lwr_cp != cp) { + utf8catcodepoint(str, lwr_cp, size); + } -str = pn; -pn = utf8codepoint(str, &cp); -} + str = pn; + pn = utf8codepoint(str, &cp); + } } utf8_constexpr14_impl utf8_int32_t utf8lwrcodepoint(utf8_int32_t cp) { - if (((0x0041 <= cp) && (0x005a >= cp)) || - ((0x00c0 <= cp) && (0x00d6 >= cp)) || - ((0x00d8 <= cp) && (0x00de >= cp)) || - ((0x0391 <= cp) && (0x03a1 >= cp)) || - ((0x03a3 <= cp) && (0x03ab >= cp)) || - ((0x0410 <= cp) && (0x042f >= cp))) { + if (((0x0041 <= cp) && (0x005a >= cp)) || ((0x00c0 <= cp) && (0x00d6 >= cp)) || + ((0x00d8 <= cp) && (0x00de >= cp)) || ((0x0391 <= cp) && (0x03a1 >= cp)) || + ((0x03a3 <= cp) && (0x03ab >= cp)) || ((0x0410 <= cp) && (0x042f >= cp))) { cp += 32; } else if ((0x0400 <= cp) && (0x040f >= cp)) { cp += 80; - } else if (((0x0100 <= cp) && (0x012f >= cp)) || - ((0x0132 <= cp) && (0x0137 >= cp)) || - ((0x014a <= cp) && (0x0177 >= cp)) || - ((0x0182 <= cp) && (0x0185 >= cp)) || - ((0x01a0 <= cp) && (0x01a5 >= cp)) || - ((0x01de <= cp) && (0x01ef >= cp)) || - ((0x01f8 <= cp) && (0x021f >= cp)) || - ((0x0222 <= cp) && (0x0233 >= cp)) || - ((0x0246 <= cp) && (0x024f >= cp)) || - ((0x03d8 <= cp) && (0x03ef >= cp)) || - ((0x0460 <= cp) && (0x0481 >= cp)) || - ((0x048a <= cp) && (0x04ff >= cp))) { + } else if (((0x0100 <= cp) && (0x012f >= cp)) || ((0x0132 <= cp) && (0x0137 >= cp)) || + ((0x014a <= cp) && (0x0177 >= cp)) || ((0x0182 <= cp) && (0x0185 >= cp)) || + ((0x01a0 <= cp) && (0x01a5 >= cp)) || ((0x01de <= cp) && (0x01ef >= cp)) || + ((0x01f8 <= cp) && (0x021f >= cp)) || ((0x0222 <= cp) && (0x0233 >= cp)) || + ((0x0246 <= cp) && (0x024f >= cp)) || ((0x03d8 <= cp) && (0x03ef >= cp)) || + ((0x0460 <= cp) && (0x0481 >= cp)) || ((0x048a <= cp) && (0x04ff >= cp))) { cp |= 0x1; - } else if (((0x0139 <= cp) && (0x0148 >= cp)) || - ((0x0179 <= cp) && (0x017e >= cp)) || - ((0x01af <= cp) && (0x01b0 >= cp)) || - ((0x01b3 <= cp) && (0x01b6 >= cp)) || + } else if (((0x0139 <= cp) && (0x0148 >= cp)) || ((0x0179 <= cp) && (0x017e >= cp)) || + ((0x01af <= cp) && (0x01b0 >= cp)) || ((0x01b3 <= cp) && (0x01b6 >= cp)) || ((0x01cd <= cp) && (0x01dc >= cp))) { cp += 1; cp &= ~0x1; @@ -1474,32 +1391,21 @@ utf8_constexpr14_impl utf8_int32_t utf8lwrcodepoint(utf8_int32_t cp) { } utf8_constexpr14_impl utf8_int32_t utf8uprcodepoint(utf8_int32_t cp) { - if (((0x0061 <= cp) && (0x007a >= cp)) || - ((0x00e0 <= cp) && (0x00f6 >= cp)) || - ((0x00f8 <= cp) && (0x00fe >= cp)) || - ((0x03b1 <= cp) && (0x03c1 >= cp)) || - ((0x03c3 <= cp) && (0x03cb >= cp)) || - ((0x0430 <= cp) && (0x044f >= cp))) { + if (((0x0061 <= cp) && (0x007a >= cp)) || ((0x00e0 <= cp) && (0x00f6 >= cp)) || + ((0x00f8 <= cp) && (0x00fe >= cp)) || ((0x03b1 <= cp) && (0x03c1 >= cp)) || + ((0x03c3 <= cp) && (0x03cb >= cp)) || ((0x0430 <= cp) && (0x044f >= cp))) { cp -= 32; } else if ((0x0450 <= cp) && (0x045f >= cp)) { cp -= 80; - } else if (((0x0100 <= cp) && (0x012f >= cp)) || - ((0x0132 <= cp) && (0x0137 >= cp)) || - ((0x014a <= cp) && (0x0177 >= cp)) || - ((0x0182 <= cp) && (0x0185 >= cp)) || - ((0x01a0 <= cp) && (0x01a5 >= cp)) || - ((0x01de <= cp) && (0x01ef >= cp)) || - ((0x01f8 <= cp) && (0x021f >= cp)) || - ((0x0222 <= cp) && (0x0233 >= cp)) || - ((0x0246 <= cp) && (0x024f >= cp)) || - ((0x03d8 <= cp) && (0x03ef >= cp)) || - ((0x0460 <= cp) && (0x0481 >= cp)) || - ((0x048a <= cp) && (0x04ff >= cp))) { + } else if (((0x0100 <= cp) && (0x012f >= cp)) || ((0x0132 <= cp) && (0x0137 >= cp)) || + ((0x014a <= cp) && (0x0177 >= cp)) || ((0x0182 <= cp) && (0x0185 >= cp)) || + ((0x01a0 <= cp) && (0x01a5 >= cp)) || ((0x01de <= cp) && (0x01ef >= cp)) || + ((0x01f8 <= cp) && (0x021f >= cp)) || ((0x0222 <= cp) && (0x0233 >= cp)) || + ((0x0246 <= cp) && (0x024f >= cp)) || ((0x03d8 <= cp) && (0x03ef >= cp)) || + ((0x0460 <= cp) && (0x0481 >= cp)) || ((0x048a <= cp) && (0x04ff >= cp))) { cp &= ~0x1; - } else if (((0x0139 <= cp) && (0x0148 >= cp)) || - ((0x0179 <= cp) && (0x017e >= cp)) || - ((0x01af <= cp) && (0x01b0 >= cp)) || - ((0x01b3 <= cp) && (0x01b6 >= cp)) || + } else if (((0x0139 <= cp) && (0x0148 >= cp)) || ((0x0179 <= cp) && (0x017e >= cp)) || + ((0x01af <= cp) && (0x01b0 >= cp)) || ((0x01b3 <= cp) && (0x01b6 >= cp)) || ((0x01cd <= cp) && (0x01dc >= cp))) { cp -= 1; cp |= 0x1; @@ -1639,19 +1545,16 @@ utf8_constexpr14_impl utf8_int32_t utf8uprcodepoint(utf8_int32_t cp) { return cp; } -utf8_constexpr14_impl utf8_int8_t * -utf8rcodepoint(const utf8_int8_t *utf8_restrict str, - utf8_int32_t *utf8_restrict out_codepoint) { +utf8_constexpr14_impl utf8_int8_t *utf8rcodepoint(const utf8_int8_t *utf8_restrict str, + utf8_int32_t *utf8_restrict out_codepoint) { const utf8_int8_t *s = (const utf8_int8_t *)str; if (0xf0 == (0xf8 & s[0])) { /* 4 byte utf8 codepoint */ - *out_codepoint = ((0x07 & s[0]) << 18) | ((0x3f & s[1]) << 12) | - ((0x3f & s[2]) << 6) | (0x3f & s[3]); + *out_codepoint = ((0x07 & s[0]) << 18) | ((0x3f & s[1]) << 12) | ((0x3f & s[2]) << 6) | (0x3f & s[3]); } else if (0xe0 == (0xf0 & s[0])) { /* 3 byte utf8 codepoint */ - *out_codepoint = - ((0x0f & s[0]) << 12) | ((0x3f & s[1]) << 6) | (0x3f & s[2]); + *out_codepoint = ((0x0f & s[0]) << 12) | ((0x3f & s[1]) << 6) | (0x3f & s[2]); } else if (0xc0 == (0xe0 & s[0])) { /* 2 byte utf8 codepoint */ *out_codepoint = ((0x1f & s[0]) << 6) | (0x3f & s[1]); diff --git a/deps/ledger-zxlib/include/view_templates.h b/deps/ledger-zxlib/include/view_templates.h index 26507149..b5a5abd2 100644 --- a/deps/ledger-zxlib/include/view_templates.h +++ b/deps/ledger-zxlib/include/view_templates.h @@ -1,170 +1,166 @@ /******************************************************************************* -* (c) 2016 Ledger -* (c) 2018 Zondax GmbH -* -* 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. -********************************************************************************/ + * (c) 2016 Ledger + * (c) 2018 - 2024 Zondax AG + * + * 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 -#define UI_CENTER11PX BAGL_FONT_OPEN_SANS_REGULAR_11px | BAGL_FONT_ALIGNMENT_CENTER -#define UI_CENTER11PX_BOLD BAGL_FONT_OPEN_SANS_EXTRABOLD_11px | BAGL_FONT_ALIGNMENT_CENTER +#define UI_CENTER11PX BAGL_FONT_OPEN_SANS_REGULAR_11px | BAGL_FONT_ALIGNMENT_CENTER +#define UI_CENTER11PX_BOLD BAGL_FONT_OPEN_SANS_EXTRABOLD_11px | BAGL_FONT_ALIGNMENT_CENTER #define UI_11PX 11 -#define DEFAULT_FONT BAGL_FONT_OPEN_SANS_LIGHT_16px | BAGL_FONT_ALIGNMENT_LEFT +#define DEFAULT_FONT BAGL_FONT_OPEN_SANS_LIGHT_16px | BAGL_FONT_ALIGNMENT_LEFT #define UI_WHITE 0xFFFFFF #define UI_BLACK 0x000000 -#define UIID_ICONLEFT 0x10 -#define UIID_ICONRIGHT 0x11 -#define UIID_ICONREVIEW 0x12 -#define UIID_LABEL 0x20 -#define UIID_LABELSCROLL 0x71 - -#define UI_FillRectangle(id, x, y, w, h, fgcolor, bgcolor) \ -{ \ - { \ - BAGL_RECTANGLE, /* type */ \ - id, /* usedid */ \ - x, /* x */ \ - y, /* y */ \ - w, /* width */ \ - h, /* height */ \ - 0, /* stroke */ \ - 0, /* radius */ \ - BAGL_FILL, /* fill */ \ - fgcolor, /* fgcolor */ \ - bgcolor, /* bgcolor */ \ - 0, /* font_id */ \ - 0 /* icon_id */ \ - }, \ - NULL, /* text */ \ -} - -#define UI_LabelLine(id, x, y, w, h, fgcolor, bgcolor, text) \ -{ \ - { \ - BAGL_LABELINE, /* type */ \ - id, /* usedid */ \ - x, /* x */ \ - y, /* y */ \ - w, /* width */ \ - h, /* height */ \ - 0, /* stroke */ \ - 0, /* radius */ \ - 0, /* fill */ \ - fgcolor, /* fgcolor */ \ - bgcolor, /* bgcolor */ \ - UI_CENTER11PX, /* font_id */ \ - 0 /* icon_id */ \ - }, \ - text, /* text */ \ -} - -#define UI_LabelLineScrolling(id, x, y, w, h, fgcolor, bgcolor, text) \ -{ \ - { \ - BAGL_LABELINE, /* type */ \ - id, /* usedid */ \ - x, /* x */ \ - y, /* y */ \ - w, /* width */ \ - h, /* height */ \ - 5 | BAGL_STROKE_FLAG_ONESHOT, /* stroke | scr pause */ \ - 0, /* radius */ \ - 0, /* fill */ \ - fgcolor, /* fgcolor */ \ - bgcolor, /* bgcolor */ \ - UI_CENTER11PX, /* font_id */ \ - 50 /* icon_id / scroll speed */ \ - }, \ - text, /* text */ \ -} +#define UIID_ICONLEFT 0x10 +#define UIID_ICONRIGHT 0x11 +#define UIID_ICONREVIEW 0x12 +#define UIID_LABEL 0x20 +#define UIID_LABELSCROLL 0x71 + +#define UI_FillRectangle(id, x, y, w, h, fgcolor, bgcolor) \ + { \ + { \ + BAGL_RECTANGLE, /* type */ \ + id, /* usedid */ \ + x, /* x */ \ + y, /* y */ \ + w, /* width */ \ + h, /* height */ \ + 0, /* stroke */ \ + 0, /* radius */ \ + BAGL_FILL, /* fill */ \ + fgcolor, /* fgcolor */ \ + bgcolor, /* bgcolor */ \ + 0, /* font_id */ \ + 0 /* icon_id */ \ + }, \ + NULL, /* text */ \ + } + +#define UI_LabelLine(id, x, y, w, h, fgcolor, bgcolor, text) \ + { \ + { \ + BAGL_LABELINE, /* type */ \ + id, /* usedid */ \ + x, /* x */ \ + y, /* y */ \ + w, /* width */ \ + h, /* height */ \ + 0, /* stroke */ \ + 0, /* radius */ \ + 0, /* fill */ \ + fgcolor, /* fgcolor */ \ + bgcolor, /* bgcolor */ \ + UI_CENTER11PX, /* font_id */ \ + 0 /* icon_id */ \ + }, \ + text, /* text */ \ + } + +#define UI_LabelLineScrolling(id, x, y, w, h, fgcolor, bgcolor, text) \ + { \ + { \ + BAGL_LABELINE, /* type */ \ + id, /* usedid */ \ + x, /* x */ \ + y, /* y */ \ + w, /* width */ \ + h, /* height */ \ + 5 | BAGL_STROKE_FLAG_ONESHOT, /* stroke | scr pause */ \ + 0, /* radius */ \ + 0, /* fill */ \ + fgcolor, /* fgcolor */ \ + bgcolor, /* bgcolor */ \ + UI_CENTER11PX, /* font_id */ \ + 50 /* icon_id / scroll speed */ \ + }, \ + text, /* text */ \ + } #if defined(TARGET_NANOX) || defined(TARGET_NANOS2) -#define UI_SCREEN_WIDTH 128 +#define UI_SCREEN_WIDTH 128 #define UI_SCREEN_HEIGHT 64 -#define BAGL_GLYPH_ICON_LEFT ((const char*)&C_icon_left) -#define BAGL_GLYPH_ICON_RIGHT ((const char*)&C_icon_right) -#define BAGL_GLYPH_ICON_CROSS ((const char*)&C_icon_crossmark) -#define BAGL_GLYPH_ICON_CHECK ((const char*)&C_icon_validate) - -#define UI_Icon(id, x, y, w, h, icon) \ -{ \ - { \ - BAGL_ICON, /* type */ \ - id, /* usedid */ \ - x, /* x */ \ - y, /* y */ \ - w, /* width */ \ - h, /* height */ \ - 0, /* stroke */ \ - 0, /* radius */ \ - 0, /* fill */ \ - UI_WHITE, /* fgcolor */ \ - UI_BLACK, /* bgcolor */ \ - 0, /* font_id */ \ - 0 /* icon_id */ \ - }, \ - icon, /* text */ \ - 0, /* touch_area_brim */ \ - 0, /* overfgcolor */ \ - 0, /* overbgcolor */ \ - NULL, /* tap */ \ - NULL, /* out */ \ - NULL, /* over */ \ -} - -#define UI_BACKGROUND \ - UI_FillRectangle(0, 0, 0, UI_SCREEN_WIDTH, UI_SCREEN_HEIGHT, 0x000000, 0xFFFFFF) - -#define UI_BACKGROUND_LEFT_RIGHT_ICONS \ - UI_BACKGROUND, \ - UI_Icon(UIID_ICONLEFT, 2, 28, 4, 7, BAGL_GLYPH_ICON_LEFT), \ +#define BAGL_GLYPH_ICON_LEFT ((const char *)&C_icon_left) +#define BAGL_GLYPH_ICON_RIGHT ((const char *)&C_icon_right) +#define BAGL_GLYPH_ICON_CROSS ((const char *)&C_icon_crossmark) +#define BAGL_GLYPH_ICON_CHECK ((const char *)&C_icon_validate) + +#define UI_Icon(id, x, y, w, h, icon) \ + { \ + { \ + BAGL_ICON, /* type */ \ + id, /* usedid */ \ + x, /* x */ \ + y, /* y */ \ + w, /* width */ \ + h, /* height */ \ + 0, /* stroke */ \ + 0, /* radius */ \ + 0, /* fill */ \ + UI_WHITE, /* fgcolor */ \ + UI_BLACK, /* bgcolor */ \ + 0, /* font_id */ \ + 0 /* icon_id */ \ + }, \ + icon, /* text */ \ + 0, /* touch_area_brim */ \ + 0, /* overfgcolor */ \ + 0, /* overbgcolor */ \ + NULL, /* tap */ \ + NULL, /* out */ \ + NULL, /* over */ \ + } + +#define UI_BACKGROUND UI_FillRectangle(0, 0, 0, UI_SCREEN_WIDTH, UI_SCREEN_HEIGHT, 0x000000, 0xFFFFFF) + +#define UI_BACKGROUND_LEFT_RIGHT_ICONS \ + UI_BACKGROUND, UI_Icon(UIID_ICONLEFT, 2, 28, 4, 7, BAGL_GLYPH_ICON_LEFT), \ UI_Icon(UIID_ICONRIGHT, 122, 28, 4, 7, BAGL_GLYPH_ICON_RIGHT) #else -#define UI_SCREEN_WIDTH 128 +#define UI_SCREEN_WIDTH 128 #define UI_SCREEN_HEIGHT 32 -#define UI_Icon(id, x, y, w, h, icon) \ -{ \ - { \ - BAGL_ICON, /* type */ \ - id, /* usedid */ \ - x, /* x */ \ - y, /* y */ \ - w, /* width */ \ - h, /* height */ \ - 0, /* stroke */ \ - 0, /* radius */ \ - 0, /* fill */ \ - UI_WHITE, /* fgcolor */ \ - UI_BLACK, /* bgcolor */ \ - 0, /* font_id */ \ - icon /* icon_id */ \ - }, \ - NULL, /* text */ \ -} - -#define UI_BACKGROUND \ - UI_FillRectangle(0, 0, 0, UI_SCREEN_WIDTH, UI_SCREEN_HEIGHT, 0x000000, 0xFFFFFF) - -#define UI_BACKGROUND_LEFT_RIGHT_ICONS \ - UI_BACKGROUND, \ - UI_Icon(UIID_ICONLEFT, 0, 0, 7, 7, BAGL_GLYPH_ICON_LEFT), \ - UI_Icon(UIID_ICONRIGHT, 128 - 7, 0, 7, 7, BAGL_GLYPH_ICON_RIGHT), \ +#define UI_Icon(id, x, y, w, h, icon) \ + { \ + { \ + BAGL_ICON, /* type */ \ + id, /* usedid */ \ + x, /* x */ \ + y, /* y */ \ + w, /* width */ \ + h, /* height */ \ + 0, /* stroke */ \ + 0, /* radius */ \ + 0, /* fill */ \ + UI_WHITE, /* fgcolor */ \ + UI_BLACK, /* bgcolor */ \ + 0, /* font_id */ \ + icon /* icon_id */ \ + }, \ + NULL, /* text */ \ + } + +#define UI_BACKGROUND UI_FillRectangle(0, 0, 0, UI_SCREEN_WIDTH, UI_SCREEN_HEIGHT, 0x000000, 0xFFFFFF) + +#define UI_BACKGROUND_LEFT_RIGHT_ICONS \ + UI_BACKGROUND, UI_Icon(UIID_ICONLEFT, 0, 0, 7, 7, BAGL_GLYPH_ICON_LEFT), \ + UI_Icon(UIID_ICONRIGHT, 128 - 7, 0, 7, 7, BAGL_GLYPH_ICON_RIGHT), \ UI_Icon(UIID_ICONREVIEW, 10, 12, 7, 7, BAGL_GLYPH_ICON_EYE_BADGE) #endif diff --git a/deps/ledger-zxlib/include/zxcanary.h b/deps/ledger-zxlib/include/zxcanary.h index de16eac2..c29d1b13 100644 --- a/deps/ledger-zxlib/include/zxcanary.h +++ b/deps/ledger-zxlib/include/zxcanary.h @@ -1,18 +1,18 @@ /******************************************************************************* -* (c) 2018 - 2023 Zondax AG -* -* 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. -********************************************************************************/ + * (c) 2018 - 2023 Zondax AG + * + * 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 __cplusplus extern "C" { diff --git a/deps/ledger-zxlib/include/zxerror.h b/deps/ledger-zxlib/include/zxerror.h index c2504d8f..82ae5dec 100644 --- a/deps/ledger-zxlib/include/zxerror.h +++ b/deps/ledger-zxlib/include/zxerror.h @@ -1,18 +1,18 @@ /******************************************************************************* -* (c) 2018 Zondax GmbH -* -* 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. -********************************************************************************/ + * (c) 2018 - 2024 Zondax AG + * + * 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 @@ -20,9 +20,11 @@ extern "C" { #endif -#define CHECK_ZXERR(CALL) { \ - zxerr_t err = CALL; \ - if (err!=zxerr_ok) return err;} +#define CHECK_ZXERR(CALL) \ + { \ + zxerr_t err = CALL; \ + if (err != zxerr_ok) return err; \ + } typedef enum { zxerr_unknown = 0b00000000, @@ -35,38 +37,38 @@ typedef enum { zxerr_ledger_api_error = 0b00001111, } zxerr_t; -//0b00000000 -//0b00000011 -//0b00000101 -//0b00000110 -//0b00001001 -//0b00001010 -//0b00001100 -//0b00001111 -//0b00010001 -//0b00010010 -//0b00010100 -//0b00010111 -//0b00011000 -//0b00011011 -//0b00011101 -//0b00011110 -//0b00100001 -//0b00100010 -//0b00100100 -//0b00100111 -//0b00101000 -//0b00101011 -//0b00101101 -//0b00101110 -//0b00110000 -//0b00110011 -//0b00110101 -//0b00110110 -//0b00111001 -//0b00111010 -//0b00111100 -//0b00111111 +// 0b00000000 +// 0b00000011 +// 0b00000101 +// 0b00000110 +// 0b00001001 +// 0b00001010 +// 0b00001100 +// 0b00001111 +// 0b00010001 +// 0b00010010 +// 0b00010100 +// 0b00010111 +// 0b00011000 +// 0b00011011 +// 0b00011101 +// 0b00011110 +// 0b00100001 +// 0b00100010 +// 0b00100100 +// 0b00100111 +// 0b00101000 +// 0b00101011 +// 0b00101101 +// 0b00101110 +// 0b00110000 +// 0b00110011 +// 0b00110101 +// 0b00110110 +// 0b00111001 +// 0b00111010 +// 0b00111100 +// 0b00111111 #ifdef __cplusplus } diff --git a/deps/ledger-zxlib/include/zxformat.h b/deps/ledger-zxlib/include/zxformat.h index 4ac02e6c..14a09bad 100644 --- a/deps/ledger-zxlib/include/zxformat.h +++ b/deps/ledger-zxlib/include/zxformat.h @@ -1,53 +1,64 @@ /******************************************************************************* -* (c) 2018 Zondax GmbH -* -* 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. -********************************************************************************/ + * (c) 2018 - 2024 Zondax AG + * + * 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 __cplusplus extern "C" { #endif -#include "zxmacros.h" #include "zxerror.h" +#include "zxmacros.h" #define IS_PRINTABLE(c) (c >= 0x20 && c <= 0x7e) -#define NUM_TO_STR(TYPE) __Z_INLINE const char * TYPE##_to_str(char *data, int dataLen, TYPE##_t number) { \ - if (dataLen < 2) return "Buffer too small"; \ - MEMZERO(data, dataLen); \ - char *p = data; \ - if (number < 0) { *(p++) = '-'; data++; } \ - else if (number == 0) { *(p++) = '0'; } \ - TYPE##_t tmp; \ - while (number != 0) { \ - if (p - data >= (dataLen - 1)) { return "Buffer too small"; } \ - tmp = number % 10; \ - tmp = tmp < 0 ? -tmp : tmp; \ - *(p++) = (char) ('0' + tmp); \ - number /= 10u; \ - } \ - while (p > data) { \ - p--; \ - char z = *data; *data = *p; *p = z; \ - data++; \ - } \ - return NULL; \ -} +#define NUM_TO_STR(TYPE) \ + __Z_INLINE const char *TYPE##_to_str(char *data, int dataLen, TYPE##_t number) { \ + if (dataLen < 2) return "Buffer too small"; \ + MEMZERO(data, dataLen); \ + char *p = data; \ + if (number < 0) { \ + *(p++) = '-'; \ + data++; \ + } else if (number == 0) { \ + *(p++) = '0'; \ + } \ + TYPE##_t tmp; \ + while (number != 0) { \ + if (p - data >= (dataLen - 1)) { \ + return "Buffer too small"; \ + } \ + tmp = number % 10; \ + tmp = tmp < 0 ? -tmp : tmp; \ + *(p++) = (char)('0' + tmp); \ + number /= 10u; \ + } \ + while (p > data) { \ + p--; \ + char z = *data; \ + *data = *p; \ + *p = z; \ + data++; \ + } \ + return NULL; \ + } NUM_TO_STR(int32) +NUM_TO_STR(uint32) + NUM_TO_STR(int64) NUM_TO_STR(uint64) @@ -105,9 +116,7 @@ __Z_INLINE void bip32_to_str(char *s, uint32_t max, const uint32_t *path, uint8_ } } -__Z_INLINE void bip44_to_str(char *s, uint32_t max, const uint32_t path[5]) { - bip32_to_str(s, max, path, 5); -} +__Z_INLINE void bip44_to_str(char *s, uint32_t max, const uint32_t path[5]) { bip32_to_str(s, max, path, 5); } __Z_INLINE int8_t str_to_int8(const char *start, const char *end, char *error) { int sign = 1; @@ -133,7 +142,7 @@ __Z_INLINE int8_t str_to_int8(const char *start, const char *end, char *error) { value *= sign; if (value >= INT8_MIN && value <= INT8_MAX) { - return (int8_t) value; + return (int8_t)value; } if (error != NULL) { *error = 1; @@ -246,7 +255,7 @@ __Z_INLINE void number_inplace_trimming(char *s, uint8_t non_trimmed) { } int16_t dec_point = -1; - for (int16_t i = 0; i < (int16_t) len && dec_point < 0; i++) { + for (int16_t i = 0; i < (int16_t)len && dec_point < 0; i++) { if (s[i] == '.') { dec_point = i; } @@ -255,7 +264,7 @@ __Z_INLINE void number_inplace_trimming(char *s, uint8_t non_trimmed) { return; } - const size_t limit = (size_t) dec_point + non_trimmed; + const size_t limit = (size_t)dec_point + non_trimmed; for (size_t i = (len - 1); i > limit && s[i] == '0'; i--) { s[i] = 0; } @@ -281,9 +290,9 @@ __Z_INLINE uint32_t array_to_hexstr(char *dst, uint16_t dstLen, const uint8_t *s *dst++ = hexchars[*src >> 4u]; *dst++ = hexchars[*src & 0x0Fu]; } - *dst = 0; // terminate string + *dst = 0; // terminate string - return (uint32_t) (count * 2); + return (uint32_t)(count * 2); } __Z_INLINE uint32_t array_to_hexstr_uppercase(char *dst, uint16_t dstLen, const uint8_t *src, uint16_t count) { @@ -297,18 +306,18 @@ __Z_INLINE uint32_t array_to_hexstr_uppercase(char *dst, uint16_t dstLen, const *dst++ = hexchars[*src >> 4u]; *dst++ = hexchars[*src & 0x0Fu]; } - *dst = 0; // terminate string + *dst = 0; // terminate string - return (uint32_t) (count * 2); + return (uint32_t)(count * 2); } __Z_INLINE uint32_t hexstr_to_array(uint8_t *dst, uint16_t dstLen, const char *src, const uint16_t srcLen) { MEMZERO(dst, dstLen); - if (srcLen % 2 != 0 || dstLen < srcLen/2) { + if (srcLen % 2 != 0 || dstLen < srcLen / 2) { return 0; } - for (size_t i = 0; i < srcLen/2; i++) { + for (size_t i = 0; i < srcLen / 2; i++) { uint8_t ch0 = src[2 * i]; uint8_t ch1 = src[2 * i + 1]; uint8_t nib0 = (ch0 & 0xF) + (ch0 >> 6) | ((ch0 >> 3) & 0x8); @@ -316,15 +325,15 @@ __Z_INLINE uint32_t hexstr_to_array(uint8_t *dst, uint16_t dstLen, const char *s dst[i] = (nib0 << 4) | nib1; } - return srcLen/2; + return srcLen / 2; } __Z_INLINE zxerr_t to_uppercase(uint8_t *letter) { if (letter == NULL) { return zxerr_no_data; } - //Check if lowercase letter - if(*letter >= 0x61 && *letter <= 0x7A) { + // Check if lowercase letter + if (*letter >= 0x61 && *letter <= 0x7A) { *letter = *letter - 0x20; } return zxerr_ok; @@ -334,8 +343,8 @@ __Z_INLINE zxerr_t to_lowercase(uint8_t *letter) { if (letter == NULL) { return zxerr_no_data; } - //Check if uppercase letter - if(*letter >= 0x41 && *letter <= 0x5A) { + // Check if uppercase letter + if (*letter >= 0x41 && *letter <= 0x5A) { *letter = *letter + 0x20; } return zxerr_ok; @@ -347,7 +356,7 @@ __Z_INLINE zxerr_t array_to_uppercase(uint8_t *input, uint16_t inputLen) { } for (uint16_t i = 0; i < inputLen; i++) { - to_uppercase(input+i); + to_uppercase(input + i); } return zxerr_ok; } @@ -358,13 +367,12 @@ __Z_INLINE zxerr_t array_to_lowercase(uint8_t *input, uint16_t inputLen) { } for (uint16_t i = 0; i < inputLen; i++) { - to_uppercase(input+i); + to_uppercase(input + i); } return zxerr_ok; } -__Z_INLINE void pageStringExt(char *outValue, uint16_t outValueLen, - const char *inValue, uint16_t inValueLen, +__Z_INLINE void pageStringExt(char *outValue, uint16_t outValueLen, const char *inValue, uint16_t inValueLen, uint8_t pageIdx, uint8_t *pageCount) { MEMZERO(outValue, outValueLen); *pageCount = 0; @@ -378,7 +386,7 @@ __Z_INLINE void pageStringExt(char *outValue, uint16_t outValueLen, return; } - *pageCount = (uint8_t) (inValueLen / outValueLen); + *pageCount = (uint8_t)(inValueLen / outValueLen); const uint16_t lastChunkLen = (inValueLen % outValueLen); if (lastChunkLen > 0) { @@ -394,19 +402,17 @@ __Z_INLINE void pageStringExt(char *outValue, uint16_t outValueLen, } } -__Z_INLINE void pageString(char *outValue, uint16_t outValueLen, - const char *inValue, - uint8_t pageIdx, uint8_t *pageCount) { - pageStringExt(outValue, outValueLen, inValue, (uint16_t) strlen(inValue), pageIdx, pageCount); +__Z_INLINE void pageString(char *outValue, uint16_t outValueLen, const char *inValue, uint8_t pageIdx, + uint8_t *pageCount) { + pageStringExt(outValue, outValueLen, inValue, (uint16_t)strlen(inValue), pageIdx, pageCount); } -__Z_INLINE void pageStringHex(char *outValue, uint16_t outValueLen, - const char *inValue, uint16_t inValueLen, +__Z_INLINE void pageStringHex(char *outValue, uint16_t outValueLen, const char *inValue, uint16_t inValueLen, uint8_t pageIdx, uint8_t *pageCount) { MEMZERO(outValue, outValueLen); *pageCount = 0; - //array_to_hexstr adds a null terminator + // array_to_hexstr adds a null terminator if (outValueLen < 2) { return; } @@ -416,7 +422,7 @@ __Z_INLINE void pageStringHex(char *outValue, uint16_t outValueLen, } // leaving space for null terminator const uint16_t bytesPerPage = (outValueLen - 1) / 2; - *pageCount = (uint8_t) (inValueLen / bytesPerPage); + *pageCount = (uint8_t)(inValueLen / bytesPerPage); const uint16_t lastChunkLen = inValueLen % bytesPerPage; if (lastChunkLen > 0) { @@ -425,24 +431,15 @@ __Z_INLINE void pageStringHex(char *outValue, uint16_t outValueLen, if (pageIdx < *pageCount) { if (lastChunkLen > 0 && pageIdx == *pageCount - 1) { - array_to_hexstr(outValue, outValueLen, - (const uint8_t *)inValue + pageIdx * bytesPerPage, - lastChunkLen); + array_to_hexstr(outValue, outValueLen, (const uint8_t *)inValue + pageIdx * bytesPerPage, lastChunkLen); } else { - array_to_hexstr(outValue, outValueLen, - (const uint8_t *)inValue + pageIdx * bytesPerPage, - bytesPerPage); + array_to_hexstr(outValue, outValueLen, (const uint8_t *)inValue + pageIdx * bytesPerPage, bytesPerPage); } } } -__Z_INLINE zxerr_t formatBufferData( - const uint8_t *ptr, - uint64_t len, - char *outValue, - uint16_t outValueLen, - uint8_t pageIdx, - uint8_t *pageCount) { +__Z_INLINE zxerr_t formatBufferData(const uint8_t *ptr, uint64_t len, char *outValue, uint16_t outValueLen, + uint8_t pageIdx, uint8_t *pageCount) { char bufferUI[500 + 1]; MEMZERO(bufferUI, sizeof(bufferUI)); MEMZERO(outValue, 0); diff --git a/deps/ledger-zxlib/include/zxtypes.h b/deps/ledger-zxlib/include/zxtypes.h index 9aae6770..d2d2ac22 100644 --- a/deps/ledger-zxlib/include/zxtypes.h +++ b/deps/ledger-zxlib/include/zxtypes.h @@ -1,18 +1,18 @@ /******************************************************************************* -* (c) 2018 Zondax GmbH -* -* 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. -********************************************************************************/ + * (c) 2018 - 2024 Zondax AG + * + * 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 diff --git a/deps/ledger-zxlib/include/zxutils_ledger.h b/deps/ledger-zxlib/include/zxutils_ledger.h index 7d3fc051..bd83346c 100644 --- a/deps/ledger-zxlib/include/zxutils_ledger.h +++ b/deps/ledger-zxlib/include/zxutils_ledger.h @@ -4,9 +4,8 @@ extern "C" { #endif -unsigned short zx_compute_line_width_light(const char* text, unsigned char text_length); - +unsigned short zx_compute_line_width_light(const char *text, unsigned char text_length); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/deps/ledger-zxlib/include/zxversion.h b/deps/ledger-zxlib/include/zxversion.h index 186967bb..646a8e4b 100644 --- a/deps/ledger-zxlib/include/zxversion.h +++ b/deps/ledger-zxlib/include/zxversion.h @@ -1,5 +1,5 @@ /******************************************************************************* - * (c) 2018 - 2022 Zondax GmbH + * (c) 2018 - 2024 Zondax AG * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,6 @@ ********************************************************************************/ #pragma once -#define ZXLIB_MAJOR 28 -#define ZXLIB_MINOR 0 -#define ZXLIB_PATCH 7 +#define ZXLIB_MAJOR 30 +#define ZXLIB_MINOR 1 +#define ZXLIB_PATCH 3 diff --git a/deps/ledger-zxlib/scripts/install_deps.sh b/deps/ledger-zxlib/scripts/install_deps.sh index 83c55b22..4b243d75 100755 --- a/deps/ledger-zxlib/scripts/install_deps.sh +++ b/deps/ledger-zxlib/scripts/install_deps.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash #******************************************************************************* -#* (c) 2018 Zondax GmbH +#* (c) 2018 - 2024 Zondax AG #* #* Licensed under the Apache License, Version 2.0 (the "License"); #* you may not use this file except in compliance with the License. diff --git a/deps/ledger-zxlib/scripts/template.sh b/deps/ledger-zxlib/scripts/template.sh index 1d0a5044..6920dfbd 100755 --- a/deps/ledger-zxlib/scripts/template.sh +++ b/deps/ledger-zxlib/scripts/template.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash #******************************************************************************* -# (c) 2018 Zondax GmbH +# (c) 2018 - 2024 Zondax AG # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/deps/ledger-zxlib/src/app_mode.c b/deps/ledger-zxlib/src/app_mode.c index 6094f6b1..41c32ca7 100644 --- a/deps/ledger-zxlib/src/app_mode.c +++ b/deps/ledger-zxlib/src/app_mode.c @@ -19,6 +19,7 @@ typedef struct { uint8_t expert; uint8_t account; + uint8_t blindsign; } app_mode_persistent_t; typedef struct { @@ -28,6 +29,8 @@ typedef struct { app_mode_temporary_t app_mode_temporary; +uint8_t blindsign_required; + #if defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \ defined(TARGET_FLEX) ////////////////////////////////////////////////////////////// @@ -50,6 +53,7 @@ void app_mode_set_expert(uint8_t val) { app_mode_persistent_t mode; mode.expert = val; mode.account = N_appmode.account; + mode.blindsign = N_appmode.blindsign; MEMCPY_NV((void *)PIC(&N_appmode_impl), (void *)&mode, sizeof(app_mode_persistent_t)); } @@ -57,9 +61,29 @@ void app_mode_set_account(uint8_t val) { app_mode_persistent_t mode; mode.expert = N_appmode.expert; mode.account = val; + mode.blindsign = N_appmode.blindsign; + MEMCPY_NV((void *)PIC(&N_appmode_impl), (void *)&mode, sizeof(app_mode_persistent_t)); +} + +bool app_mode_blindsign() { + if (N_appmode.blindsign) { + blindsign_required = 1; + } + return N_appmode.blindsign; +} + +void app_mode_set_blindsign(uint8_t val) { + app_mode_persistent_t mode; + mode.expert = N_appmode.expert; + mode.account = N_appmode.account; + mode.blindsign = val; + blindsign_required = val; MEMCPY_NV((void *)PIC(&N_appmode_impl), (void *)&mode, sizeof(app_mode_persistent_t)); } +bool app_mode_blindsign_required() { return blindsign_required; } + +void app_mode_skip_blindsign_ui() { blindsign_required = 0; } #else ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// @@ -71,8 +95,10 @@ app_mode_persistent_t app_mode; void app_mode_reset() { app_mode.expert = 0; app_mode.account = 0; + app_mode.blindsign = 0; app_mode_temporary.secret = 0; app_mode_temporary.shortcut = 0; + blindsign_required = 0; } bool app_mode_expert() { return app_mode.expert; } @@ -83,6 +109,22 @@ void app_mode_set_expert(uint8_t val) { app_mode.expert = val; } void app_mode_set_account(uint8_t val) { app_mode.account = val; } +bool app_mode_blindsign() { + if (app_mode.blindsign) { + blindsign_required = 1; + } + return app_mode.blindsign; +} + +void app_mode_set_blindsign(uint8_t val) { + app_mode.blindsign = val; + blindsign_required = val; +} + +bool app_mode_blindsign_required() { return blindsign_required; } + +void app_mode_skip_blindsign_ui() { blindsign_required = 0; } + ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// diff --git a/deps/ledger-zxlib/src/base64.c b/deps/ledger-zxlib/src/base64.c index ad601f8c..d9ee0e75 100644 --- a/deps/ledger-zxlib/src/base64.c +++ b/deps/ledger-zxlib/src/base64.c @@ -1,28 +1,28 @@ /******************************************************************************* -* (c) 2020 Zondax GmbH -* -* 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 + * (c) 2018 - 2024 Zondax AG + * + * 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 "base64.h" +#include + #define BASE64_PADDING_CHAR '=' const char base64_charset[] = { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', - 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', - 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', - 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', + 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', + 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', }; uint16_t base64_encode(char *out, uint16_t outlen, const uint8_t *in, uint16_t inlen) { @@ -31,7 +31,7 @@ uint16_t base64_encode(char *out, uint16_t outlen, const uint8_t *in, uint16_t i // Check uppeer bound or bailout uint16_t minspace = inlen / 6; if (inlen % 6 != 0) minspace++; - minspace++; // zero termination + minspace++; // zero termination if (outlen < minspace) { return 0; } diff --git a/deps/ledger-zxlib/src/bech32.c b/deps/ledger-zxlib/src/bech32.c index 5158abcf..7177f125 100644 --- a/deps/ledger-zxlib/src/bech32.c +++ b/deps/ledger-zxlib/src/bech32.c @@ -1,32 +1,29 @@ /******************************************************************************* -* (c) 2019 Zondax GmbH -* -* 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. -********************************************************************************/ + * (c) 2018 - 2024 Zondax AG + * + * 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 "bech32.h" -#include #include +#include #include -#include "bech32.h" -#include "segwit_addr.h" + #include "bittools.h" +#include "segwit_addr.h" -zxerr_t bech32EncodeFromBytes(char *out, - size_t out_len, - const char *hrp, - const uint8_t *in, - size_t in_len, - uint8_t pad, +zxerr_t bech32EncodeFromBytes(char *out, size_t out_len, const char *hrp, const uint8_t *in, size_t in_len, uint8_t pad, bech32_encoding enc) { MEMZERO(out, out_len); diff --git a/deps/ledger-zxlib/src/bignum.c b/deps/ledger-zxlib/src/bignum.c index 189a7d5c..d960e85d 100644 --- a/deps/ledger-zxlib/src/bignum.c +++ b/deps/ledger-zxlib/src/bignum.c @@ -1,23 +1,23 @@ /******************************************************************************* -* (c) 2019 Zondax GmbH -* -* 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 "zxtypes.h" + * (c) 2018 - 2024 Zondax AG + * + * 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 "bignum.h" -bool_t bignumLittleEndian_bcdprint(char *outBuffer, uint16_t outBufferLen, - const uint8_t *inBCD, uint16_t inBCDLen) { +#include "zxtypes.h" + +bool_t bignumLittleEndian_bcdprint(char *outBuffer, uint16_t outBufferLen, const uint8_t *inBCD, uint16_t inBCDLen) { static const char hexchars[] = "0123456789ABCDEF"; uint8_t started = 0; MEMZERO(outBuffer, outBufferLen); @@ -50,8 +50,7 @@ bool_t bignumLittleEndian_bcdprint(char *outBuffer, uint16_t outBufferLen, return bool_true; } -void bignumLittleEndian_to_bcd(uint8_t *bcdOut, uint16_t bcdOutLen, - const uint8_t *binValue, uint16_t binValueLen) { +void bignumLittleEndian_to_bcd(uint8_t *bcdOut, uint16_t bcdOutLen, const uint8_t *binValue, uint16_t binValueLen) { MEMZERO(bcdOut, bcdOutLen); uint8_t carry = 0; @@ -69,11 +68,11 @@ void bignumLittleEndian_to_bcd(uint8_t *bcdOut, uint16_t bcdOutLen, // get bit const uint16_t byteIdx = bitIdx >> 3u; const uint8_t mask = 0x80u >> (bitIdx & 0x7u); - carry = (uint8_t) ((binValue[binValueLen - byteIdx - 1] & mask) > 0); + carry = (uint8_t)((binValue[binValueLen - byteIdx - 1] & mask) > 0); // Shift bcd for (uint16_t j = 0; j < bcdOutLen; j++) { - uint8_t carry2 = (uint8_t) (bcdOut[bcdOutLen - j - 1] > 127u); + uint8_t carry2 = (uint8_t)(bcdOut[bcdOutLen - j - 1] > 127u); bcdOut[bcdOutLen - j - 1] <<= 1u; bcdOut[bcdOutLen - j - 1] += carry; carry = carry2; @@ -81,8 +80,7 @@ void bignumLittleEndian_to_bcd(uint8_t *bcdOut, uint16_t bcdOutLen, } } -bool_t bignumBigEndian_bcdprint(char *outBuffer, uint16_t outBufferLen, - const uint8_t *bcdIn, uint16_t bcdInLen) { +bool_t bignumBigEndian_bcdprint(char *outBuffer, uint16_t outBufferLen, const uint8_t *bcdIn, uint16_t bcdInLen) { static const char hexchars[] = "0123456789ABCDEF"; uint8_t started = 0; MEMZERO(outBuffer, outBufferLen); @@ -116,8 +114,7 @@ bool_t bignumBigEndian_bcdprint(char *outBuffer, uint16_t outBufferLen, return bool_true; } -void bignumBigEndian_to_bcd(uint8_t *bcdOut, uint16_t bcdOutLen, - const uint8_t *binValue, uint16_t binValueLen) { +void bignumBigEndian_to_bcd(uint8_t *bcdOut, uint16_t bcdOutLen, const uint8_t *binValue, uint16_t binValueLen) { MEMZERO(bcdOut, bcdOutLen); uint8_t carry = 0; @@ -135,11 +132,11 @@ void bignumBigEndian_to_bcd(uint8_t *bcdOut, uint16_t bcdOutLen, // get bit const uint16_t byteIdx = bitIdx >> 3u; const uint8_t mask = 0x80u >> (bitIdx & 0x7u); - carry = (uint8_t) ((binValue[byteIdx] & mask) > 0); + carry = (uint8_t)((binValue[byteIdx] & mask) > 0); // Shift bcd for (uint16_t j = 0; j < bcdOutLen; j++) { - uint8_t carry2 = (uint8_t) (bcdOut[j] > 127u); + uint8_t carry2 = (uint8_t)(bcdOut[j] > 127u); bcdOut[j] <<= 1u; bcdOut[j] += carry; carry = carry2; diff --git a/deps/ledger-zxlib/src/buffering.c b/deps/ledger-zxlib/src/buffering.c index 01602adb..0fc2d2d8 100644 --- a/deps/ledger-zxlib/src/buffering.c +++ b/deps/ledger-zxlib/src/buffering.c @@ -1,33 +1,31 @@ /******************************************************************************* -* (c) 2018 Zondax GmbH -* -* 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. -********************************************************************************/ + * (c) 2018 - 2024 Zondax AG + * + * 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 "buffering.h" + #include #ifdef __cplusplus extern "C" { #endif -buffer_state_t ram; // Ram -buffer_state_t flash; // Flash +buffer_state_t ram; // Ram +buffer_state_t flash; // Flash -void buffering_init(uint8_t *ram_buffer, - size_t ram_buffer_size, - uint8_t *flash_buffer, - size_t flash_buffer_size) { +void buffering_init(uint8_t *ram_buffer, size_t ram_buffer_size, uint8_t *flash_buffer, size_t flash_buffer_size) { ram.data = ram_buffer; ram.size = ram_buffer_size; ram.pos = 0; @@ -75,13 +73,9 @@ int buffering_append(uint8_t *data, size_t length) { return length; } -buffer_state_t *buffering_get_ram_buffer() { - return &ram; -} +buffer_state_t *buffering_get_ram_buffer() { return &ram; } -buffer_state_t *buffering_get_flash_buffer() { - return &flash; -} +buffer_state_t *buffering_get_flash_buffer() { return &flash; } buffer_state_t *buffering_get_buffer() { if (ram.in_use) { diff --git a/deps/ledger-zxlib/src/hexutils.c b/deps/ledger-zxlib/src/hexutils.c index 66b80894..4571f185 100644 --- a/deps/ledger-zxlib/src/hexutils.c +++ b/deps/ledger-zxlib/src/hexutils.c @@ -1,42 +1,43 @@ /******************************************************************************* -* (c) 2018 Zondax GmbH -* -* 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. -********************************************************************************/ + * (c) 2018 - 2024 Zondax AG + * + * 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 "hexutils.h" #include #include -#include "hexutils.h" uint8_t hex2dec(char c, char *out) { - c = (char) tolower((int) c); + c = (char)tolower((int)c); - if (!isxdigit((int) c)) { + if (!isxdigit((int)c)) { return 1; } - if (isdigit((int) c)) { - *out = (char) (c - '0'); + if (isdigit((int)c)) { + *out = (char)(c - '0'); return 0; } - *out = (char) (c - 'a' + 10); + *out = (char)(c - 'a' + 10); return 0; } size_t parseHexString(uint8_t *out, uint16_t outLen, const char *input) { size_t len = strnlen(input, outLen * 2u + 1u); - if ( (len / 2) > outLen) { + if ((len / 2) > outLen) { return 0; } if (len % 2 == 1) { @@ -45,10 +46,8 @@ size_t parseHexString(uint8_t *out, uint16_t outLen, const char *input) { for (size_t i = 0; i < len; i += 2) { char tmp1, tmp2; - if (hex2dec(input[i], &tmp1)) - return 0; - if (hex2dec(input[i + 1], &tmp2)) - return 0; + if (hex2dec(input[i], &tmp1)) return 0; + if (hex2dec(input[i + 1], &tmp2)) return 0; out[i >> 1u] = (tmp1 << 4u) + tmp2; } diff --git a/deps/ledger-zxlib/src/segwit_addr.c b/deps/ledger-zxlib/src/segwit_addr.c index 93aa1ab0..ae1a6be4 100644 --- a/deps/ledger-zxlib/src/segwit_addr.c +++ b/deps/ledger-zxlib/src/segwit_addr.c @@ -18,20 +18,16 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include +#include "segwit_addr.h" + #include +#include #include -#include "segwit_addr.h" - uint32_t bech32_polymod_step(uint32_t pre) { uint8_t b = pre >> 25u; - return ((pre & 0x1FFFFFFu) << 5u) ^ - (-((b >> 0u) & 1u) & 0x3b6a57b2UL) ^ - (-((b >> 1u) & 1u) & 0x26508e6dUL) ^ - (-((b >> 2u) & 1u) & 0x1ea119faUL) ^ - (-((b >> 3u) & 1u) & 0x3d4233ddUL) ^ - (-((b >> 4u) & 1u) & 0x2a1462b3UL); + return ((pre & 0x1FFFFFFu) << 5u) ^ (-((b >> 0u) & 1u) & 0x3b6a57b2UL) ^ (-((b >> 1u) & 1u) & 0x26508e6dUL) ^ + (-((b >> 2u) & 1u) & 0x1ea119faUL) ^ (-((b >> 3u) & 1u) & 0x3d4233ddUL) ^ (-((b >> 4u) & 1u) & 0x2a1462b3UL); } static uint32_t bech32_final_constant(bech32_encoding enc) { @@ -40,18 +36,14 @@ static uint32_t bech32_final_constant(bech32_encoding enc) { return 0; } -static const char* charset = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"; +static const char *charset = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"; static const int8_t charset_rev[128] = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 15, -1, 10, 17, 21, 20, 26, 30, 7, 5, -1, -1, -1, -1, -1, -1, - -1, 29, -1, 24, 13, 25, 9, 8, 23, -1, 18, 22, 31, 27, 19, -1, - 1, 0, 3, 16, 11, 28, 12, 14, 6, 4, 2, -1, -1, -1, -1, -1, - -1, 29, -1, 24, 13, 25, 9, 8, 23, -1, 18, 22, 31, 27, 19, -1, - 1, 0, 3, 16, 11, 28, 12, 14, 6, 4, 2, -1, -1, -1, -1, -1 -}; + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, 10, 17, + 21, 20, 26, 30, 7, 5, -1, -1, -1, -1, -1, -1, -1, 29, -1, 24, 13, 25, 9, 8, 23, -1, 18, 22, 31, 27, + 19, -1, 1, 0, 3, 16, 11, 28, 12, 14, 6, 4, 2, -1, -1, -1, -1, -1, -1, 29, -1, 24, 13, 25, 9, 8, + 23, -1, 18, 22, 31, 27, 19, -1, 1, 0, 3, 16, 11, 28, 12, 14, 6, 4, 2, -1, -1, -1, -1, -1}; int bech32_encode(char *output, const char *hrp, const uint8_t *data, size_t data_len, bech32_encoding enc) { uint32_t chk = 1; @@ -89,7 +81,7 @@ int bech32_encode(char *output, const char *hrp, const uint8_t *data, size_t dat return 1; } -bech32_encoding bech32_decode(char* hrp, uint8_t *data, size_t *data_len, const char *input) { +bech32_encoding bech32_decode(char *hrp, uint8_t *data, size_t *data_len, const char *input) { uint32_t chk = 1; size_t i; size_t input_len = strlen(input); @@ -152,7 +144,7 @@ bech32_encoding bech32_decode(char* hrp, uint8_t *data, size_t *data_len, const } } -int convert_bits(uint8_t* out, size_t* outlen, int outBits, const uint8_t* in, size_t inLen, int inBits, int pad) { +int convert_bits(uint8_t *out, size_t *outlen, int outBits, const uint8_t *in, size_t inLen, int inBits, int pad) { uint32_t val = 0; int bits = 0; uint32_t maxv = (((uint32_t)1u) << outBits) - 1u; @@ -188,7 +180,7 @@ int segwit_addr_encode(char *output, const char *hrp, int witver, const uint8_t return bech32_encode(output, hrp, data, datalen, enc); } -int segwit_addr_decode(int* witver, uint8_t* witdata, size_t* witdata_len, const char* hrp, const char* addr) { +int segwit_addr_decode(int *witver, uint8_t *witdata, size_t *witdata_len, const char *hrp, const char *addr) { uint8_t data[84]; char hrp_actual[84]; size_t data_len; diff --git a/deps/ledger-zxlib/src/sigutils.c b/deps/ledger-zxlib/src/sigutils.c index 107088fd..ddfa257e 100644 --- a/deps/ledger-zxlib/src/sigutils.c +++ b/deps/ledger-zxlib/src/sigutils.c @@ -1,18 +1,18 @@ /******************************************************************************* -* (c) 2020 Zondax GmbH -* -* 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. -********************************************************************************/ + * (c) 2018 - 2024 Zondax AG + * + * 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 #include @@ -21,12 +21,8 @@ #define PAYLOADLEN 32 #define MAXPAYLOADLEN 33 -err_convert_e convertDERtoRSV(const uint8_t *inSignatureDER, - unsigned int inInfo, - uint8_t *outR, - uint8_t *outS, +err_convert_e convertDERtoRSV(const uint8_t *inSignatureDER, unsigned int inInfo, uint8_t *outR, uint8_t *outS, uint8_t *outV) { - // https://github.com/libbitcoin/libbitcoin-system/wiki/ECDSA-and-DER-Signatures#serialised-der-signature-sequence // 0 [1 byte] - DER Prefix // 1 [1 byte] - Payload len @@ -86,7 +82,7 @@ err_convert_e convertDERtoRSV(const uint8_t *inSignatureDER, outR += PAYLOADLEN - rLen; } if (rLen > PAYLOADLEN) { - rPtr += rLen - PAYLOADLEN; // move forward get only 32 bytes + rPtr += rLen - PAYLOADLEN; // move forward get only 32 bytes rLen = PAYLOADLEN; } @@ -94,7 +90,7 @@ err_convert_e convertDERtoRSV(const uint8_t *inSignatureDER, outS += PAYLOADLEN - sLen; } if (sLen > PAYLOADLEN) { - sPtr += sLen - PAYLOADLEN; // move forward get only 32 bytes + sPtr += sLen - PAYLOADLEN; // move forward get only 32 bytes sLen = PAYLOADLEN; } diff --git a/deps/ledger-zxlib/src/timeutils.c b/deps/ledger-zxlib/src/timeutils.c index 785a8e5d..b410f7a5 100644 --- a/deps/ledger-zxlib/src/timeutils.c +++ b/deps/ledger-zxlib/src/timeutils.c @@ -1,677 +1,79 @@ /******************************************************************************* -* (c) 2018 Zondax GmbH -* -* 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 "zxmacros.h" + * (c) 2018 - 2024 Zondax AG + * + * 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 "timeutils.h" +#include "zxmacros.h" + #ifdef __cplusplus extern "C" { #endif -#include #include +#include -const uint8_t monthDays[] = { - 31, - 28, - 31, - 30, - 31, - 30, - 31, - 31, - 30, - 31, - 30, - 31 -}; +const uint8_t monthDays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // This table can be generated using scripts/yearLookup.py. It covers up to year 2600 const uint32_t yearLookup[] = { - 0, - 365, - 730, - 1096, - 1461, - 1826, - 2191, - 2557, - 2922, - 3287, - 3652, - 4018, - 4383, - 4748, - 5113, - 5479, - 5844, - 6209, - 6574, - 6940, - 7305, - 7670, - 8035, - 8401, - 8766, - 9131, - 9496, - 9862, - 10227, - 10592, - 10957, - 11323, - 11688, - 12053, - 12418, - 12784, - 13149, - 13514, - 13879, - 14245, - 14610, - 14975, - 15340, - 15706, - 16071, - 16436, - 16801, - 17167, - 17532, - 17897, - 18262, - 18628, - 18993, - 19358, - 19723, - 20089, - 20454, - 20819, - 21184, - 21550, - 21915, - 22280, - 22645, - 23011, - 23376, - 23741, - 24106, - 24472, - 24837, - 25202, - 25567, - 25933, - 26298, - 26663, - 27028, - 27394, - 27759, - 28124, - 28489, - 28855, - 29220, - 29585, - 29950, - 30316, - 30681, - 31046, - 31411, - 31777, - 32142, - 32507, - 32872, - 33238, - 33603, - 33968, - 34333, - 34699, - 35064, - 35429, - 35794, - 36160, - 36525, - 36890, - 37255, - 37621, - 37986, - 38351, - 38716, - 39082, - 39447, - 39812, - 40177, - 40543, - 40908, - 41273, - 41638, - 42004, - 42369, - 42734, - 43099, - 43465, - 43830, - 44195, - 44560, - 44926, - 45291, - 45656, - 46021, - 46387, - 46752, - 47117, - 47482, - 47847, - 48212, - 48577, - 48942, - 49308, - 49673, - 50038, - 50403, - 50769, - 51134, - 51499, - 51864, - 52230, - 52595, - 52960, - 53325, - 53691, - 54056, - 54421, - 54786, - 55152, - 55517, - 55882, - 56247, - 56613, - 56978, - 57343, - 57708, - 58074, - 58439, - 58804, - 59169, - 59535, - 59900, - 60265, - 60630, - 60996, - 61361, - 61726, - 62091, - 62457, - 62822, - 63187, - 63552, - 63918, - 64283, - 64648, - 65013, - 65379, - 65744, - 66109, - 66474, - 66840, - 67205, - 67570, - 67935, - 68301, - 68666, - 69031, - 69396, - 69762, - 70127, - 70492, - 70857, - 71223, - 71588, - 71953, - 72318, - 72684, - 73049, - 73414, - 73779, - 74145, - 74510, - 74875, - 75240, - 75606, - 75971, - 76336, - 76701, - 77067, - 77432, - 77797, - 78162, - 78528, - 78893, - 79258, - 79623, - 79989, - 80354, - 80719, - 81084, - 81450, - 81815, - 82180, - 82545, - 82911, - 83276, - 83641, - 84006, - 84371, - 84736, - 85101, - 85466, - 85832, - 86197, - 86562, - 86927, - 87293, - 87658, - 88023, - 88388, - 88754, - 89119, - 89484, - 89849, - 90215, - 90580, - 90945, - 91310, - 91676, - 92041, - 92406, - 92771, - 93137, - 93502, - 93867, - 94232, - 94598, - 94963, - 95328, - 95693, - 96059, - 96424, - 96789, - 97154, - 97520, - 97885, - 98250, - 98615, - 98981, - 99346, - 99711, - 100076, - 100442, - 100807, - 101172, - 101537, - 101903, - 102268, - 102633, - 102998, - 103364, - 103729, - 104094, - 104459, - 104825, - 105190, - 105555, - 105920, - 106286, - 106651, - 107016, - 107381, - 107747, - 108112, - 108477, - 108842, - 109208, - 109573, - 109938, - 110303, - 110669, - 111034, - 111399, - 111764, - 112130, - 112495, - 112860, - 113225, - 113591, - 113956, - 114321, - 114686, - 115052, - 115417, - 115782, - 116147, - 116513, - 116878, - 117243, - 117608, - 117974, - 118339, - 118704, - 119069, - 119435, - 119800, - 120165, - 120530, - 120895, - 121260, - 121625, - 121990, - 122356, - 122721, - 123086, - 123451, - 123817, - 124182, - 124547, - 124912, - 125278, - 125643, - 126008, - 126373, - 126739, - 127104, - 127469, - 127834, - 128200, - 128565, - 128930, - 129295, - 129661, - 130026, - 130391, - 130756, - 131122, - 131487, - 131852, - 132217, - 132583, - 132948, - 133313, - 133678, - 134044, - 134409, - 134774, - 135139, - 135505, - 135870, - 136235, - 136600, - 136966, - 137331, - 137696, - 138061, - 138427, - 138792, - 139157, - 139522, - 139888, - 140253, - 140618, - 140983, - 141349, - 141714, - 142079, - 142444, - 142810, - 143175, - 143540, - 143905, - 144271, - 144636, - 145001, - 145366, - 145732, - 146097, - 146462, - 146827, - 147193, - 147558, - 147923, - 148288, - 148654, - 149019, - 149384, - 149749, - 150115, - 150480, - 150845, - 151210, - 151576, - 151941, - 152306, - 152671, - 153037, - 153402, - 153767, - 154132, - 154498, - 154863, - 155228, - 155593, - 155959, - 156324, - 156689, - 157054, - 157420, - 157785, - 158150, - 158515, - 158881, - 159246, - 159611, - 159976, - 160342, - 160707, - 161072, - 161437, - 161803, - 162168, - 162533, - 162898, - 163264, - 163629, - 163994, - 164359, - 164725, - 165090, - 165455, - 165820, - 166186, - 166551, - 166916, - 167281, - 167647, - 168012, - 168377, - 168742, - 169108, - 169473, - 169838, - 170203, - 170569, - 170934, - 171299, - 171664, - 172030, - 172395, - 172760, - 173125, - 173491, - 173856, - 174221, - 174586, - 174952, - 175317, - 175682, - 176047, - 176413, - 176778, - 177143, - 177508, - 177874, - 178239, - 178604, - 178969, - 179335, - 179700, - 180065, - 180430, - 180796, - 181161, - 181526, - 181891, - 182257, - 182622, - 182987, - 183352, - 183718, - 184083, - 184448, - 184813, - 185179, - 185544, - 185909, - 186274, - 186640, - 187005, - 187370, - 187735, - 188101, - 188466, - 188831, - 189196, - 189562, - 189927, - 190292, - 190657, - 191023, - 191388, - 191753, - 192118, - 192484, - 192849, - 193214, - 193579, - 193944, - 194309, - 194674, - 195039, - 195405, - 195770, - 196135, - 196500, - 196866, - 197231, - 197596, - 197961, - 198327, - 198692, - 199057, - 199422, - 199788, - 200153, - 200518, - 200883, - 201249, - 201614, - 201979, - 202344, - 202710, - 203075, - 203440, - 203805, - 204171, - 204536, - 204901, - 205266, - 205632, - 205997, - 206362, - 206727, - 207093, - 207458, - 207823, - 208188, - 208554, - 208919, - 209284, - 209649, - 210015, - 210380, - 210745, - 211110, - 211476, - 211841, - 212206, - 212571, - 212937, - 213302, - 213667, - 214032, - 214398, - 214763, - 215128, - 215493, - 215859, - 216224, - 216589, - 216954, - 217320, - 217685, - 218050, - 218415, - 218781, - 219146, - 219511, - 219876, - 220242, - 220607, - 220972, - 221337, - 221703, - 222068, - 222433, - 222798, - 223164, - 223529, - 223894, - 224259, - 224625, - 224990, - 225355, - 225720, - 226086, - 226451, - 226816, - 227181, - 227547, - 227912, - 228277, - 228642, - 229008, - 229373, - 229738, - 230103 -}; + 0, 365, 730, 1096, 1461, 1826, 2191, 2557, 2922, 3287, 3652, 4018, 4383, 4748, + 5113, 5479, 5844, 6209, 6574, 6940, 7305, 7670, 8035, 8401, 8766, 9131, 9496, 9862, + 10227, 10592, 10957, 11323, 11688, 12053, 12418, 12784, 13149, 13514, 13879, 14245, 14610, 14975, + 15340, 15706, 16071, 16436, 16801, 17167, 17532, 17897, 18262, 18628, 18993, 19358, 19723, 20089, + 20454, 20819, 21184, 21550, 21915, 22280, 22645, 23011, 23376, 23741, 24106, 24472, 24837, 25202, + 25567, 25933, 26298, 26663, 27028, 27394, 27759, 28124, 28489, 28855, 29220, 29585, 29950, 30316, + 30681, 31046, 31411, 31777, 32142, 32507, 32872, 33238, 33603, 33968, 34333, 34699, 35064, 35429, + 35794, 36160, 36525, 36890, 37255, 37621, 37986, 38351, 38716, 39082, 39447, 39812, 40177, 40543, + 40908, 41273, 41638, 42004, 42369, 42734, 43099, 43465, 43830, 44195, 44560, 44926, 45291, 45656, + 46021, 46387, 46752, 47117, 47482, 47847, 48212, 48577, 48942, 49308, 49673, 50038, 50403, 50769, + 51134, 51499, 51864, 52230, 52595, 52960, 53325, 53691, 54056, 54421, 54786, 55152, 55517, 55882, + 56247, 56613, 56978, 57343, 57708, 58074, 58439, 58804, 59169, 59535, 59900, 60265, 60630, 60996, + 61361, 61726, 62091, 62457, 62822, 63187, 63552, 63918, 64283, 64648, 65013, 65379, 65744, 66109, + 66474, 66840, 67205, 67570, 67935, 68301, 68666, 69031, 69396, 69762, 70127, 70492, 70857, 71223, + 71588, 71953, 72318, 72684, 73049, 73414, 73779, 74145, 74510, 74875, 75240, 75606, 75971, 76336, + 76701, 77067, 77432, 77797, 78162, 78528, 78893, 79258, 79623, 79989, 80354, 80719, 81084, 81450, + 81815, 82180, 82545, 82911, 83276, 83641, 84006, 84371, 84736, 85101, 85466, 85832, 86197, 86562, + 86927, 87293, 87658, 88023, 88388, 88754, 89119, 89484, 89849, 90215, 90580, 90945, 91310, 91676, + 92041, 92406, 92771, 93137, 93502, 93867, 94232, 94598, 94963, 95328, 95693, 96059, 96424, 96789, + 97154, 97520, 97885, 98250, 98615, 98981, 99346, 99711, 100076, 100442, 100807, 101172, 101537, 101903, + 102268, 102633, 102998, 103364, 103729, 104094, 104459, 104825, 105190, 105555, 105920, 106286, 106651, 107016, + 107381, 107747, 108112, 108477, 108842, 109208, 109573, 109938, 110303, 110669, 111034, 111399, 111764, 112130, + 112495, 112860, 113225, 113591, 113956, 114321, 114686, 115052, 115417, 115782, 116147, 116513, 116878, 117243, + 117608, 117974, 118339, 118704, 119069, 119435, 119800, 120165, 120530, 120895, 121260, 121625, 121990, 122356, + 122721, 123086, 123451, 123817, 124182, 124547, 124912, 125278, 125643, 126008, 126373, 126739, 127104, 127469, + 127834, 128200, 128565, 128930, 129295, 129661, 130026, 130391, 130756, 131122, 131487, 131852, 132217, 132583, + 132948, 133313, 133678, 134044, 134409, 134774, 135139, 135505, 135870, 136235, 136600, 136966, 137331, 137696, + 138061, 138427, 138792, 139157, 139522, 139888, 140253, 140618, 140983, 141349, 141714, 142079, 142444, 142810, + 143175, 143540, 143905, 144271, 144636, 145001, 145366, 145732, 146097, 146462, 146827, 147193, 147558, 147923, + 148288, 148654, 149019, 149384, 149749, 150115, 150480, 150845, 151210, 151576, 151941, 152306, 152671, 153037, + 153402, 153767, 154132, 154498, 154863, 155228, 155593, 155959, 156324, 156689, 157054, 157420, 157785, 158150, + 158515, 158881, 159246, 159611, 159976, 160342, 160707, 161072, 161437, 161803, 162168, 162533, 162898, 163264, + 163629, 163994, 164359, 164725, 165090, 165455, 165820, 166186, 166551, 166916, 167281, 167647, 168012, 168377, + 168742, 169108, 169473, 169838, 170203, 170569, 170934, 171299, 171664, 172030, 172395, 172760, 173125, 173491, + 173856, 174221, 174586, 174952, 175317, 175682, 176047, 176413, 176778, 177143, 177508, 177874, 178239, 178604, + 178969, 179335, 179700, 180065, 180430, 180796, 181161, 181526, 181891, 182257, 182622, 182987, 183352, 183718, + 184083, 184448, 184813, 185179, 185544, 185909, 186274, 186640, 187005, 187370, 187735, 188101, 188466, 188831, + 189196, 189562, 189927, 190292, 190657, 191023, 191388, 191753, 192118, 192484, 192849, 193214, 193579, 193944, + 194309, 194674, 195039, 195405, 195770, 196135, 196500, 196866, 197231, 197596, 197961, 198327, 198692, 199057, + 199422, 199788, 200153, 200518, 200883, 201249, 201614, 201979, 202344, 202710, 203075, 203440, 203805, 204171, + 204536, 204901, 205266, 205632, 205997, 206362, 206727, 207093, 207458, 207823, 208188, 208554, 208919, 209284, + 209649, 210015, 210380, 210745, 211110, 211476, 211841, 212206, 212571, 212937, 213302, 213667, 214032, 214398, + 214763, 215128, 215493, 215859, 216224, 216589, 216954, 217320, 217685, 218050, 218415, 218781, 219146, 219511, + 219876, 220242, 220607, 220972, 221337, 221703, 222068, 222433, 222798, 223164, 223529, 223894, 224259, 224625, + 224990, 225355, 225720, 226086, 226451, 226816, 227181, 227547, 227912, 228277, 228642, 229008, 229373, 229738, + 230103}; // ARM does not implement gmtime. This is a simple alternative implementation // based on section 4.16 @@ -682,36 +84,35 @@ zxerr_t extractTime(uint64_t time, timedata_t *date) { } MEMZERO(date, sizeof(timedata_t)); - date->tm_sec = (uint8_t) (time % 60); + date->tm_sec = (uint8_t)(time % 60); time -= date->tm_sec; time /= 60; - date->tm_min = (uint8_t) (time % 60); + date->tm_min = (uint8_t)(time % 60); time -= date->tm_min; time /= 60; - date->tm_hour = (uint8_t) (time % 24); + date->tm_hour = (uint8_t)(time % 24); time -= date->tm_hour; time /= 24; // Look up tm_year date->tm_year = 0; - const uint16_t yearLookupSize = sizeof(yearLookup)/sizeof(yearLookup[0]); + const uint16_t yearLookupSize = sizeof(yearLookup) / sizeof(yearLookup[0]); while (date->tm_year < yearLookupSize && yearLookup[date->tm_year] <= time) { date->tm_year++; } - if (date->tm_year == 0 || date->tm_year == yearLookupSize) { return zxerr_out_of_bounds; } date->tm_year--; - date->tm_day = (uint16_t) (time - yearLookup[date->tm_year] + 1); - date->tm_year = (uint16_t) (1970 + date->tm_year); + date->tm_day = (uint16_t)(time - yearLookup[date->tm_year] + 1); + date->tm_year = (uint16_t)(1970 + date->tm_year); // Get day/month - uint8_t leap = (uint8_t) (date->tm_year % 4 == 0 && (date->tm_year % 100 != 0 || date->tm_year % 400 == 0) ? 1 : 0); + uint8_t leap = (uint8_t)(date->tm_year % 4 == 0 && (date->tm_year % 100 != 0 || date->tm_year % 400 == 0) ? 1 : 0); for (date->tm_mon = 0; date->tm_mon < 12; date->tm_mon++) { uint8_t tmp = monthDays[date->tm_mon]; @@ -727,21 +128,15 @@ zxerr_t extractTime(uint64_t time, timedata_t *date) { return zxerr_ok; } -zxerr_t decodeTime(timedata_t* td, uint64_t t) { - return extractTime(t, td); -} +zxerr_t decodeTime(timedata_t *td, uint64_t t) { return extractTime(t, td); } zxerr_t printTime(char *out, uint16_t outLen, uint64_t t) { timedata_t date; CHECK_ZXERR(extractTime(t, &date)) // YYYYmmdd HH:MM:SS - snprintf(out, outLen, "%02d%s%04d %02d:%02d:%02dUTC", - date.tm_day, - date.monthName, - date.tm_year, - date.tm_hour, date.tm_min, date.tm_sec - ); + snprintf(out, outLen, "%02d%s%04d %02d:%02d:%02dUTC", date.tm_day, date.monthName, date.tm_year, date.tm_hour, + date.tm_min, date.tm_sec); return zxerr_ok; } @@ -751,17 +146,12 @@ zxerr_t printTimeSpecialFormat(char *out, uint16_t outLen, uint64_t t) { CHECK_ZXERR(extractTime(t, &date)) // YYYYmmdd HH:MM:SS - snprintf(out, outLen, "%d-%02d-%02dT%02d:%02d:%02dZ", - date.tm_year, - date.tm_mon, - date.tm_day, - date.tm_hour, date.tm_min, date.tm_sec - ); + snprintf(out, outLen, "%d-%02d-%02dT%02d:%02d:%02dZ", date.tm_year, date.tm_mon, date.tm_day, date.tm_hour, + date.tm_min, date.tm_sec); return zxerr_ok; } - #ifdef __cplusplus } #endif diff --git a/deps/ledger-zxlib/src/zxcanary.c b/deps/ledger-zxlib/src/zxcanary.c index 16394e49..6ba21b1f 100644 --- a/deps/ledger-zxlib/src/zxcanary.c +++ b/deps/ledger-zxlib/src/zxcanary.c @@ -1,26 +1,28 @@ /******************************************************************************* -* (c) 2018 - 2023 Zondax AG -* -* 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. -********************************************************************************/ + * (c) 2018 - 2023 Zondax AG + * + * 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 "zxcanary.h" -#include + #include +#include + #include "zxmacros.h" // This symbol is defined by the link script to be at the start of the stack area. extern unsigned int app_stack_canary; -#define ZONDAX_CANARY (*((volatile uint32_t*) (&app_stack_canary + sizeof(uint32_t)))) +#define ZONDAX_CANARY (*((volatile uint32_t *)(((uint8_t *)&app_stack_canary) + sizeof(uint32_t)))) #if defined(HAVE_ZONDAX_CANARY) #include "errors.h" @@ -39,7 +41,7 @@ void init_zondax_canary() { handle_stack_overflow(); } - for(uint8_t i = 0; i < sizeof(uint32_t); i++) { + for (uint8_t i = 0; i < sizeof(uint32_t); i++) { ZEMU_LOGF(50, "BYTE %d is: %x\n", i, randomNum[i]) dynamicCanary += randomNum[i] << (8 * i); } diff --git a/deps/ledger-zxlib/src/zxformat.c b/deps/ledger-zxlib/src/zxformat.c index 6066abdb..3f18fc10 100644 --- a/deps/ledger-zxlib/src/zxformat.c +++ b/deps/ledger-zxlib/src/zxformat.c @@ -1,36 +1,36 @@ /******************************************************************************* -* (c) 2020 Zondax GmbH -* -* 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. -********************************************************************************/ + * (c) 2018 - 2024 Zondax AG + * + * 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 "zxformat.h" + #include #include + #include "utf8.h" -size_t asciify(char *utf8_in_ascii_out) { - return asciify_ext(utf8_in_ascii_out, utf8_in_ascii_out); -} +size_t asciify(char *utf8_in_ascii_out) { return asciify_ext(utf8_in_ascii_out, utf8_in_ascii_out); } size_t asciify_ext(const char *utf8_in, char *ascii_only_out) { - void *p = (void *) utf8_in; + void *p = (void *)utf8_in; char *q = ascii_only_out; // utf8valid returns zero on success - while (*((char *) p) && utf8valid(p) == 0) { + while (*((char *)p) && utf8valid(p) == 0) { utf8_int32_t tmp_codepoint = 0; p = utf8codepoint(p, &tmp_codepoint); - *q = (char) ((tmp_codepoint >= 32 && tmp_codepoint <= (int32_t) 0x7F) ? tmp_codepoint : '.'); + *q = (char)((tmp_codepoint >= 32 && tmp_codepoint <= (int32_t)0x7F) ? tmp_codepoint : '.'); q++; } @@ -88,11 +88,11 @@ uint8_t intstr_to_fpstr_inplace(char *number, size_t number_max_size, uint8_t de // Now insert decimal point -// 0123456789012 <-decimal places -// abcd < numChars = 4 -// abcd < shift -// 000000000abcd < fill -// 0.00000000abcd < add decimal point + // 0123456789012 <-decimal places + // abcd < numChars = 4 + // abcd < shift + // 000000000abcd < fill + // 0.00000000abcd < add decimal point const uint16_t tmpDecimalPlaces = decimalPlaces; if (numChars < tmpDecimalPlaces + 1) { // Move to end @@ -112,11 +112,11 @@ uint8_t intstr_to_fpstr_inplace(char *number, size_t number_max_size, uint8_t de numChars = strnlen(number, number_max_size); - if (numChars > UINT8_MAX) { - // Overflow - return 0; - } - return (uint8_t) numChars; + if (numChars > UINT8_MAX) { + // Overflow + return 0; + } + return (uint8_t)numChars; } zxerr_t insertDecimalPoint(char *output, uint16_t outputLen, uint16_t decimalPlaces) { diff --git a/deps/ledger-zxlib/src/zxutils_ledger.c b/deps/ledger-zxlib/src/zxutils_ledger.c index 48006657..db00941f 100644 --- a/deps/ledger-zxlib/src/zxutils_ledger.c +++ b/deps/ledger-zxlib/src/zxutils_ledger.c @@ -1,19 +1,19 @@ -//#******************************************************************************* -//#* (c) 2021 Zondax GmbH -//#* (c) 2020 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. -//#******************************************************************************** +// #******************************************************************************* +// #* (c) 2018 - 2024 Zondax AG +// #* (c) 2020 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. +// #******************************************************************************** #include "zxutils_ledger.h" #ifndef NULL @@ -24,131 +24,130 @@ // nano S characters, in the two possible fonts: // - BAGL_FONT_OPEN_SANS_EXTRABOLD_11px, // - BAGL_FONT_OPEN_SANS_REGULAR_11px. -#define NANOS_FIRST_CHAR 0x20 -#define NANOS_LAST_CHAR 0x7F +#define NANOS_FIRST_CHAR 0x20 +#define NANOS_LAST_CHAR 0x7F // OPEN_SANS_REGULAR_11PX << 4 | OPEN_SANS_EXTRABOLD_11PX const char nanos_characters_width[96] = { - 3 << 4 | 3, /* code 0020 */ - 3 << 4 | 3, /* code 0021 */ - 4 << 4 | 6, /* code 0022 */ - 7 << 4 | 7, /* code 0023 */ - 6 << 4 | 6, /* code 0024 */ - 9 << 4 | 10, /* code 0025 */ - 8 << 4 | 9, /* code 0026 */ - 2 << 4 | 3, /* code 0027 */ - 3 << 4 | 4, /* code 0028 */ - 3 << 4 | 4, /* code 0029 */ - 6 << 4 | 6, /* code 002A */ - 6 << 4 | 6, /* code 002B */ - 3 << 4 | 3, /* code 002C */ - 4 << 4 | 4, /* code 002D */ - 3 << 4 | 3, /* code 002E */ - 4 << 4 | 5, /* code 002F */ - 6 << 4 | 8, /* code 0030 */ - 6 << 4 | 6, /* code 0031 */ - 6 << 4 | 7, /* code 0032 */ - 6 << 4 | 7, /* code 0033 */ - 8 << 4 | 8, /* code 0034 */ - 6 << 4 | 6, /* code 0035 */ - 6 << 4 | 8, /* code 0036 */ - 6 << 4 | 7, /* code 0037 */ - 6 << 4 | 8, /* code 0038 */ - 6 << 4 | 8, /* code 0039 */ - 3 << 4 | 3, /* code 003A */ - 3 << 4 | 3, /* code 003B */ - 6 << 4 | 5, /* code 003C */ - 6 << 4 | 6, /* code 003D */ - 6 << 4 | 5, /* code 003E */ - 5 << 4 | 6, /* code 003F */ - 10 << 4 | 10, /* code 0040 */ - 7 << 4 | 8, /* code 0041 */ - 7 << 4 | 7, /* code 0042 */ - 7 << 4 | 7, /* code 0043 */ - 8 << 4 | 8, /* code 0044 */ - 6 << 4 | 6, /* code 0045 */ - 6 << 4 | 6, /* code 0046 */ - 8 << 4 | 8, /* code 0047 */ - 8 << 4 | 8, /* code 0048 */ - 3 << 4 | 4, /* code 0049 */ - 4 << 4 | 5, /* code 004A */ - 7 << 4 | 8, /* code 004B */ - 6 << 4 | 6, /* code 004C */ - 10 << 4 | 11, /* code 004D */ - 8 << 4 | 9, /* code 004E */ - 9 << 4 | 9, /* code 004F */ - 7 << 4 | 7, /* code 0050 */ - 9 << 4 | 9, /* code 0051 */ - 7 << 4 | 8, /* code 0052 */ - 6 << 4 | 6, /* code 0053 */ - 7 << 4 | 6, /* code 0054 */ - 8 << 4 | 8, /* code 0055 */ - 7 << 4 | 6, /* code 0056 */ - 10 << 4 | 11, /* code 0057 */ - 6 << 4 | 8, /* code 0058 */ - 6 << 4 | 7, /* code 0059 */ - 6 << 4 | 7, /* code 005A */ - 4 << 4 | 5, /* code 005B */ - 4 << 4 | 5, /* code 005C */ - 4 << 4 | 5, /* code 005D */ - 6 << 4 | 7, /* code 005E */ - 5 << 4 | 6, /* code 005F */ - 6 << 4 | 7, /* code 0060 */ - 6 << 4 | 7, /* code 0061 */ - 7 << 4 | 7, /* code 0062 */ - 5 << 4 | 6, /* code 0063 */ - 7 << 4 | 7, /* code 0064 */ - 6 << 4 | 7, /* code 0065 */ - 5 << 4 | 6, /* code 0066 */ - 6 << 4 | 7, /* code 0067 */ - 7 << 4 | 7, /* code 0068 */ - 3 << 4 | 4, /* code 0069 */ - 4 << 4 | 5, /* code 006A */ - 6 << 4 | 7, /* code 006B */ - 3 << 4 | 4, /* code 006C */ - 10 << 4 | 10, /* code 006D */ - 7 << 4 | 7, /* code 006E */ - 7 << 4 | 7, /* code 006F */ - 7 << 4 | 7, /* code 0070 */ - 7 << 4 | 7, /* code 0071 */ - 4 << 4 | 5, /* code 0072 */ - 5 << 4 | 6, /* code 0073 */ - 4 << 4 | 5, /* code 0074 */ - 7 << 4 | 7, /* code 0075 */ - 6 << 4 | 7, /* code 0076 */ - 9 << 4 | 10, /* code 0077 */ - 6 << 4 | 7, /* code 0078 */ - 6 << 4 | 7, /* code 0079 */ - 5 << 4 | 6, /* code 007A */ - 4 << 4 | 5, /* code 007B */ - 6 << 4 | 6, /* code 007C */ - 4 << 4 | 5, /* code 007D */ - 6 << 4 | 6, /* code 007E */ - 7 << 4 | 6, /* code 007F */ + 3 << 4 | 3, /* code 0020 */ + 3 << 4 | 3, /* code 0021 */ + 4 << 4 | 6, /* code 0022 */ + 7 << 4 | 7, /* code 0023 */ + 6 << 4 | 6, /* code 0024 */ + 9 << 4 | 10, /* code 0025 */ + 8 << 4 | 9, /* code 0026 */ + 2 << 4 | 3, /* code 0027 */ + 3 << 4 | 4, /* code 0028 */ + 3 << 4 | 4, /* code 0029 */ + 6 << 4 | 6, /* code 002A */ + 6 << 4 | 6, /* code 002B */ + 3 << 4 | 3, /* code 002C */ + 4 << 4 | 4, /* code 002D */ + 3 << 4 | 3, /* code 002E */ + 4 << 4 | 5, /* code 002F */ + 6 << 4 | 8, /* code 0030 */ + 6 << 4 | 6, /* code 0031 */ + 6 << 4 | 7, /* code 0032 */ + 6 << 4 | 7, /* code 0033 */ + 8 << 4 | 8, /* code 0034 */ + 6 << 4 | 6, /* code 0035 */ + 6 << 4 | 8, /* code 0036 */ + 6 << 4 | 7, /* code 0037 */ + 6 << 4 | 8, /* code 0038 */ + 6 << 4 | 8, /* code 0039 */ + 3 << 4 | 3, /* code 003A */ + 3 << 4 | 3, /* code 003B */ + 6 << 4 | 5, /* code 003C */ + 6 << 4 | 6, /* code 003D */ + 6 << 4 | 5, /* code 003E */ + 5 << 4 | 6, /* code 003F */ + 10 << 4 | 10, /* code 0040 */ + 7 << 4 | 8, /* code 0041 */ + 7 << 4 | 7, /* code 0042 */ + 7 << 4 | 7, /* code 0043 */ + 8 << 4 | 8, /* code 0044 */ + 6 << 4 | 6, /* code 0045 */ + 6 << 4 | 6, /* code 0046 */ + 8 << 4 | 8, /* code 0047 */ + 8 << 4 | 8, /* code 0048 */ + 3 << 4 | 4, /* code 0049 */ + 4 << 4 | 5, /* code 004A */ + 7 << 4 | 8, /* code 004B */ + 6 << 4 | 6, /* code 004C */ + 10 << 4 | 11, /* code 004D */ + 8 << 4 | 9, /* code 004E */ + 9 << 4 | 9, /* code 004F */ + 7 << 4 | 7, /* code 0050 */ + 9 << 4 | 9, /* code 0051 */ + 7 << 4 | 8, /* code 0052 */ + 6 << 4 | 6, /* code 0053 */ + 7 << 4 | 6, /* code 0054 */ + 8 << 4 | 8, /* code 0055 */ + 7 << 4 | 6, /* code 0056 */ + 10 << 4 | 11, /* code 0057 */ + 6 << 4 | 8, /* code 0058 */ + 6 << 4 | 7, /* code 0059 */ + 6 << 4 | 7, /* code 005A */ + 4 << 4 | 5, /* code 005B */ + 4 << 4 | 5, /* code 005C */ + 4 << 4 | 5, /* code 005D */ + 6 << 4 | 7, /* code 005E */ + 5 << 4 | 6, /* code 005F */ + 6 << 4 | 7, /* code 0060 */ + 6 << 4 | 7, /* code 0061 */ + 7 << 4 | 7, /* code 0062 */ + 5 << 4 | 6, /* code 0063 */ + 7 << 4 | 7, /* code 0064 */ + 6 << 4 | 7, /* code 0065 */ + 5 << 4 | 6, /* code 0066 */ + 6 << 4 | 7, /* code 0067 */ + 7 << 4 | 7, /* code 0068 */ + 3 << 4 | 4, /* code 0069 */ + 4 << 4 | 5, /* code 006A */ + 6 << 4 | 7, /* code 006B */ + 3 << 4 | 4, /* code 006C */ + 10 << 4 | 10, /* code 006D */ + 7 << 4 | 7, /* code 006E */ + 7 << 4 | 7, /* code 006F */ + 7 << 4 | 7, /* code 0070 */ + 7 << 4 | 7, /* code 0071 */ + 4 << 4 | 5, /* code 0072 */ + 5 << 4 | 6, /* code 0073 */ + 4 << 4 | 5, /* code 0074 */ + 7 << 4 | 7, /* code 0075 */ + 6 << 4 | 7, /* code 0076 */ + 9 << 4 | 10, /* code 0077 */ + 6 << 4 | 7, /* code 0078 */ + 6 << 4 | 7, /* code 0079 */ + 5 << 4 | 6, /* code 007A */ + 4 << 4 | 5, /* code 007B */ + 6 << 4 | 6, /* code 007C */ + 4 << 4 | 5, /* code 007D */ + 6 << 4 | 6, /* code 007E */ + 7 << 4 | 6, /* code 007F */ }; -unsigned short zx_compute_line_width_light(const char* text, unsigned char text_length) { - char current_char; - unsigned short line_width = 0; +unsigned short zx_compute_line_width_light(const char *text, unsigned char text_length) { + char current_char; + unsigned short line_width = 0; - if(text == NULL) { - return 0xFFFF; - } + if (text == NULL) { + return 0xFFFF; + } - // We parse the characters of the input text on all the input length. - while (text_length--) { - current_char = *text; + // We parse the characters of the input text on all the input length. + while (text_length--) { + current_char = *text; - if (current_char < NANOS_FIRST_CHAR || current_char > NANOS_LAST_CHAR) { - if (current_char == '\n' || current_char == '\r') { - break; - } - } - else { - // Regular. - line_width += (nanos_characters_width[current_char - NANOS_FIRST_CHAR] >> 0x04) & 0x0F; + if (current_char < NANOS_FIRST_CHAR || current_char > NANOS_LAST_CHAR) { + if (current_char == '\n' || current_char == '\r') { + break; + } + } else { + // Regular. + line_width += (nanos_characters_width[current_char - NANOS_FIRST_CHAR] >> 0x04) & 0x0F; + } + text++; } - text++; - } - return line_width; + return line_width; } diff --git a/deps/ledger-zxlib/templates/Makefile.root b/deps/ledger-zxlib/templates/Makefile.root index 566f6073..6ce16398 100644 --- a/deps/ledger-zxlib/templates/Makefile.root +++ b/deps/ledger-zxlib/templates/Makefile.root @@ -1,5 +1,5 @@ #******************************************************************************* -#* (c) 2019 Zondax GmbH +#* (c) 2018 - 2024 Zondax AG #* #* Licensed under the Apache License, Version 2.0 (the "License"); #* you may not use this file except in compliance with the License. diff --git a/deps/ledger-zxlib/tests/asciify.cpp b/deps/ledger-zxlib/tests/asciify.cpp index f54e0a0a..ce6ca4eb 100644 --- a/deps/ledger-zxlib/tests/asciify.cpp +++ b/deps/ledger-zxlib/tests/asciify.cpp @@ -1,5 +1,5 @@ /******************************************************************************* -* (c) 2018 Zondax GmbH +* (c) 2018 - 2024 Zondax AG * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/deps/ledger-zxlib/tests/base64.cpp b/deps/ledger-zxlib/tests/base64.cpp index af9a8e55..4905aeb2 100644 --- a/deps/ledger-zxlib/tests/base64.cpp +++ b/deps/ledger-zxlib/tests/base64.cpp @@ -1,5 +1,5 @@ /******************************************************************************* -* (c) 2019 Zondax GmbH +* (c) 2018 - 2024 Zondax AG * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/deps/ledger-zxlib/tests/bech32.cpp b/deps/ledger-zxlib/tests/bech32.cpp index b11d2fee..a5161ed9 100644 --- a/deps/ledger-zxlib/tests/bech32.cpp +++ b/deps/ledger-zxlib/tests/bech32.cpp @@ -1,5 +1,5 @@ /******************************************************************************* -* (c) 2019 Zondax GmbH +* (c) 2018 - 2024 Zondax AG * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/deps/ledger-zxlib/tests/bip44path.cpp b/deps/ledger-zxlib/tests/bip44path.cpp index 807d5a6a..92639699 100644 --- a/deps/ledger-zxlib/tests/bip44path.cpp +++ b/deps/ledger-zxlib/tests/bip44path.cpp @@ -1,5 +1,5 @@ /******************************************************************************* -* (c) 2018 Zondax GmbH +* (c) 2018 - 2024 Zondax AG * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/deps/ledger-zxlib/tests/buffering_tests.cpp b/deps/ledger-zxlib/tests/buffering_tests.cpp index c7292d1b..c5ec5d99 100644 --- a/deps/ledger-zxlib/tests/buffering_tests.cpp +++ b/deps/ledger-zxlib/tests/buffering_tests.cpp @@ -1,5 +1,5 @@ /******************************************************************************* -* (c) 2018 Zondax GmbH +* (c) 2018 - 2024 Zondax AG * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/deps/ledger-zxlib/tests/doubledabble.cpp b/deps/ledger-zxlib/tests/doubledabble.cpp index 4b7b0488..8d3f20b3 100644 --- a/deps/ledger-zxlib/tests/doubledabble.cpp +++ b/deps/ledger-zxlib/tests/doubledabble.cpp @@ -1,5 +1,5 @@ /******************************************************************************* -* (c) 2019 Zondax GmbH +* (c) 2018 - 2024 Zondax AG * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/deps/ledger-zxlib/tests/hexutils.cpp b/deps/ledger-zxlib/tests/hexutils.cpp index e9d3ae4c..8baa826c 100644 --- a/deps/ledger-zxlib/tests/hexutils.cpp +++ b/deps/ledger-zxlib/tests/hexutils.cpp @@ -1,5 +1,5 @@ /******************************************************************************* -* (c) 2018 Zondax GmbH +* (c) 2018 - 2024 Zondax AG * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/deps/ledger-zxlib/tests/macros.cpp b/deps/ledger-zxlib/tests/macros.cpp index a4a2e862..bbd2b8f6 100644 --- a/deps/ledger-zxlib/tests/macros.cpp +++ b/deps/ledger-zxlib/tests/macros.cpp @@ -1,5 +1,5 @@ /******************************************************************************* -* (c) 2018 Zondax GmbH +* (c) 2018 - 2024 Zondax AG * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -324,6 +324,40 @@ namespace { EXPECT_EQ(std::string(number), "12.34567"); } + TEST(UINT32_TO_STR, Zero) { + char temp[10]; + const char *error = uint32_to_str(temp, sizeof(temp), uint32_t(0)); + EXPECT_STREQ(temp, "0"); + EXPECT_TRUE(error == nullptr); + } + + TEST(UINT32_TO_STR, Positive_1234) { + char temp[10]; + const char *error = uint32_to_str(temp, sizeof(temp), uint32_t(1234)); + EXPECT_STREQ(temp, "1234"); + EXPECT_TRUE(error == nullptr); + } + + TEST(UINT32_TO_STR, TooSmall_0) { + char temp[1]; + const char *error = uint32_to_str(temp, sizeof(temp), uint32_t(0)); + EXPECT_STREQ("Buffer too small", error); + } + + TEST(UINT32_TO_STR, FitsJust) { + char temp[4]; + const char *error = uint32_to_str(temp, sizeof(temp), uint32_t(999)); + EXPECT_STREQ(temp, "999"); + EXPECT_TRUE(error == nullptr); + } + + TEST(UINT32_TO_STR, Max) { + char temp[20]; + const char *error = uint32_to_str(temp, sizeof(temp), std::numeric_limits::max()); + EXPECT_STREQ(temp, "4294967295"); + EXPECT_TRUE(error == nullptr); + } + TEST(INT64_TO_STR, Zero) { char temp[10]; const char *error = int64_to_str(temp, sizeof(temp), int64_t(0)); diff --git a/deps/ledger-zxlib/tests/sigutils.cpp b/deps/ledger-zxlib/tests/sigutils.cpp index 21fde60c..77d2c904 100644 --- a/deps/ledger-zxlib/tests/sigutils.cpp +++ b/deps/ledger-zxlib/tests/sigutils.cpp @@ -1,5 +1,5 @@ /******************************************************************************* -* (c) 2020 Zondax GmbH +* (c) 2018 - 2024 Zondax AG * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/deps/ledger-zxlib/tests/zxformat.cpp b/deps/ledger-zxlib/tests/zxformat.cpp index af65eb3c..2e5f8787 100644 --- a/deps/ledger-zxlib/tests/zxformat.cpp +++ b/deps/ledger-zxlib/tests/zxformat.cpp @@ -1,5 +1,5 @@ /******************************************************************************* -* (c) 2018 Zondax GmbH +* (c) 2018 - 2024 Zondax AG * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/tests/snapshots/flex/test_app_mainmenu/part0/00001.png b/tests/snapshots/flex/test_app_mainmenu/part0/00001.png index 599332a7..454309f4 100644 Binary files a/tests/snapshots/flex/test_app_mainmenu/part0/00001.png and b/tests/snapshots/flex/test_app_mainmenu/part0/00001.png differ diff --git a/tests/snapshots/flex/test_app_mainmenu/part0/00002.png b/tests/snapshots/flex/test_app_mainmenu/part0/00002.png index 53597b43..7b6422f4 100644 Binary files a/tests/snapshots/flex/test_app_mainmenu/part0/00002.png and b/tests/snapshots/flex/test_app_mainmenu/part0/00002.png differ diff --git a/tests/snapshots/flex/test_app_mainmenu/part0/00003.png b/tests/snapshots/flex/test_app_mainmenu/part0/00003.png index b6fde3aa..5522de53 100644 Binary files a/tests/snapshots/flex/test_app_mainmenu/part0/00003.png and b/tests/snapshots/flex/test_app_mainmenu/part0/00003.png differ diff --git a/tests/snapshots/flex/test_arbitrary_transaction_signing_expert/part0/00001.png b/tests/snapshots/flex/test_arbitrary_transaction_signing_expert/part0/00001.png index 599332a7..454309f4 100644 Binary files a/tests/snapshots/flex/test_arbitrary_transaction_signing_expert/part0/00001.png and b/tests/snapshots/flex/test_arbitrary_transaction_signing_expert/part0/00001.png differ diff --git a/tests/snapshots/flex/test_arbitrary_transaction_signing_expert/part0/00002.png b/tests/snapshots/flex/test_arbitrary_transaction_signing_expert/part0/00002.png index b6873297..6e3c43a4 100644 Binary files a/tests/snapshots/flex/test_arbitrary_transaction_signing_expert/part0/00002.png and b/tests/snapshots/flex/test_arbitrary_transaction_signing_expert/part0/00002.png differ diff --git a/tests/snapshots/flex/test_get_public_key_expert/00001.png b/tests/snapshots/flex/test_get_public_key_expert/00001.png index 599332a7..454309f4 100644 Binary files a/tests/snapshots/flex/test_get_public_key_expert/00001.png and b/tests/snapshots/flex/test_get_public_key_expert/00001.png differ diff --git a/tests/snapshots/flex/test_get_public_key_expert/00002.png b/tests/snapshots/flex/test_get_public_key_expert/00002.png index b6873297..6e3c43a4 100644 Binary files a/tests/snapshots/flex/test_get_public_key_expert/00002.png and b/tests/snapshots/flex/test_get_public_key_expert/00002.png differ diff --git a/tests/snapshots/flex/test_message_normal/part1/00001.png b/tests/snapshots/flex/test_message_normal/part1/00001.png index 599332a7..454309f4 100644 Binary files a/tests/snapshots/flex/test_message_normal/part1/00001.png and b/tests/snapshots/flex/test_message_normal/part1/00001.png differ diff --git a/tests/snapshots/flex/test_message_normal/part1/00002.png b/tests/snapshots/flex/test_message_normal/part1/00002.png index b6873297..6e3c43a4 100644 Binary files a/tests/snapshots/flex/test_message_normal/part1/00002.png and b/tests/snapshots/flex/test_message_normal/part1/00002.png differ diff --git a/tests/snapshots/flex/test_message_normal/part5/00001.png b/tests/snapshots/flex/test_message_normal/part5/00001.png index b6873297..6e3c43a4 100644 Binary files a/tests/snapshots/flex/test_message_normal/part5/00001.png and b/tests/snapshots/flex/test_message_normal/part5/00001.png differ diff --git a/tests/snapshots/flex/test_message_normal/part5/00002.png b/tests/snapshots/flex/test_message_normal/part5/00002.png index 599332a7..454309f4 100644 Binary files a/tests/snapshots/flex/test_message_normal/part5/00002.png and b/tests/snapshots/flex/test_message_normal/part5/00002.png differ diff --git a/tests/snapshots/flex/test_transaction_expert/part0/00001.png b/tests/snapshots/flex/test_transaction_expert/part0/00001.png index 599332a7..454309f4 100644 Binary files a/tests/snapshots/flex/test_transaction_expert/part0/00001.png and b/tests/snapshots/flex/test_transaction_expert/part0/00001.png differ diff --git a/tests/snapshots/flex/test_transaction_expert/part0/00002.png b/tests/snapshots/flex/test_transaction_expert/part0/00002.png index b6873297..6e3c43a4 100644 Binary files a/tests/snapshots/flex/test_transaction_expert/part0/00002.png and b/tests/snapshots/flex/test_transaction_expert/part0/00002.png differ diff --git a/tests/snapshots/stax/test_app_mainmenu/part0/00001.png b/tests/snapshots/stax/test_app_mainmenu/part0/00001.png index 5804b118..76ec19f3 100644 Binary files a/tests/snapshots/stax/test_app_mainmenu/part0/00001.png and b/tests/snapshots/stax/test_app_mainmenu/part0/00001.png differ diff --git a/tests/snapshots/stax/test_app_mainmenu/part0/00002.png b/tests/snapshots/stax/test_app_mainmenu/part0/00002.png index 3d3d784e..cde6547a 100644 Binary files a/tests/snapshots/stax/test_app_mainmenu/part0/00002.png and b/tests/snapshots/stax/test_app_mainmenu/part0/00002.png differ diff --git a/tests/snapshots/stax/test_app_mainmenu/part0/00003.png b/tests/snapshots/stax/test_app_mainmenu/part0/00003.png index f695dd51..3f20b1d5 100644 Binary files a/tests/snapshots/stax/test_app_mainmenu/part0/00003.png and b/tests/snapshots/stax/test_app_mainmenu/part0/00003.png differ diff --git a/tests/snapshots/stax/test_arbitrary_transaction_signing_expert/part0/00001.png b/tests/snapshots/stax/test_arbitrary_transaction_signing_expert/part0/00001.png index 5804b118..76ec19f3 100644 Binary files a/tests/snapshots/stax/test_arbitrary_transaction_signing_expert/part0/00001.png and b/tests/snapshots/stax/test_arbitrary_transaction_signing_expert/part0/00001.png differ diff --git a/tests/snapshots/stax/test_arbitrary_transaction_signing_expert/part0/00002.png b/tests/snapshots/stax/test_arbitrary_transaction_signing_expert/part0/00002.png index 5ab2885f..a100e217 100644 Binary files a/tests/snapshots/stax/test_arbitrary_transaction_signing_expert/part0/00002.png and b/tests/snapshots/stax/test_arbitrary_transaction_signing_expert/part0/00002.png differ diff --git a/tests/snapshots/stax/test_get_public_key_expert/00001.png b/tests/snapshots/stax/test_get_public_key_expert/00001.png index 5804b118..76ec19f3 100644 Binary files a/tests/snapshots/stax/test_get_public_key_expert/00001.png and b/tests/snapshots/stax/test_get_public_key_expert/00001.png differ diff --git a/tests/snapshots/stax/test_get_public_key_expert/00002.png b/tests/snapshots/stax/test_get_public_key_expert/00002.png index 5ab2885f..a100e217 100644 Binary files a/tests/snapshots/stax/test_get_public_key_expert/00002.png and b/tests/snapshots/stax/test_get_public_key_expert/00002.png differ diff --git a/tests/snapshots/stax/test_message_normal/part1/00001.png b/tests/snapshots/stax/test_message_normal/part1/00001.png index 5804b118..76ec19f3 100644 Binary files a/tests/snapshots/stax/test_message_normal/part1/00001.png and b/tests/snapshots/stax/test_message_normal/part1/00001.png differ diff --git a/tests/snapshots/stax/test_message_normal/part1/00002.png b/tests/snapshots/stax/test_message_normal/part1/00002.png index 5ab2885f..a100e217 100644 Binary files a/tests/snapshots/stax/test_message_normal/part1/00002.png and b/tests/snapshots/stax/test_message_normal/part1/00002.png differ diff --git a/tests/snapshots/stax/test_message_normal/part5/00001.png b/tests/snapshots/stax/test_message_normal/part5/00001.png index 5ab2885f..a100e217 100644 Binary files a/tests/snapshots/stax/test_message_normal/part5/00001.png and b/tests/snapshots/stax/test_message_normal/part5/00001.png differ diff --git a/tests/snapshots/stax/test_message_normal/part5/00002.png b/tests/snapshots/stax/test_message_normal/part5/00002.png index 5804b118..76ec19f3 100644 Binary files a/tests/snapshots/stax/test_message_normal/part5/00002.png and b/tests/snapshots/stax/test_message_normal/part5/00002.png differ diff --git a/tests/snapshots/stax/test_transaction_expert/part0/00001.png b/tests/snapshots/stax/test_transaction_expert/part0/00001.png index 5804b118..76ec19f3 100644 Binary files a/tests/snapshots/stax/test_transaction_expert/part0/00001.png and b/tests/snapshots/stax/test_transaction_expert/part0/00001.png differ diff --git a/tests/snapshots/stax/test_transaction_expert/part0/00002.png b/tests/snapshots/stax/test_transaction_expert/part0/00002.png index 5ab2885f..a100e217 100644 Binary files a/tests/snapshots/stax/test_transaction_expert/part0/00002.png and b/tests/snapshots/stax/test_transaction_expert/part0/00002.png differ