Skip to content

Commit

Permalink
Merge pull request #139 from LedgerHQ/136-add-support-for-ed25519-sli…
Browse files Browse the repository at this point in the history
…p10-derivation

Add SLIP10 derivation support for Ed25519
  • Loading branch information
yogh333 authored Mar 1, 2024
2 parents 78cbf80 + 08f8a9c commit bdb512a
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions ledger_device_sdk/src/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,29 @@ 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();
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(),
core::ptr::null_mut(),
0,
);
}
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 +848,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 bdb512a

Please sign in to comment.