Skip to content

Commit

Permalink
Merge pull request #207 from Zondax/fixes
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
ftheirs committed Oct 12, 2023
2 parents 813aedc + 88665eb commit d16d0cb
Show file tree
Hide file tree
Showing 42 changed files with 1,777 additions and 2,310 deletions.
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
url = https://github.com/LedgerHQ/nanos-secure-sdk.git
[submodule "deps/nanox-secure-sdk"]
path = deps/nanox-secure-sdk
url = https://github.com/LedgerHQ/nanox-secure-sdk.git
url = https://github.com/LedgerHQ/ledger-secure-sdk.git
[submodule "deps/nanosplus-secure-sdk"]
path = deps/nanosplus-secure-sdk
url = https://github.com/LedgerHQ/nanosplus-secure-sdk
url = https://github.com/LedgerHQ/ledger-secure-sdk.git
[submodule "deps/ledger-zxlib"]
path = deps/ledger-zxlib
url = https://github.com/zondax/ledger-zxlib
Expand Down
2 changes: 1 addition & 1 deletion app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ APP_SOURCE_PATH += $(CURDIR)/rust/include

.PHONY: rust
rust:
cd rust && CARGO_HOME="$(CURDIR)/rust/.cargo" cargo build --target thumbv6m-none-eabi --release
cd rust && RUSTC_BOOTSTRAP=1 CARGO_HOME="$(CURDIR)/rust/.cargo" cargo build --target thumbv6m-none-eabi --release

# Before linking, we need to be sure rust lib is there
bin/app.elf: rust
Expand Down
2 changes: 1 addition & 1 deletion app/Makefile.version
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
APPVERSION_M=2
APPVERSION_N=5
APPVERSION_P=4
APPVERSION_P=5
3 changes: 3 additions & 0 deletions app/rust/.cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ rustflags = [
"-C", "link-arg=-nostartfiles",
"-C", "link-arg=-Tlink.ld",
]
[unstable]
build-std=["core"]
build-std-features=["panic_immediate_abort"]
2 changes: 1 addition & 1 deletion app/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ panic-halt = "0.2.0"
lto=false
codegen-units = 1
debug=true
opt-level = "s"
opt-level = "z"

[profile.dev]
panic = "abort"
Expand Down
1 change: 1 addition & 0 deletions app/rust/include/rslib.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <stdint.h>

void expanded_sr25519_sk(uint8_t *sk_ed25519, uint8_t *sk_ed25519_expanded);
void get_sr25519_sk(uint8_t *sk_ed25519_expanded);

void sign_sr25519_phase1(const uint8_t *sk_ed25519_expanded, const uint8_t *pk, const uint8_t *context_ptr, uint32_t context_len, const uint8_t *msg_ptr, uint32_t msg_len, uint8_t *sig_ptr);
Expand Down
10 changes: 9 additions & 1 deletion app/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use curve25519_dalek::scalar::Scalar;
use merlin::{Transcript, TranscriptRng, TranscriptRngBuilder};
use rand::RngCore;
use schnorrkel::context::{SigningContext, SigningTranscript};
use schnorrkel::{PublicKey, SecretKey};
use schnorrkel::{ExpansionMode, MiniSecretKey, PublicKey, SecretKey};
use zeroize::Zeroize;

use crate::bolos::*;
Expand Down Expand Up @@ -154,6 +154,14 @@ pub extern "C" fn sign_sr25519_phase2(
signature[63] |= 128;
}

#[no_mangle]
pub extern "C" fn expanded_sr25519_sk(sk_ed25519_ptr: *mut u8, sk_ed25519_expanded_ptr: *mut u8) {
let sk_ed25519 = unsafe { from_raw_parts_mut(sk_ed25519_ptr as *mut u8, 32) };
let sk_ed25519_expanded = unsafe { from_raw_parts_mut(sk_ed25519_expanded_ptr as *mut u8, 64) };
let secret: MiniSecretKey = MiniSecretKey::from_bytes(&sk_ed25519[..]).unwrap();
sk_ed25519_expanded.copy_from_slice(&secret.expand(ExpansionMode::Uniform).to_bytes());
}

#[no_mangle]
pub extern "C" fn get_sr25519_sk(sk_ed25519_expanded_ptr: *mut u8) {
let sk_ed25519_expanded = unsafe { from_raw_parts_mut(sk_ed25519_expanded_ptr as *mut u8, 64) };
Expand Down
4 changes: 2 additions & 2 deletions app/src/consumer/parser_consumer.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ static const char * methodsMap[] = {
"Reclaim escrow", "Amend commission schedule", "Deregister Entity",
"Unfreeze Node", "Register Entity", "Submit proposal", "Cast vote",
" Transfer (ParaTime)", " Deposit (ParaTime)",
" Withdraw (ParaTime)", " Delegate (ParaTime)",
" Undelegate (ParaTime)"," Instantiate (ParaTime)",
" Withdraw (ParaTime)", " Delegate (ParaTime)",
" Undelegate (ParaTime)"," Instantiate (ParaTime)",
" Call (ParaTime)"," Upgrade (ParaTime)",
" Transaction (ParaTime)", " Call (ParaTime)",
};
Expand Down
24 changes: 21 additions & 3 deletions app/src/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,17 @@ zxerr_t crypto_extractPublicKeySr25519(uint8_t *pubKey, uint16_t pubKeyLen) {
privateKeyData,
NULL,
NULL,
0))
get_sr25519_sk(privateKeyData);
0));

