@@ -192,7 +192,7 @@ impl Server {
192192
193193 let precomputed_keys = PrecomputedCache :: new ( sk. clone ( ) , PRECOMPUTED_LRU_CACHE_SIZE ) ;
194194
195- let onion_symmetric_key = XSalsa20Poly1305 :: new ( & rng . gen :: < [ u8 ; xsalsa20poly1305 :: KEY_SIZE ] > ( ) . into ( ) ) ;
195+ let onion_symmetric_key = XSalsa20Poly1305 :: new ( & XSalsa20Poly1305 :: generate_key ( & mut rng ) ) ;
196196 Server {
197197 sk,
198198 pk,
@@ -1032,6 +1032,7 @@ impl Server {
10321032 pub async fn handle_onion_request_0 ( & self , packet : OnionRequest0 , addr : SocketAddr ) -> Result < ( ) , HandlePacketError > {
10331033 let onion_symmetric_key = self . onion_symmetric_key . read ( ) . await ;
10341034 let onion_return = OnionReturn :: new (
1035+ & mut thread_rng ( ) ,
10351036 & onion_symmetric_key,
10361037 & IpPort :: from_udp_saddr ( addr) ,
10371038 None , // no previous onion return
@@ -1058,6 +1059,7 @@ impl Server {
10581059 pub async fn handle_onion_request_1 ( & self , packet : OnionRequest1 , addr : SocketAddr ) -> Result < ( ) , HandlePacketError > {
10591060 let onion_symmetric_key = self . onion_symmetric_key . read ( ) . await ;
10601061 let onion_return = OnionReturn :: new (
1062+ & mut thread_rng ( ) ,
10611063 & onion_symmetric_key,
10621064 & IpPort :: from_udp_saddr ( addr) ,
10631065 Some ( & packet. onion_return )
@@ -1083,6 +1085,7 @@ impl Server {
10831085 pub async fn handle_onion_request_2 ( & self , packet : OnionRequest2 , addr : SocketAddr ) -> Result < ( ) , HandlePacketError > {
10841086 let onion_symmetric_key = self . onion_symmetric_key . read ( ) . await ;
10851087 let onion_return = OnionReturn :: new (
1088+ & mut thread_rng ( ) ,
10861089 & onion_symmetric_key,
10871090 & IpPort :: from_udp_saddr ( addr) ,
10881091 Some ( & packet. onion_return ) ,
@@ -1273,7 +1276,7 @@ impl Server {
12731276 /// Refresh onion symmetric key to enforce onion paths expiration.
12741277 async fn refresh_onion_key ( & self ) {
12751278 * self . onion_symmetric_key . write ( ) . await =
1276- XSalsa20Poly1305 :: new ( & thread_rng ( ) . gen :: < [ u8 ; xsalsa20poly1305 :: KEY_SIZE ] > ( ) . into ( ) ) ;
1279+ XSalsa20Poly1305 :: new ( & XSalsa20Poly1305 :: generate_key ( & mut thread_rng ( ) ) ) ;
12771280 }
12781281
12791282 /// Handle `OnionRequest` from TCP relay and send `OnionRequest1` packet
@@ -1283,6 +1286,7 @@ impl Server {
12831286 let onion_symmetric_key = self . onion_symmetric_key . read ( ) . await ;
12841287
12851288 let onion_return = OnionReturn :: new (
1289+ & mut thread_rng ( ) ,
12861290 & onion_symmetric_key,
12871291 & IpPort :: from_tcp_saddr ( addr) ,
12881292 None // no previous onion return
@@ -2484,7 +2488,7 @@ mod tests {
24842488 nonce : [ 42 ; xsalsa20poly1305:: NONCE_SIZE ] ,
24852489 payload : vec ! [ 42 ; ONION_RETURN_2_PAYLOAD_SIZE ]
24862490 } ;
2487- let onion_return = OnionReturn :: new ( & onion_symmetric_key, & ip_port, Some ( & next_onion_return) ) ;
2491+ let onion_return = OnionReturn :: new ( & mut thread_rng ( ) , & onion_symmetric_key, & ip_port, Some ( & next_onion_return) ) ;
24882492 let payload = InnerOnionResponse :: OnionAnnounceResponse ( OnionAnnounceResponse {
24892493 sendback_data : 12345 ,
24902494 nonce : gen_nonce ( ) ,
@@ -2545,7 +2549,7 @@ mod tests {
25452549 ip_addr : "5.6.7.8" . parse ( ) . unwrap ( ) ,
25462550 port : 12345
25472551 } ;
2548- let onion_return = OnionReturn :: new ( & onion_symmetric_key, & ip_port, None ) ;
2552+ let onion_return = OnionReturn :: new ( & mut thread_rng ( ) , & onion_symmetric_key, & ip_port, None ) ;
25492553 let inner = OnionDataResponse {
25502554 nonce : gen_nonce ( ) ,
25512555 temporary_pk : gen_keypair ( ) . 0 ,
@@ -2577,7 +2581,7 @@ mod tests {
25772581 nonce : [ 42 ; xsalsa20poly1305:: NONCE_SIZE ] ,
25782582 payload : vec ! [ 42 ; ONION_RETURN_1_PAYLOAD_SIZE ]
25792583 } ;
2580- let onion_return = OnionReturn :: new ( & onion_symmetric_key, & ip_port, Some ( & next_onion_return) ) ;
2584+ let onion_return = OnionReturn :: new ( & mut thread_rng ( ) , & onion_symmetric_key, & ip_port, Some ( & next_onion_return) ) ;
25812585 let payload = InnerOnionResponse :: OnionAnnounceResponse ( OnionAnnounceResponse {
25822586 sendback_data : 12345 ,
25832587 nonce : gen_nonce ( ) ,
@@ -2638,7 +2642,7 @@ mod tests {
26382642 ip_addr : "5.6.7.8" . parse ( ) . unwrap ( ) ,
26392643 port : 12345
26402644 } ;
2641- let onion_return = OnionReturn :: new ( & onion_symmetric_key, & ip_port, None ) ;
2645+ let onion_return = OnionReturn :: new ( & mut thread_rng ( ) , & onion_symmetric_key, & ip_port, None ) ;
26422646 let inner = OnionDataResponse {
26432647 nonce : gen_nonce ( ) ,
26442648 temporary_pk : gen_keypair ( ) . 0 ,
@@ -2666,7 +2670,7 @@ mod tests {
26662670 ip_addr : "5.6.7.8" . parse ( ) . unwrap ( ) ,
26672671 port : 12345
26682672 } ;
2669- let onion_return = OnionReturn :: new ( & onion_symmetric_key, & ip_port, None ) ;
2673+ let onion_return = OnionReturn :: new ( & mut thread_rng ( ) , & onion_symmetric_key, & ip_port, None ) ;
26702674 let inner = OnionAnnounceResponse {
26712675 sendback_data : 12345 ,
26722676 nonce : gen_nonce ( ) ,
@@ -2700,7 +2704,7 @@ mod tests {
27002704 ip_addr : "5.6.7.8" . parse ( ) . unwrap ( ) ,
27012705 port : 12345
27022706 } ;
2703- let onion_return = OnionReturn :: new ( & onion_symmetric_key, & ip_port, None ) ;
2707+ let onion_return = OnionReturn :: new ( & mut thread_rng ( ) , & onion_symmetric_key, & ip_port, None ) ;
27042708 let inner = OnionDataResponse {
27052709 nonce : gen_nonce ( ) ,
27062710 temporary_pk : gen_keypair ( ) . 0 ,
@@ -2736,7 +2740,7 @@ mod tests {
27362740 ip_addr : "5.6.7.8" . parse ( ) . unwrap ( ) ,
27372741 port : 12345
27382742 } ;
2739- let onion_return = OnionReturn :: new ( & onion_symmetric_key, & ip_port, None ) ;
2743+ let onion_return = OnionReturn :: new ( & mut thread_rng ( ) , & onion_symmetric_key, & ip_port, None ) ;
27402744 let inner = InnerOnionResponse :: OnionAnnounceResponse ( OnionAnnounceResponse {
27412745 sendback_data : 12345 ,
27422746 nonce : gen_nonce ( ) ,
@@ -2767,7 +2771,7 @@ mod tests {
27672771 ip_addr : "5.6.7.8" . parse ( ) . unwrap ( ) ,
27682772 port : 12345
27692773 } ;
2770- let onion_return = OnionReturn :: new ( & onion_symmetric_key, & ip_port, None ) ;
2774+ let onion_return = OnionReturn :: new ( & mut thread_rng ( ) , & onion_symmetric_key, & ip_port, None ) ;
27712775 let inner = OnionAnnounceResponse {
27722776 sendback_data : 12345 ,
27732777 nonce : gen_nonce ( ) ,
@@ -2824,7 +2828,7 @@ mod tests {
28242828 nonce : [ 42 ; xsalsa20poly1305:: NONCE_SIZE ] ,
28252829 payload : vec ! [ 42 ; ONION_RETURN_1_PAYLOAD_SIZE ]
28262830 } ;
2827- let onion_return = OnionReturn :: new ( & onion_symmetric_key, & ip_port, Some ( & next_onion_return) ) ;
2831+ let onion_return = OnionReturn :: new ( & mut thread_rng ( ) , & onion_symmetric_key, & ip_port, Some ( & next_onion_return) ) ;
28282832 let inner = OnionDataResponse {
28292833 nonce : gen_nonce ( ) ,
28302834 temporary_pk : gen_keypair ( ) . 0 ,
0 commit comments