Skip to content

Commit

Permalink
Merge pull request #58 from neicnordic/feature/new-x25519-generation
Browse files Browse the repository at this point in the history
new way to generate x25519 keys
  • Loading branch information
jbygdell authored Feb 21, 2023
2 parents 712704d + 14c7248 commit 54c4cd4
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions keys/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,13 @@ var x25519Algorithm = []int{1, 3, 101, 110}

// GenerateKeyPair method generates X25519 key pair.
func GenerateKeyPair() (publicKey, privateKey [chacha20poly1305.KeySize]byte, err error) {
edPublicKey, edPrivateKey, err := ed25519.GenerateKey(nil)
edCurve, err := ecdh.X25519().GenerateKey(rand.Reader)
if err != nil {
return
}
privateKey = [32]byte(edCurve.Bytes())

var edPublicKeyBytes [chacha20poly1305.KeySize]byte
copy(edPublicKeyBytes[:], edPublicKey)
PublicKeyToCurve25519(&publicKey, edPublicKey)

var edPrivateKeyBytes [chacha20poly1305.KeySize * 2]byte
copy(edPrivateKeyBytes[:], edPrivateKey)
PrivateKeyToCurve25519(&privateKey, edPrivateKey)
publicKey = [32]byte(edCurve.PublicKey().Bytes())

return
}
Expand Down

0 comments on commit 54c4cd4

Please sign in to comment.