From 00838349995bc113d3632f2fe38be30be9a5c381 Mon Sep 17 00:00:00 2001 From: GroM Date: Wed, 28 Feb 2024 15:03:56 +0100 Subject: [PATCH 1/2] Add SLIP10 derivation support for Ed25519 --- ledger_device_sdk/src/ecc.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/ledger_device_sdk/src/ecc.rs b/ledger_device_sdk/src/ecc.rs index e2870179..f01a1697 100644 --- a/ledger_device_sdk/src/ecc.rs +++ b/ledger_device_sdk/src/ecc.rs @@ -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) { @@ -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() { { From 08f8a9c6fdaaebe81e1b460b89febd7379fb8cb2 Mon Sep 17 00:00:00 2001 From: GroM Date: Wed, 28 Feb 2024 15:53:13 +0100 Subject: [PATCH 2/2] Do not need to set seed (defaut value already set) --- ledger_device_sdk/src/ecc.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ledger_device_sdk/src/ecc.rs b/ledger_device_sdk/src/ecc.rs index f01a1697..5e2696d6 100644 --- a/ledger_device_sdk/src/ecc.rs +++ b/ledger_device_sdk/src/ecc.rs @@ -527,8 +527,6 @@ impl SeedDerive 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, @@ -537,8 +535,8 @@ impl Ed25519 { path.len() as u32, tmp.as_mut().as_mut_ptr(), core::ptr::null_mut(), - seed_key.as_mut_ptr(), - 12, + core::ptr::null_mut(), + 0, ); } let mut sk = ECPrivateKey::new(CurvesId::Ed25519);