Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Update to SDK 2.0 #80

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev/sdk/nanos-secure-sdk
Submodule nanos-secure-sdk updated 249 files
4 changes: 2 additions & 2 deletions src/chars_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
5 changes: 3 additions & 2 deletions src/iota/addresses.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <string.h>
#include "iota/addresses.h"
#include "iota/conversion.h"
#include "iota/iota_types.h"
Expand All @@ -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);

Expand Down Expand Up @@ -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);
}
10 changes: 5 additions & 5 deletions src/iota/bundle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down
7 changes: 4 additions & 3 deletions src/iota/conversion.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "iota/conversion.h"
#include <limits.h>
#include <stdint.h>
#include <string.h>
#include "iota/iota_types.h"
#include "os.h"

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/iota/kerl.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "iota/kerl.h"
#include <stddef.h>
#include <string.h>
#include "iota/conversion.h"
#include "os.h"

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/iota/kerl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions src/iota/signing.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <string.h>
#include "iota/signing.h"
#include "iota/bundle.h"
#include "iota/conversion.h"
Expand All @@ -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.
Expand All @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions src/iota_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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;
Expand Down Expand Up @@ -56,15 +57,15 @@ 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)
{
if (ms == 0) {
THROW_PARAMETER("ms");
}
UX_CALLBACK_SET_INTERVAL(ms);
// UX_CALLBACK_SET_INTERVAL(ms);
}

void io_timeout_callback(const bool ux_allowed)
Expand Down
2 changes: 1 addition & 1 deletion src/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
13 changes: 7 additions & 6 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <stddef.h>
#include <stdint.h>
#include "api.h"
#include "bolos_target.h"
#include "iota_io.h"
#include "macros.h"
#include "os.h"
Expand All @@ -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
Expand Down Expand Up @@ -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]) {
Expand All @@ -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:
Expand Down
14 changes: 7 additions & 7 deletions src/ui/blue/blue_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,21 @@ 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()
{
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();
}
}

Expand All @@ -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();
}
}

Expand All @@ -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()
Expand All @@ -87,7 +87,7 @@ void ui_sign_tx()
void ui_reset()
{
ui_display_main_menu();
ui_force_draw();
UX_WAIT_DISPLAYED();
}

void ui_restore()
Expand All @@ -103,7 +103,7 @@ void ui_restore()
ui_display_main_menu();
break;
}
ui_force_draw();
UX_WAIT_DISPLAYED();
}

#endif // TARGET_BLUE
6 changes: 3 additions & 3 deletions src/ui/blue/blue_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading