Created
July 15, 2021 05:04
-
-
Save polynomialspace/a4526eb369cc4f588d333fc0ba1eda79 to your computer and use it in GitHub Desktop.
quick and dirty go impl of tor hsv3 onion address generation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/ed25519" | |
"encoding/base32" | |
"encoding/hex" | |
"fmt" | |
"strings" | |
"golang.org/x/crypto/sha3" | |
) | |
func main() { | |
var pubkey string = "d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a" | |
var version byte = 3 | |
checksum := v3checksum(decodePubkey(pubkey), version) | |
address := append(decodePubkey(pubkey), checksum...) | |
address = append(address, version) | |
onion := strings.ToLower(base32.StdEncoding.EncodeToString(address)) | |
fmt.Println(onion) | |
} | |
func decodePubkey(encoded string) (decoded []byte) { | |
decoded, err := hex.DecodeString(encoded) | |
if err != nil { | |
panic(err) | |
} | |
if len(decoded) != ed25519.PublicKeySize { | |
panic("invalid key data length") | |
} | |
return decoded | |
} | |
func v3checksum(pubkey []byte, version byte) (checksum []byte) { | |
prefix := []byte(".onion checksum") | |
data := append(prefix, pubkey...) | |
data = append(data, version) | |
shasum := sha3.Sum256(data) | |
checksum = shasum[:][:2] | |
return checksum | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment