A one-way hash function is a mathematical function that generates a fingerprint of the input, but there is no way to get back to the original input. If the input is the same then the hash is always the same, if it changes at all, even by one character the output hash is completely different. A hash can be used to verify that input A is identical to input B but cannot be used to get the input back from the output like with another mathematical function, encryption.
Technipages Explains One-Way Hash Function
The output of a one-way hash is always the same length no matter how long the input is. For example, the output for the hashing algorithm md5 is always 32 characters if represented in hexadecimal, this is true if the input is one character long or the length of the entire works of Shakespeare.
A hash is ideal for verifying that two things are identical, this has two main uses. “Integrity verification” is used to verify that a file that has been downloaded is identical to the one on the server by comparing a known hash of the server file to a hash of the downloaded file.
Hashing algorithms are also used in databases to verify that the hash of the submitted password matches the stored hash. This also means that if a hacker gains unauthorised access to the database they do not get passwords themselves but rather their hashes which cannot be used to log in directly.
The length of the output of a hashing algorithm set limits on how many possible outputs there are and as such describes its strength against hash “collision attacks”. Collision attacks are where two different inputs generate the same output. It is pretty difficult to find two random inputs that generate the same output, it is significantly more difficult to find a collision for a single specific hash output.
Common Uses of One-Way Hash Function
- There are two types of one way hashing algorithms, fast and slow, fast is used for file verification and slow for password hashing.
- The input of a one-way hashing algorithm cannot be determined by analysing the output or running it through another function.
- When a hacker has a list of password hashes from a stolen database they work out what one-way hashing algorithm was used and then guess as many possible passwords as they can, when they have an output that matches an entry in the database they know that the input is the user’s password.
Common Misuses of One-Way Hash Function
- A one-way hashing algorithm is a type of encryption and can be used to securely store data for retrieval at a later date with the use of a password and another function.