5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-09-19 16:09:36 +00:00

make genkeys use the new address/crypto packages

This commit is contained in:
Arceliar 2018-12-14 20:58:52 -06:00
parent ea4ca02681
commit 72cc1bb321

View File

@ -12,11 +12,16 @@ This only matters if it's high enough to make you the root of the tree.
*/ */
package main package main
import "encoding/hex" import (
import "flag" "encoding/hex"
import "fmt" "flag"
import "runtime" "fmt"
import . "github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil" "net"
"runtime"
"github.com/yggdrasil-network/yggdrasil-go/src/address"
"github.com/yggdrasil-network/yggdrasil-go/src/crypto"
)
var doSig = flag.Bool("sig", false, "generate new signing keys instead") var doSig = flag.Bool("sig", false, "generate new signing keys instead")
@ -82,12 +87,7 @@ func isBetter(oldID, newID []byte) bool {
} }
func doBoxKeys(out chan<- keySet, in <-chan []byte) { func doBoxKeys(out chan<- keySet, in <-chan []byte) {
c := Core{} var bestID crypto.NodeID
pub, _ := c.DEBUG_newBoxKeys()
bestID := c.DEBUG_getNodeID(pub)
for idx := range bestID {
bestID[idx] = 0
}
for { for {
select { select {
case newBestID := <-in: case newBestID := <-in:
@ -95,22 +95,20 @@ func doBoxKeys(out chan<- keySet, in <-chan []byte) {
copy(bestID[:], newBestID) copy(bestID[:], newBestID)
} }
default: default:
pub, priv := c.DEBUG_newBoxKeys() pub, priv := crypto.NewBoxKeys()
id := c.DEBUG_getNodeID(pub) id := crypto.GetNodeID(pub)
if !isBetter(bestID[:], id[:]) { if !isBetter(bestID[:], id[:]) {
continue continue
} }
bestID = id bestID = *id
ip := c.DEBUG_addrForNodeID(id) ip := net.IP(address.AddrForNodeID(id)[:]).String()
out <- keySet{priv[:], pub[:], id[:], ip} out <- keySet{priv[:], pub[:], id[:], ip}
} }
} }
} }
func doSigKeys(out chan<- keySet, in <-chan []byte) { func doSigKeys(out chan<- keySet, in <-chan []byte) {
c := Core{} var bestID crypto.TreeID
pub, _ := c.DEBUG_newSigKeys()
bestID := c.DEBUG_getTreeID(pub)
for idx := range bestID { for idx := range bestID {
bestID[idx] = 0 bestID[idx] = 0
} }
@ -122,12 +120,12 @@ func doSigKeys(out chan<- keySet, in <-chan []byte) {
} }
default: default:
} }
pub, priv := c.DEBUG_newSigKeys() pub, priv := crypto.NewSigKeys()
id := c.DEBUG_getTreeID(pub) id := crypto.GetTreeID(pub)
if !isBetter(bestID[:], id[:]) { if !isBetter(bestID[:], id[:]) {
continue continue
} }
bestID = id bestID = *id
out <- keySet{priv[:], pub[:], id[:], ""} out <- keySet{priv[:], pub[:], id[:], ""}
} }
} }