@@ -6,7 +6,7 @@ use bitcoin::blockdata::transaction::{OutPoint, TxOut};
6
6
use bitcoin:: blockdata:: script:: { Script , Builder } ;
7
7
use bitcoin:: blockdata:: opcodes;
8
8
use bitcoin:: network:: constants:: Network ;
9
- use bitcoin:: util:: hash:: Hash160 ;
9
+ use bitcoin:: util:: hash:: { Hash160 , Sha256dHash } ;
10
10
use bitcoin:: util:: bip32:: { ExtendedPrivKey , ExtendedPubKey , ChildNumber } ;
11
11
12
12
use secp256k1:: key:: { SecretKey , PublicKey } ;
@@ -17,7 +17,10 @@ use crypto::hkdf::{hkdf_extract,hkdf_expand};
17
17
18
18
use util:: sha2:: Sha256 ;
19
19
use util:: logger:: Logger ;
20
+ use util:: rng;
21
+ use util:: byte_utils;
20
22
23
+ use std:: time:: { SystemTime , UNIX_EPOCH } ;
21
24
use std:: sync:: Arc ;
22
25
use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
23
26
@@ -195,11 +198,16 @@ impl KeysInterface for KeysManager {
195
198
}
196
199
197
200
fn get_channel_keys ( & self , _inbound : bool ) -> ChannelKeys {
201
+ let mut seed = [ 0u8 ; 32 + 4 + 8 + 33 ] ;
202
+ rng:: fill_bytes ( & mut seed[ ..32 ] ) ;
203
+ let now = SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . expect ( "Time went backwards" ) ;
204
+ seed[ 32 ..32 +4 ] . copy_from_slice ( & byte_utils:: be32_to_array ( now. subsec_micros ( ) ) ) ;
205
+ seed[ 32 +4 ..32 +4 +8 ] . copy_from_slice ( & byte_utils:: be64_to_array ( now. as_secs ( ) ) ) ;
206
+
198
207
let child_ix = self . channel_child_index . fetch_add ( 1 , Ordering :: SeqCst ) ;
199
208
let child_privkey = self . channel_master_key . ckd_priv ( & self . secp_ctx , ChildNumber :: from_hardened_idx ( child_ix as u32 ) ) . expect ( "Your RNG is busted" ) ;
200
209
let child_pubkey = ExtendedPubKey :: from_private ( & self . secp_ctx , & child_privkey) ;
201
- let mut seed = [ 0u8 ; 32 ] ;
202
- seed. copy_from_slice ( & child_pubkey. public_key . serialize ( ) [ 1 ..33 ] ) ;
203
- ChannelKeys :: new_from_seed ( & seed)
210
+ seed[ 32 +4 +8 ..] . copy_from_slice ( & child_pubkey. public_key . serialize ( ) ) ;
211
+ ChannelKeys :: new_from_seed ( & Sha256dHash :: from_data ( & seed) . as_bytes ( ) )
204
212
}
205
213
}
0 commit comments