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

Murisi/fix signature indexing #71

Closed
wants to merge 1 commit into from
Closed
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
17 changes: 9 additions & 8 deletions app/src/nvdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,29 +120,29 @@ uint8_t transaction_get_n_converts() {
}

bool spend_signatures_more_extract() {
return transaction_header.spends_sign_index > 0;
return transaction_header.spends_sign_index < transaction_header.spends_sign_len;
}

zxerr_t spend_signatures_append(uint8_t *signature) {
if (transaction_header.spends_sign_index >=
if (transaction_header.spends_sign_len >=
transaction_header.spendlist_len) {
return zxerr_unknown;
}

MEMCPY_NV((void *)&N_transactioninfo
.spend_signatures[transaction_header.spends_sign_index],
.spend_signatures[transaction_header.spends_sign_len],
signature, SIGNATURE_SIZE);
transaction_header.spends_sign_index++;
transaction_header.spends_sign_len++;
return zxerr_ok;
}

zxerr_t get_next_spend_signature(uint8_t *result) {
const uint8_t index = transaction_header.spendlist_len - transaction_header.spends_sign_index;
if (index >= transaction_header.spendlist_len) {
const uint8_t index = transaction_header.spends_sign_index;
if (index >= transaction_header.spends_sign_len) {
return zxerr_unknown;
}
MEMCPY(result, (void *)&N_transactioninfo.spend_signatures[index], SIGNATURE_SIZE);
transaction_header.spends_sign_index--;
transaction_header.spends_sign_index++;
if (!spend_signatures_more_extract()) {
transaction_reset();
}
Expand All @@ -152,10 +152,11 @@ zxerr_t get_next_spend_signature(uint8_t *result) {
void zeroize_signatures() {
uint8_t sig[SIGNATURE_SIZE] = {0};

transaction_header.spends_sign_index = 0;
transaction_header.spends_sign_len = 0;
for (int i = 0; i < SPEND_LIST_SIZE; i++) {
spend_signatures_append(sig);
}
transaction_header.spends_sign_len = 0;
transaction_header.spends_sign_index = 0;
}

Expand Down
1 change: 1 addition & 0 deletions app/src/nvdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ typedef struct {
uint8_t spendlist_len;
uint8_t outputlist_len;
uint8_t convertlist_len;
uint8_t spends_sign_len;
uint8_t spends_sign_index;
} transaction_header_t;

Expand Down