0% found this document useful (0 votes)
16 views21 pages

Lec 23-26 Hash Functions

Uploaded by

Muhammad Anas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views21 pages

Lec 23-26 Hash Functions

Uploaded by

Muhammad Anas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Hash Functions

Overview, Properties, Applications, and Practical Examples


By Dr. Khalid Hamid
Introduction to Hash Functions
• A hash function is an algorithm that takes an input (or "message") and
returns a fixed-length string of characters, which is typically a
hexadecimal number. This output is often referred to as the "hash
value" or "digest.“
Purpose
• Hash functions are widely used in computer science and cryptography
for tasks like data integrity, data indexing, password storage, and
digital signatures.
• These are widely used in tasks like data integrity, data indexing,
password storage, and digital signatures.
Essential Properties of Hash Functions

For a hash function to be useful in cryptographic applications, it must


have certain essential properties
1. Deterministic: The hash of the same input should always produce the same
output.

2. Fast Computation: Computing the hash value for any data should be efficient.

3. Pre-image Resistance: Given a hash value h(x)h(x)h(x), it should be


computationally infeasible to find the original input xxx. This property ensures
that hashes cannot be reversed to reveal the original data.
Essential Properties of Hash Functions

4. Second Pre-image Resistance: Given an input xxx and its hash


h(x)h(x)h(x), it should be hard to find another input yyy where y≠xy
\neq xy =x and h(y)=h(x)h(y) = h(x)h(y)=h(x).
5. Collision Resistance: It should be difficult to find any two distinct
inputs xxx and yyy such that h(x)=h(y)h(x) = h(y)h(x)=h(y). This
property is vital for security, especially in digital signatures.
6. Avalanche Effect: A small change in input (even a single bit) should
produce a significantly different output.
Types of Hash Functions

Hash functions vary based on design, complexity, and use cases. Some
of the most common cryptographic hash functions include
• MD5 (Message Digest Algorithm 5): Produces a 128-bit hash, but due to
vulnerabilities, it is not considered secure today.

• SHA Family (Secure Hash Algorithm): Includes SHA-1, SHA-256, SHA-512,


etc., with SHA-256 and SHA-512 widely used for security purposes.

• BLAKE2: Designed to be faster than MD5, SHA-1, and SHA-2, and it's efficient
in software.
Applications of Hash Functions
1. Data Integrity Verification: Hash values can verify that data hasn’t been altered
during transmission. For instance, file downloads often come with hash values to
check if the file is corrupted or tampered with.

2. Digital Signatures: In public key cryptography, hash functions are used to create
digital signatures. The message is hashed, and the hash is then encrypted with the
sender’s private key, ensuring the message’s authenticity.

3. Password Storage: Instead of storing plaintext passwords, systems hash the


password and store only the hash value. When a user logs in, the system hashes
the input and checks if it matches the stored hash.
Applications of Hash Functions
4. Blockchain and Cryptocurrency: Hash functions are foundational to blockchain
technology. They ensure data integrity across distributed ledgers and validate
transactions in cryptocurrency networks.

5. Message Authentication Codes (MACs): Hash functions can be combined with


secret keys to produce MACs, which ensure both the integrity and authenticity of a
message.
Common Vulnerabilities and Attacks
• Collision Attacks: An attacker tries to find two distinct inputs that produce the
same hash. SHA-1, for example, is vulnerable to collision attacks.

• Birthday Attacks: Based on the birthday paradox, this attack exploits the
probability of finding two inputs with the same hash value.

• Length Extension Attacks: This applies to certain hash functions (like MD5 and
SHA-1) when used inappropriately. It allows an attacker to predict the hash of a
concatenated message if the hash and message length are known.
Practical Example in Python
• import hashlib

• message = "Hello, Info Security Class"

• hash_object = hashlib.sha256(message.encode())

• hash_hex = hash_object.hexdigest()

• print("Original Message:", message)

• print("SHA-256 Hash:", hash_hex)

