This commit is contained in:
meshmayhem 2024-11-26 00:15:34 +00:00 committed by GitHub
commit dd074bb1fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 75 additions and 16 deletions

View file

@ -13,12 +13,14 @@ package main
import (
"crypto/ed25519"
"encoding/hex"
"flag"
"fmt"
"net"
"runtime"
"time"
"github.com/yggdrasil-network/yggdrasil-go/src/address"
"github.com/yggdrasil-network/yggdrasil-go/src/config"
)
type keySet struct {
@ -27,23 +29,37 @@ type keySet struct {
}
func main() {
threads := runtime.GOMAXPROCS(0)
fmt.Println("Threads:", threads)
security := flag.Int("security", 0, "generates a key with a specific amount of security bits. defaults to 0 which continuously generates more keys")
flag.Parse()
start := time.Now()
var currentBest ed25519.PublicKey
newKeys := make(chan keySet, threads)
for i := 0; i < threads; i++ {
go doKeys(newKeys)
}
for {
newKey := <-newKeys
if isBetter(currentBest, newKey.pub) || len(currentBest) == 0 {
currentBest = newKey.pub
fmt.Println("-----", time.Since(start))
fmt.Println("Priv:", hex.EncodeToString(newKey.priv))
fmt.Println("Pub:", hex.EncodeToString(newKey.pub))
addr := address.AddrForKey(newKey.pub)
fmt.Println("IP:", net.IP(addr[:]).String())
if (*security > 0) {
// If higher than 0, generates a key with the set amount of security bits
var secureKey keySet
secureKey.priv, secureKey.pub = config.NewSecureKeyPair(*security)
fmt.Println("-----", time.Since(start))
fmt.Println("Priv:", hex.EncodeToString(secureKey.priv))
fmt.Println("Pub:", hex.EncodeToString(secureKey.pub))
addr := address.AddrForKey(secureKey.pub)
fmt.Println("IP:", net.IP(addr[:]).String())
} else {
threads := runtime.GOMAXPROCS(0)
fmt.Println("Threads:", threads)
var currentBest ed25519.PublicKey
newKeys := make(chan keySet, threads)
for i := 0; i < threads; i++ {
go doKeys(newKeys)
}
for {
newKey := <-newKeys
if isBetter(currentBest, newKey.pub) || len(currentBest) == 0 {
currentBest = newKey.pub
fmt.Println("-----", time.Since(start))
fmt.Println("Priv:", hex.EncodeToString(newKey.priv))
fmt.Println("Pub:", hex.EncodeToString(newKey.pub))
addr := address.AddrForKey(newKey.pub)
fmt.Println("IP:", net.IP(addr[:]).String())
}
}
}
}

View file

@ -40,6 +40,7 @@ type node struct {
// The main function is responsible for configuring and starting Yggdrasil.
func main() {
genconf := flag.Bool("genconf", false, "print a new config to stdout")
security := flag.Int("security", 0, "use in combination with either -genconf or -autoconf, generates a higher security address up to the security bits desired")
useconf := flag.Bool("useconf", false, "read HJSON/JSON config from stdin")
useconffile := flag.String("useconffile", "", "read HJSON/JSON config from specified file path")
normaliseconf := flag.Bool("normaliseconf", false, "use in combination with either -useconf or -useconffile, outputs your configuration normalised")
@ -88,6 +89,11 @@ func main() {
}
cfg := config.GenerateConfig()
if (*security > 0) {
// Checks if the security flag is set, and generates a key with that many security bits
newKey, _ := config.NewSecureKeyPair(*security)
cfg.PrivateKey = []byte(newKey)
}
var err error
switch {
case *ver: