I fixed your bad code and i dont know how to get it to you so started this feel free to reply to it!
jamieduk opened this issue · 2 comments
your code sucks i made it million times better i suggest you update your code with this
// sudo apt install golang
// go run main.go YOURSTRING 1
package main
import (
"bytes"
"crypto/ed25519"
"crypto/sha512"
"encoding/base32"
"fmt"
"io/ioutil"
"os"
"regexp"
"runtime"
"strconv"
"strings"
"sync"
"golang.org/x/crypto/sha3"
)
func generate(wg *sync.WaitGroup, re *regexp.Regexp) {
for {
publicKey, secretKey, err := ed25519.GenerateKey(nil)
checkErr(err)
onionAddress := encodePublicKey(publicKey)
// If a matching address is found, save key and notify wait group
if re.MatchString(onionAddress) == true {
fmt.Println(onionAddress)
save(onionAddress, publicKey, expandSecretKey(secretKey))
wg.Done()
}
}
}
func expandSecretKey(secretKey ed25519.PrivateKey) [64]byte {
hash := sha512.Sum512(secretKey[:32])
hash[0] &= 248
hash[31] &= 127
hash[31] |= 64
return hash
}
func encodePublicKey(publicKey ed25519.PublicKey) string {
// checksum=H(".onion checksum" || pubkey || version)
var checksumBytes bytes.Buffer
checksumBytes.Write([]byte(".onion checksum"))
checksumBytes.Write([]byte(publicKey))
checksumBytes.Write([]byte{0x03})
checksum := sha3.Sum256(checksumBytes.Bytes())
// onion_address=base32(pubkey || checksum || version)
var onionAddressBytes bytes.Buffer
onionAddressBytes.Write([]byte(publicKey))
onionAddressBytes.Write([]byte(checksum[:2]))
onionAddressBytes.Write([]byte{0x03})
onionAddress := base32.StdEncoding.EncodeToString(onionAddressBytes.Bytes())
return strings.ToLower(onionAddress)
}
func save(onionAddress string, publicKey ed25519.PublicKey, secretKey [64]byte) {
os.MkdirAll(onionAddress, 0700)
secretKeyFile := append([]byte("== ed25519v1-secret: type0 ==\x00\x00\x00"), secretKey[:]...)
checkErr(ioutil.WriteFile(onionAddress+"/hs_ed25519_secret_key", secretKeyFile, 0600))
publicKeyFile := append([]byte("== ed25519v1-public: type0 ==\x00\x00\x00"), publicKey...)
checkErr(ioutil.WriteFile(onionAddress+"/hs_ed25519_public_key", publicKeyFile, 0600))
checkErr(ioutil.WriteFile(onionAddress+"/hostname", []byte(onionAddress+".onion\n"), 0600))
}
func checkErr(err error) {
if err != nil {
panic(err)
}
}
func main() {
// Set runtime to use all available CPUs.
runtime.GOMAXPROCS(runtime.NumCPU())
// Compile regex from first argument.
re, _ := regexp.Compile("^" + os.Args[1])
// Get the number of desired addreses from second argument.
numAddresses, _ := strconv.Atoi(os.Args[2])
// WaitGroup of size equal to desired number of addresses
var wg sync.WaitGroup
wg.Add(numAddresses)
// For each CPU, run a generate goroutine
for i := 0; i < runtime.NumCPU(); i++ {
go generate(&wg, re)
}
// Exit after the desired number of addresses have been found.
wg.Wait()
}
Alsao your readme should never point to a website thats dumb asf always put actual instructions its not fkin hard
sudo apt install -y golang
go run main.go YOURSTRING 1
Where Yourstring is your desired hostname start string
And Where 1 is the number of found hostname matches to stop at!
@jamieduk - I don't know what you are on about, because your code actually has errors too. lol
"Also" your spelling and grammar is poor.
_
Alas, If you are saying where 1 is the number of found hostname that the match would stop on.
go run cmd/tor_oniongen/main.go gi 1
gilwjn6rhlzzde5hr2sgt4pagd4hk2awva5tbt2ltvd32xeph2643dyd
gi6tqwh65qvzqf45a4hmmhals455dymyfzaorhne5nedhsrfvc3rzaad
gindlcw4ta2rcra4b7p3mf6fu5bqbitpcgyfst6apq52vagv4cgvhsad
Enjoy, - So I see not how your code is any better.
go run cmd/tor_oniongen/main.go gi 1
gibmvhsu2xjfxdjop54lix47bec3mfkz6nqakupnmg43e2lgc7twedqd
gibdlum7gqiqawagnwzwgzgv6ry2rblq57pvfmjsw2rr3a32kasneyid
panic: sync: negative WaitGroup countergoroutine 11 [running]:
sync.(*WaitGroup).Add(0xd6ae6e22080b9ba0?, 0xa38d2f61f1ba42b6?)
/snap/go/10585/src/sync/waitgroup.go:62 +0xd8