wireguard.lists.zx2c4.com archive mirror
 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

* Re: [PATCH] embeddable-dll-service: add ability to derive public key from private key
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Jason A. Donenfeld @ 2021-08-10 20:38 UTC (permalink / raw)
  To: dotneutron; +Cc: WireGuard mailing list

Hi,

Why do you want this functionality in the tunnel.dll? What are you
doing that would require it?

Jason

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

* Re: [PATCH] embeddable-dll-service: add ability to derive public key from private key
  2021-08-10 20:38 ` Jason A. Donenfeld
@ 2021-08-10 21:13   ` Neutron
  0 siblings, 0 replies; 3+ messages in thread
From: Neutron @ 2021-08-10 21:13 UTC (permalink / raw)
  To: Jason A. Donenfeld; +Cc: WireGuard mailing list

Hey,

I started working on a C# WPF client based on the reference implementation you provided. I made it so the tunnel configurations can be added or edited via a custom form much alike the one of wg-android. Since I'm only storing the private key in the interface section of a config file, I need to be able to derive the public key and display it to the user.

As a personal example, I'm using Mullvad's wg configurations to test it. I'm able to export all configurations for their servers, for a given private key. I'm left with the typical wg conf files. When I fill in the details for a tunnel configuration in the client I created, I want to be able to write in the private key and have it generate the public key automatically. This is the behavior of wg-android.

Adding that method, rebuilding the dll and invoking it from C# worked like a charm, so I thought it might help other people as well. It is a convenience method for anyone who wants to create a client of their own.

Neutron

^ 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).