Skip to content

Commit

Permalink
Merge pull request #9 from Zondax/update_hashes
Browse files Browse the repository at this point in the history
Update app
  • Loading branch information
ftheirs authored Aug 14, 2023
2 parents 356a4a1 + d8a2608 commit d49f83b
Show file tree
Hide file tree
Showing 234 changed files with 1,533 additions and 4,765 deletions.
2 changes: 1 addition & 1 deletion app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ endif

APP_LOAD_PARAMS = --curve ed25519 $(COMMON_LOAD_PARAMS) --path $(APPPATH)

NANOS_STACK_SIZE := 2888
NANOS_STACK_SIZE := 2850
include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.devices

$(info TARGET_NAME = [$(TARGET_NAME)])
Expand Down
2 changes: 1 addition & 1 deletion app/Makefile.version
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ APPVERSION_M=0
# This is the `spec_version` field of `Runtime`
APPVERSION_N=0
# This is the patch version of this release
APPVERSION_P=6
APPVERSION_P=7
Binary file modified app/glyphs/icon_app.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/nanos_icon.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/nanox_icon.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/src/addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ zxerr_t addr_getItem(int8_t displayIdx,
switch (displayIdx) {
case 0:
snprintf(outKey, outKeyLen, "Address");
pageString(outVal, outValLen, (char *) (G_io_apdu_buffer + PK_LEN_25519), pageIdx, pageCount);
pageString(outVal, outValLen, (char *) (G_io_apdu_buffer + PK_LEN_25519_PLUS_TAG), pageIdx, pageCount);
return zxerr_ok;
case 1: {
if (!app_mode_expert()) {
Expand Down
23 changes: 2 additions & 21 deletions app/src/apdu_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,6 @@ __Z_INLINE void handleSignTransaction(volatile uint32_t *flags, volatile uint32_
*flags |= IO_ASYNCH_REPLY;
}

__Z_INLINE void handleGetSignature(volatile uint32_t *tx) {
ZEMU_LOGF(50, "HandleGetSignature")
*tx = 0;
const uint8_t slot = G_io_apdu_buffer[OFFSET_P2];

const zxerr_t err = crypto_getSignature(G_io_apdu_buffer, IO_APDU_BUFFER_SIZE - 3, slot);
if (err == zxerr_ok){
*tx = SALT_LEN + HASH_LEN + PK_LEN_25519 + SIG_ED25519_LEN;
THROW(APDU_CODE_OK);
} else {
THROW(APDU_CODE_CONDITIONS_NOT_SATISFIED);
}
}

// For wrapper transactions, address is derived from Ed25519 pubkey
__Z_INLINE void handleGetAddr(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
zemu_log("handleGetAddr\n");
Expand Down Expand Up @@ -176,7 +162,8 @@ __Z_INLINE void handle_getversion(__Z_UNUSED volatile uint32_t *flags, volatile
G_io_apdu_buffer[5] = (LEDGER_PATCH_VERSION >> 8) & 0xFF;
G_io_apdu_buffer[6] = (LEDGER_PATCH_VERSION >> 0) & 0xFF;

G_io_apdu_buffer[7] = !IS_UX_ALLOWED;
// SDK won't reply if device is blocked ---> Always false
G_io_apdu_buffer[7] = 0;

G_io_apdu_buffer[8] = (TARGET_ID >> 24) & 0xFF;
G_io_apdu_buffer[9] = (TARGET_ID >> 16) & 0xFF;
Expand Down Expand Up @@ -226,12 +213,6 @@ void handleApdu(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
break;
}

case INS_GET_SIGNATURE: {
CHECK_PIN_VALIDATED()
handleGetSignature(tx);
break;
}

#if defined(APP_TESTING)
case INS_TEST: {
handleTest(flags, tx, rx);
Expand Down
12 changes: 10 additions & 2 deletions app/src/coin.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,20 @@ extern "C" {
#define SECP256K1_SK_LEN 32u
#define SCALAR_LEN_SECP256K1 32u

#define SK_LEN_25519 64u
#define SK_LEN_25519 32u
#define SCALAR_LEN_ED25519 32u
#define SIG_PLUS_TYPE_LEN 65u

#define ED25519_SIGNATURE_SIZE 64u

#define PK_LEN_25519 32u
#define PK_HASH_LEN 40u
#define PK_HASH_LEN 20u
#define PK_HASH_STR_LEN 40u

// Extra byte at the beginning to indicate type (ED25519 = 0)
#define PK_LEN_25519_PLUS_TAG 33u
#define SIG_LEN_25519_PLUS_TAG 65u


#define ADDRESS_LEN_MAINNET 80u
#define ADDRESS_LEN_TESTNET 84u
Expand All @@ -65,6 +71,8 @@ extern "C" {
#define COIN_AMOUNT_DECIMAL_PLACES 6
#define COIN_TICKER "NAM "

#define POS_DECIMAL_PRECISION 12

#define MENU_MAIN_APP_LINE1 "Namada"
#define MENU_MAIN_APP_LINE2 "Ready"
#define MENU_MAIN_APP_LINE2_SECRET "???"
Expand Down
17 changes: 5 additions & 12 deletions app/src/common/actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#pragma once

#include <stdint.h>
#include "crypto_helper.h"
#include "crypto.h"
#include "tx.h"
#include "apdu_codes.h"
Expand Down Expand Up @@ -57,24 +58,16 @@ __Z_INLINE zxerr_t app_fill_address(signing_key_type_e addressKind) {

__Z_INLINE void app_sign() {
const parser_tx_t *txObj = tx_get_txObject();

uint8_t pubkey[PK_LEN_25519] = {0};
const bytes_t pubkey_bytes = {.ptr = pubkey, .len = PK_LEN_25519};
zxerr_t err = crypto_extractPublicKey_ed25519(pubkey, sizeof(pubkey));
if (err == zxerr_ok) {
const zxerr_t headerSigErr = crypto_signHeader(&txObj->transaction.header, &pubkey_bytes);
const zxerr_t dataSigErr = crypto_signDataSection(&txObj->transaction.sections.data, &pubkey_bytes);
const zxerr_t codeSigErr = crypto_signCodeSection(&txObj->transaction.sections.code, &pubkey_bytes);
err = (headerSigErr == zxerr_ok && dataSigErr == zxerr_ok && codeSigErr == zxerr_ok) ? zxerr_ok : zxerr_unknown;
}
const zxerr_t err = crypto_sign(txObj, G_io_apdu_buffer, sizeof(G_io_apdu_buffer) - 2);

if (err != zxerr_ok) {
MEMZERO(G_io_apdu_buffer, sizeof(G_io_apdu_buffer));
set_code(G_io_apdu_buffer, 0, APDU_CODE_SIGN_VERIFY_ERROR);
io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, 2);
} else {
set_code(G_io_apdu_buffer, 0, APDU_CODE_OK);
io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, 2);
const uint16_t responseLen = PK_LEN_25519_PLUS_TAG + 2 * SALT_LEN + 2 * SIG_LEN_25519_PLUS_TAG;
set_code(G_io_apdu_buffer, responseLen, APDU_CODE_OK);
io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, responseLen + 2);
}
}

Expand Down
Loading

0 comments on commit d49f83b

Please sign in to comment.