I created an onion v3 service and the Tor created three files for it: private and public keys and hostname. The private key is actually contains the public key internally. So why do we need the public key file? Usually the splitting makes sense to share the public key. But for the Tor it looks like doesn't make sense. The actual pubkey sharing is the onion domain itself.

I checked sources and found a big function ed_key_init_from_file() Internally it will load the pubkey and compare with a pubkey from secret key. If the pubkey is not exists then if will "repair" it from a secret file.


This looks for me as an overcomplication. Basically if the pubkey is not needed then we can skip it's loading, repairing, comparison. I'm using the Tor for access to an old router behind CGNAT. And if we can make the binary smaller, don't waste time and space for the pubkey and keep the NAND flash that would be great.

On the line 511 we are loading the pubkey even if a secret doesn't exists with a comment "We only have the public key; better use that". I can't understand why to do that because without a secret key nothing should work anyway.

And I have and additional questions: Does the Tor recreates the hostname file if only a secret key exists?

1 Answer 1


Well, it's a rudimentary function - the only real use for the public key file is to read it from a shell script for some use, but - basically - even the hostname file is rudimentary on the same manner: you can construct it from the key. Anyway - it's not making a mess at all and let it be to keep things simple. Later on, when and if Tor will evolve it's control protocol - it will vanish completely, IMHO. For your second question look here at the very same source file https://gitlab.torproject.org/tpo/core/tor/-/blob/main/src/feature/keymgt/loadkey.c#L488 - it should

  • so if it doesn't really used then maybe to worth to send a PR with removing it? What do you think Commented Oct 19, 2023 at 18:47
  • as I said - it has it's side uses for now, so there's no grounds for a pull request for now. If they will evolve the control protocol - then it will be removed by them, as I see it. Now it has it's side uses - so there's a place for it for sure
    – Alexey Vesnin
    Commented Oct 19, 2023 at 21:11
  • what are the possible side uses? Commented Oct 19, 2023 at 21:14
  • for example: you have a shell script that works with keys from another username+group and you need to do something like a check-up with your hosted services. It can safely read the public key and/or hostname from a file and do it's job without any unnecessary privilege expansion
    – Alexey Vesnin
    Commented Oct 21, 2023 at 12:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .