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

First signature after confirmation should return #5

Merged
merged 1 commit into from Feb 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -31,7 +31,7 @@ include $(BOLOS_SDK)/Makefile.defines
APPNAME = "Tendermint"
APPVERSION_M=0
APPVERSION_N=5
APPVERSION_P=0
APPVERSION_P=1

APP_LOAD_PARAMS = --appFlags 0x00 --delete $(COMMON_LOAD_PARAMS) --path "44'/118'"
ICONNAME=$(CURDIR)/icon.gif
Expand Down
36 changes: 18 additions & 18 deletions src/app_main.c
Expand Up @@ -162,23 +162,21 @@ void extract_keys(uint8_t bip32_depth, uint32_t bip32_path[10]) {
keys_initialized = 1;
}

void sign_vote(volatile uint32_t *tx) {
unsigned int sign_vote() {
uint8_t *signature = G_io_apdu_buffer;
unsigned int signature_capacity = IO_APDU_BUFFER_SIZE - 2;
unsigned int info = 0;

unsigned int signature_length = cx_eddsa_sign(&cx_privateKey,
CX_LAST,
CX_SHA512,
vote_get_buffer(),
vote_get_buffer_length(),
NULL,
0,
signature,
signature_capacity,
&info);

*tx += signature_length;
return cx_eddsa_sign(&cx_privateKey,
CX_LAST,
CX_SHA512,
vote_get_buffer(),
vote_get_buffer_length(),
NULL,
0,
signature,
signature_capacity,
&info);
}

void handleApdu(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
Expand Down Expand Up @@ -256,17 +254,16 @@ void handleApdu(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
view_set_msg(vote);
view_display_vote_init();
*flags |= IO_ASYNCH_REPLY;
THROW(APDU_CODE_DATA_INVALID);
break;
}

// Check with vote FSM if vote can be signed
if (!try_state_transition()) {
THROW(APDU_CODE_DATA_INVALID);
}

sign_vote(tx);
*tx = sign_vote();
view_set_state(vote_state, public_key);

THROW(APDU_CODE_OK);

}
Expand Down Expand Up @@ -318,8 +315,11 @@ void accept_vote_state(vote_t *v) {

view_set_state(s, public_key);

set_code(G_io_apdu_buffer, 0, APDU_CODE_OK);
io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, 2);
unsigned int tx = sign_vote();

set_code(G_io_apdu_buffer + tx, 0, APDU_CODE_OK);
io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, tx + 2);

view_display_vote_processing();
}

Expand Down
2 changes: 1 addition & 1 deletion src/app_main.h
Expand Up @@ -36,4 +36,4 @@ void app_init();

void app_main();

void sign_vote(volatile uint32_t *tx);
unsigned int sign_vote();