Jump to content

Cryptographic hash function

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 62.245.75.68 (talk) at 16:35, 19 August 2004 (Applications of hash functions). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

In cryptography, a cryptographic hash function is a hash function with certain additional security properties to make it suitable for use as a primitive in various information security applications, such as authentication and message integrity. A hash function takes a long string (or message) of any length as input and produces a fixed length string as output; not all such are suitable for use in cryptography. The output of is sometimes termed a message digest or a digital fingerprint.

Overview

Broadly speaking, the security properties are required to ensure that the digest is "random" to prospective attackers, and does not leak any information about the message itself, and that other messages cannot be found that produce the same digest. Any change to the message, even a single bit, should result in a dramatically different message digest when re-generated from the received message. A cryptographic hash function is considered secure if

  • it is not computationally feasible to determine the content of a message from its message digest, nor
  • to find "collisions", wherein two different messages have the same message digest.

In the first case, an insecure message digest might be used to reconstruct a message which had been encrypted, thus defeating the encryption. In the second case, being able to find a different message which produces a given message digest allows substitution of messages by an attacker; this is a dangerous insecurity.

Checksums and Cyclic redundancy checks (CRCs) are quite distinct from cryptographic hash functions, and are used for different applications. If used for security, they are vulnerable to attack; for example, a CRC was used for message integrity in the WEP encryption standard, but an attack was readily discovered which exploited the linearity of the checksum specified.

In the sense in which cryptographic hash functions are discussed in this article, they take only one input - the message. No key is required to compute them before sending or after receiving. In contrast, message authentication codes are keyed hash functions; only the owner of a secret key can compute hashes with that key. Properly employed, a MAC avoids potential attacks against unkeyed hashes and can be used to provide sender authentication as well as message integrity checks.

Cryptographic properties

Mathematically, a cryptographic hash function is a hash function that is:

  • Preimage resistant (one way): given h such that h = hash(m1) it should be hard to find m1.
  • Second preimage resistant: given m1 it should be hard to find m2 ≠ m1 such that hash(m1) = hash(m2).

Usually the function is also required to be:

  • Collision-resistant: it should be hard to find two messages m1 and m2 such that hash(m1) = hash(m2). Because of the birthday paradox this means the hash function must have a larger image than is required to be preimage-resistant.

An idealized, imaginary cryptographic hash often used in academic papers is the random oracle. This is an oracle which keeps a list of every input it receives. When it receives an input it has never seen before, it generates a random number which it records in its table as the output for that input, then returns that output to the caller. When it receives an input it has seen, it returns the output recorded in its table. Since the mapping from inputs to outputs is random, it is easy to see that random oracles are preimage and collision resistant given a sufficiently large set of possible outputs.

It is important to note that most real cryptographic hashes fail to approximate random oracles in a significant way. That is, they are subject to length-extension: given h(m), it is possible to compute h(m+m'), where + denotes concatenation. The SHAd and HMAC constructions were designed to avoid the attacks that result from length-extension.

Applications of hash functions

A typical use of a cryptographic hash would be as follows: Alice poses to Bob a tough math problem and claims she has solved it. Bob would like to try it himself, but would yet like to be sure that Alice is not bluffing. Therefore, Alice writes down her solution, computes its hash and tells Bob the hash value (whilst keeping the solution secret). This way, when Bob comes up with the solution himself a few days later, Alice can verify his solution but still be able to prove that she had the solution earlier.

In actual practice, Alice and Bob will often be computer programs, and the secret would be something less easily spoofed than a claimed puzzle solution. In cryptography, the above application is called timestamping. Another important application of secure hashes is verification of message integrity. Determination of whether or not any changes have been made to a message (or a file), for example, can be accomplished by comparing message digests calculated before, and after, transmission (or any other event) (see Tripwire, a system using this property as a defense against malware and malfeasance). A message digest can also serve as a means of reliably identifying a file. A related application is password verification. Passwords are usually not stored in cleartext, for obvious reasons, but instead in digest form. To authenticate a user, the password presented by the user is hashed and compared with the stored hash.

To decrease computational delays, most digital signature algorithms specify that only the digest of the message be "signed", not the entire message. Hash functions can also be used in the generation of pseudorandom bits, if they meet some additional, statistical, tests.

SHA-1, MD5, and RIPEMD-160 are among the most commonly-used message digest algorithms, although this may change due to collisions found in SHA (sometimes called SHA-0), MD5 and RIPEMD. Note: RIPEMD-160 is a strengthened version of RIPEMD; SHA-1 is a strengthened version of SHA.

Iterated hash functions

A hash function must be able to process an arbitrary-length message into a fixed-length output. In practice, this can be achieved by breaking the input up into a series of equal-size blocks, and operating on them in sequence using a compression function. This design is known as an iterated hash function, or alternatively, the Merkle-Damgård structure; most widely-used hash functions take this form:

Iterated hash function

In the diagram, the compression function is denoted by f, and transforms a fixed-length input to an output of the same size. The algorithm starts with an initial value, the initialisation vector (IV). For each message block, the compression function f takes the result so far, combines it with the block, and produces an intermediate result. The value after the last block is taken to be the hash value for the entire message.

List of cryptographic hash functions

HAVAL, MD2, MD4, MD5, N-Hash, RIPEMD-160, SHA, Snefru, Tiger, Whirlpool

See also