@@ -1733,26 +1733,46 @@ void run_ecdsa_openssl(void) {
17331733#endif
17341734
17351735int main (int argc , char * * argv ) {
1736- uint64_t seed ;
1736+ unsigned char seed16 [16 ] = {0 };
1737+ unsigned char run32 [32 ] = {0 };
17371738 /* find iteration count */
17381739 if (argc > 1 ) {
17391740 count = strtol (argv [1 ], NULL , 0 );
17401741 }
17411742
17421743 /* find random seed */
17431744 if (argc > 2 ) {
1744- sscanf (argv [2 ], "%" I64uFORMAT , (unsigned long long * )& seed );
1745+ int pos = 0 ;
1746+ const char * ch = argv [2 ];
1747+ while (pos < 16 && * ch != 0 ) {
1748+ unsigned short sh ;
1749+ if (sscanf (ch , "%2hx" , & sh )) {
1750+ seed16 [pos ] = sh ;
1751+ } else {
1752+ break ;
1753+ }
1754+ ch += 2 ;
1755+ pos ++ ;
1756+ }
17451757 } else {
17461758 FILE * frand = fopen ("/dev/urandom" , "r" );
1747- if (!frand || !fread (& seed , sizeof (seed ), 1 , frand )) {
1748- seed = time (NULL ) * 1337 ;
1759+ if (!frand || !fread (& seed16 , sizeof (seed16 ), 1 , frand )) {
1760+ uint64_t t = time (NULL ) * (uint64_t )1337 ;
1761+ seed16 [0 ] ^= t ;
1762+ seed16 [1 ] ^= t >> 8 ;
1763+ seed16 [2 ] ^= t >> 16 ;
1764+ seed16 [3 ] ^= t >> 24 ;
1765+ seed16 [4 ] ^= t >> 32 ;
1766+ seed16 [5 ] ^= t >> 40 ;
1767+ seed16 [6 ] ^= t >> 48 ;
1768+ seed16 [7 ] ^= t >> 56 ;
17491769 }
17501770 fclose (frand );
17511771 }
1752- secp256k1_rand_seed (seed );
1772+ secp256k1_rand_seed (seed16 );
17531773
17541774 printf ("test count = %i\n" , count );
1755- printf ("random seed = %" I64uFORMAT " \n" , ( unsigned long long ) seed );
1775+ 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 ] );
17561776
17571777 /* initialize */
17581778 secp256k1_start (SECP256K1_START_SIGN | SECP256K1_START_VERIFY );
@@ -1798,7 +1818,8 @@ int main(int argc, char **argv) {
17981818 run_ecdsa_openssl ();
17991819#endif
18001820
1801- printf ("random run = %llu\n" , (unsigned long long )secp256k1_rand32 () + ((unsigned long long )secp256k1_rand32 () << 32 ));
1821+ secp256k1_rand256 (run32 );
1822+ 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 ]);
18021823
18031824 /* shutdown */
18041825 secp256k1_stop ();
0 commit comments