Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

9555 CSS Lab3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

FR.

CONCEICAO RODRIGUES COLLEGE OF ENGINEERING


Department of Computer Engineering

Course, Subject & Experiment Details


Academic Year 2023-24 Estimated Time 02 - Hours

Course & Semester T.E. (CMPN)- Sem VI Subject CSS - (CSC602)


Name &
Code

Module No. 03 – Mapped to CO- 3 Chapter Title Cryptographic


Hash Functions

Practical No: 5

Title: Performance Analysis of Hash Algorithms

Date of Performance:

Date of Submission:

Roll No: 9555

Name of the Student: Melbin Abraham Koshy

Evaluation:
Sr. No Rubric Grade

1 On time submission
Or completion (2)

2 Preparedness(2)

3 Skill (4)

4 Output (2)
Signature of the Teacher:

Date:

Lab Manual prepared by : Prof. Monali Shetty


Title: For varying message sizes, test integrity of message using MD-5, SHA-1, and analyse the
performance of the two protocols.

Lab Objective:

This lab provides insight into:


∙ The working of MD5 and SHA-1 and variations of SHA-1 and analyze the performance
of both for varying message sizes.

Reference: “Cryptography and Network Security” B. A. Forouzan


“Cryptography and Network Security” Atul Kahate
www.md5summer.org/download.html

Prerequisite: Java or Python and Knowledge of hashing and Crypt API.

Theory:

Cryptographic hash functions are a very useful tool in cryptography. They are applied in many
areas like integrity of messages, storage of passwords securely and protect signatures. The three
hash algorithms SHA-1, SHA-512 and MD5 are considered to analyze their performance.

MD5
∙ Takes as input a message of arbitrary length and produces as output a 128 bit
“fingerprint” or “message digest” of the input.
∙ It is conjectured that it is computationally infeasible to produce two messages having the
same message digest.
∙ Intended where a large file must be “compressed” in a secure manner before being
encrypted with a private key under a public-key cryptosystem such as PGP

Input:
Suppose a b-bit message as input, and that we need to find its message digest.

Algorithm:
Step 1 – append padding bits:
– The message is padded so that its length is congruent to 448, modulo
512. - Means extended to just 64 bits of being of 512 bits long.
– A single “1” bit is appended to the message, and then “0” bits are appended so that
the length in bits equals 448 modulo 512.

• Step 2 – append length


– A 64 bit binary representation of b is appended to the result of the previous
step. – The resulting message has a length that is an exact multiple of 512 bits.

• Step 3 – Divide the input into 512-bit blocks


Now we divide the input message into into blocks , each of length 512 bits.

• Step 4 – Initialize MD Buffer


- A four-word buffer (A,B,C,D) is used to compute the message digest.
– Here each of A,B,C,D, is a 32 bit register.
- These registers are initialized to the following values in hexadecimal:
word A: 01 23 45 67
word B: 89 ab cd ef
word C: fe dc ba 98
word D: 76 54 32 10

Four auxiliary functions

In addition MD5 uses four auxiliary functions that each take as input three 32-bit words and
produce as output one 32-bit word. They apply the logical operators and, or, not and xor to the
input bits.

Round 1 = (b and c) or ((not(b) and d))


Round 2 = (b and d) or (c and not(d))
Round 3 = B xor c xor d
Round 4 = C xor (b or not(d))

The Constant t[i] or k[i]

MD5 further uses a table K that has 64 elements. Element number i is indicated as Ki. The
table is computed beforehand to speed up the computations. The elements are computed using
the mathematical sin function:

Ki = abs(sin(i + 1)) * 232

• Step 5 – Process message in 16-word blocks.

1. – Process message in 16-word (512-bit) blocks:


– Using 4 rounds of 16 bit operations on message block & buffer
– Add output to buffer input to form new buffer value
2. Output hash value is the final buffer value
3. The contents of the four buffers (A, B, C and D) are now mixed with the words of the
input, using the four auxiliary functions (F). There are four rounds, each involves 16
basic operations. One operation is illustrated in the figure below.

Lab Manual prepared by : Prof. Monali Shetty

The figure shows how the auxiliary function F is applied to the four buffers (A, B, C and D),
using message word Mi and constant Ki. The item "<<<s" denotes a binary left shift by s bits.

Round 1.
[abcd k s i] denote the operation a = b + ((a + F (b, c, d) + X [k] + T [i]) <<< s).

Do the following 16 operations.


[ABCD 0 7 1] [DABC 1 12 2] [CDAB 2 17 3] [BCDA 3 22 4] [ABCD 4 7
5] [DABC 5 12 6] [CDAB 6 17 7] [BCDA 7 22 8] [ABCD 8 7 9] [DABC
9 12 10] [CDAB 10 17 11] [BCDA 11 22 12] [ABCD 12 7 13] [DABC 13
12 14] [CDAB 14 17 15] [BCDA 15 22 16]

