<p>Use <a href="https://github.com/bitcoin-core/secp256k1/blob/7b50483/include/secp256k1.h#L329-L371" rel="nofollow noreferrer"><code>secp256k1_ec_pubkey_parse</code> and <code>secp256k1_ec_pubkey_serialize</code></a>:</p>



<pre><code>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, &amp;pubkey, input, 33) != 1) {
    puts("Public key not on curve");
    secp256k1_context_destroy(ctx);
    return 1;
}

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

printf("Uncompress public key: ");

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

puts("");

secp256k1_context_destroy(ctx);
</code></pre>

CC BY-SA 4.0
2020-04-27T02:37:34.843Z
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
CC BY-SA 4.0
2020-04-27T02:57:13.740Z
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
CC BY-SA 4.0
2020-04-27T07:36:16.013Z
Did you run `make install` in the libsecp256k1 folder? @LeonMSH
MCCCS
CC BY-SA 4.0
2020-04-28T05:57:44.530Z
oh yes, that solves my problem! thanks so much!!
LeonMSH
CC BY-SA 4.0
2020-04-24T12:33:34.400Z
2020-04-26T12:57:26.733Z
2020-04-26T12:57:26.733Z
MCCCS
<p>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.</p>

<p>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?</p>

<p>Thanks!</p>

<api><ecdsa><secp256k1>
Does secp256k1 library provide API for generating uncompressed key?
LeonMSH
# Does secp256k1 library provide API for generating uncompressed key?

(Asked by: username_0 on 2020-04-24)

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?

Thanks!

**Tags:** api, ecdsa, secp256k1


---

## 1 answers

### Answer by username_1 on 2020-04-24. Score: 2

Use [`secp256k1_ec_pubkey_parse` and `secp256k1_ec_pubkey_serialize`](https://github.com/bitcoin-core/secp256k1/blob/7b50483/include/secp256k1.h#L329-L371):

```
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");
    secp256k1_context_destroy(ctx);
    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]);
}

puts("");

secp256k1_context_destroy(ctx);

```

> **Comments:**
> **username_0**: 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.  
> **username_0**: 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'  
> **username_1**: Did you run `make install` in the libsecp256k1 folder? @username_0  
> **username_0**: oh yes, that solves my problem! thanks so much!!  

---

