1

I'm trying to work out a minimal example with the bitcoin core secp256k1 library but am a bit lost due to the many options available. Concretely, I simply want to use libsecp256k1 to multiply the generator point G as defined by the standard with an integer k, ie H = k*G.

So far, I found secp256k1_scalar_mul, which multiplies two scalars and secp256k1_fe_mul which multiplies two field elements, while close neither is what I'm looking for. So I was wondering if someone could point me to a suitable function in libsecp256k1?

Thanks!

2

1 Answer 1

2

Remember, as Pieter Wuille said, all exposed functions (only those that you'd need to use) are in include/secp256k1.h

You can use secp256k1_ec_pubkey_create like this:

secp256k1_context *sign = secp256k1_context_create(SECP256K1_CONTEXT_SIGN);
secp256k1_pubkey pubkey;

// Here our private key is 1, little endian
const unsigned char seckey[32] = {1};

if (!secp256k1_ec_pubkey_create(sign, &pubkey, seckey)) {
    // Private key out of range
    // abort!
    secp256k1_context_destroy(sign);
    exit(1);
}

// Use 65 and SECP256K1_EC_UNCOMPRESSED for uncompressed public key
unsigned char outpubkey[33];
size_t written_bytes = 33;
secp256k1_ec_pubkey_serialize(sign, outpubkey, &written_bytes, &pubkey, SECP256K1_EC_COMPRESSED);

printf("Public key: ");

for (int i = 0; i < 33; i++) {
    printf("%.2x", (unsigned int) outpubkey[i]);
}

printf("\n");

secp256k1_context_destroy(sign);

Whose output can be verified with ThePiachu's tool and the private key 0100000000000000000000000000000000000000000000000000000000000000

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.