orlp/ed25519

Inconsistent signature results

Opened this issue · 1 comments

idcmp commented

Note: this library stores private keys in a different format than some other libraries, notably libsodium. They tend to store the concatenation of the seed and public_key as their private key representation. If you wish to be compatible with these libraries you must keep the seed around.

Can you expand on this? In Go, I'm generating a key pair, and using it for signing:

        // pubKey = 32 bytes, privKey = 64 bytes (which is seed + publicKey)
	pubKey, privKey, err := ed25519.GenerateKey(rand.Reader)

	goSignature := ed25519.Sign(privKey, exampleBytes)

When I do something similar with the same key material and ed25519_sign, I get a different signature:

	var pubBuf, privBuf, messageBuf, signatureBuf bytes.Buffer
	messageBuf.Write(exampleBytes)
	pubBuf.Write(pubKey)
	privBuf.Write(privKey)

	for i := 0; i != 64; i++ {
		signatureBuf.WriteByte(0)
	}
	C.ed25519_sign(
		(*C.uchar)(&signatureBuf.Bytes()[0]),
		(*C.uchar)(&messageBuf.Bytes()[0]),
		(C.ulong)(len(exampleBytes)),
		(*C.uchar)(&pubBuf.Bytes()[0]),
		(*C.uchar)(&privBuf.Bytes()[0]))

I'm guessing this is related to the comment above, but I'm not quite sure?

the "privKey" in Go should be "seed[32]" concatenate "public_key[32]" in test.c