How to generate various key-pair by using secp256k1 C library?

742 views Asked by At

I am just writing a small test program by using secp256k1 C lib, targeting to generate various random ecdsa key pairs, by using secp256k1-zkp API, simply follow up some example in tests.c.

However, a little bit surprised, I find that I can not get the varied key-pair, every time I run the test program I get the exact same private key (thereafter the same public key).

This does not make sense but I can not figure out where is the problem, someone can kindly give help and suggestion?

Below are the sample code I am using:

random_scalar_order_test(&rand);
secp256k1_scalar_get_b32(privkey, &rand);
CHECK(secp256k1_ec_seckey_verify(ctx, privkey) == 1);
CHECK(secp256k1_ec_pubkey_create(ctx, pubkey, &pubkeylen, 
                                 privkey, (secp256k1_rand32() & 3) != 0) == 1);

It looks after compiling, every time I run the test, the first two lines of code always provide the exact same privkey, so the public key will be also fixed. Is there any rand seed API can be used to generate the different private key every time called?

1

There are 1 answers

1
Jeremy Busk On

Curve public keys will always be different even if for the same private key. This is normal behavior.