Skip to content

Commit

Permalink
Add SLIP10 derivation support for Ed25519
Browse files Browse the repository at this point in the history
  • Loading branch information
yogh333 committed Feb 28, 2024
1 parent 78cbf80 commit 0083834
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions ledger_device_sdk/src/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,31 @@ impl SeedDerive for Ed25519 {
}
}

/// Support SLIP10 derivation for Ed25519
impl Ed25519 {
pub fn derive_from_path_slip10(path: &[u32]) -> ECPrivateKey<32, 'E'> {
let mut tmp = Secret::<64>::new();
let seed_key: &mut [u8; 12] = &mut [0; 12];
seed_key.copy_from_slice(b"ed25519 seed");
unsafe {
os_perso_derive_node_with_seed_key(
HDW_ED25519_SLIP10,
CurvesId::Ed25519 as u8,
path.as_ptr(),
path.len() as u32,
tmp.as_mut().as_mut_ptr(),
core::ptr::null_mut(),
seed_key.as_mut_ptr(),
12,
);
}
let mut sk = ECPrivateKey::new(CurvesId::Ed25519);
let keylen = sk.key.len();
sk.key.copy_from_slice(&tmp.0[..keylen]);
sk
}
}

impl SeedDerive for Stark256 {
type Target = ECPrivateKey<32, 'W'>;
fn derive_from(path: &[u32]) -> (Self::Target, Option<ChainCode>) {
Expand Down Expand Up @@ -825,6 +850,15 @@ mod tests {
assert_eq!(pk.verify((&s.0, s.1), TEST_HASH, CX_SHA512), true);
}

#[test]
fn eddsa_ed25519_slip10() {
let path: [u32; 5] = make_bip32_path(b"m/44'/535348'/0'/0'/1'");
let sk = Ed25519::derive_from_path_slip10(&path);
let s = sk.sign(TEST_HASH).map_err(display_error_code)?;
let pk = sk.public_key().map_err(display_error_code)?;
assert_eq!(pk.verify((&s.0, s.1), TEST_HASH, CX_SHA512), true);
}

#[test]
fn test_make_bip32_path() {
{
Expand Down

0 comments on commit 0083834

Please sign in to comment.