2017-CE-008 Lab # 10 SHA
2017-CE-008 Lab # 10 SHA
LAB#09
SHA-512 ALGORITHM
OBJECTIVE
The purpose of this lab is to implement SHA-512 algorithm in MATLAB. The main objectives
are to implement the following:
▪
Perform SHA-512 key generation
▪
Perform a encryption rounds for SHA-512
THEORY
Algorithm:
SHA-512 processing consists of the following steps:
• Step 1: Append padding bits, consists of a single 1-bit followed by the necessary
number of 0-bits, so that its length is congruent to 896 modulo 1024
• Step 2: Append length as an (big-endian) unsigned 128-bit integer
• Step 3: Initialize hash buffer to a set of 64-bit integer constants
• Step 4: Process the message in 1024-bit (128-word) blocks, which forms the heart of the
algorithm. Each round takes as input the 512-bit buffer value Hi, and updates the contents
of that buffer.
• Step 5: Output the final state value as the resulting hash
CE-408: Cryptography & Network Security SSUET/QR/114
Round Function:
Each 64-bit word is shuffled along one place, and in some cases manipulated using a series of simple
logical functions (ANDs, NOTs, ORs, XORs, ROTates), in order to provide the avalanche
& completeness properties of the hash function. The elements are:
Six of the eight words of the output of the round function involve simply permutation (b, c, d, f,
g, h) by means of rotation. This is indicated by shading in Figure 11.10. Only two of the output
words (a, e) are generated by substitution. Word e is a function of input variables d, e, f, g, h, as
well as the round word W t and the constant Kt. Word a is a function of all of the input
variables, as well as the round word W t and the constant Kt.
Key Generation:
Wt are derived from the 1024-bit message. The first 16 values of Wt are taken directly from
the 16 words of the current block. The remaining values are defined as a function of the earlier
values using ROTates, SHIFTs and XORs as shown. The function elements are:
Thus, in the first 16 steps of processing, the value of Wt is equal to the corresponding
word in the message block. For the remaining 64 steps, the value of Wt consists of the circular
left shift by one bit of the XOR of four of the preceding values of Wt, with two of those values
subjected to shift and rotate operations. This introduces a great deal of redundancy and
interdependence into the message blocks that are compressed, which complicates the task of
finding a different message block that maps to the same compression function output.
Lab Tasks:
CODE:
CE-408: Cryptography & Network Security SSUET/QR/114
CE-408: Cryptography & Network Security SSUET/QR/114
OUTPUT:
Message to be encrypted with SHA-512 :
I am KAMRAN SULEMAN Roll# 2017-CE-008 Section A
Length of Message is : 47
--------------------------------------------
Message in Hexadecimal :
4920616d204b414d52414e2053554c454d414e20526f6c6c2320323031372d43452d3030382053656374696f6e2041
--------------------------------------------
Hash Code of message in SHA-512 :
f7765937a1e257488b903b42bd1fb4c5737728e03b28b1c01874e5eeef0befb8912124d2d3b2c550c42038ea0bb8c1a00df7
93eb86f54344ced173e974becfff
TASK#2 Write the program for generating sub keys for each round.
CODE:
OUTPUT:
Entered Message: I am KAMRAN SULEMAN Roll# 2017-CE-008 Section A
'Length of Message:' '47'
'4920616D204B414D'
'52414E2053554C45'
'4D414E20526F6C6C'
'2320323031372D43'
'452D303038205365'
'6374696F6E204180'
'0000000000000000'
'0000000000000000'
'0000000000000000'
'0000000000000000'
'0000000000000000'
'0000000000000000'
'0000000000000000'
'0000000000000000'
'0000000000000000'
'000000000000002F'
'2E24C444E529E99E'
'6FDFC8E94CE2D105'
'3B4E16FB23675086'
'1A22BA2E6226D37F'
'8049DB978441120A'
'6374696F6E204180'
'000000000000002F'
'2E24C444E529E99E'
'6FDFC8E94CE2D105'
'3B4E16FB23675086'
'1A22BA2E6226D37F'
'8049DB978441120A'
'6374696F6E204180'
'000000000000002F'
'81212444E529F4B1'
'31A55AA715DA74C4'
'9B224D475EA45110'
'AA8F8445F7CD4FA7'
'DB851C5F64F93A17'
'2566D5C77015BDD4'
'452D30303820534A'
'4D50AD2B8B09A81E'
'6FDFC8E94CE2D105'
'3B4E16FB23675086'
'1A22BA2E6226D37F'
'8049DB978441120A'
'6374696F6E204180'
'000000000000002F'
'81212444E529F4B1'
'F18A5AA7A9D34F0F'
'1EC593F5759653AF'
'7C086F41D8468459'
'702D3F8E3FE2D07D'
'EB41C7F9B264D82C'
'6B40A89A4E276ED7'
'3240999DC62DAA76'
'2FB9137E74AAF8C4'
'DDDDA126667513B9'
'CCA5512A4DAD1881'
'2BE1F846DF5AF860'
'AD537B51AC512478'
'2E6D98AA76073DB2'
'FE3110F2A80DF6D9'
'B1EC8130919B66CE'
'E9C0F35968A65A81'
'F2A77C701BB1E788'
'E4B87169FA088C45'
'D28BD00CB4E24F3C'
'B692A50F69E60F65'
'B01A01E059705FE0'
'229E86C91E8DBD69'
'186E24CB12507DC5'
'5F0F8A1E5A06801A'
'E33DB2F8EA61538A'
'6374696F6E204180'
'000000000000002F'
'81212444E529F4B1'
'F18A5AA7A9D34F0F'
'1EC593F5759653AF'
'8EF86F6C0744745B'
'A8F7813AF98F525C'
'60044C81B9638643'
'8B8A0DFC386AF79C'
'75D76EAD7B44A797'