Skip to content

Commit 22bc9c4

Browse files
authored
genkeys print the number of generated keys (#1217)
It is good to know how many resources have we carelessly wasted. :-)
1 parent 9c73bac commit 22bc9c4

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

cmd/genkeys/main.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
type keySet struct {
2727
priv ed25519.PrivateKey
2828
pub ed25519.PublicKey
29+
count uint64
2930
}
3031

3132
func main() {
@@ -36,6 +37,8 @@ func main() {
3637
threads := runtime.GOMAXPROCS(0)
3738
fmt.Println("Threads:", threads)
3839
start := time.Now()
40+
var totalKeys uint64
41+
totalKeys = 0
3942
var currentBest ed25519.PublicKey
4043
newKeys := make(chan keySet, threads)
4144
for i := 0; i < threads; i++ {
@@ -44,8 +47,9 @@ func main() {
4447
for {
4548
newKey := <-newKeys
4649
if isBetter(currentBest, newKey.pub) || len(currentBest) == 0 {
50+
totalKeys += newKey.count
4751
currentBest = newKey.pub
48-
fmt.Println("-----", time.Since(start))
52+
fmt.Println("-----", time.Since(start), "---", totalKeys, "keys tried")
4953
fmt.Println("Priv:", hex.EncodeToString(newKey.priv))
5054
fmt.Println("Pub:", hex.EncodeToString(newKey.pub))
5155
addr := address.AddrForKey(newKey.pub)
@@ -68,18 +72,22 @@ func isBetter(oldPub, newPub ed25519.PublicKey) bool {
6872

6973
func doKeys(out chan<- keySet) {
7074
bestKey := make(ed25519.PublicKey, ed25519.PublicKeySize)
75+
var count uint64
76+
count = 0
7177
for idx := range bestKey {
7278
bestKey[idx] = 0xff
7379
}
7480
for {
7581
pub, priv, err := ed25519.GenerateKey(nil)
82+
count++
7683
if err != nil {
7784
panic(err)
7885
}
7986
if !isBetter(bestKey, pub) {
8087
continue
8188
}
8289
bestKey = pub
83-
out <- keySet{priv, pub}
90+
out <- keySet{priv, pub, count}
91+
count = 0
8492
}
8593
}

0 commit comments

Comments
 (0)