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!

Vojtěch Strnad
  • 5,623
  • 1
  • 8
  • 31
fdffd
  • 13
  • 3
  • https://github.com/bitcoin-core/secp256k1/blob/7b50483/include/secp256k1.h#L566 ? – MCCCS Apr 18 '20 at 16:02
  • 1
    @MCCCS Exactly, you should turn that into an answer. The functions listed by OP are internal operations that aren't exposed outside the library. – Pieter Wuille Apr 18 '20 at 19:51

1 Answers1

1

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

MCCCS
  • 10,097
  • 5
  • 27
  • 55