use 128-bit hex seed
This commit is contained in:
35
src/tests.c
35
src/tests.c
@@ -1763,7 +1763,8 @@ void run_ecdsa_openssl(void) {
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
uint64_t seed;
|
||||
unsigned char seed16[16] = {0};
|
||||
unsigned char run32[32] = {0};
|
||||
/* find iteration count */
|
||||
if (argc > 1) {
|
||||
count = strtol(argv[1], NULL, 0);
|
||||
@@ -1771,18 +1772,37 @@ int main(int argc, char **argv) {
|
||||
|
||||
/* find random seed */
|
||||
if (argc > 2) {
|
||||
sscanf(argv[2], "%" I64uFORMAT, (unsigned long long*)&seed);
|
||||
int pos = 0;
|
||||
const char* ch = argv[2];
|
||||
while (pos < 16 && ch[0] != 0 && ch[1] != 0) {
|
||||
unsigned short sh;
|
||||
if (sscanf(ch, "%2hx", &sh)) {
|
||||
seed16[pos] = sh;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
ch += 2;
|
||||
pos++;
|
||||
}
|
||||
} else {
|
||||
FILE *frand = fopen("/dev/urandom", "r");
|
||||
if (!frand || !fread(&seed, sizeof(seed), 1, frand)) {
|
||||
seed = time(NULL) * 1337;
|
||||
if (!frand || !fread(&seed16, sizeof(seed16), 1, frand)) {
|
||||
uint64_t t = time(NULL) * (uint64_t)1337;
|
||||
seed16[0] ^= t;
|
||||
seed16[1] ^= t >> 8;
|
||||
seed16[2] ^= t >> 16;
|
||||
seed16[3] ^= t >> 24;
|
||||
seed16[4] ^= t >> 32;
|
||||
seed16[5] ^= t >> 40;
|
||||
seed16[6] ^= t >> 48;
|
||||
seed16[7] ^= t >> 56;
|
||||
}
|
||||
fclose(frand);
|
||||
}
|
||||
secp256k1_rand_seed(seed);
|
||||
secp256k1_rand_seed(seed16);
|
||||
|
||||
printf("test count = %i\n", count);
|
||||
printf("random seed = %" I64uFORMAT "\n", (unsigned long long)seed);
|
||||
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]);
|
||||
|
||||
/* initialize */
|
||||
secp256k1_start(SECP256K1_START_SIGN | SECP256K1_START_VERIFY);
|
||||
@@ -1828,7 +1848,8 @@ int main(int argc, char **argv) {
|
||||
run_ecdsa_openssl();
|
||||
#endif
|
||||
|
||||
printf("random run = %llu\n", (unsigned long long)secp256k1_rand32() + ((unsigned long long)secp256k1_rand32() << 32));
|
||||
secp256k1_rand256(run32);
|
||||
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]);
|
||||
|
||||
/* shutdown */
|
||||
secp256k1_stop();
|
||||
|
||||
Reference in New Issue
Block a user