0

I'm writing a tool to generate onion addresses but obviously want to make sure the addresses actually work.

Rather than setting up a hidden service with the keys etc it would be nice to do it quickly or even make my own tool to do it. How can I do this?

1

For any (sane) code, when you generate an RSA key you generate the private key then the public key is derived from it.

The onion address is the base32 encoded first 10 bytes of the sha1 sum of the asn1 encoded public key. So the private key derives directly to the public key and the address derives directly from the public key.

So, to ensure that the address matches, just generate the private key, derive the public key from it, encode the public key into it's asn1 encoding, sha1 hash the whole key, take the first 10 bytes of the sum and encode them into base32, giving you 16 base32 digits.

There is no guarantee that a given address maps to a private key, since the hashing process loses information (the set of possible public keys is larger than the set of possible 10 byte truncated sha1 values) it's possible that two distinct private keys generate two distinct public keys which happen to share the same first 10 bytes of their hash. There is no one-to-one mapping between the two values, you can ensure that a specific private key maps to a specific address, but not the other way around.

  • thanks, this is probably as close to an answer as I'll get. I just assumed that there is some form of mathematical link between the two otherwise surely people can use what ever address they want with any private key. – Peter Fox Feb 5 '17 at 16:13
  • "just generate the private key, derive the public key from it, encode the public key into it's asn1 encoding, sha1 hash the whole key, take the first 10 bytes of the sum and encode them into base32, giving you 16 base32 digits." I will add I believe there is also a step of dropping the first 22 bytes from the public key as well? Or maybe the article I read was wrong? – Peter Fox Feb 5 '17 at 16:14
  • Maybe it's confused or goes into lower level details but no there's no step about dropping any bytes from the public key. This is my implementation using openssl/libssl. – cacahuatl Feb 6 '17 at 2:00
  • Also there is a mathematical link, from public key to onion. The difficulty is in producing a SHA1 collision and in your case, a sha1 preimage collision (which is exponentially more difficult). – cacahuatl Feb 6 '17 at 2:03
0

Take a look cat Scallion code - it's already all-set there.

  • I've ready written code just wanted to know as they're asymmetric keys etc if there is a way to test them without using for a hidden service – Peter Fox Feb 5 '17 at 1:12
  • scallion does exactly this thing trying to generate a key for a given name. And it's verification works fine - never saw a case when the key generated was not working – Alexey Vesnin Feb 5 '17 at 1:40
  • But how does it verify it? – Peter Fox Feb 5 '17 at 1:41
  • it has a regex of "how it should be" and tries to make a key with a hash looking like this. To test the existing key you either need to get a piece of Tor code to create the service or just use a tor control protocol for service creation attempt. The onion address is basically a Base32 hash of it's key – Alexey Vesnin Feb 5 '17 at 1:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.