File tree 1 file changed +24
-0
lines changed
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,30 @@ fn test_diff() {
40
40
assert ! ( d < 4500 ) ;
41
41
}
42
42
43
+ // Tests the quality of calling getrandom repeatedly on small buffers
44
+ #[ test]
45
+ #[ cfg( not( feature = "custom" ) ) ]
46
+ fn test_small ( ) {
47
+ // For each buffer size, get at least 256 bytes and check that between
48
+ // 3 and 5 bits per byte differ. Probability of failure:
49
+ // ~ 2^(-91) = 64 * 2 * CDF[BinomialDistribution[8*256, 0.5], 3*256]
50
+ for size in 1 ..=64 {
51
+ let mut num_bytes = 0 ;
52
+ let mut diff_bits = 0 ;
53
+ while num_bytes < 256 {
54
+ let mut s1 = vec ! [ 0u8 ; size] ;
55
+ getrandom_impl ( & mut s1) . unwrap ( ) ;
56
+ let mut s2 = vec ! [ 0u8 ; size] ;
57
+ getrandom_impl ( & mut s2) . unwrap ( ) ;
58
+
59
+ num_bytes += size;
60
+ diff_bits += num_diff_bits ( & s1, & s2) ;
61
+ }
62
+ assert ! ( diff_bits > 3 * num_bytes) ;
63
+ assert ! ( diff_bits < 5 * num_bytes) ;
64
+ }
65
+ }
66
+
43
67
#[ test]
44
68
fn test_huge ( ) {
45
69
let mut huge = [ 0u8 ; 100_000 ] ;
You can’t perform that action at this time.
0 commit comments