# Find hash algorithm and work factor

Knowing a password, corresponding hash value and the used salt I was able to reduce the possible algorithms used.

How can I obtain the hash algorithm used and its workfactor?

Note: This question is not a duplicate of "How can I find what hashing algorithm was used?" as that questions doesn't contemplate the workfactor.

The work factor only applies to some hashing algorithms, so you still need to find a reliable way of identifying the hash - and most hashes are pretty much indistinguishable in terms of output, beyond having set lengths:

``````539080ba278cf4cf4db2e4a32642ff30
8d777f385d3dfec8815d20f7496026dc
042636dba1586150f13670473360ca06
2eb9b7b30492034d392888f72ace81a1
``````

are all 32 character hashes of the same input. The only way to tell which is which is to try hashing them all with functions which produce 32 character output (128-bit, in Base-64 representation).

Since the work factor needs to be known in order for the legitimate user to be able to recreate the hash, it has to be stored in some way. For example, bcrypt hashes have the cost included as the second parameter:

``````\$2a\$04\$BsM7V0W/.V5z.p//XMUJeu.C537J/XoMYYKuCV8vDBq65KgKiDH4.
\$2a\$12\$noxpk3amerDxXofuz4ViS.nOsnK4TWqXnmlfj6Y8b71ERVeZ7Bj5G
``````

In these (which hash the same string as before), the cost for the first example is 4 (2^4 key expansion rounds), and for the second is 12 (2^12 key expansion rounds).

For other algorithms, it's usually part of "common representations", else it has to be stored in code, which tends to be more difficult to update should advances in hash calculation mean that increased work factors should be used. If you've only got the raw hash, without the other parts, the only way is to brute force your way through possible work factors...