• SHA-256 hash of a message with the avalanche effect – small changes to input drastically change output
Practical Example in Python (Output)
• Original Message: Hello, Info Security Class
• SHA-256 Hash:
1db9ceeabc0c845441ed419ef1f7f9a47f2df7bcf8a7adf3d299d577a52ec15d
Summary
• Hash functions are crucial for security and data integrity.
• Used across applications in cryptography, blockchain, password
security, and digital signatures.
• Choosing secure hash functions and using them properly is essential to
avoid vulnerabilities.
Summary
• Hash functions are crucial for security and data integrity.
• Used across applications in cryptography, blockchain, password
security, and digital signatures.
• Choosing secure hash functions and using them properly is essential to
avoid vulnerabilities.
SHA-1 (Secure Hash Algorithm 1)
• SHA-1 (Secure Hash Algorithm 1) is a cryptographic hash function designed by
the National Security Agency (NSA) and published by the National Institute of
Standards and Technology (NIST) in 1993.

• It generates a 160-bit (20-byte) hash value, often represented as a 40-digit


hexadecimal number.

• SHA-1 was widely adopted and used for secure communications, data integrity,
and digital certificates until vulnerabilities were discovered.
Properties of SHA-1
• SHA-1 was initially favored due to the following properties:
1. Fixed Output: Produces a 160-bit (20-byte) hash regardless of input size.
2. Deterministic: The same input will always result in the same hash.
3. Fast and Efficient: Designed for speed and low computational requirements.
4. Avalanche Effect: A small change in input results in a significantly different
hash output.
• However, these properties are now overshadowed by its vulnerabilities to collision
attacks.
Working of SHA-1
1. Input Padding:

o The input message is padded to ensure its length is a multiple of 512 bits. Padding adds a "1" bit
followed by zeros and the message length as a 64-bit integer.

2. Initialization:

o SHA-1 initializes five 32-bit variables, often denoted as A, B, C, D, and E.

3. Processing:

o The algorithm processes data in blocks of 512 bits (64 bytes) in 80 rounds. Each round uses bitwise
operations, shifts, and constants to modify the variables.

4. Output:

• After processing, the variables A, B, C, D, and E are combined to produce a final 160-bit hash output.
SHA-1 Use Cases
1. Digital Signatures and Certificates:
o SHA-1 was commonly used in digital certificates to verify the authenticity of public keys.

2. Data Integrity Verification:


o SHA-1 was used to verify the integrity of files, ensuring they weren’t tampered with.

3. Version Control Systems:


o Systems like Git used SHA-1 to uniquely identify commits. Git now supports more secure
alternatives due to SHA-1’s vulnerabilities.
Vulnerabilities and Attacks on SHA-1
1. Collision Vulnerability:
o A collision occurs when two different inputs produce the same hash. SHA-1
was designed to resist collisions, but as computing power increased, it became
susceptible to these attacks.
o In 2005, researchers demonstrated practical collision attacks on SHA-1.

2. Birthday Attack:
o This attack exploits the probability that, with enough attempts, two different
inputs will produce the same hash due to the birthday paradox. In SHA-1, a
collision can be found with a complexity of 2632^{63}263 operations.
Vulnerabilities and Attacks on SHA-1
3. SHAttered Attack (2017):
o Google and the CWI Institute in Amsterdam announced a successful collision
attack on SHA-1, known as SHAttered.
o This attack demonstrated that two different PDF files could produce the same
SHA-1 hash, undermining the algorithm’s reliability in practical applications.
SHA-1 Deprecation and Transition to Secure
Alternatives
Due to its vulnerabilities, major standards bodies, software companies, and security protocols have
deprecated SHA-1:

1. Digital Certificates:
o In 2014, web browsers and certificate authorities (CAs) began deprecating SHA-1 for digital
certificates. SHA-2 and SHA-3 are now the standard.

2. File Integrity Verification:


o Software distributors and file verification systems have shifted to SHA-256 or SHA-3 for
enhanced security.

3. Version Control Systems:


o Git now supports SHA-256 to mitigate SHA-1 vulnerabilities.
Modern Hash Function Alternatives
• SHA-1’s weaknesses highlight the need for more secure hash functions:

• SHA-2 (SHA-224, SHA-256, SHA-384, SHA-512):


o Designed by the NSA as an improved version of SHA-1. It offers stronger security with
longer hash lengths, making it more resistant to collision and pre-image attacks.

• SHA-3:
o Designed by a third party, SHA-3 uses a different structure (Keccak) and is less vulnerable to
the types of attacks affecting SHA-1 and SHA-2.
• Summary
• SHA-1 was a widely used hash function that provided security for
years, but its collision vulnerabilities have led to its deprecation.
• Modern cryptographic applications have transitioned to SHA-2 and
SHA-3, which are more secure against modern computational attacks.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy