Here's a quick text explanation on how the password hash generator in Tor works:
- Obtain 8 random bytes from the system as
- Append the bytes of the user specified password to the salt
- Repeat this sequence until the length is 65536 (0x10000) bytes. If repeating the sequence doesn't exactly end up at this number, cut off any excess bytes.
- Hash the sequence using SHA1
- Your hashed control password will be
"16:" + Hex(Salt) + "60" + Hex(Sha1) where
+ is string concatenation and
Hex() is "convert bytes to uppercase hexadecimal"
To test your implementation, use the password "TestPassword12345678" and the Salt
The resulting hash should be
This takes a big shortcut. Namely, the repetition count from step 3 is in reality dynamic.
The formula in use by Tor is
count = (16 + (c & 15)) << ((c >> 4) + EXPBIAS);
EXPBIAS is defined as
c is defined as
0x60 (this is the number we insert between the salt and hash in step 5).
Because these numbers are currently constant, the result of the formula is always the same. However, if you make a function that checks the user password against the hash, you don't want to use a constant 0x60 but use the value that is actually in use in the password hash.