Hash Function

Hash functions take some data of an arbitrary length (and possibly a key or password) and generate a fixed-length hash based on this input. Hash functions used in cryptography have the property that it is easy to calculate the hash, but difficult or impossible to re-generate the original input if only the hash value is known. In addition, hash functions useful for cryptography have the property that it is difficult to craft an initial input such that the hash will match a specific desired value.


A cryptographic hash function must have the following properties:

  • Preimage Resistance - Given a hash h, it should be difficult to find any message m such that h = hash(m).
  • Second Preimage Resistance - Given an input x, it should be difficult to find another input y, where x ≠ y, such that hash(x) = hash(y).
  • Collision Resistance - It should be difficult to find two different messages x and y such that hash(x) = hash(y). Such a pair is called a cryptographic hash collision. This property is sometimes referred to as strong collision resistance. It requires a hash value at least twice as long as that required for Preimage Resistance, otherwise collisions may be found by a method known as a birthday attack.

Verifying Message IntegrityEdit

We can use cryptography to provide a means to ensure data is not viewed or altered during storage or transmission. A Message Authentication Code (often abbreviated as MAC) is a piece of information generated by a sender, and sent with the message, that can be compared to a piece of information generated by the receiver to ensure the message has not been altered in transmission or by a malicious entity.

The MAC takes a variable-length message and a secret key as input to a hash function. The resulting hash value is appended to the end of the plaintext message and sent to the recipient. On the receiving end, the plaintext message is passed through the same hash function with an identical secret key. If this produces the same hash value as the one transmitted, the message has not been changed since it was first sent.

Cryptographic Hash AlgorithmsEdit

The two most common cryptographic hash algorithms in use are MD5 and SHA-1. A vulnerability in MD5 was discovered in 2008 and was exploited in an attack against the Secure Sockets Layer protocol. The Federal Information Processing Standard 180-3, Secure Hash Standard, specifies five cryptographic hash algorithms for federal use: SHA-1, SHA-224, SHA-256, SHA-384, and SHA-512. Serious attacks against SHA-1 have been documented as well. To ensure the future security of hash functions, the National Institute of Standards and Technology has called for a new standard to be chosen that will be named SHA-3 and put into use in 2012. There are currently five finalists in the competition.