Cryptography - Hash Functions
Cryptography - Hash Functions
The importance of this process lies in its generation of a unique "fingerprint" for
each input. Any minor alteration in the input results in a substantially different
fingerprint, a quality known as "collision resistance."
https://www.tutorialspoint.com/cryptography/cryptography_hash_functions.htm 25/11/24, 7 16 PM
Page 1 of 10
:
Hash functions have a variety of complexity and difficulty levels and are
used in cryptography.
Explore our latest online courses and learn new skills at your own pace. Enroll
and become a certified expert to boost your career.
Pre-Image Resistance
https://www.tutorialspoint.com/cryptography/cryptography_hash_functions.htm 25/11/24, 7 16 PM
Page 2 of 10
:
According to this feature, reversing a hash function should be
computationally difficult.
In other words, if a hash function h generates a hash value z, it should
be difficult to identify an input value x that hashes to z.
This feature defends against an attacker attempting to locate the input
with just the hash value.
This property says that given an input and its hash, it should be difficult
to find another input with the same hash.
In other words, it should be challenging to find another input value y
such that h(y) equals h(x) if a hash function h for an input x returns the
hash value h(x).
This feature of the hash function protects against an attacker who wants
to replace a new value for the original input value and hash, but only
holds the input value and its hash.
Collision Resistance
This feature says that it should be difficult to identify two different inputs
of any length that produce the same hash. This characteristic is also
known as a collision-free hash function.
In other words, for a hash function h, it is difficult to identify two distinct
inputs x and y such that h(x)=h(y).
A hash function cannot be free of collisions because it is a compression
function with a set hash length. The collision-free condition simply
indicates that these collisions should be difficult to locate.
This characteristic makes it very hard for an attacker to identify two input
values that have the same hash.
Furthermore, a hash function is second pre-image resistant if it is
collision-resistant.
https://www.tutorialspoint.com/cryptography/cryptography_hash_functions.htm 25/11/24, 7 16 PM
Page 3 of 10
:
Efficiency of Operation
Computation of h(x) for any hash function h given input x can be an easy
process.
Hash functions are computationally considerably faster than symmetric
encryption.
Deterministic
For a given input, the hash function consistently produces the same output, like
a recipe that always yields the same dish when followed precisely.
Fast Computation
Hashing operations occur rapidly, even for large amounts of data sets.
https://www.tutorialspoint.com/cryptography/cryptography_hash_functions.htm 25/11/24, 7 16 PM
Page 4 of 10
:
Hashing algorithms use a sequence of rounds, similar to a block cipher, to
process a message. In each round, a fixed-size input is used, which usually
combines the current message block and the result from the previous round.
This process continues for multiple rounds until the entire message is hashed. A
visual representation of this process is provided in the illustration below.
Due to the interconnected nature of hashing, where the output of one operation
affects the input of the next, even a minor change (a single bit difference) in the
original message can drastically alter the final hash value.
A hashing algorithm, on the other hand, establishes how the message is divided
into blocks and how the outcomes of multiple hash operations are combined.
https://www.tutorialspoint.com/cryptography/cryptography_hash_functions.htm 25/11/24, 7 16 PM
Page 5 of 10
:
Popular Hash Functions
Hash functions play an important role in computing, providing versatile
capabilities like: Quick retrieval of data, Secure protection of information
(cryptography), Ensuring data remains unaltered (integrity verification). Some
commonly used hash functions are −
The hash functions MD2, MD4, MD5, and MD6 are members of the MD
family. It was adopted as the RFC 1321, Internet Standard. It is a 128-bit
hash function.
In the software industry, MD5 digests are frequently used to ensure the
integrity of transferred files. To enable users to compare the checksum of
the downloaded file with the pre-computed MD5 checksum, file servers
frequently provide this feature.
In 2004, collisions were found in MD5. It was claimed that an analytical
attack using a computer cluster was successful in under one hour. Since
MD5 was compromised by this collision attack, using it is no longer
recommended.
SHA-1 is the most widely used of the existing SHA hash functions. It is
used in most of the applications and protocols including Secure Socket
Layer (SSL) security.
In 2005, a technique was discovered for SHA-1 collision detection that
https://www.tutorialspoint.com/cryptography/cryptography_hash_functions.htm 25/11/24, 7 16 PM
Page 6 of 10
:
can be used in a realistic time frame. So it is doubtful on SHA-1's long-
term usability.
SHA-224, SHA-256, SHA-384, and SHA-512 are the other four SHA
variants in the SHA-2 family, which vary based on the number of bits in
their hash value. The SHA-2 hash function has not yet been the target of
any effective attacks
Though SHA-2 is a strong hash function. Though significantly different,
its basic design still follows the design of SHA-1. NIST thus demanded
the creation of new competitive hash function designs.
CityHash
CityHash is another non-cryptographic hash function that is designed for fast
hashing of large amounts of data. It is optimized for modern processors and
offers good performance on both 32-bit and 64-bit architectures.
BLAKE2
BLAKE2 is a fast and secure hash function that improves upon SHA-3. It is
widely used in applications like cryptocurrency mining that need fast hashing.
There are two types of BLAKE2 −
https://www.tutorialspoint.com/cryptography/cryptography_hash_functions.htm 25/11/24, 7 16 PM
Page 7 of 10
:
When the data is received, the recipient recalculates the checksum using the
same method. If the new checksum matches the original one, it's likely that the
message was transmitted without errors. While CRC is effective for error
detection, it's not a security measure. It is primarily used to ensure the integrity
of data during transmission, not to protect it from unauthorized access or
modification.
MurmurHash
MurmurHash is a speedy and effective hash function that is not meant for
security. It is great for things like hash tables but not for tasks that need
protection against collisions (situations where different inputs produce the same
hash).
Standard Length
Hashing involves converting a data set of any size into a shorter, fixed-length
output using a mathematical formula.
Input
Hash Function Output (Hash Value)
Message
MD5 (128-bit, 16- 3A10 0B15 B943 0B17 11F2 E38F 0593
CFI
byte) 32 characters 9A9A
SHA-1 (160-bit,
569D C9F0 7B48 7F58 9241 AD4C 5C28
CFI 20-byte) 40
7DA0 A448 8D08
characters
https://www.tutorialspoint.com/cryptography/cryptography_hash_functions.htm 25/11/24, 7 16 PM
Page 8 of 10
:
Table II: Using the Same Hash Function (SHA-1) with
different Inputs
Besides the data (input) used, a hash function consistently generates a hash
value with a fixed number of characters. As shown in Table II, different
messages inputted into the same hash function (SHA-1 in this case) consistently
produce output values of 40 hexadecimal characters in length.
Input Hash
Output (Hash Value)
Message Function
Password Storage
Hash functions provide protection to password storage. Instead of storing
passwords in clear, mostly all login processes store the hash values of passwords
in the file.
The Password file is a table of pairs in the format (user id, h(P)).
Even if an attacker has access to the password, all they can see is the hashes of
the passwords. Because the hash function contains the pre-image resistance
feature, he cannot use it to log in or get the password from it.
https://www.tutorialspoint.com/cryptography/cryptography_hash_functions.htm 25/11/24, 7 16 PM
Page 9 of 10
:
Data integrity checks, commonly using hash functions, provide assurances about
the accuracy of data files by creating checksums. This method allows users to
detect any alterations made to the original file.
However, it does not guarantee the authenticity of the file. An attacker could
potentially modify the entire file and generate a new hash, sending it to the
receiver. This integrity check is only effective if the user trusts the file's original
source.
Hashing vs Encryption
Encryption transforms data into a disguised form, requiring a cipher (key) to
decipher and read it. Encryption and decryption are reversible processes enabled
by the cipher. Encryption is used with the goal of later deciphering the data.
https://www.tutorialspoint.com/cryptography/cryptography_hash_functions.htm 25/11/24, 7 16 PM
Page 10 of 10
: