@@ -804,78 +804,6 @@ static void run_tagged_sha256_tests(void) {
804
804
CHECK (secp256k1_memcmp_var (hash32 , hash_expected , sizeof (hash32 )) == 0 );
805
805
}
806
806
807
- /***** RANDOM TESTS *****/
808
-
809
- static void test_rand_bits (int rand32 , int bits ) {
810
- /* (1-1/2^B)^rounds[B] < 1/10^9, so rounds is the number of iterations to
811
- * get a false negative chance below once in a billion */
812
- static const unsigned int rounds [7 ] = {1 , 30 , 73 , 156 , 322 , 653 , 1316 };
813
- /* We try multiplying the results with various odd numbers, which shouldn't
814
- * influence the uniform distribution modulo a power of 2. */
815
- static const uint32_t mults [6 ] = {1 , 3 , 21 , 289 , 0x9999 , 0x80402011 };
816
- /* We only select up to 6 bits from the output to analyse */
817
- unsigned int usebits = bits > 6 ? 6 : bits ;
818
- unsigned int maxshift = bits - usebits ;
819
- /* For each of the maxshift+1 usebits-bit sequences inside a bits-bit
820
- number, track all observed outcomes, one per bit in a uint64_t. */
821
- uint64_t x [6 ][27 ] = {{0 }};
822
- unsigned int i , shift , m ;
823
- /* Multiply the output of all rand calls with the odd number m, which
824
- should not change the uniformity of its distribution. */
825
- for (i = 0 ; i < rounds [usebits ]; i ++ ) {
826
- uint32_t r = (rand32 ? secp256k1_testrand32 () : secp256k1_testrand_bits (bits ));
827
- CHECK ((((uint64_t )r ) >> bits ) == 0 );
828
- for (m = 0 ; m < sizeof (mults ) / sizeof (mults [0 ]); m ++ ) {
829
- uint32_t rm = r * mults [m ];
830
- for (shift = 0 ; shift <= maxshift ; shift ++ ) {
831
- x [m ][shift ] |= (((uint64_t )1 ) << ((rm >> shift ) & ((1 << usebits ) - 1 )));
832
- }
833
- }
834
- }
835
- for (m = 0 ; m < sizeof (mults ) / sizeof (mults [0 ]); m ++ ) {
836
- for (shift = 0 ; shift <= maxshift ; shift ++ ) {
837
- /* Test that the lower usebits bits of x[shift] are 1 */
838
- CHECK (((~x [m ][shift ]) << (64 - (1 << usebits ))) == 0 );
839
- }
840
- }
841
- }
842
-
843
- /* Subrange must be a whole divisor of range, and at most 64 */
844
- static void test_rand_int (uint32_t range , uint32_t subrange ) {
845
- /* (1-1/subrange)^rounds < 1/10^9 */
846
- int rounds = (subrange * 2073 ) / 100 ;
847
- int i ;
848
- uint64_t x = 0 ;
849
- CHECK ((range % subrange ) == 0 );
850
- for (i = 0 ; i < rounds ; i ++ ) {
851
- uint32_t r = secp256k1_testrand_int (range );
852
- CHECK (r < range );
853
- r = r % subrange ;
854
- x |= (((uint64_t )1 ) << r );
855
- }
856
- /* Test that the lower subrange bits of x are 1. */
857
- CHECK (((~x ) << (64 - subrange )) == 0 );
858
- }
859
-
860
- static void run_rand_bits (void ) {
861
- size_t b ;
862
- test_rand_bits (1 , 32 );
863
- for (b = 1 ; b <= 32 ; b ++ ) {
864
- test_rand_bits (0 , b );
865
- }
866
- }
867
-
868
- static void run_rand_int (void ) {
869
- static const uint32_t ms [] = {1 , 3 , 17 , 1000 , 13771 , 999999 , 33554432 };
870
- static const uint32_t ss [] = {1 , 3 , 6 , 9 , 13 , 31 , 64 };
871
- unsigned int m , s ;
872
- for (m = 0 ; m < sizeof (ms ) / sizeof (ms [0 ]); m ++ ) {
873
- for (s = 0 ; s < sizeof (ss ) / sizeof (ss [0 ]); s ++ ) {
874
- test_rand_int (ms [m ] * ss [s ], ss [s ]);
875
- }
876
- }
877
- }
878
-
879
807
/***** MODINV TESTS *****/
880
808
881
809
/* Compute the modular inverse of (odd) x mod 2^64. */
@@ -7730,10 +7658,6 @@ int main(int argc, char **argv) {
7730
7658
/* scratch tests */
7731
7659
run_scratch_tests ();
7732
7660
7733
- /* randomness tests */
7734
- run_rand_bits ();
7735
- run_rand_int ();
7736
-
7737
7661
/* integer arithmetic tests */
7738
7662
#ifdef SECP256K1_WIDEMUL_INT128
7739
7663
run_int128_tests ();
0 commit comments