orlp / ed25519

Portable C implementation of Ed25519, a high-speed high-security public-key signature system.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Get public key (and seed) from private key

stv0g opened this issue Β· comments

Hi,

as far as I know it should be possible to get the public key from a private one.
Unfortunatly I'm not feeling confident enough to code this by myself.

So maybe someone could do this? Consider this a feature request πŸ˜„

There are different ways to store a Ed25519 private key. The seed gets hashed to get the private key, and then the private key gets multiplied by the Ed25519 curve basepoint to get the public key. You can store the seed and hash it everytime you need the private key, or just store the result of the hash. My library does the latter, as this saves a bit of performance on every operation. This means that it's impossible to get the seed back from the private or public key.

Also interesting is that Ed25519 also requires the public key while signing. Some libraries hide this by concatenating the public key and the private key/seed and calling that result the private key. I don't, and require you to pass both the public key and private key to the sign operation.

So to answer your issue:

It's impossible to get the seed from the private key. To turn a private key (which is the hashed seed) into a public key, look into ed25519_create_keypair and remove the hashing code.

#include "ge.h"

void ed25519_get_pubkey(unsigned char *public_key, const unsigned char *private_key) {
    ge_p3 A;

    ge_scalarmult_base(&A, private_key);
    ge_p3_tobytes(public_key, &A);
}

Hi @nightcracker !
Thanks a lot πŸ˜„ That was exactly what I was looking for.