Development discussion of WireGuard
 help / color / mirror / Atom feed
* [PATCH] embeddable-dll-service: add ability to derive public key from private key
@ 2021-08-10 20:29 dotneutron
  2021-08-10 20:38 ` Jason A. Donenfeld
  0 siblings, 1 reply; 3+ messages in thread
From: dotneutron @ 2021-08-10 20:29 UTC (permalink / raw)
  To: wireguard; +Cc: Jason, Neutron

Developers using the embeddable service might find it useful to be able
to derive the public key from a given private key.

There was no apparent explanation for the bit setting/unsetting when
generating a private key. The reading material should help developers
understand the reasoning.

Signed-off-by: Neutron <dotneutron@protonmail.ch>
---
 embeddable-dll-service/main.go | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/embeddable-dll-service/main.go b/embeddable-dll-service/main.go
index b2e02fa4..a9b9dacd 100644
--- a/embeddable-dll-service/main.go
+++ b/embeddable-dll-service/main.go
@@ -53,10 +53,20 @@ func WireGuardGenerateKeypair(publicKey *byte, privateKey *byte) {
 	if err != nil || n != len(privateKeyArray) {
 		panic("Unable to generate random bytes")
 	}
+
+	// See https://www.jcraige.com/an-explainer-on-ed25519-clamping.
 	privateKeyArray[0] &= 248
 	privateKeyArray[31] = (privateKeyArray[31] & 127) | 64

 	curve25519.ScalarBaseMult(publicKeyArray, privateKeyArray)
 }

+//export WireGuardDerivePublicKeyFromPrivateKey
+func WireGuardDerivePublicKeyFromPrivateKey(publicKey *byte, privateKey *byte) {
+	publicKeyArray := (*[32]byte)(unsafe.Pointer(publicKey))
+	privateKeyArray := (*[32]byte)(unsafe.Pointer(privateKey))
+
+	curve25519.ScalarBaseMult(publicKeyArray, privateKeyArray)
+}
+
 func main() {}
--
2.32.0.windows.2



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-10 21:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-10 20:29 [PATCH] embeddable-dll-service: add ability to derive public key from private key dotneutron
2021-08-10 20:38 ` Jason A. Donenfeld
2021-08-10 21:13   ` Neutron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).