@@ -5530,9 +5530,6 @@ void run_cmov_tests(void) {
55305530}
55315531
55325532int main (int argc , char * * argv ) {
5533- unsigned char seed16 [16 ] = {0 };
5534- unsigned char run32 [32 ] = {0 };
5535-
55365533 /* Disable buffering for stdout to improve reliability of getting
55375534 * diagnostic information. Happens right at the start of main because
55385535 * setbuf must be used before any other operation on the stream. */
@@ -5545,52 +5542,20 @@ int main(int argc, char **argv) {
55455542 if (argc > 1 ) {
55465543 count = strtol (argv [1 ], NULL , 0 );
55475544 }
5545+ printf ("test count = %i\n" , count );
55485546
55495547 /* find random seed */
5550- if (argc > 2 ) {
5551- int pos = 0 ;
5552- const char * ch = argv [2 ];
5553- while (pos < 16 && ch [0 ] != 0 && ch [1 ] != 0 ) {
5554- unsigned short sh ;
5555- if ((sscanf (ch , "%2hx" , & sh )) == 1 ) {
5556- seed16 [pos ] = sh ;
5557- } else {
5558- break ;
5559- }
5560- ch += 2 ;
5561- pos ++ ;
5562- }
5563- } else {
5564- FILE * frand = fopen ("/dev/urandom" , "r" );
5565- if ((frand == NULL ) || fread (& seed16 , 1 , sizeof (seed16 ), frand ) != sizeof (seed16 )) {
5566- uint64_t t = time (NULL ) * (uint64_t )1337 ;
5567- fprintf (stderr , "WARNING: could not read 16 bytes from /dev/urandom; falling back to insecure PRNG\n" );
5568- seed16 [0 ] ^= t ;
5569- seed16 [1 ] ^= t >> 8 ;
5570- seed16 [2 ] ^= t >> 16 ;
5571- seed16 [3 ] ^= t >> 24 ;
5572- seed16 [4 ] ^= t >> 32 ;
5573- seed16 [5 ] ^= t >> 40 ;
5574- seed16 [6 ] ^= t >> 48 ;
5575- seed16 [7 ] ^= t >> 56 ;
5576- }
5577- if (frand ) {
5578- fclose (frand );
5579- }
5580- }
5581- secp256k1_rand_seed (seed16 );
5582-
5583- printf ("test count = %i\n" , count );
5584- printf ("random seed = %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n" , seed16 [0 ], seed16 [1 ], seed16 [2 ], seed16 [3 ], seed16 [4 ], seed16 [5 ], seed16 [6 ], seed16 [7 ], seed16 [8 ], seed16 [9 ], seed16 [10 ], seed16 [11 ], seed16 [12 ], seed16 [13 ], seed16 [14 ], seed16 [15 ]);
5548+ secp256k1_rand_init (argc > 2 ? argv [2 ] : NULL );
55855549
55865550 /* initialize */
55875551 run_context_tests (0 );
55885552 run_context_tests (1 );
55895553 run_scratch_tests ();
55905554 ctx = secp256k1_context_create (SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY );
55915555 if (secp256k1_rand_bits (1 )) {
5592- secp256k1_rand256 (run32 );
5593- CHECK (secp256k1_context_randomize (ctx , secp256k1_rand_bits (1 ) ? run32 : NULL ));
5556+ unsigned char rand32 [32 ];
5557+ secp256k1_rand256 (rand32 );
5558+ CHECK (secp256k1_context_randomize (ctx , secp256k1_rand_bits (1 ) ? rand32 : NULL ));
55945559 }
55955560
55965561 run_rand_bits ();
@@ -5678,8 +5643,7 @@ int main(int argc, char **argv) {
56785643
56795644 run_cmov_tests ();
56805645
5681- secp256k1_rand256 (run32 );
5682- printf ("random run = %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n" , run32 [0 ], run32 [1 ], run32 [2 ], run32 [3 ], run32 [4 ], run32 [5 ], run32 [6 ], run32 [7 ], run32 [8 ], run32 [9 ], run32 [10 ], run32 [11 ], run32 [12 ], run32 [13 ], run32 [14 ], run32 [15 ]);
5646+ secp256k1_rand_finish ();
56835647
56845648 /* shutdown */
56855649 secp256k1_context_destroy (ctx );
0 commit comments