if (mode == HDW_ED25519_SLIP10) {
uint8_t privateKeyData_expanded[SK_LEN_25519] = {0};
expanded_sr25519_sk(privateKeyData, privateKeyData_expanded);
MEMCPY(privateKeyData, privateKeyData_expanded, SK_LEN_25519);
MEMZERO(privateKeyData_expanded, sizeof(privateKeyData_expanded));
} else {
get_sr25519_sk(privateKeyData);
}

CATCH_CXERROR(crypto_scalarmult_ristretto255_base_sdk(pubKey, privateKeyData))
error = zxerr_ok;

Expand Down Expand Up @@ -305,7 +314,16 @@ zxerr_t crypto_sign_sr25519(const uint8_t *data, size_t len, const uint8_t *ctx,
NULL,
NULL,
0))
get_sr25519_sk(sk);

if (mode == HDW_ED25519_SLIP10) {
uint8_t privateKeyData_expanded[SK_LEN_25519] = {0};
expanded_sr25519_sk(sk, privateKeyData_expanded);
MEMCPY(sk, privateKeyData_expanded, SK_LEN_25519);
MEMZERO(privateKeyData_expanded, sizeof(privateKeyData_expanded));
} else {
get_sr25519_sk(sk);
}

CATCH_CXERROR(crypto_scalarmult_ristretto255_base_sdk(pk, sk))
sign_sr25519_phase1(sk, pk, ctx, ctx_len, data, len, sr25519_signature);
CATCH_CXERROR(crypto_scalarmult_ristretto255_base_sdk(sr25519_signature, sr25519_signature + PK_LEN_SR25519))
Expand Down
2 changes: 1 addition & 1 deletion deps/nanosplus-secure-sdk
2 changes: 1 addition & 1 deletion deps/nanox-secure-sdk
38 changes: 19 additions & 19 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,42 @@
},
"homepage": "https://github.com/zondax/ledger-oasis",
"dependencies": {
"@babel/runtime": "^7.22.6",
"@ledgerhq/hw-app-eth": "6.34.2",
"@ledgerhq/hw-transport": "^6.28.7",
"@babel/runtime": "^7.23.1",
"@ledgerhq/hw-app-eth": "6.34.7",
"@ledgerhq/hw-transport": "^6.28.8",
"bech32": "^2.0.0"
},
"devDependencies": {
"@babel/cli": "^7.22.9",
"@babel/core": "^7.22.9",
"@babel/eslint-parser": "^7.22.9",
"@babel/node": "^7.22.6",
"@babel/plugin-transform-runtime": "^7.22.9",
"@babel/preset-env": "^7.22.9",
"@ledgerhq/hw-transport-node-hid": "^6.27.20",
"@ledgerhq/hw-transport-webusb": "^6.27.18",
"@babel/cli": "^7.23.0",
"@babel/core": "^7.23.0",
"@babel/eslint-parser": "^7.22.15",
"@babel/node": "^7.22.19",
"@babel/plugin-transform-runtime": "^7.22.15",
"@babel/preset-env": "^7.22.20",
"@ledgerhq/hw-transport-node-hid": "^6.27.21",
"@ledgerhq/hw-transport-webusb": "^6.27.19",
"@ledgerhq/logs": "^6.10.1",
"@vue/cli-plugin-babel": "^5.0.8",
"@vue/cli-plugin-eslint": "^5.0.8",
"@vue/cli-service": "^5.0.8",
"babel-jest": "^29.6.2",
"babel-jest": "^29.7.0",
"bip32": "4.0.0",
"bip39": "3.1.0",
"core-js": "^3.32.0",
"core-js": "^3.33.0",
"crypto-js": "4.1.1",
"ed25519-supercop": "^2.0.1",
"eslint": "^8.46.0",
"eslint": "^8.51.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-jest": "^27.2.3",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jest": "^27.4.2",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-vue": "^9.16.1",
"eslint-plugin-vue": "^9.17.0",
"index.js": "^0.0.3",
"jest": "^29.6.2",
"jest": "^29.7.0",
"jest-serial-runner": "^1.2.1",
"js-sha512": "^0.8.0",
"prettier": "^3.0.1",
"prettier": "^3.0.3",
"vue": "^3.3.4",
"vue-template-compiler": "^2.7.14"
},
Expand Down

0 comments on commit d16d0cb

Please sign in to comment.