diff --git a/dev/sdk/nanos-secure-sdk b/dev/sdk/nanos-secure-sdk index e3293938..1a20ae6b 160000 --- a/dev/sdk/nanos-secure-sdk +++ b/dev/sdk/nanos-secure-sdk @@ -1 +1 @@ -Subproject commit e3293938e5988e1ffa05d1f2ba23db431275f21c +Subproject commit 1a20ae6b83329c6c0107eec0a3002a199355abbb diff --git a/src/chars_utils.c b/src/chars_utils.c index 25c444ce..4b5e51cc 100644 --- a/src/chars_utils.c +++ b/src/chars_utils.c @@ -30,6 +30,6 @@ void rpad_chars(char *destination, const char *source, const unsigned int num_chars) { const size_t len = strnlen(source, num_chars); - os_memcpy(destination, source, len); - os_memset(destination + len, PAD_CHAR, num_chars - len); + memcpy(destination, source, len); + memset(destination + len, PAD_CHAR, num_chars - len); } diff --git a/src/iota/addresses.c b/src/iota/addresses.c index e16b4be9..5cd1cafb 100644 --- a/src/iota/addresses.c +++ b/src/iota/addresses.c @@ -1,3 +1,4 @@ +#include #include "iota/addresses.h" #include "iota/conversion.h" #include "iota/iota_types.h" @@ -24,7 +25,7 @@ static void init_shas(const unsigned char *seed_bytes, uint32_t idx, unsigned char *buffer) { // use temp bigint so seed not destroyed - os_memcpy(buffer, seed_bytes, NUM_HASH_BYTES); + memcpy(buffer, seed_bytes, NUM_HASH_BYTES); bytes_add_u32_mem(buffer, idx); @@ -101,7 +102,7 @@ void get_address_with_checksum(const unsigned char *address_bytes, bytes_to_chars(address_bytes, full_address, NUM_HASH_BYTES); - os_memcpy(full_address + NUM_HASH_TRYTES, + memcpy(full_address + NUM_HASH_TRYTES, full_checksum + NUM_HASH_TRYTES - NUM_CHECKSUM_TRYTES, NUM_CHECKSUM_TRYTES); } diff --git a/src/iota/bundle.c b/src/iota/bundle.c index dbfa15d2..c7a4caf2 100644 --- a/src/iota/bundle.c +++ b/src/iota/bundle.c @@ -21,7 +21,7 @@ void bundle_initialize(BUNDLE_CTX *ctx, const uint8_t last_tx_index) THROW_PARAMETER("last_tx_index"); } - os_memset(ctx, 0, sizeof(BUNDLE_CTX)); + memset(ctx, 0, sizeof(BUNDLE_CTX)); ctx->bundle.last_tx_index = last_tx_index; } @@ -167,7 +167,7 @@ static bool validate_address(const unsigned char *addr_bytes, unsigned char expected_addr_bytes[NUM_HASH_BYTES]; get_public_addr(seed_bytes, idx, security, expected_addr_bytes); - return (os_memcmp(addr_bytes, expected_addr_bytes, NUM_HASH_BYTES) == 0); + return (memcmp(addr_bytes, expected_addr_bytes, NUM_HASH_BYTES) == 0); } /** @return Whether all values sum up to zero. */ @@ -195,7 +195,7 @@ static bool has_valid_meta_txs(const BUNDLE_CTX *ctx, const uint8_t security, return false; } // and have the same address - if (os_memcmp(input_addr_bytes, bundle_get_address_bytes(ctx, index), + if (memcmp(input_addr_bytes, bundle_get_address_bytes(ctx, index), NUM_HASH_BYTES) != 0) { return false; } @@ -277,7 +277,7 @@ static bool validate_address_reuse(const BUNDLE_CTX *ctx) for (uint8_t j = i + 1; j <= ctx->bundle.last_tx_index; j++) { if (ctx->bundle.values[j] != 0 && - os_memcmp(addr_bytes, bundle_get_address_bytes(ctx, j), + memcmp(addr_bytes, bundle_get_address_bytes(ctx, j), NUM_HASH_BYTES) == 0) { return false; } @@ -349,7 +349,7 @@ int bundle_validating_finalize(BUNDLE_CTX *ctx, uint8_t change_tx_index, compute_hash(ctx); if (!validate_hash(ctx, security)) { // if the hash is invalid, reset it to zero - os_memset(ctx->hash, 0, NUM_HASH_BYTES); + memset(ctx->hash, 0, NUM_HASH_BYTES); return UNSECURE_HASH; } diff --git a/src/iota/conversion.c b/src/iota/conversion.c index 4915ad26..ddd93efc 100644 --- a/src/iota/conversion.c +++ b/src/iota/conversion.c @@ -1,6 +1,7 @@ #include "iota/conversion.h" #include #include +#include #include "iota/iota_types.h" #include "os.h" @@ -250,7 +251,7 @@ static void trytes_to_bigint(const tryte_t *trytes, uint32_t *bigint) { // initialy there is no non-zero word unsigned int ms_index = 0; - os_memset(bigint, 0, BIGINT_LENGTH * sizeof(bigint[0])); + memset(bigint, 0, BIGINT_LENGTH * sizeof(bigint[0])); // special case for the last tryte only holding two trits of value bigint[0] = tryte_set_last_trit_zero(trytes[NUM_CHUNK_TRYTES - 1]) + 4; @@ -358,7 +359,7 @@ void chars_to_trits(const char *chars, trit_t *trits, unsigned int chars_len) bool s64_to_trits(const int64_t value, trit_t *trits, unsigned int num_trits) { - os_memset(trits, 0, num_trits); + memset(trits, 0, num_trits); // nothing to compute for zero value if (value == 0) { @@ -400,7 +401,7 @@ bool s64_to_trits(const int64_t value, trit_t *trits, unsigned int num_trits) bool u32_to_trits(const uint32_t value, trit_t *trits, unsigned int num_trits) { uint32_t v = value; - os_memset(trits, 0, num_trits); + memset(trits, 0, num_trits); for (unsigned int i = 0; i < num_trits; i++) { if (v == 0) { diff --git a/src/iota/kerl.c b/src/iota/kerl.c index ae205bf9..8efefc59 100644 --- a/src/iota/kerl.c +++ b/src/iota/kerl.c @@ -1,5 +1,6 @@ #include "iota/kerl.h" #include +#include #include "iota/conversion.h" #include "os.h" @@ -60,7 +61,7 @@ void kerl_state_squeeze_chunk(cx_sha3_t *sha3, unsigned char *state_bytes, cx_hash((cx_hash_t *)sha3, CX_LAST, state_bytes, 0, state_bytes, KERL_HASH_SIZE); - os_memcpy(bytes, state_bytes, KERL_HASH_SIZE); + memcpy(bytes, state_bytes, KERL_HASH_SIZE); bytes_set_last_trit_zero(bytes); // flip bytes for multiple squeeze diff --git a/src/iota/kerl.h b/src/iota/kerl.h index ed2ad427..1d8dee57 100644 --- a/src/iota/kerl.h +++ b/src/iota/kerl.h @@ -6,6 +6,7 @@ #define KERL_H #include "os.h" +#include "cx.h" /// Size of the kerl hash in bytes. #define KERL_HASH_SIZE (CX_SHA384_SIZE) diff --git a/src/iota/signing.c b/src/iota/signing.c index 3676da29..040998f1 100644 --- a/src/iota/signing.c +++ b/src/iota/signing.c @@ -1,3 +1,4 @@ +#include #include "iota/signing.h" #include "iota/bundle.h" #include "iota/conversion.h" @@ -10,8 +11,8 @@ void signing_initialize(SIGNING_CTX *ctx, const BUNDLE_INFO *bundle_info, const tryte_t *normalized_hash) { // source and destination can potentially overlap - os_memmove(&ctx->bundle, bundle_info, sizeof(BUNDLE_INFO)); - os_memcpy(ctx->hash, normalized_hash, NUM_HASH_TRYTES); + memmove(&ctx->bundle, bundle_info, sizeof(BUNDLE_INFO)); + memcpy(ctx->hash, normalized_hash, NUM_HASH_TRYTES); } /// Returns the total number of signature fragments. @@ -25,7 +26,7 @@ static uint8_t num_fragments(const uint8_t security) static void initialize_state(const unsigned char *seed_bytes, uint32_t address_idx, unsigned char *state) { - os_memcpy(state, seed_bytes, NUM_HASH_BYTES); + memcpy(state, seed_bytes, NUM_HASH_BYTES); bytes_add_u32_mem(state, address_idx); cx_sha3_t sha; diff --git a/src/iota_io.c b/src/iota_io.c index 3d4dc54f..974f2770 100644 --- a/src/iota_io.c +++ b/src/iota_io.c @@ -3,12 +3,13 @@ #include "macros.h" #include "os.h" #include "os_io_seproxyhal.h" +#include "ui/ui.h" extern unsigned char G_io_apdu_buffer[IO_APDU_BUFFER_SIZE]; void io_initialize() { - os_memset(G_io_apdu_buffer, 0, IO_APDU_BUFFER_SIZE); + memset(G_io_apdu_buffer, 0, IO_APDU_BUFFER_SIZE); api_initialize(); io_timeout_reset(); } @@ -19,7 +20,7 @@ void io_send(const void *ptr, unsigned int length, unsigned short sw) THROW_PARAMETER("length"); } - os_memcpy(G_io_apdu_buffer, ptr, length); + memcpy(G_io_apdu_buffer, ptr, length); G_io_apdu_buffer[length++] = sw >> 8; G_io_apdu_buffer[length++] = sw >> 0; @@ -56,7 +57,7 @@ unsigned int iota_dispatch(const uint8_t ins, const uint8_t p1, void io_timeout_reset() { - UX_CALLBACK_SET_INTERVAL(0); + // UX_CALLBACK_SET_INTERVAL(0); } void io_timeout_set(const unsigned int ms) @@ -64,7 +65,7 @@ void io_timeout_set(const unsigned int ms) if (ms == 0) { THROW_PARAMETER("ms"); } - UX_CALLBACK_SET_INTERVAL(ms); + // UX_CALLBACK_SET_INTERVAL(ms); } void io_timeout_callback(const bool ux_allowed) diff --git a/src/macros.h b/src/macros.h index 04136a72..74ec08d0 100644 --- a/src/macros.h +++ b/src/macros.h @@ -9,7 +9,7 @@ #define AS_STRING(x) AS_STRING_INTERNAL(x) #define AS_STRING_INTERNAL(x) #x -#define MEMCLEAR(x) os_memset(&(x), 0, sizeof(x)) +#define MEMCLEAR(x) memset(&(x), 0, sizeof(x)) /// Devide x by y and round up. #define CEILING(x, y) \ diff --git a/src/main.c b/src/main.c index 3b691c92..c5acde84 100644 --- a/src/main.c +++ b/src/main.c @@ -2,6 +2,7 @@ #include #include #include "api.h" +#include "bolos_target.h" #include "iota_io.h" #include "macros.h" #include "os.h" @@ -10,12 +11,14 @@ #include "seproxyhal_protocol.h" #include "ui/ui.h" +#ifndef TARGET_BLUE +#include "ux.h" +#endif + // define global SDK variables unsigned char G_io_seproxyhal_spi_buffer[IO_SEPROXYHAL_BUFFER_SIZE_B]; #ifdef TARGET_NANOX -#include "ux.h" - ux_state_t G_ux; bolos_ux_params_t G_ux_params; #else // NANOS/BLUE @@ -162,8 +165,7 @@ void io_seproxyhal_display(const bagl_element_t *element) unsigned char io_event(unsigned char channel) { - // nothing done with the event, throw an error on the transport layer if - // needed + UNUSED(channel); // can't have more than one tag in the reply, not supported yet. switch (G_io_seproxyhal_spi_buffer[0]) { @@ -180,8 +182,7 @@ unsigned char io_event(unsigned char channel) break; case SEPROXYHAL_TAG_TICKER_EVENT: - UX_TICKER_EVENT(G_io_seproxyhal_spi_buffer, - { io_timeout_callback(UX_ALLOWED); }); + UX_TICKER_EVENT(G_io_seproxyhal_spi_buffer, {}); break; default: diff --git a/src/ui/blue/blue_core.c b/src/ui/blue/blue_core.c index 847ffa3b..8da4edad 100644 --- a/src/ui/blue/blue_core.c +++ b/src/ui/blue/blue_core.c @@ -38,13 +38,13 @@ void ui_display_main_menu() void ui_display_getting_addr() { UX_DISPLAY(bagl_ui_generating_addr, NULL); - ui_force_draw(); + UX_WAIT_DISPLAYED(); } void ui_display_validating() { UX_DISPLAY(bagl_ui_validating, NULL); - ui_force_draw(); + UX_WAIT_DISPLAYED(); } void ui_display_recv() @@ -52,7 +52,7 @@ void ui_display_recv() if (blue_ui_state.state != STATE_RECV) { blue_ui_state.state = STATE_RECV; UX_DISPLAY(bagl_ui_receiving_tx, NULL); - ui_force_draw(); + UX_WAIT_DISPLAYED(); } } @@ -61,7 +61,7 @@ void ui_display_signing() if (blue_ui_state.state != STATE_SIGN) { blue_ui_state.state = STATE_SIGN; UX_DISPLAY(bagl_ui_signing_tx, NULL); - ui_force_draw(); + UX_WAIT_DISPLAYED(); } } @@ -70,7 +70,7 @@ void ui_display_address(const unsigned char *addr_bytes) get_address_with_checksum(addr_bytes, blue_ui_state.addr); break_address(); UX_DISPLAY(bagl_ui_disp_addr, NULL); - ui_force_draw(); + UX_WAIT_DISPLAYED(); } void ui_sign_tx() @@ -87,7 +87,7 @@ void ui_sign_tx() void ui_reset() { ui_display_main_menu(); - ui_force_draw(); + UX_WAIT_DISPLAYED(); } void ui_restore() @@ -103,7 +103,7 @@ void ui_restore() ui_display_main_menu(); break; } - ui_force_draw(); + UX_WAIT_DISPLAYED(); } #endif // TARGET_BLUE diff --git a/src/ui/blue/blue_misc.c b/src/ui/blue/blue_misc.c index b7d6fba6..f8079f83 100644 --- a/src/ui/blue/blue_misc.c +++ b/src/ui/blue/blue_misc.c @@ -57,19 +57,19 @@ void update_tx_type() // first tx is output if (blue_ui_state.menu_idx == 0) { - os_memcpy(blue_ui_state.tx_type, "Output:\0", TX_TYPE_SPLIT); + memcpy(blue_ui_state.tx_type, "Output:\0", TX_TYPE_SPLIT); } else { // Negative val is input, positive is change if (blue_ui_state.val < 0) { - os_memcpy(blue_ui_state.tx_type, "Input: \0", TX_TYPE_SPLIT); + memcpy(blue_ui_state.tx_type, "Input: \0", TX_TYPE_SPLIT); snprintf(&blue_ui_state.tx_type[TX_TYPE_SPLIT], TEXT_LEN_TX_TYPE - TX_TYPE_SPLIT, "Idx: %u", (unsigned int)api.ctx.bundle.bundle .indices[ui_state_get_tx_index()]); } else { - os_memcpy(blue_ui_state.tx_type, "Change:\0", TX_TYPE_SPLIT); + memcpy(blue_ui_state.tx_type, "Change:\0", TX_TYPE_SPLIT); snprintf(&blue_ui_state.tx_type[TX_TYPE_SPLIT], TEXT_LEN_TX_TYPE - TX_TYPE_SPLIT, "Idx: %u", (unsigned int)api.ctx.bundle.bundle diff --git a/src/ui/nano/nano_core.c b/src/ui/nano/nano_core.c index 96ccc540..c68b592f 100644 --- a/src/ui/nano/nano_core.c +++ b/src/ui/nano/nano_core.c @@ -60,6 +60,11 @@ static void nano_display(void) UX_DISPLAY(bagl_ui_omega_screen, element_preprocessor); } +static void nano_wait_displayed() +{ + UX_WAIT_DISPLAYED() +} + static void nano_draw_state(void) { switch (ui_state.state) { @@ -138,7 +143,7 @@ void ui_display_getting_addr() nano_draw_getting_addr(); nano_display(); - ui_force_draw(); + nano_wait_displayed(); } void ui_display_validating() @@ -147,7 +152,7 @@ void ui_display_validating() nano_draw_validating(); nano_display(); - ui_force_draw(); + nano_wait_displayed(); } void ui_display_recv() @@ -156,7 +161,7 @@ void ui_display_recv() nano_draw_receiving(); nano_display(); - ui_force_draw(); + nano_wait_displayed(); } void ui_display_signing() @@ -165,17 +170,17 @@ void ui_display_signing() nano_draw_signing(); nano_display(); - ui_force_draw(); + nano_wait_displayed(); } void ui_display_address(const unsigned char *addr_bytes) { // write the address trytes into the UI state - os_memcpy(ui_state.buffer.addr_bytes, addr_bytes, NUM_HASH_TRYTES); + memcpy(ui_state.buffer.addr_bytes, addr_bytes, NUM_HASH_TRYTES); set_and_draw_state(STATE_ADDRESS_DIGEST); nano_display(); - ui_force_draw(); + nano_wait_displayed(); } void ui_sign_tx() @@ -188,7 +193,7 @@ void ui_reset() { set_and_draw_state(STATE_MAIN_MENU); nano_display(); - ui_force_draw(); + nano_wait_displayed(); } void ui_restore() @@ -197,7 +202,7 @@ void ui_restore() nano_draw_state(); nano_display(); - ui_force_draw(); + nano_wait_displayed(); } static UI_BUTTON_PRESS translate_button_mask(const unsigned int button_mask) diff --git a/src/ui/nano/nano_draw.c b/src/ui/nano/nano_draw.c index ed762ec3..87106814 100644 --- a/src/ui/nano/nano_draw.c +++ b/src/ui/nano/nano_draw.c @@ -1,6 +1,7 @@ #include "ui/nano/nano_draw.h" #include #include +#include #include "api.h" #include "iota/addresses.h" #include "iota/bundle.h" @@ -297,7 +298,7 @@ static void nano_draw_bundle_address(void) // buffer the address of the current transaction const unsigned char *addr_bytes = bundle_get_address_bytes(&api.ctx.bundle, ui_state_get_tx_index()); - os_memcpy(ui_state.buffer.addr_bytes, addr_bytes, NUM_HASH_BYTES); + memcpy(ui_state.buffer.addr_bytes, addr_bytes, NUM_HASH_BYTES); nano_draw_address_digest(); } diff --git a/src/ui/nano/nano_screens.h b/src/ui/nano/nano_screens.h index 54bfa6d6..772090dc 100644 --- a/src/ui/nano/nano_screens.h +++ b/src/ui/nano/nano_screens.h @@ -2,6 +2,7 @@ #define S_SCREENS_H #include "glyphs.h" +#include "ux.h" #ifdef TARGET_NANOS diff --git a/src/ui/ui.c b/src/ui/ui.c deleted file mode 100644 index 844624cc..00000000 --- a/src/ui/ui.c +++ /dev/null @@ -1,25 +0,0 @@ -#include "ui/ui.h" -#include -#include "os_io_seproxyhal.h" - -#define WAIT_EVENT() \ - io_seproxyhal_spi_recv(G_io_seproxyhal_spi_buffer, \ - sizeof(G_io_seproxyhal_spi_buffer), 0) - -void ui_force_draw() -{ - bool display_event_occurred = false; - - while (!UX_DISPLAYED()) { - UX_DISPLAY_NEXT_ELEMENT(); - WAIT_EVENT(); - display_event_occurred = true; - } - - // this is only necessary, if anything has actually been displayed - if (display_event_occurred) { - // if everything is in the buffer, the next general status renders it - io_seproxyhal_general_status(); - WAIT_EVENT(); - } -} diff --git a/src/ui/ui.h b/src/ui/ui.h index 2ec733a1..8f5dd7a3 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -1,9 +1,6 @@ #ifndef UI_H #define UI_H -/// Displays the current screen without sending an APDU message. -void ui_force_draw(void); - // the following implementation are different for Blue and Nano void ui_init(void); void ui_display_main_menu(void); diff --git a/tests b/tests index 901875cb..72dfd97c 160000 --- a/tests +++ b/tests @@ -1 +1 @@ -Subproject commit 901875cbcb05d6a962951da5f8b82e805f57e8f2 +Subproject commit 72dfd97cdd4d2b7e7271f7b6b19ea858ac63feda