Hi I am right now want to do a make a small tool to generate some test vector for ecdsa. Openssl is quite good, for support secp256k1 bitcoin provides an excellent library.

However, it looks what I get from secp256k1 API only the compressed key. I find some post about how to convert the compressed key (Qx) to uncompressed key (Qx,Qy). But I just wondering if I can directly get the uncompressed key?


1 Answer 1


Use secp256k1_ec_pubkey_parse and secp256k1_ec_pubkey_serialize:

secp256k1_context *ctx = secp256k1_context_create(SECP256K1_CONTEXT_NONE);
secp256k1_pubkey pubkey;

const unsigned char input[33] = {0x02,0x8c,0x28,0xa9,0x7b,0xf8,0x29,0x8b,0xc0,0xd2,0x3d,0x8c,0x74,0x94,0x52,0xa3,0x2e,0x69,0x4b,0x65,0xe3,0x0a,0x94,0x72,0xa3,0x95,0x4a,0xb3,0x0f,0xe5,0x32,0x4c,0xaa};

if (secp256k1_ec_pubkey_parse(ctx, &pubkey, input, 33) != 1) {
    puts("Public key not on curve");
    return 1;

unsigned char outpubkey[65];
size_t written_bytes = 65;
secp256k1_ec_pubkey_serialize(ctx, outpubkey, &written_bytes, &pubkey, SECP256K1_EC_UNCOMPRESSED);

printf("Uncompress public key: ");

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


  • thanks a lot for the suggestion. I find the similar way, firstly use the secp256k1_ec_pubkey_create() to get the pub key, then using secp256k1_ec_pubkey_serialize to form the either compresss or uncompressed key.
    – LeonMSH
    Apr 27, 2020 at 2:37
  • by the way, for secp256k1 library, in linker stage, what is the -l flag to be used--I find someone metioned to use -lsecp256k1 but it does not work for me? I can compile the program by using some CMake but it is too heavy and what I need is just a small tool--so I want to make a small make file, then I meet warning as keygen.cpp:(.text+0x558): undefined reference to `secp256k1_ecdsa_signature_serialize_compact'
    – LeonMSH
    Apr 27, 2020 at 2:57
  • Did you run make install in the libsecp256k1 folder? @LeonMSH
    – MCCCS
    Apr 27, 2020 at 7:36
  • oh yes, that solves my problem! thanks so much!!
    – LeonMSH
    Apr 28, 2020 at 5:57

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.