@@ -113,6 +113,8 @@ var(FCryptoTests) int CurrentTestDelegateIndex;
113
113
114
114
var private bool bRandPrimesRequested ;
115
115
116
+ var const array <byte > RepeatedBinaryRandoms ;
117
+
116
118
/*
117
119
* AES known-answer tests. Order: key, plaintext, ciphertext.
118
120
*/
@@ -618,6 +620,7 @@ private final simulated function RandomBigInt(
618
620
local array <int> BigIntN ;
619
621
local int BICLen ;
620
622
local int BINLen ;
623
+ local int RandomIndex ;
621
624
// local string BigIntNString;
622
625
623
626
class 'FCryptoBigInt' .static .Decode (BigIntN , N , N .Length );
@@ -654,11 +657,27 @@ private final simulated function RandomBigInt(
654
657
return ;
655
658
}
656
659
660
+ RandomIndex = 0 ;
657
661
Dst .Length = 0 ;
658
662
for (I = 0 ; I <= Rounds ; ++I )
659
663
{
660
664
Ctl = 0 ;
661
- Dst [I ] = Rand (256 );
665
+
666
+ // NOTE: this is attempting to somewhat imitate GMP mpz_rrandomb behavior
667
+ // to generate an integer with long strings of zeros and ones in the
668
+ // binary representation.
669
+ // TODO: better algorithm.
670
+ if (FRand () >= 0.33 )
671
+ {
672
+ // Pick one of known numbers with a binary representation that has a lot
673
+ // of consecutive ones or zeros.
674
+ Dst [I ] = RepeatedBinaryRandoms [RandomIndex ];
675
+ RandomIndex = (RandomIndex + 1 ) % RepeatedBinaryRandoms .Length ;
676
+ }
677
+ else
678
+ {
679
+ Dst [I ] = Rand (256 );
680
+ }
662
681
663
682
// Convert Dst to a BigInt for checking whether it's
664
683
// less or greater than BigIntN.
@@ -1375,6 +1394,27 @@ DefaultProperties
1375
1394
Begin Object Class =FCryptoUtils Name =Utils
1376
1395
End Object
1377
1396
1397
+ RepeatedBinaryRandoms ={(
1398
+ 255 , // 11111111
1399
+ 255 , // 11111111
1400
+ 255 , // 11111111
1401
+ 245 , // 11111110
1402
+ 0 , // 00000000
1403
+ 64 , // 10000000
1404
+ 0 , // 00000000
1405
+ 0 , // 00000000
1406
+ 0 , // 00000000
1407
+ 0 , // 00000000
1408
+ 65 , // 10000010
1409
+ 0 , // 00000000
1410
+ 66 , // 10000100
1411
+ 0 , // 00000000
1412
+ 255 , // 11111111
1413
+ 255 , // 11111111
1414
+ 255 , // 11111111
1415
+ 255 , // 11111111
1416
+ )}
1417
+
1378
1418
Bytes_0 (0 )=0
1379
1419
1380
1420
// GMP mpz big endian export format.
0 commit comments