Skip to content

Commit 88d7ce1

Browse files
small fmt
1 parent 648b166 commit 88d7ce1

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

dash/src/bip32.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,6 @@ impl ExtendedPrivKey {
567567
Ok(sk)
568568
}
569569

570-
/// Private->Private child key derivation
571570
/// Private->Private child key derivation
572571
pub fn ckd_priv<C: secp256k1::Signing>(
573572
&self,
@@ -576,20 +575,20 @@ impl ExtendedPrivKey {
576575
) -> Result<ExtendedPrivKey, Error> {
577576
let mut hmac_engine: HmacEngine<sha512::Hash> = HmacEngine::new(&self.chain_code[..]);
578577
match i {
579-
ChildNumber::Normal { .. } => {
578+
ChildNumber::Normal { index } => {
580579
// Non-hardened key: compute public data and use that
581580
hmac_engine.input(
582581
&secp256k1::PublicKey::from_secret_key(secp, &self.private_key).serialize()[..],
583582
);
583+
hmac_engine.input(&index.to_be_bytes());
584584
}
585-
ChildNumber::Hardened { .. } => {
585+
ChildNumber::Hardened { index } => {
586586
// Hardened key: use only secret data to prevent public derivation
587587
hmac_engine.input(&[0u8]);
588588
hmac_engine.input(&self.private_key[..]);
589+
hmac_engine.input(&(index | (1 << 31)).to_be_bytes());
589590
}
590591
}
591-
592-
hmac_engine.input(&u32::from(i).to_be_bytes());
593592
let hmac_result: Hmac<sha512::Hash> = Hmac::from_engine(hmac_engine);
594593
let sk = secp256k1::SecretKey::from_slice(&hmac_result[..32])
595594
.expect("statistically impossible to hit");

0 commit comments

Comments
 (0)