Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
1.1.
What is Cryptography
2.
What are Hash Functions
3.
Security of Hash Functions
3.1.
Preimage Resistance
3.2.
Second Preimage Resistance
3.3.
Collision Resistance
4.
Comparison between the Security Criterias
5.
Frequently Asked Questions
5.1.
What is Cryptography?
5.2.
What are hash functions?
5.3.
What are the security criteria in Hash?
5.4.
What is the encrypted data called in cryptography?
5.5.
What is the Collision resistance security criteria in the Hash function?
5.6.
How do you know if a hash function is second preimage resistance?
6.
Conclusion
Last Updated: Mar 27, 2024

Comparison of Security Criteria in Hash

Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

Introduction

Hello Ninjas, we are back with another article based on Security in Cryptography. We will learn about the comparison between different security criteria in Hash Functions. Let us start with some basic definitions to understand the concepts of security in cryptography. 

Comparison of Security Criteria in Hash

How will you react if your messages, like passwords, address are visible or accessible to third parties? Of course, you will not feel safe, and that's why your messages are encrypted. Encryption means security and privacy, which are obtained by cryptography.

What is Cryptography

Cryptography is the art of protecting Data and Information in an unreadable format and then retransmitting that message back to its original form. Cryptography allows you to store some sensitive information like passwords and addresses or send it through insecure networks like on the Internet. It uses some codes to protect the data from attacks so that it is in a readable format only for the ones the data is supposed to be.

Cryptography is similar to the Navajo code used by the military. They have symbols for every letter and word that can be used only if both personnel know the language.

Let's see what hash functions are first before moving toward the Security criteria in Hash.

What are Hash Functions

Hash Functions in cryptography are mathematical functions that are used to create secure and authenticated messages.

Working of Hash Functions

Hash Functions in cryptography generate a code to check the message's authenticity. In layman's language, we say that any document is hashed (passes through a hash function) to develop a hash value(code) using a hash function in cryptography. 

The hash value is also called a message digest.

As discussed in the previous section, we require a message, keys, and function in general to perform any authentication. Hash functions are a bit different.

H(x)= fixed length code (hash code h)

Where "H" is the hash function,

"x" is the message,

"h" is the hash value or code(message digest).

There are three requirements for the practical application of Hash functions

  • Variable input size
  • Fixed Input size
  • Efficiency

 

Moving forward now, let's see what the security criteria in Hash functions are.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Security of Hash Functions

There are, in total, three ways by which the security of hash functions in cryptography is achieved. We will learn and understand all of them one by one and then compare them with each other to know how to use them better.

These three properties, Preimage resistance, Second preimage resistance, and Collision resistance, make a cryptographic hash function cryptographically strong.

Preimage Resistance

Hash functions provide preimage resistance. Preimage resistance is a one-way property that is difficult to turn; for any given hash value, it is computationally infeasible to find y such that H(y) = h.

Where y is the message input,

h is the hash code,

H is a hash function.

Preimage resistance

This property is important if the authentication technique involves the use of a secret value.

Second Preimage Resistance

Second preimage resistance is another security criteria in Hash that is impossible to find an alternative message with the same hash value as a given message. 

For any given block, it is computationally infeasible to find y!=x with H(y) = H(x).

Where x and y are different message inputs,

H is a hash function.

Second preimage resistance

The second preimage resistance works on the one-way principle of hash functions.

Collision Resistance

A strong hash function is one that also satisfies collision-resistant security criteria. A collision attack, in which one party creates a message for another party to sign, is prevented by a robust hash function.

It is computationally infeasible to find two messages, x and y, such that Hash(x) = Hash(y).

Where x and y are different message inputs,

H is a hash function.

And such a pair of messages, x and y, is called a cryptographic hash function. This means that it is practically impossible to create a hash value that indicates two different message inputs.

Collision-resistant

It leads to more security from attacks.

Comparison between the Security Criterias

The following table compares the three security requirements for hash functions: collision resistance, second preimage resistance, and preimage resistance.

Feature

Preimage resistance

Second preimage resistance

Collision resistance

Hash function Weak Weak  Strong 
Requirements It is the first property. Before the second preimage resistance, the preimage resistance is needed. Before collision resistance, the second preimage resistance is needed.
Length of Bits Minimum 80 bits Not less than 90 bits 160 bits
Checking of Hash Function Computationally infeasible to find y such that H(y) = h. Computationally infeasible to find y!=x with H(y) = H(x). Computationally infeasible to find two messages, x and y, such that Hash(x) = Hash(y).
Function It is practically impossible to obtain a message from a hash code. It is practically impossible to obtain a different input message when we decode a hash value.  It is practically impossible to create a hash value that indicates two distinct message inputs.
Attacks Difficult Difficult Easier
Resistance Weak Weak Strong

Also read - active and passive attacks

Frequently Asked Questions

What is Cryptography?

Cryptography allows you to store sensitive information or send it through insecure networks (such as the Internet).

What are hash functions?

Hash Functions in cryptography generate a code to check the message's authenticity.

What are the security criteria in Hash?

Three security Criteria in Hash are preimage resistance, second preimage resistance, and collision resistance. 

What is the encrypted data called in cryptography?

The encrypted data is called the CipherText. Only the person with access to the decryption key can decode and understand the plain text.

What is the Collision resistance security criteria in the Hash function?

It becomes a strong hash function if the collision-resistant security criteria is met. A collision attack, in which one party creates a message for another party to sign, is prevented by a strong hash function.

How do you know if a hash function is second preimage resistance?

A hash function is second preimage resistance if it is infeasible to find y!=x with H(y) = H(x).

Conclusion

Kudos, Ninjas; we are at the end of the article on Comparison of Security Criteria in Hash, where we discussed what cryptography is, what hash functions are, what are the security of hash functions and the comparison between them.

Keep going and read more articles based on cryptography and the security of hash functions.

  1. Security of Hash functions in Cryptography
  2. What is Identity-based Cryptography?
  3. Message Integrity
  4. Active Attack and Passive Attack

 

Refer to our Guided Path to upskill yourself in DSACompetitive ProgrammingJavaScriptSystem Design, and many more! If you want to test your competency in coding, check out the mock test series and participate in the contests hosted on Coding Ninjas Studio!

You must look at the problemsinterview experiences, and interview bundles.

Happy Learning!

Previous article
Neo4j Query Cypher Language
Next article
Iterated Hash Functions
Live masterclass