Skip to content
This repository was archived by the owner on Feb 2, 2019. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions ed25519.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,27 @@ func GenerateKey(rand io.Reader) (publicKey *[PublicKeySize]byte, privateKey *[P
return
}

// MakePublicKey makes a publicKey from the first half of privateKey.
// MakePublicKey makes a publicKey from the first 32 bytes
// of privateKey, and at the end mutates privateKey setting
// its first 32 bytes to those of the generated publicKey.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its second 32 bytes

func MakePublicKey(privateKey *[PrivateKeySize]byte) (publicKey *[PublicKeySize]byte) {
publicKey = new([32]byte)
publicKey = new([PublicKeySize]byte)

h := sha512.New()
h.Write(privateKey[:32])
h.Write(privateKey[:PublicKeySize])
digest := h.Sum(nil)

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

var A edwards25519.ExtendedGroupElement
var hBytes [32]byte
var hBytes [PublicKeySize]byte
copy(hBytes[:], digest)
edwards25519.GeScalarMultBase(&A, &hBytes)
A.ToBytes(publicKey)

copy(privateKey[32:], publicKey[:])
copy(privateKey[PublicKeySize:], publicKey[:])
return
}

Expand Down