File tree Expand file tree Collapse file tree 1 file changed +4
-5
lines changed Expand file tree Collapse file tree 1 file changed +4
-5
lines changed Original file line number Diff line number Diff 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" ) ;
You can’t perform that action at this time.
0 commit comments