File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -32,17 +32,20 @@ public CryptoRandom() : base(Seed: 0)
32
32
33
33
static void SanityCheck ( )
34
34
{
35
- var testBuffer = new byte [ BYTE_CACHE_SIZE ] ;
35
+ var testBuffer = new byte [ BYTE_CACHE_SIZE / 2 ] ;
36
36
int status , i , j ;
37
+ const int COLLISION_FREE_BLOCK_SIZE = 16 ;
37
38
38
- status = ( int ) BCrypt . BCryptGenRandom ( testBuffer , BYTE_CACHE_SIZE / 2 ) ;
39
+ status = ( int ) BCrypt . BCryptGenRandom ( testBuffer , testBuffer . Length ) ;
39
40
if ( status != ( int ) BCrypt . NTSTATUS . STATUS_SUCCESS ) throw new CryptographicException ( status ) ;
40
41
41
- for ( i = BYTE_CACHE_SIZE / 2 ; i < BYTE_CACHE_SIZE ; ++ i )
42
- if ( testBuffer [ i ] != 0 ) throw new CryptographicException ( "CryptoRandom failed sanity check #1." ) ;
43
-
44
- for ( i = 0 , status = 0 , j = BYTE_CACHE_SIZE / 2 ; i < j ; ++ i ) status |= testBuffer [ i ] ;
45
- if ( status == 0 ) throw new CryptographicException ( "CryptoRandom failed sanity check #2." ) ;
42
+ if ( testBuffer . Length < COLLISION_FREE_BLOCK_SIZE * 2 ) return ; // should be compiled away
43
+ for ( i = 0 ; i < testBuffer . Length - COLLISION_FREE_BLOCK_SIZE ; i += COLLISION_FREE_BLOCK_SIZE )
44
+ {
45
+ for ( j = 0 , status = 0 ; j < COLLISION_FREE_BLOCK_SIZE ; ++ j )
46
+ status |= testBuffer [ i + j ] ^ testBuffer [ i + j + COLLISION_FREE_BLOCK_SIZE ] ;
47
+ if ( status == 0 ) throw new CryptographicException ( "CryptoRandom failed sanity check #2." ) ;
48
+ }
46
49
} // SanityCheck()
47
50
48
51
#region NextLong()
You can’t perform that action at this time.
0 commit comments