aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/embeddable-dll-service/main.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-10-03 17:39:35 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-10-06 22:19:54 +0200
commit9af60b6aa4df035a9627277f20f976019dfc8d8f (patch)
tree5c49bd91e776728d4cd2f67a79053eb386c949ed /embeddable-dll-service/main.go
parentembeddable-dll-service: add csharp example code (diff)
downloadwireguard-windows-9af60b6aa4df035a9627277f20f976019dfc8d8f.tar.xz
wireguard-windows-9af60b6aa4df035a9627277f20f976019dfc8d8f.zip
embeddable-dll-service: add key generation function to replace bcrypt
BCrypt is Win10+ and kind of clunky to use. The tunnel.dll binary has this code in it anyway, so doing it there doesn't actually increase the size of the binary. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r--embeddable-dll-service/main.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/embeddable-dll-service/main.go b/embeddable-dll-service/main.go
index a8ce7c10..edf72fba 100644
--- a/embeddable-dll-service/main.go
+++ b/embeddable-dll-service/main.go
@@ -7,10 +7,16 @@ package main
import (
"C"
+
+ "golang.org/x/crypto/curve25519"
+
"golang.zx2c4.com/wireguard/windows/conf"
"golang.zx2c4.com/wireguard/windows/tunnel"
+
+ "crypto/rand"
"log"
"path/filepath"
+ "unsafe"
)
//export WireGuardTunnelService
@@ -24,4 +30,18 @@ func WireGuardTunnelService(confFile string) bool {
return err == nil
}
+//export WireGuardGenerateKeypair
+func WireGuardGenerateKeypair(publicKey *byte, privateKey *byte) {
+ publicKeyArray := (*[32]byte)(unsafe.Pointer(publicKey))
+ privateKeyArray := (*[32]byte)(unsafe.Pointer(privateKey))
+ n, err := rand.Read(privateKeyArray[:])
+ if err != nil || n != len(privateKeyArray) {
+ panic("Unable to generate random bytes")
+ }
+ privateKeyArray[0] &= 248
+ privateKeyArray[31] = (privateKeyArray[31] & 127) | 64
+
+ curve25519.ScalarBaseMult(publicKeyArray, privateKeyArray)
+}
+
func main() {}