Skip to content

Instantly share code, notes, and snippets.

Created July 15, 2021 05:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save polynomialspace/a4526eb369cc4f588d333fc0ba1eda79 to your computer and use it in GitHub Desktop.
quick and dirty go impl of tor hsv3 onion address generation
package main
import (
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))
func decodePubkey(encoded string) (decoded []byte) {
decoded, err := hex.DecodeString(encoded)
if err != nil {
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