Skip to content

Commit

Permalink
genkeys print the number of generated keys (#1217)
Browse files Browse the repository at this point in the history
It is good to know how many resources have we carelessly wasted. :-)
  • Loading branch information
grinapo authored Dec 18, 2024
1 parent 9c73bac commit 22bc9c4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cmd/genkeys/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
type keySet struct {
priv ed25519.PrivateKey
pub ed25519.PublicKey
count uint64
}

func main() {
Expand All @@ -36,6 +37,8 @@ func main() {
threads := runtime.GOMAXPROCS(0)
fmt.Println("Threads:", threads)
start := time.Now()
var totalKeys uint64
totalKeys = 0
var currentBest ed25519.PublicKey
newKeys := make(chan keySet, threads)
for i := 0; i < threads; i++ {
Expand All @@ -44,8 +47,9 @@ func main() {
for {
newKey := <-newKeys
if isBetter(currentBest, newKey.pub) || len(currentBest) == 0 {
totalKeys += newKey.count
currentBest = newKey.pub
fmt.Println("-----", time.Since(start))
fmt.Println("-----", time.Since(start), "---", totalKeys, "keys tried")
fmt.Println("Priv:", hex.EncodeToString(newKey.priv))
fmt.Println("Pub:", hex.EncodeToString(newKey.pub))
addr := address.AddrForKey(newKey.pub)
Expand All @@ -68,18 +72,22 @@ func isBetter(oldPub, newPub ed25519.PublicKey) bool {

func doKeys(out chan<- keySet) {
bestKey := make(ed25519.PublicKey, ed25519.PublicKeySize)
var count uint64
count = 0
for idx := range bestKey {
bestKey[idx] = 0xff
}
for {
pub, priv, err := ed25519.GenerateKey(nil)
count++
if err != nil {
panic(err)
}
if !isBetter(bestKey, pub) {
continue
}
bestKey = pub
out <- keySet{priv, pub}
out <- keySet{priv, pub, count}
count = 0
}
}

0 comments on commit 22bc9c4

Please sign in to comment.