@@ -234,10 +234,10 @@ impl fmt::Display for Error {
234
234
"Packet size exceeds maximum 4MiB size for automatic allocation."
235
235
) ,
236
236
Error :: NoGarbageTerminator => {
237
- write ! ( f, "More than 4095 bytes of garbage recieved in the handshake before a terminator was sent." )
237
+ write ! ( f, "More than 4095 bytes of garbage received in the handshake before a terminator was sent." )
238
238
}
239
239
Error :: SecretGeneration ( e) => write ! ( f, "Cannot generate secrets: {e:?}." ) ,
240
- Error :: Decryption ( e) => write ! ( f, "Decrytion error: {e:?}." ) ,
240
+ Error :: Decryption ( e) => write ! ( f, "Decryption error: {e:?}." ) ,
241
241
Error :: V1Protocol => write ! ( f, "The remote peer is communicating on the V1 protocol." ) ,
242
242
Error :: TooMuchGarbage => write ! (
243
243
f,
@@ -376,7 +376,7 @@ impl SessionKeyMaterial {
376
376
hk. expand ( garbage_info, & mut garbage) ?;
377
377
let initiator_garbage_terminator: [ u8 ; 16 ] = garbage[ ..16 ]
378
378
. try_into ( )
379
- . expect ( "first 16 btyes of expanded garbage" ) ;
379
+ . expect ( "first 16 bytes of expanded garbage" ) ;
380
380
let responder_garbage_terminator: [ u8 ; 16 ] = garbage[ 16 ..]
381
381
. try_into ( )
382
382
. expect ( "last 16 bytes of expanded garbage" ) ;
@@ -783,15 +783,41 @@ impl CipherSession {
783
783
}
784
784
}
785
785
786
+ /// Fill a slice with random bytes. This trait _should_ be cryptographically secure; however, a
787
+ /// psuedo-random number generator may be sufficient depending on your security model.
788
+ pub trait FillBytes {
789
+ /// Fill a 32 byte slice with random data.
790
+ fn fill_bytes ( & mut self , dest : & mut [ u8 ; 32 ] ) ;
791
+ }
792
+
793
+ #[ cfg( feature = "std" ) ]
794
+ macro_rules! impl_fill_bytes {
795
+ ( $rng: ident) => {
796
+ impl FillBytes for $rng {
797
+ fn fill_bytes( & mut self , dest: & mut [ u8 ; 32 ] ) {
798
+ use bitcoin:: secp256k1:: rand:: RngCore ;
799
+ RngCore :: fill_bytes( self , dest) ;
800
+ }
801
+ }
802
+ } ;
803
+ }
804
+
805
+ #[ cfg( feature = "std" ) ]
806
+ use bitcoin:: secp256k1:: rand:: rngs:: { StdRng , ThreadRng } ;
807
+ #[ cfg( feature = "std" ) ]
808
+ impl_fill_bytes ! ( StdRng ) ;
809
+ #[ cfg( feature = "std" ) ]
810
+ impl_fill_bytes ! ( ThreadRng ) ;
811
+
786
812
#[ cfg( all( test, feature = "std" ) ) ]
787
813
mod tests {
788
814
789
815
use super :: * ;
790
816
use bitcoin:: secp256k1:: ellswift:: { ElligatorSwift , ElligatorSwiftParty } ;
817
+ use bitcoin:: secp256k1:: rand:: Rng ;
791
818
use bitcoin:: secp256k1:: SecretKey ;
792
819
use core:: str:: FromStr ;
793
820
use hex:: prelude:: * ;
794
- use rand:: Rng ;
795
821
use std:: vec;
796
822
use std:: vec:: Vec ;
797
823
@@ -972,7 +998,7 @@ mod tests {
972
998
973
999
#[ test]
974
1000
fn test_fuzz_packets ( ) {
975
- let mut rng = rand:: thread_rng ( ) ;
1001
+ let mut rng = bitcoin :: secp256k1 :: rand:: thread_rng ( ) ;
976
1002
let alice =
977
1003
SecretKey :: from_str ( "61062ea5071d800bbfd59e2e8b53d47d194b095ae5a4df04936b49772ef0d4d7" )
978
1004
. unwrap ( ) ;
@@ -1039,7 +1065,7 @@ mod tests {
1039
1065
1040
1066
#[ test]
1041
1067
fn test_additional_authenticated_data ( ) {
1042
- let mut rng = rand:: thread_rng ( ) ;
1068
+ let mut rng = bitcoin :: secp256k1 :: rand:: thread_rng ( ) ;
1043
1069
let alice =
1044
1070
SecretKey :: from_str ( "61062ea5071d800bbfd59e2e8b53d47d194b095ae5a4df04936b49772ef0d4d7" )
1045
1071
. unwrap ( ) ;
@@ -1088,7 +1114,7 @@ mod tests {
1088
1114
1089
1115
#[ test]
1090
1116
fn test_vector_1 ( ) {
1091
- let mut rng = rand:: thread_rng ( ) ;
1117
+ let mut rng = bitcoin :: secp256k1 :: rand:: thread_rng ( ) ;
1092
1118
let alice =
1093
1119
SecretKey :: from_str ( "61062ea5071d800bbfd59e2e8b53d47d194b095ae5a4df04936b49772ef0d4d7" )
1094
1120
. unwrap ( ) ;
0 commit comments