genkeys print the number of generated keys (#1217)

It is good to know how many resources have we carelessly wasted. :-)
This commit is contained in:
Peter Gervai 2024-12-18 20:56:46 +01:00 committed by GitHub
parent 9c73bacab9
commit 22bc9c44e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -26,6 +26,7 @@ import (
type keySet struct { type keySet struct {
priv ed25519.PrivateKey priv ed25519.PrivateKey
pub ed25519.PublicKey pub ed25519.PublicKey
count uint64
} }
func main() { func main() {
@ -36,6 +37,8 @@ func main() {
threads := runtime.GOMAXPROCS(0) threads := runtime.GOMAXPROCS(0)
fmt.Println("Threads:", threads) fmt.Println("Threads:", threads)
start := time.Now() start := time.Now()
var totalKeys uint64
totalKeys = 0
var currentBest ed25519.PublicKey var currentBest ed25519.PublicKey
newKeys := make(chan keySet, threads) newKeys := make(chan keySet, threads)
for i := 0; i < threads; i++ { for i := 0; i < threads; i++ {
@ -44,8 +47,9 @@ func main() {
for { for {
newKey := <-newKeys newKey := <-newKeys
if isBetter(currentBest, newKey.pub) || len(currentBest) == 0 { if isBetter(currentBest, newKey.pub) || len(currentBest) == 0 {
totalKeys += newKey.count
currentBest = newKey.pub 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("Priv:", hex.EncodeToString(newKey.priv))
fmt.Println("Pub:", hex.EncodeToString(newKey.pub)) fmt.Println("Pub:", hex.EncodeToString(newKey.pub))
addr := address.AddrForKey(newKey.pub) addr := address.AddrForKey(newKey.pub)
@ -68,11 +72,14 @@ func isBetter(oldPub, newPub ed25519.PublicKey) bool {
func doKeys(out chan<- keySet) { func doKeys(out chan<- keySet) {
bestKey := make(ed25519.PublicKey, ed25519.PublicKeySize) bestKey := make(ed25519.PublicKey, ed25519.PublicKeySize)
var count uint64
count = 0
for idx := range bestKey { for idx := range bestKey {
bestKey[idx] = 0xff bestKey[idx] = 0xff
} }
for { for {
pub, priv, err := ed25519.GenerateKey(nil) pub, priv, err := ed25519.GenerateKey(nil)
count++
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -80,6 +87,7 @@ func doKeys(out chan<- keySet) {
continue continue
} }
bestKey = pub bestKey = pub
out <- keySet{priv, pub} out <- keySet{priv, pub, count}
count = 0
} }
} }