Css Module 3
Css Module 3
Css Module 3
A hash function is a mathematical function that converts a numerical input value into another
compressed numerical value. The input to the hash function is of arbitrary length but output is
always of fixed length.
Values returned by a hash function are called message digest or simply hash values. The
following picture illustrated hash function −
1. Deterministic: This means that the same message always results in the same hash.
2. Quick: It is quick to compute the hash value for any given message.
3. Avalanche Effect: This means that every minor change in the message results in a major
change in the hash value.
4. One-Way Function: You cannot reverse the cryptographic hash function to get to the data.
5. Collision Resistance: It is infeasible to find two different messages that produce the same
hash value.
6. Non Predictable: The hash value shouldn’t be predictable from the given string and vice
versa.
Hash Function Requirements
H can be applied to a block of data of any size
H produces a fixed length output
H(x) is relatively easy to compute
For any given code h, it is computationally infeasible to find x such that H(x) = h
For any given block x, it is computationally infeasible to find y x with H(y) = H(x)
It is computationally infeasible to find any pair (x,y) such that H(x) = H(y)
In order to be an effective cryptographic tool, the hash function is desired to possess following
properties −
Pre-Image Resistance
o This property means that it should be computationally hard to reverse a hash
function.
o In other words, if a hash function h produced a hash value z, then it should be a
difficult process to find any input value x that hashes to z.
o This property protects against an attacker who only has a hash value and is trying to
find the input.
Second Pre-Image Resistance
o This property means given an input and its hash, it should be hard to find a different
input with the same hash.
o In other words, if a hash function h for an input x produces hash value h(x), then it
should be difficult to find any other input value y such that h(y) = h(x).
o This property of hash function protects against an attacker who has an input value
and its hash, and wants to substitute different value as legitimate value in place of
original input value.
Collision Resistance
o This property means it should be hard to find two different inputs of any length that
result in the same hash. This property is also referred to as collision free hash
function.
o In other words, for a hash function h, it is hard to find any two different inputs x and
y such that h(x) = h(y).
o Since, hash function is compressing function with fixed hash length, it is impossible
for a hash function not to have collisions. This property of collision free only
confirms that these collisions should be hard to find.
o This property makes it very difficult for an attacker to find two input values with the
same hash.
o Also, if a hash function is collision-resistant then it is second pre-image resistant.
Message Authentication Code (MAC)
MAC algorithm is a symmetric key cryptographic technique to provide message authentication.
For establishing MAC process, the sender and receiver share a symmetric key K.
Essentially, a MAC is an encrypted checksum generated on the underlying message that is sent
along with a message to ensure message authentication.
The process of using MAC for authentication is depicted in the following illustration −
Limitations of MAC
There are two major limitations of MAC, both due to its symmetric nature of operation −
Establishment of Shared Secret.
o It can provide message authentication among pre-decided legitimate users who have
shared key.
o This requires establishment of shared secret prior to use of MAC.
Inability to Provide Non-Repudiation
o Non-repudiation is the assurance that a message originator cannot deny any
previously sent messages and commitments or actions.
o MAC technique does not provide a non-repudiation service. If the sender and
receiver get involved in a dispute over message origination, MACs cannot provide
a proof that a message was indeed sent by the sender.
o Though no third party can compute the MAC, still sender could deny having sent
the message and claim that the receiver forged it, as it is impossible to determine
which of the two parties computed the MAC.
Working of HMAC
HMACs provides client and server with a shared private key that is known only to
them. The client makes a unique hash (HMAC) for every request. When the client
requests the server, it hashes the requested data with a private key and sends it as a part
of the request. Both the message and key are hashed in separate steps making it secure.
When the server receives the request, it makes its own HMAC. Both the HMACS are
compared and if both are equal, the client is considered legitimate.
The formula for HMAC:
HMAC = hashFunc(secret key + message)
There are three types of authentication functions. They are message encryption,
message authentication code, and hash functions. The major difference between MAC
and hash (HMAC here) is the dependence of a key. In HMAC we have to apply the
hash function along with a key on the plain text. The hash function will be applied to
the plain text message. But before applying, we have to compute S bits and then append
it to plain text and after that apply the hash function. For generating those S bits we
make use of a key that is shared between the sender and receiver.
Using key K (0 < K < b), K+ is generated by padding O’s on left side of key K until length
becomes b bits. The reason why it’s not padded on right is change(increase) in the length of
key. b bits because it is the block size of plain text. There are two predefined padding bits
called ipad and opad. All this is done before applying hash function to the plain text message.
ipad - 00110110
opad - 01011100
Now we have to calculate S bits
K+ is EXORed with ipad and the result is S1 bits which is equivalent to b bits since both K+
and ipad are b bits. We have to append S1 with plain text messages. Let P be the plain text
message.
S1, p0, p1 upto Pm each is b bits. m is the number of plain text blocks. P0 is plain text block
and b is plain text block size. After appending S1 to Plain text we have to apply HASH
algorithm (any variant). Simultaneously we have to apply initialization vector (IV) which is a
buffer of size n-bits. The result produced is therefore n-bit hashcode i.e H( S1 || M ).
Similarly, n-bits are padded to b-bits And K+ is EXORed with opad producing output S2 bits.
S2 is appended to the b-bits and once again hash function is applied with IV to the block. This
further results into n-bit hashcode which is H( S2 || H( S1 || M )).
Advantages
HMACs are ideal for high-performance systems like routers due to the use of hash
functions which are calculated and verified quickly unlike the public key systems.
Digital signatures are larger than HMACs, yet the HMACs provide comparably higher
security.
HMACs are used in administrations where public key systems are prohibited.
Disadvantages
HMACs uses shared key which may lead to non-repudiation. If either sender or receiver’s
key is compromised, then it will be easy for attackers to create unauthorized messages.
MD5 is a cryptographic hash function algorithm that takes the message as input of any length
and changes it into a fixed-length message of 16 bytes. MD5 algorithm stands for the message-
digest algorithm. MD5 was developed as an improvement of MD4, with advanced security
purposes. The output of MD5 (Digest size) is always 128 bits. MD5 was developed in 1991
by Ronald Rivest.
Use Of MD5 Algorithm:
It is used for file authentication.
In a web application, it is used for security purposes. e.g. Secure password of users etc.
Using this algorithm, We can store our password in 128 bits format.
Working of the MD5 Algorithm:
A 512-bit string is divided into 16 words of 32 bits each using the MD5 message-digest hashing
method. MD5 generates a 128-bit message digest as a result of the operation.
There are four steps involved in producing a message digest:
Padding is the process of adding more bits to the original message. Additions of padding bits
must be made in such a way that the resulting total number of bits falls 64 bits short of the
multiple of 512. The initial bit of padding is a 1, while the remaining bits are all zeros
In this step, we add length bits to the above message generated i.e., the original message and
padding bits. We combine the length bits in such a way that the message’s overall bit length is a
perfect multiple of 512. Thus, 64 bits are added to the message.
In this phase, four 32-bit buffers are used. Let’s say there are four buffers, E, F, G, and H. Each
of these buffers has a size of 32 bits, and they are set up as follows:
Word E = 01 23 45 67
Word F = 89 ab cd ef
Word G = fe dc ba 98
Word H = 76 54 32 10
Each 512-bit block is split into 16 smaller blocks, each of 32 bits. There are four rounds of
processing.
To begin, we use four auxiliary functions, each of which accepts three 32-bit words as input and
outputs one 32-bit word as a result. These functions make use of logical operators such as AND,
XOR, OR, and NOT.
This continues until the final 512-bit block has been processed. The final 512-bit block’s output
is the message digest.
It’s easier to compare and store smaller hashes using MD5 Algorithms than it is to
store a large variable-length text.
By using MD5, passwords are stored in 128-bit format.
You may check for file corruption by comparing the hash values before and after
transmission. To prevent data corruption, file integrity tests are valid once the hashes
match.
A message digest can easily be created from an original message using MD5.
When compared to other algorithms like the SHA algorithm, MD5 is comparatively
slow.
It is possible to construct the same hash function for two distinct inputs using MD5.
MD5 is less secure when compared to the SHA algorithm since MD5 is more
vulnerable to collision attacks.
Application Of MD5 Algorithm:
The Secure Hash Algorithm (SHA) was invented by the National Security Agency (NSA) and
published in 1993 through the National Institute of Standard and Technology (NIST) as a U.S.
Federal Information Processing Standard (FIPS PUB 180).
SHA depends on and shares the similar building blocks as the MD4 algorithm. The design of SHA
introduced a new process which develop the 16-word message block input to the compression
function to an 80-word block between other things.
The processing of SHA works as follows −
Step 1 − Append padding bits − The original message is padded and its duration is congruent to
448 modulo 512. Padding is continually inserted although the message already has the desired
length. Padding includes a single 1 followed by the essential number of 0 bits.
Step 2 − Append length − A 64-bit block considered as an unsigned 64-bit integer (most essential
byte first), and defining the length of the original message (before padding in step 1), is added to
the message. The complete message's length is a multiple of 512.
Step 3 −Initialize the buffer − The buffer includes five (5) registers of 32 bits each indicated by
A, B, C, D, and E. This 160-bit buffer can be used to influence temporary and final outcomes of
the compression function. These five registers are initialized to the following 32-bit integers (in
hexadecimal notation).
A = 67 45 23 01
B = ef cd ab 89
C = 98 ba dc fe
D = 10 32 54 76
E = c3 d2 e1 f0
The registers A, B, C, and D are actually the same as the four registers used in MD5 algorithm.
But in SHA-1, these values are saved in big-endian format, which define that the most essential
byte of the word is located in the low-address byte position. Therefore the initialization values (in
hexadecimal notation) occurs as follows −
word A = 67 45 23 01
word B = ef cd ab 89
word C = 98 ba dc fe
word D = 10 32 54 76
word E = c3 d2 e1 f0
Step 4 − Process message in 512-bit blocks − The compression function is divided into 20
sequential steps includes four rounds of processing where each round is made up of 20 steps.
The four rounds are structurally same as one another with the only difference that each round need
a different Boolean function, which it can define as f1, f2, f3, f4 and one of four multiple additive
constants Kt (0 ≤t ≤79) which is based on the step under consideration.
Step 5 − Output − After processing the final 512-bit message block t (considering that the
message is divided into t 512-bit blocks), and it can obtain a 160-bit message digest.
MD5 can have 128 bits length of message Whereas SHA1 can have 160 bits
2. digest. length of message digest.
The speed of MD5 is fast in comparison of While the speed of SHA1 is slow
3. SHA1’s speed. in comparison of MD5’s speed.
To make out the initial message the aggressor On the opposite hand, in SHA1
would want 2^128 operations whereas it’ll be 2^160 that makes it quite
4. exploitation the MD5 algorithmic program. troublesome to seek out.
In MD5, if the assailant needs to seek out the 2 Whereas in SHA1, assailant
7. messages having identical message digest then would need to perform 2^80
S.NO MD5 SHA1