0

I am just writing a small test program by using secp256k1-zkp 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:

secp256k1_scalar_t rand; //a 256bit,32byte scalar rand?

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);

I have been using the tweak API (this by my understanding, change the private/public key by using a rand number by multiply or add), it works but again, after tweak I indeed get another key pair and each time run the program it will not change.

    secp256k1_rand256_test(rnd);
    ret1 = secp256k1_ec_privkey_tweak_mul(ctx, privkey, rnd);  
    ret2 = secp256k1_ec_pubkey_tweak_mul(ctx, pubkey, pubkeylen, rnd);
    CHECK(ret1 == ret2);
    if (ret1 == 0) {
        return;
    }
    //create the new pubkey2 from tweaked private key, compared with tweaked pubkey 
    CHECK(secp256k1_ec_pubkey_create(ctx, pubkey2, &pubkeylen2, privkey, pubkeylen == 33) == 1);

I am now guessing that this API: secp256k1_rand256_test() does not accept some random seed so as soon as compiled it will always generate the same rand number. is there any other API that can be used to output not "terminate rand number"?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.