From: dotneutron <dotneutron@protonmail.ch>
To: wireguard@lists.zx2c4.com
Cc: Jason@zx2c4.com, Neutron <dotneutron@protonmail.ch>
Subject: [PATCH] embeddable-dll-service: add ability to derive public key from private key
Date: Tue, 10 Aug 2021 20:29:52 +0000 [thread overview]
Message-ID: <20210810202936.1537-1-dotneutron@protonmail.ch> (raw)
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
next reply other threads:[~2021-08-10 20:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-10 20:29 dotneutron [this message]
2021-08-10 20:38 ` Jason A. Donenfeld
2021-08-10 21:13 ` Neutron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210810202936.1537-1-dotneutron@protonmail.ch \
--to=dotneutron@protonmail.ch \
--cc=Jason@zx2c4.com \
--cc=wireguard@lists.zx2c4.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).