-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
637 additions
and
564 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,23 @@ | ||
#pragma once | ||
|
||
#define ZIP32_SIZE 32 | ||
void get_pkd(uint32_t zip32_account, const uint8_t *diversifier_ptr, uint8_t *pkd); | ||
|
||
void get_pkd(const uint8_t (*seed_ptr)[ZIP32_SIZE], | ||
uint32_t zip32_account, | ||
const uint8_t *diversifier_ptr, | ||
uint8_t (*pkd)[32]); | ||
|
||
void get_pkd_from_seed(const uint8_t (*seed_ptr)[ZIP32_SIZE], | ||
uint32_t zip32_account, | ||
const uint8_t *start_index, | ||
uint8_t *diversifier_ptr, | ||
uint8_t (*pkd)[32]); | ||
void get_pkd_from_seed(uint32_t zip32_account, const uint8_t *start_index, uint8_t *diversifier_ptr, uint8_t *pkd); | ||
|
||
bool diversifier_is_valid(const uint8_t *diversifier); | ||
|
||
void diversifier_get_list(const uint8_t (*seed_ptr)[ZIP32_SIZE], | ||
uint32_t zip32_account, | ||
const uint8_t *startindex, | ||
uint8_t *diversifier_list); | ||
void diversifier_get_list(uint32_t zip32_account, const uint8_t *startindex, uint8_t *diversifier_list); | ||
|
||
void diversifier_find_valid(const uint8_t (*seed_ptr)[ZIP32_SIZE], uint32_t zip32_account, uint8_t *default_diversifier); | ||
void diversifier_find_valid(uint32_t zip32_account, uint8_t *default_diversifier); | ||
|
||
void zip32_child_ask_nsk(const uint8_t (*seed_ptr)[ZIP32_SIZE], uint32_t pos, uint8_t *ask, uint8_t *nsk); | ||
void zip32_child_ask_nsk(uint32_t pos, uint8_t *ask, uint8_t *nsk); | ||
|
||
void zip32_nsk_from_seed(const uint8_t (*seed_ptr)[ZIP32_SIZE], uint32_t zip32_account, uint8_t *nsk); | ||
void zip32_nsk_from_seed(uint32_t zip32_account, uint8_t *nsk); | ||
|
||
void zip32_ovk(const uint8_t (*seed_ptr)[ZIP32_SIZE], uint32_t zip32_account, uint8_t *ovk); | ||
void zip32_ovk(uint32_t zip32_account, uint8_t *ovk); | ||
|
||
void zip32_child_proof_key(const uint8_t (*seed_ptr)[ZIP32_SIZE], uint32_t account, uint8_t *ak_ptr, uint8_t *nsk_ptr); | ||
void zip32_child_proof_key(uint32_t account, uint8_t *ak_ptr, uint8_t *nsk_ptr); | ||
|
||
void zip32_ivk(const uint8_t (*seed_ptr)[ZIP32_SIZE], uint32_t zip32_account, uint8_t *ivk); | ||
void zip32_ivk(uint32_t zip32_account, uint8_t *ivk); | ||
|
||
void zip32_fvk(const uint8_t (*seed_ptr)[ZIP32_SIZE], uint32_t zip32_account, uint8_t *fvk_ptr); | ||
void zip32_fvk(uint32_t zip32_account, uint8_t *fvk_ptr); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
//! Rust interfaces to Ledger SDK APIs. | ||
|
||
pub mod aes; | ||
pub mod blake2b; | ||
mod heartbeat; | ||
pub mod jubjub; | ||
pub(crate) mod aes; | ||
pub(crate) mod blake2b; | ||
pub(crate) mod canary; | ||
pub(crate) mod heartbeat; | ||
pub(crate) mod jubjub; | ||
pub(crate) mod rng; | ||
mod zemu; | ||
|
||
mod canary; | ||
pub(crate) mod seed; | ||
pub(crate) mod zemu; | ||
|
||
pub(crate) use heartbeat::heartbeat; | ||
|
||
pub use canary::c_check_app_canary; | ||
pub use seed::c_device_seed; | ||
pub use zemu::c_zemu_log_stack; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use crate::types::Zip32Seed; | ||
|
||
extern "C" { | ||
fn crypto_fillDeviceSeed(seed: *mut u8); | ||
} | ||
|
||
#[cfg(not(test))] | ||
pub fn c_device_seed() -> Zip32Seed { | ||
let mut seed: Zip32Seed = [0; 32]; | ||
unsafe { | ||
crypto_fillDeviceSeed(seed.as_mut_ptr()); | ||
} | ||
seed | ||
} | ||
|
||
#[cfg(test)] | ||
use lazy_static::lazy_static; | ||
|
||
#[cfg(test)] | ||
use parking_lot::ReentrantMutex; | ||
|
||
#[cfg(test)] | ||
use std::cell::RefCell; | ||
|
||
#[cfg(test)] | ||
lazy_static! { | ||
static ref CUSTOM_TEST_SEED: ReentrantMutex<RefCell<Option<Zip32Seed>>> = | ||
ReentrantMutex::new(RefCell::new(None)); | ||
} | ||
|
||
#[cfg(test)] | ||
pub fn with_device_seed_context<F: FnOnce()>(temporary_seed: Zip32Seed, test: F) { | ||
let guard = CUSTOM_TEST_SEED.lock(); | ||
|
||
guard.replace(Some(temporary_seed)); | ||
|
||
// Run the test lambda | ||
test(); | ||
|
||
guard.replace(None); | ||
} | ||
|
||
#[cfg(test)] | ||
pub fn c_device_seed() -> Zip32Seed { | ||
let guard = CUSTOM_TEST_SEED.lock(); | ||
let seed_ref = guard.borrow(); | ||
|
||
match &*seed_ref { | ||
Some(temporary_seed) => { | ||
// Handle the case where the seed is Some | ||
// `seed` here is a reference to the value inside Some | ||
temporary_seed.clone() | ||
} | ||
None => { | ||
let mut seed: Zip32Seed = [0; 32]; | ||
// Handle the case where the override seed is None | ||
for (i, elem) in seed.iter_mut().enumerate() { | ||
*elem = i as u8; | ||
} | ||
seed | ||
} | ||
} | ||
} |
Oops, something went wrong.