Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: add ed25519 to curve25519 conversion functions #38074

Closed
baha-ai opened this issue Mar 25, 2020 · 1 comment
Closed

proposal: add ed25519 to curve25519 conversion functions #38074

baha-ai opened this issue Mar 25, 2020 · 1 comment
Labels
FrozenDueToAge Proposal Proposal-Crypto Proposal related to crypto packages or other security issues
Milestone

Comments

@baha-ai
Copy link

baha-ai commented Mar 25, 2020

As per this comment:
agl/ed25519#24 (comment)

It would be much appreciated if the original functions that were hosted at (now gone in favour of crypto/ed25519 package):
https://github.com/agl/blob/master/ed25519/extra25519/extra25519.go
for converting ed25519 keys into curve15519 keys to be hosted in here, or somewhere in /x/crypto/ed25519 (or x/crypto/extra25519) if they are not suitable for the core library.

Namely, these functions are needed:

// PrivateKeyToCurve25519 converts an ed25519 private key into a corresponding
// curve25519 private key such that the resulting curve25519 public key will
// equal the result from PublicKeyToCurve25519.
func PrivateKeyToCurve25519(curve25519Private *[32]byte, privateKey *[64]byte) {
	h := sha512.New()
	h.Write(privateKey[:32])
	digest := h.Sum(nil)

	digest[0] &= 248
	digest[31] &= 127
	digest[31] |= 64

	copy(curve25519Private[:], digest)
}

and

// PublicKeyToCurve25519 converts an Ed25519 public key into the curve25519
// public key that would be generated from the same private key.
func PublicKeyToCurve25519(curve25519Public *[32]byte, publicKey *[32]byte) bool {
	var A edwards25519.ExtendedGroupElement
	if !A.FromBytes(publicKey) {
		return false
	}

	// A.Z = 1 as a postcondition of FromBytes.
	var x edwards25519.FieldElement
	edwardsToMontgomeryX(&x, &A.Y)
	edwards25519.FeToBytes(curve25519Public, &x)
	return true
}

I think many projects are currently using these functions and now hit a wall because the original repo has been removed.

@andybons andybons changed the title ed25519 to curve25519 conversion proposal: ed25519 to curve25519 conversion Mar 25, 2020
@andybons andybons added the Proposal-Crypto Proposal related to crypto packages or other security issues label Mar 25, 2020
@gopherbot gopherbot added this to the Proposal milestone Mar 25, 2020
@andybons andybons changed the title proposal: ed25519 to curve25519 conversion proposal: add ed25519 to curve25519 conversion functions Mar 25, 2020
@FiloSottile
Copy link
Contributor

Duplicate of #20504.

@golang golang locked and limited conversation to collaborators Mar 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Proposal Proposal-Crypto Proposal related to crypto packages or other security issues
Projects
None yet
Development

No branches or pull requests

4 participants