Output:

– The message digest produced as output is A, B, C, D.


– That is, output begins with the low-order byte of A, and end with the high-order byte of D.

SHA-1
Processing is similar to SHA-1 with small variations. In SHA-1, chaining variables are 5 and
Boolean operations are different.
Lab Manual prepared by : Prof. Monali Shetty

Analysis

Differences between MD5 and SHA Algorithms


Keys For Comparison MD5 SHA

Security Less Secure than High Secure than


SHA MD5

Message Digest 128 Bits 160 Bits


Length

Attacks required 2128 bit operations 2160 bit operations


to find out required to break required to break
original Message

Attacks to try and 264 bit operations 280 bit operations


find two required to break required to break
messages
producing the
same MD

Speed Faster, only 64 Slower than MD5,


iterations Required 80
Iterations

Successful Attacks reported to No such attach


attacks so far some extents report yet

Lab Manual prepared by : Prof. Monali Shetty


MD5 Execution
Test Strings MD5 SHA-1

1234567890 e807f1fcf82d132f9bb018ca67 01b307acba4f54f55aafc33bb06bb


38a19f bf6ca803e9a

abcdefghijklm c3fcd3d76192e4007dfb496cca 32d10c7b8cf96570ca04ce37f2a19


nopqrstuvwxyz 67e13b d84240d3a89

message digest 5c33b66cec053762ad6f2cb06b 0592d2ecdd4a32e39f9f431e5861


cd598b 857d40574c7c

10101010101010 0ab25d8934fdfd7fa8aa13e5d3 10911da2fc40c3036a76d7f8f06ed


10101010101010 c0bb5e 8
10101010101010 a85d27a652
10101010101010
10101010101010
10101010101010
1010101010

Timing comparison between MD5 and SHA-1


File Size MD5 SHA-1

1 KB 1.3828277587890625e-05 1.6450881958007812e-05

5 KB 2.4080276489257812e-05 2.2172927856445312e-05

10 KB 3.0040740966796875e-05 2.2411346435546875e-05

10101010101010101010101 1.430511474609375e-06 3.5762786865234375e-06


01010101010101010101010
10101010101010101010101
01010101010101010101010
10
Practical and Real Time Applications
∙ In Windows OS, PowerShell function "Get-FileHash"
∙ Android ROMs
∙ File servers - file servers often provide a pre-computed MD5 (known as
md5sum) checksum for the files, so that a user can compare the checksum of
the downloaded file to it.
∙ Most unix-based operating systems include MD5 sum utilities in their
distribution packages
Conclusion:

The program was tested for different sets of inputs.


Program is working SATISFACTORY NOT SATISFACTORY ( Tick
appropriate outcome)

Lab Manual prepared by : Prof. Monali Shetty


Post Lab Assignment:

1. Why is SHA-1 more secure than MD5?


Both MD5 and SHA1 are hashing algorithms. MD5 is simple and fast, but it does
not provide good security. SHA1 is complex as compared to MD5 and it provides
greater level of security.
MD5 generates a message digest of 128-bits, while SHA1 generates a message
digest of 160-bit hash value. Hence, SHA1 is a relatively complex algorithm and
provides better security than MD5.

2. Which of the following is not included in hash function?


a. Authentication.
b. Message integrity.
c. Fingerprinting.
d. Inefficiency.
3. Which of the following is used to detect transmission errors, and not
to detect intentional tampering with data?
a. CRC.
b. Similar checksum.
c. WEP.
d. Hash function.
4. Which of the following is not provide by hash function?
a. Efficiency.
b. Two-way.
c. Compression.
d. Weak collision resistance.
import hashlib
import time
def calculate_md5(file_path):
with open(file_path, "rb") as f:
# Read the file in binary mode
content = f.read()
# Calculate MD5 hash
md5_hash = hashlib.md5(content).hexdigest()
return md5_hash

file_path = "1kbfile.txt"
begin=time.time()
md5_hash = calculate_md5(file_path)
end=time.time()
print("MD5 hash:", md5_hash)
print("Total time taken is ",end-begin)

SHA1:

import hashlib
import time
def calculate_sha1(file_path):
with open(file_path, "rb") as f:
# Read the file in binary mode
content = f.read()
# Calculate SHA1 hash
md5_hash = hashlib.sha1(content).hexdigest()
return md5_hash

file_path = "1kbfile.txt"
begin=time.time()
sha1_hash = calculate_sha1(file_path)
end=time.time()
print("SHA1 hash:", sha1_hash)
print("Total time taken is ",end-begin)

Lab Manual prepared by : Prof. Monali Shetty

You might also like