cryptography icon indicating copy to clipboard operation
cryptography copied to clipboard

Export more ed25519 function for Convert the Curve25519 public key into an Ed25519 public key.

Open crossle opened this issue 5 years ago • 2 comments

I wanna convert the Convert the Curve25519 public key into an Ed25519 public key, hope export more function for FeFromBytes FeOne..

	publicKey[31] &= 0x7F

	/* Convert the Curve25519 public key into an Ed25519 public key.  In
	particular, convert Curve25519's "montgomery" x-coordinate into an
	Ed25519 "edwards" y-coordinate:

	ed_y = (mont_x - 1) / (mont_x + 1)

	NOTE: mont_x=-1 is converted to ed_y=0 since fe_invert is mod-exp

	Then move the sign bit into the pubkey from the signature.
	*/

	var edY, one, montX, montXMinusOne, montXPlusOne edwards25519.FieldElement
	edwards25519.FeFromBytes(&montX, &publicKey)
	edwards25519.FeOne(&one)
	edwards25519.FeSub(&montXMinusOne, &montX, &one)
	edwards25519.FeAdd(&montXPlusOne, &montX, &one)
	edwards25519.FeInvert(&montXPlusOne, &montXPlusOne)
	edwards25519.FeMul(&edY, &montXMinusOne, &montXPlusOne)

	var A_ed [32]byte
	edwards25519.FeToBytes(&A_ed, &edY)

	A_ed[31] |= signature[63] & 0x80
	signature[63] &= 0x7F

	return ed25519.Verify(&A_ed, message, signature)

crossle avatar May 13 '20 13:05 crossle

Any suggestions for this?

crossle avatar May 18 '20 16:05 crossle

If anyone creates a pull request that implements this, I can do code review. :)

terrier989 avatar May 31 '20 13:05 terrier989