You are on page 1of 25

BCSE309L – Cryptography and Network

Security
SECURE HASH ALGORITHM (SHA)

2
SHA
• Published by National Institute of Standards and Technology
(NIST) in the year of 1993.
• It is used for - data integrity and authentication.
• The various version of SHA are

Algorithm Block Size (bits) Message Digest Size (bits)


SHA 1 512 160
SHA 256 512 256
SHA 512 1024 512

3
SHA
• SHA originally designed by NIST & NSA in 1993
• was revised in 1995 as SHA-1
• US standard for use with DSA signature scheme
– standard is FIPS 180-1 1995, also Internet RFC3174
• Based on design of MD4 with key differences
• Produces 160-bit hash values
• Recent 2005 results on security of SHA-1 have raised
concerns on its use in future applications

4
SHA
• NIST issued revision FIPS 180-2 in 2002
• Adds 3 additional versions of SHA
– SHA-256, SHA-384, SHA-512
• Designed for compatibility with increased security
provided by the AES cipher
• Structure & detail is similar to SHA-1
• Hence analysis should be similar
• But security levels are rather higher

5
SHA 512
• Plain text is processed in terms of blocks
• Input - 1024 bits size of Blocks
• Output - 512 bits size of Message Digest
• Processing of messages – 1024 bits
• Steps involve in SHA 512 are
1. Append Padding Bits
2. Append Length Bits
3. Initialize MD buffer
4. Process Each 1024-bit Block
5. Output 6
SHA

• Step 1: Append padding bits


• Step 2: Append length
• Step 3: Initialize hash buffer
• Step 4: Process the message in 1024-bit (128-word)
blocks, which forms the heart of the algorithm
• Step 5: Output the final state value as the resulting hash

7
SHA 512

1024 bits 1024 bits 1024 bits 1024 bits

8
SHA 512

9
SHA 512
Append Padding Bits: ASCII
Original Message is “abc” a  61
b  62
• Message in binary c  63
abc => 01100001 01100010 01100011
• Message length (M) = 24 bits.
Needed,
Message length (M) ≡ 896 mod 1024
24 ≡ 896 mod 1024
24 mod 1024 = 896
24 ≠ 896
24 + 872 mod 1024 = 896
896 = 896
Pad 872 bits to message such that M mod 1024=896
872 bits to be padded → 1 bit followed by 871 zeros 10
11
SHA 512
abc  01100001 01100010 01100011
 6 1 6 2 6 3

872 bits to be padded → 1 bit followed by 871 zeros

abc  01100001 01100010 01100011 1000 0000 0000 0000


 6 1 6 2 6 3 8 0 0 0
0000 0000 0000 0000 0000 0000…
0 0 0 0 0 0
[ 896 bits=24+1+871]
64 * 14 =896

6162638000000000 0000000000000000 0000000000000000 0000000000000000


0000000000000000 0000000000000000 0000000000000000 0000000000000000
0000000000000000 0000000000000000 0000000000000000 0000000000000000
0000000000000000 0000000000000000
Append Length Bits SHA 512
6162638000000000 0000000000000000 0000000000000000 0000000000000000
0000000000000000 0000000000000000 0000000000000000 0000000000000000
0000000000000000 0000000000000000 0000000000000000 0000000000000000
0000000000000000 0000000000000000

128 bits remaining  Length bit


 24bits
Length = 24
24 in Hexa  18
Length bits to be added is
0000 0000 0000 0000 0000 0000 0000 0018
[ 896 bits] + 128 bits remaining ]

6162638000000000 0000000000000000 0000000000000000 0000000000000000


0000000000000000 0000000000000000 0000000000000000 0000000000000000
0000000000000000 0000000000000000 0000000000000000 0000000000000000
0000000000000000 0000000000000000 0000000000000000 0000000000000018
SHA 512
Example:
Input original message length = 2348
Find the number of bits need to pad?

14
Practice
Input original message length = 2348
Find the number of bits need to pad?
Message length (M) 2348 ≡ 896 mod 1024
2348 mod 1024 = 896
300 ≠ 896
2348 + 596 mod 1024 = 896
896 = 896
Pad 596 bits to message such that M mod 1024=896
596 bits to be padded → 1 bit followed by 595 zeros

Add message length


2348 + 596 = 2944
2944 + 128 = 3072 [ 1024*3=3072, so 3 blocks]
15
SHA 512

8*64 Hash Code


SHA 512
M1 W0 to W79 – each 64 bits
16*64=1024

8*64=512

Each buffer  64 bits

17
SHA 512
Module F
Message scheduling

18
SHA 512

8*64 Hash Code


SHA 512

20
SHA 512

21
SHA 512 Round Constants (K0 to K79) SHA 512
Round Operation

23
SHA 512
• After all N number of 1024-bit blocks have
been processed, the output from the Nth block
is the 512-bit message digest.

24
Practice
Given a plain text “FLY”. Using SHA-512 algorithm, Derive the following
information. Consider the ASCII values for the plaintext F-70 L-76 Y-121
• Find the length of padding bits.
• Derive theeighteen 64 bit words (W0 to W17) in hexa-decimal format.
• Apply the majority function of round operation on buffers A, B, and C.
• Apply the condition function of round operation on buffers E, F, and G.
Consider the following values for the buffers.
A - 01100001
B - 01100010
C - 01100011
E - 01100101
F - 01100110
G - 01100111
25

You might also like